Skip to content

Commit

Permalink
Fix point requests in RasterizeWKT (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervdw committed Sep 25, 2020
1 parent a841716 commit 6a13c63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog of dask-geomodeling
2.2.12 (unreleased)
-------------------

- Nothing changed yet.
- Fixed point requests for RasterizeWKT.


2.2.11 (2020-09-01)
Expand Down
11 changes: 10 additions & 1 deletion dask_geomodeling/raster/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from geopandas import GeoSeries

from shapely.geometry import box
from shapely.geometry import Point
from shapely.errors import WKTReadingError
from shapely.wkt import loads as load_wkt

Expand Down Expand Up @@ -782,14 +783,22 @@ def process(data, request):
geometry = utils.shapely_transform(
geometry, data["projection"], request["projection"]
)

# take a shortcut when the geometry does not intersect the bbox
if not geometry.intersects(box(*request["bbox"])):
x1, y1, x2, y2 = request["bbox"]
if (x1 == x2) and (y1 == y2):
# Don't do box(x1, y1, x2, y2), this gives an invalid geometry.
bbox_geom = Point(x1, y1)
else:
bbox_geom = box(x1, y1, x2, y2)
if not geometry.intersects(bbox_geom):
return {
"values": np.full(
(1, request["height"], request["width"]), False, dtype=np.bool
),
"no_data_value": None,
}

return utils.rasterize_geoseries(
geoseries=GeoSeries([geometry]) if not geometry.is_empty else None,
bbox=request["bbox"],
Expand Down

0 comments on commit 6a13c63

Please sign in to comment.