You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to split polygons which straddle x=0 or y=0 by a raster grid with snail.core.intersection.split_polygon_experimental, sometimes triggers RuntimeError from here.
Code to reproduce for 0.3.1 is something like:
#!/usr/bin/env python
# coding: utf-8
"""
Failing test case for snail==0.3.1
Try to split a polygon by a raster grid, where that polygon crosses a coordinate zero line.
Fails with `RuntimeError: Expected even number of crossings on gridline.`
"""
import geopandas as gpd
import shapely
import snail
from snail.intersection import (
Transform,
prepare_polygons,
split_polygons_experimental
)
bad_poly = shapely.wkt.loads(
(
'POLYGON (('
'-0.0062485600499826 51.61041647955, '
'-0.0062485600499826 51.602083146149994, '
'0.0020847733500204 51.602083146149994, '
'0.0020847733500204 51.61041647955, '
'-0.0062485600499826 51.61041647955'
'))'
)
)
bad_gdf = gpd.GeoDataFrame(geometry=[bad_poly])
# mimicking cli.split
transform = Transform(
crs=(
'PROJCS["World_Mollweide",GEOGCS["WGS 84",DATUM["WGS_1984",'
'SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],'
'AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],'
'UNIT["Degree",0.0174532925199433]],PROJECTION["Mollweide"],'
'PARAMETER["central_meridian",0],PARAMETER["false_easting",0],'
'PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],'
'AXIS["Easting",EAST],AXIS["Northing",NORTH]]'
),
width=36082,
height=18000,
transform=(1000.0, 0.0, -18041000.0, 0.0, -1000.0, 9000000.0)
)
prepared = prepare_polygons(bad_gdf)
# will raise RuntimeError; number of gridline crossings is not even
splits = split_polygons_experimental(prepared, transform)
See below for an example with gridfinder 'targets' and a population raster.
Not all polygons overlapping Greenwich meridian fail to split, but many do.
The text was updated successfully, but these errors were encountered:
thomas-fred
changed the title
split_polygon failing on polygons crossing x or y datum
split_polygons_experimental failing on polygons crossing x or y datum
Jun 19, 2023
Trying to split polygons which straddle x=0 or y=0 by a raster grid with
snail.core.intersection.split_polygon_experimental
, sometimes triggersRuntimeError
from here.Code to reproduce for 0.3.1 is something like:
See below for an example with gridfinder 'targets' and a population raster.
Not all polygons overlapping Greenwich meridian fail to split, but many do.
![snail_meridian_failures_closeup](https://private-user-images.githubusercontent.com/39301725/246464558-5a58ac5d-4dec-45b2-96fe-33a3b5bfb8fc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk4MzUyMTAsIm5iZiI6MTczOTgzNDkxMCwicGF0aCI6Ii8zOTMwMTcyNS8yNDY0NjQ1NTgtNWE1OGFjNWQtNGRlYy00NWIyLTk2ZmUtMzNhM2I1YmZiOGZjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE3VDIzMjgzMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc3MmNhM2E5NDJjY2ViZDJiYTU1Njk2YmUxNGRjMjQ1MGQ1NWZmMjBhOWNhNDU3N2NiMjQ2NDYzMzcxZTI4NTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.9lvBhJIREqlwsdR9Mj4OULq_H_sDdAYqHxLrEMbflWo)
The text was updated successfully, but these errors were encountered: