Skip to content

Commit

Permalink
Shapely multi geometries no longer iterable (#11923)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 0143cd182b0b7cc44ccfab0fa505b5c7f31819ff
  • Loading branch information
stephencpope authored and Descartes Labs Build committed Jun 9, 2023
1 parent 0781f12 commit 22ae309
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
17 changes: 16 additions & 1 deletion descarteslabs/core/common/dltile/utm.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,24 @@ def _transform(points, *args, axis=-1, **kwargs):
transformed_points = _transform(points, *args, **kwargs)
return geo.mapping(transformed_points)

elif isinstance(points, geo.MultiPoint):
return geo.MultiPoint(
[_transform(geom, *args, **kwargs) for geom in points.geoms]
)

elif isinstance(points, geo.MultiLineString):
return geo.MultiLineString(
[_transform(geom, *args, **kwargs) for geom in points.geoms]
)

elif isinstance(points, geo.MultiPolygon):
return geo.MultiPolygon(
[_transform(polygon, *args, **kwargs) for polygon in points]
[_transform(geom, *args, **kwargs) for geom in points.geoms]
)

elif isinstance(points, geo.GeometryCollection):
return geo.GeometryCollection(
[_transform(geom, *args, **kwargs) for geom in points.geoms]
)

elif isinstance(points, Sequence):
Expand Down
35 changes: 35 additions & 0 deletions descarteslabs/core/common/geo/tests/test_geocontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,41 @@ def test_iter_from_shape(self):
assert type(dltiles1[1]) == str
assert len(dltiles1) == len(dltiles2)

def test_iter_from_shape_multi(self):
params = {"resolution": 1.5, "tilesize": 512, "pad": 0, "keys_only": True}
shape = {
"type": "Feature",
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[-122.51140471760839, 37.77130087547876],
[-122.45475646845254, 37.77475476721895],
[-122.45303985468301, 37.76657207194229],
[-122.51057242081689, 37.763446782666094],
[-122.51140471760839, 37.77130087547876],
]
],
[
[
[-123.51140471760839, 37.77130087547876],
[-123.45475646845254, 37.77475476721895],
[-123.45303985468301, 37.76657207194229],
[-123.51057242081689, 37.763446782666094],
[-123.51140471760839, 37.77130087547876],
]
],
],
},
"properties": None,
}
dltiles1 = [tile for tile in geocontext.DLTile.iter_from_shape(shape, **params)]
dltiles2 = geocontext.DLTile.from_shape(shape, **params)
assert type(dltiles1[0]) == str
assert type(dltiles1[1]) == str
assert len(dltiles1) == len(dltiles2)

def test_subtile(self):
tile = geocontext.DLTile.from_key("2048:0:30.0:15:3:80")
tiles = [t for t in tile.subtile(8, keys_only=True)]
Expand Down

0 comments on commit 22ae309

Please sign in to comment.