Skip to content

Commit 904d1f8

Browse files
committed
Merge branch 'feature/geojson' of github.com:developmentseed/label-maker into feature/geojson
2 parents 62ef479 + 51b1e11 commit 904d1f8

File tree

9 files changed

+64
-18
lines changed

9 files changed

+64
-18
lines changed

CHANGES.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
0.4.0 (2018-10-04)
2+
------------------
3+
- Read file drivers to determine file type rather than relying on extension (#80)
4+
- Add support for WMS endpoints as an imagery source (#93)
5+
- Add documentation site (#108)
6+
- Fix rendering errors at tile boundaries (#78)
7+
- New examples and updates to example code (#89, #91, #105, #107)
8+
19
0.3.2 (2018-05-14)
210
------------------
311
- Provide a default value of False for imagery_offset to preview function (#79)

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ Full documentation is available here: http://devseed.com/label-maker/
2525
## Acknowledgements
2626

2727
This library builds on the concepts of [skynet-data](https://github.com/developmentseed/skynet-data). It wouldn't be possible without the excellent data from OpenStreetMap and Mapbox under the following licenses:
28-
- OSM QA tile data
29-
[copyright OpenStreetMap contributors](http://www.openstreetmap.org/copyright)
30-
and licensed under
31-
[ODbL](http://opendatacommons.org/licenses/odbl/)
32-
- Mapbox Satellite data can be
33-
[traced for noncommercial purposes](https://www.mapbox.com/tos/#[YmtMIywt]).
34-
- Marc Farra's [tilepie](https://github.com/kamicut/tilepie) to asynchronously process vector tiles
28+
- OSM QA tile data [copyright OpenStreetMap contributors](http://www.openstreetmap.org/copyright) and licensed under [ODbL](http://opendatacommons.org/licenses/odbl/)
29+
- Mapbox Satellite data can be [traced for noncommercial purposes](https://www.mapbox.com/tos/#[YmtMIywt]).
30+
- Marc Farra's [tilepie](https://github.com/kamicut/tilepie) to asynchronously process vector tiles

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import sys
1717
sys.path.insert(0, os.path.abspath('.'))
1818
sys.path.insert(0, os.path.abspath('../label_maker'))
19-
19+
from label_maker.version import __version__
2020

2121
# -- Project information -----------------------------------------------------
2222

@@ -25,9 +25,9 @@
2525
author = 'Development Seed'
2626

2727
# The short X.Y version
28-
version = '0.3.2'
28+
version = __version__
2929
# The full version, including alpha/beta/rc tags
30-
release = '0.3.2'
30+
release = __version__
3131

3232

3333
# -- General configuration ---------------------------------------------------

docs/parameters.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Here is the full list of configuration parameters you can specify in a ``config.
99
The bounding box to create images from. This should be given in the form: ``[xmin, ymin, xmax, ymax]`` as longitude and latitude values between ``[-180, 180]`` and ``[-90, 90]``, respectively. Values should use the WGS84 datum, with longitude and latitude units in decimal degrees.
1010

1111
**geojson**: string
12-
An input ``GeoJSON`` file containing labels. Adding this parameter will override the values in the ``country`` and ``bounding_box`` parameters. The ``GeoJSON`` should only contain polygons.
12+
An input ``GeoJSON`` file containing labels. Adding this parameter will override the values in the ``country`` and ``bounding_box`` parameters. The ``GeoJSON`` should only contain `Polygon` and not `Multipolygon` or a `GeometryCollection`.
1313

1414
**zoom**: int
1515
The `zoom level <http://wiki.openstreetmap.org/wiki/Zoom_levels>`_ used to create images. This functions as a rough proxy for resolution. Value should be given as an int on the interval [0, 19].
@@ -41,7 +41,7 @@ Here is the full list of configuration parameters you can specify in a ``config.
4141
One of ``'classification'``, ``'object-detection'``, or ``'segmentation'``. This defines the output format for the final label numpy arrays (``y_train`` and ``y_test``).
4242

4343
``'classification'``
44-
Output is an array of the same length as `classes`. Each array value will be either `1` or `0` based on whether it matches the class at the same index.
44+
Output is an array of ``len(classes) + 1``. Each array value will be either `1` or `0` based on whether it matches the class at the same index. The additional array element belongs to the background class, which will always be the first element.
4545

4646
``'object-detection'``
4747
Output is an array of bounding boxes of the form ``[xmin, ymin, width, height, class_index]``. In this case, the values are pixel values measured from the upper left-hand corner (not latitude and longitude values). Each feature is tested against each class, so if a feature matches two or more classes, it will have the corresponding number of bounding boxes created.

label_maker/label.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def make_labels(dest_folder, zoom, country, classes, ml_type, bounding_box, spar
5959
sparse: boolean
6060
Limit the total background tiles to write based on `background_ratio` kwarg.
6161
geojson: str
62-
File name for optional geojson label input
62+
Filepath to optional geojson label input
6363
**kwargs: dict
6464
Other properties from CLI config passed as keywords to other utility functions
6565
"""

label_maker/utils.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,21 @@ def get_tile_wms(tile, imagery, folder, imagery_offset):
119119

120120

121121
def is_tif(imagery):
122-
"""Determine if an imagery path has a valid tif extension"""
123-
return op.splitext(imagery)[1].lower() in ['.tif', '.tiff', '.vrt']
122+
"""Determine if an imagery path leads to a valid tif"""
123+
valid_drivers = ['GTiff', 'VRT']
124+
try:
125+
with rasterio.open(imagery) as test_ds:
126+
if test_ds.meta['driver'] not in valid_drivers:
127+
# rasterio can open path, but it is not a tif
128+
valid_tif = False
129+
else:
130+
valid_tif = True
131+
except rasterio._err.CPLE_HttpResponseError: #pylint: disable=protected-access
132+
# rasterio cannot open the path. this is the case for a
133+
# tile service
134+
valid_tif = False
135+
136+
return valid_tif
124137

125138
def is_wms(imagery):
126139
"""Determine if an imagery path is a WMS endpoint"""

label_maker/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""Library verison"""
2-
__version__ = '0.3.2'
2+
__version__ = '0.4.0'

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pyclipper==1.0.6
1414
pycurl==7.43.0.1
1515
pyproj==1.9.5.1
1616
rasterio==1.0a12
17-
requests==2.11.0
17+
requests>=2.20.0
1818
Shapely>=1.6.3
1919
six==1.10.0
2020
tilepie==0.2.1

test/unit/test_utils.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""Tests for utils.py"""
22
import os
33
from os import path as op, makedirs
4+
import shutil
5+
import tempfile
46
import unittest
57
import numpy as np
68
from PIL import Image
79

8-
from label_maker.utils import url, class_match, get_tile_tif, get_tile_wms
10+
from label_maker.utils import url, class_match, get_tile_tif, get_tile_wms, is_tif
911

1012
class TestUtils(unittest.TestCase):
1113
"""Tests for utility functions"""
@@ -43,6 +45,33 @@ def test_class_match_segmentation(self):
4345
self.assertTrue(class_match(ml_type, passing, class_index))
4446
self.assertFalse(class_match(ml_type, failing, class_index))
4547

48+
def test_is_tif(self):
49+
"""Test identifying tif or vrt files as tif"""
50+
img_dir = op.join('test', 'fixtures')
51+
52+
# tif with .tif extension identified as tif
53+
test_tif = op.join(img_dir, 'drone.tif')
54+
self.assertTrue(is_tif(test_tif))
55+
56+
# vrt with .vrt extension identified as tif
57+
test_vrt = op.join(img_dir, 'drone.vrt')
58+
self.assertTrue(is_tif(test_vrt))
59+
60+
61+
# tif with no extension identified as tif
62+
with tempfile.TemporaryDirectory() as tmpdirname:
63+
test_tif_no_ext = op.join(tmpdirname, 'drone')
64+
shutil.copy(test_tif, test_tif_no_ext)
65+
self.assertTrue(is_tif(test_tif_no_ext))
66+
67+
# vrt with no extension identified as tif
68+
with tempfile.TemporaryDirectory() as tmpdirname:
69+
test_vrt_no_ext = op.join(tmpdirname, 'drone')
70+
shutil.copy(test_vrt, test_vrt_no_ext)
71+
self.assertTrue(is_tif(test_vrt_no_ext))
72+
73+
74+
4675
def test_get_tile_tif(self):
4776
"""Test reading of tile from geotiff"""
4877
tile = '1087767-1046604-21'

0 commit comments

Comments
 (0)