Skip to content

Commit

Permalink
Fix bug with crs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgleith committed Nov 10, 2024
1 parent 124b7bc commit cf50e98
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 7 additions & 2 deletions dep_tools/grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def get_tiles(

def grid(
resolution: int | float = 30,
simplify_tolerance: float = 0.1,
crs=PACIFIC_EPSG,
return_type: Literal["GridSpec", "GeoSeries", "GeoDataFrame"] = "GridSpec",
intersect_with: GeoDataFrame | None = None,
Expand Down Expand Up @@ -122,12 +123,16 @@ def grid(
return _intersect_grid(full_grid, intersect_with)
else:
gridspec = _gridspec(resolution, crs)
geometry = Geometry(
simplified = (
intersect_with.to_crs(PACIFIC_EPSG)
.simplify(0.1)
.simplify(simplify_tolerance)
.to_frame()
.to_geo_dict()
)
geometry = Geometry(
simplified,
crs=PACIFIC_EPSG,
)
if buffer_distance is not None:
geometry = geometry.buffer(buffer_distance)
else:
Expand Down
2 changes: 1 addition & 1 deletion dep_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def bbox_across_180(region: GeoDataFrame | GeoBox) -> BBOX | tuple[BBOX, BBOX]:
geometry = region.to_crs(4326).geometry.make_valid().explode()
geometry = geometry[
geometry.geom_type.isin(["Polygon", "MultiPolygon"])
].unary_union
].union_all()

geometry = _fix_geometry(geometry)
bbox = antimeridian_bbox(geometry)
Expand Down
2 changes: 0 additions & 2 deletions tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def test_get_gadm():

def test_get_tiles():
# This takes 2 minutes to retrieve all the tiles. Keep it as a generator.
print("a")
tiles = get_tiles(resolution=30)

# Let's just check one
Expand All @@ -23,7 +22,6 @@ def test_get_tiles():
assert type(tile) is tuple
assert geobox.crs == PACIFIC_EPSG

print("b")
# Check the count here, shouldn't take too long
tiles = list(get_tiles(resolution=30, country_codes=["FJI"]))
assert len(tiles) == 27
Expand Down

0 comments on commit cf50e98

Please sign in to comment.