-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6840ca5
commit a83fbeb
Showing
6 changed files
with
187 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
build | ||
dist | ||
|
||
env | ||
env3 | ||
|
||
*.vrt | ||
*.egg-info | ||
*.pyc | ||
|
||
*.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,43 @@ | ||
# wms-downloader | ||
Downloads large geo TIFF files from a WMS service. | ||
wms-downloader | ||
============== | ||
|
||
Install | ||
------- | ||
|
||
```bash | ||
pip install wms-downloader | ||
``` | ||
|
||
Usage | ||
----- | ||
|
||
Create a `config.yml` specifying your setup like this: | ||
|
||
```yml | ||
service: | ||
version: 1.1.1 | ||
url: http://fbinter.stadt-berlin.de/fb/wms/senstadt/k_luftbild1953? | ||
srs: EPSG:25833 | ||
format: jpeg | ||
layer: 0 | ||
bbox: | ||
west: 370000.0 | ||
south: 5800000.0 | ||
east: 415000.0 | ||
north: 5837000.0 | ||
|
||
size: 10000 | ||
resolution: 600 | ||
timeout: 300 | ||
projection: EPSG:25833 | ||
directory: images | ||
vrtfile: tiles.vrt | ||
tmpfile: /tmp/wms.xml | ||
``` | ||
Then run the script in the same directory as `config.yml` or use the `-c` argument: | ||
|
||
``` | ||
wms-downloader | ||
wms-downloader -c /path/to/my_custom_config.yml | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env python | ||
|
||
from wms_downloader.download import main | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from setuptools import setup, find_packages | ||
|
||
from wms_downloader import ( | ||
__title__ as title, | ||
__version__ as version, | ||
__author__ as author, | ||
__license__ as license | ||
) | ||
|
||
description = 'Downloads large geo TIFF files from a WMS service.' | ||
email = '[email protected]' | ||
url = 'https://github.com/jochenklar/wms-downloader' | ||
|
||
requirements = [ | ||
'mercantile', | ||
'PyYAML', | ||
'numpy' | ||
] | ||
|
||
scripts = [ | ||
'bin/wms-downloader' | ||
] | ||
|
||
setup( | ||
name=title, | ||
version=version, | ||
description=description, | ||
url=url, | ||
author=author, | ||
author_email=email, | ||
maintainer=author, | ||
maintainer_email=email, | ||
license=license, | ||
packages=find_packages(), | ||
install_requires=requirements, | ||
classifiers=[], | ||
scripts=scripts, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
__title__ = 'wms-downloader' | ||
__version__ = '1.0.0' | ||
__author__ = 'Jochen Klar' | ||
__license__ = 'MIT' | ||
__copyright__ = 'Copyright 2017 Jochen Klar' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env python | ||
import argparse | ||
import os | ||
import subprocess | ||
import yaml | ||
|
||
|
||
xml_template = '''<GDAL_WMS> | ||
<Service name="WMS"> | ||
<Version>%(version)s</Version> | ||
<ServerUrl>%(url)s</ServerUrl> | ||
<SRS>%(srs)s</SRS> | ||
<ImageFormat>image/%(format)s</ImageFormat> | ||
<Layers>%(layer)s</Layers> | ||
</Service> | ||
<DataWindow> | ||
<UpperLeftX>%(west)s</UpperLeftX> | ||
<UpperLeftY>%(north)s</UpperLeftY> | ||
<LowerRightX>%(east)s</LowerRightX> | ||
<LowerRightY>%(south)s</LowerRightY> | ||
<SizeX>%(resolution)s</SizeX> | ||
<SizeY>%(resolution)s</SizeY> | ||
</DataWindow> | ||
<Timeout>%(timeout)s</Timeout> | ||
<Projection>%(projection)s</Projection> | ||
</GDAL_WMS>''' | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(usage='Downloads large geo TIFF files from a WMS service.') | ||
parser.add_argument('config', nargs='?', default='config.yml', help='config file [default: config.yml]') | ||
args = parser.parse_args() | ||
|
||
with open(args.config) as f: | ||
config = yaml.load(f.read()) | ||
|
||
try: | ||
os.makedirs(config['directory']) | ||
except OSError: | ||
pass | ||
|
||
west_range = list(arange(config['bbox']['west'], config['bbox']['east'], config['size'])) | ||
south_range = list(arange(config['bbox']['south'], config['bbox']['north'], config['size'])) | ||
|
||
for west in west_range: | ||
for south in south_range: | ||
filename = '%(directory)s/%(west)s_%(south)s_%(resolution)s.gdal.tif' % { | ||
'directory': config['directory'], | ||
'west': west, | ||
'south': south, | ||
'resolution': config['resolution'] | ||
} | ||
|
||
if not os.path.exists(filename + '.aux.xml'): | ||
print(filename) | ||
|
||
xml_params = { | ||
'west': west, | ||
'south': south, | ||
'east': west + config['size'], | ||
'north': south + config['size'], | ||
'resolution': config['resolution'], | ||
'timeout': config['timeout'], | ||
'projection': config['projection'] | ||
} | ||
xml_params.update(config['service']) | ||
|
||
with open(config['tmpfile'], 'w') as f: | ||
f.write(xml_template % xml_params) | ||
|
||
args = ['gdal_translate', '-of', 'JPEG', config['tmpfile'], filename] | ||
subprocess.check_call(args) | ||
|
||
file_pattern = '%s/*.gdal.tif' | ||
args = ['gdalbuildvrt', '-a_srs', config['projection'], '-overwrite', config['vrtfile'], file_pattern] | ||
subprocess.check_call(args) | ||
|
||
|
||
def arange(start, stop, step): | ||
current = start | ||
while current < stop: | ||
yield current | ||
current += step | ||
|
||
if __name__ == "__main__": | ||
main() |