Skip to content

Commit 0d87e0d

Browse files
authored
Merge pull request #2 from developmentseed/master
sync with original master
2 parents c559fcf + 4b0f2ef commit 0d87e0d

File tree

7 files changed

+17
-10
lines changed

7 files changed

+17
-10
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Label Maker
22
## Data Preparation for Satellite Machine Learning
33

4-
The tool downloads [OpenStreetMap QA Tile]((https://osmlab.github.io/osm-qa-tiles/)) information and satellite imagery tiles and saves them as an [`.npz` file](https://docs.scipy.org/doc/numpy/reference/generated/numpy.savez.html) for use in machine learning training.
4+
Label Maker downloads [OpenStreetMap QA Tile]((https://osmlab.github.io/osm-qa-tiles/)) information and satellite imagery tiles and saves them as an [`.npz` file](https://docs.scipy.org/doc/numpy/reference/generated/numpy.savez.html) for use in machine learning training.
55

66
![example classification image overlaid over satellite imagery](examples/images/classification.png)
77
_satellite imagery from [Mapbox](https://www.mapbox.com/) and [Digital Globe](https://www.digitalglobe.com/)_

label_maker/utils.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,17 @@ def get_tile_wms(tile, imagery, folder, imagery_offset):
9191
"""
9292
Read a WMS endpoint with query parameters corresponding to a TMS tile
9393
94-
Converts the tile boundaries to the spatial reference system (SRS) specified
95-
by the WMS query parameter.
94+
Converts the tile boundaries to the spatial/coordinate reference system
95+
(SRS or CRS) specified by the WMS query parameter.
9696
"""
9797
# retrieve the necessary parameters from the query string
9898
query_dict = parse_qs(imagery.lower())
99-
image_format = query_dict['format'][0].split('/')[1]
100-
wms_srs = query_dict['srs'][0]
99+
image_format = query_dict.get('format')[0].split('/')[1]
100+
wms_version = query_dict.get('version')[0]
101+
if wms_version == '1.3.0':
102+
wms_srs = query_dict.get('crs')[0]
103+
else:
104+
wms_srs = query_dict.get('srs')[0]
101105

102106
# find our tile bounding box
103107
bound = bounds(*[int(t) for t in tile.split('-')])
@@ -107,7 +111,10 @@ def get_tile_wms(tile, imagery, folder, imagery_offset):
107111
# project the tile bounding box from lat/lng to WMS SRS
108112
tile_ll_proj = transform(p1, p2, bound.west, bound.south)
109113
tile_ur_proj = transform(p1, p2, bound.east, bound.north)
110-
bbox = tile_ll_proj + tile_ur_proj
114+
if wms_version == '1.3.0':
115+
bbox = tile_ll_proj[::-1] + tile_ur_proj[::-1]
116+
else:
117+
bbox = tile_ll_proj + tile_ur_proj
111118

112119
# request the image with the transformed bounding box and save
113120
wms_url = imagery.replace('{bbox}', ','.join([str(b) for b in bbox]))

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protobuf==3.5.0.post1
1313
pyclipper==1.0.6
1414
pycurl==7.43.0.1
1515
pyproj==1.9.5.1
16-
rasterio==1.0a12
16+
rasterio[s3]==1.0a12
1717
requests>=2.20.0
1818
Shapely>=1.6.3
1919
six==1.10.0

test/fixtures/146-195-9.jpeg

11.5 KB
Loading

test/fixtures/4686-6267-14.jpeg

-36.1 KB
Binary file not shown.

test/tiles/1087767-1046604-21.jpg

-14.3 KB
Binary file not shown.

test/unit/test_utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,16 @@ def test_get_tile_vrt(self):
116116

117117
def test_get_tile_wms(self):
118118
"""Test reading of tile from a WMS endpoint"""
119-
tile = '4686-6267-14'
119+
tile = '146-195-9'
120120
# create tiles directory
121121
dest_folder = 'test'
122122
tiles_dir = op.join(dest_folder, 'tiles')
123123
if not op.isdir(tiles_dir):
124124
makedirs(tiles_dir)
125125

126-
usgs_url = 'https://basemap.nationalmap.gov/arcgis/services/USGSImageryOnly/MapServer/WMSServer?SERVICE=WMS&REQUEST=GetMap&VERSION=1.1.1&LAYERS=0&STYLES=&FORMAT=image%2Fjpeg&TRANSPARENT=false&HEIGHT=256&WIDTH=256&SRS=EPSG%3A3857&BBOX={bbox}'
126+
nasa_url = 'https://gibs.earthdata.nasa.gov/wms/epsg4326/best/wms.cgi?SERVICE=WMS&REQUEST=GetMap&layers=MODIS_Aqua_CorrectedReflectance_TrueColor&version=1.3.0&crs=EPSG:4326&transparent=false&width=256&height=256&bbox={bbox}&format=image/jpeg&time=2019-03-05'
127127

128-
get_tile_wms(tile, usgs_url, tiles_dir, None)
128+
get_tile_wms(tile, nasa_url, tiles_dir, None)
129129
test_tile = Image.open('test/tiles/{}.jpeg'.format(tile))
130130
fixture_tile = Image.open('test/fixtures/{}.jpeg'.format(tile))
131131
self.assertEqual(test_tile, fixture_tile)

0 commit comments

Comments
 (0)