-
-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OSM Map features are not exactly clipped by AOI #1904
Comments
Thanks @manjitapandey 🙏 Setting I'm surprised we are only just encountering this issue, as we have had this set for months. The geometries we are seeing are far outside the extent of the AOI, so I'm really surprised by this. Anyway, if this is the only solution, then we might have to do it. For the future, as part of the revised project creation workflow, add extra configurability:
|
@spwoodcock Thanks for the mention ! Pasting here the request body :
And this is the output which looks perfectly fine to me Attaching the export zip file as well RawExport_geojson_uid_b5d52672-15d7-4c1d-9c4e-a8fd04f610ad.zip |
By taking closer look at screenshot : Issue could be this : if you are passing multipolygons directly to rawdataapi , or polygons with hole inside , raw data api will try to fix the polygons to get a bounding polygon. Try passing valid polygons or atleast polygon without holes or geometry problem free ! May be use shapely union to find the outer boundary of the input area and making a request ! |
I will also share the logic how raw data API tries to fix those geometry problems : I think the geometry pasted on the screenshot contains hole and small distinct polygons which is why raw data API tries to fix it by getting union and hence the extra area ! |
This is so helpful! Thanks so much Kshitij 🤩 I will dig into it tomorrow and see if we can find the cause. Hopefully just converting multipolygon --> polygon first could fix the problem (if indeed multipolygons are being used). The polygon may be wrapped in a FeatreCollection, so possibly that's related too. @manjitapandey could you share the AOI geojson for debugging please? 🙏 |
These are the AOI I was using, ward 4 of Tokha municipality(without hole) and AOI of janapur (with hole) |
Here is the export for your AOI
fmtm_test_tokha_geojson_uid_752543f7-0748-4da4-911a-0a9b191cdc32.zip
I think this is the exact issue , I recommend doing some geometry cleanup : Either letting user know their geometry has issues or getting the union out of geometry might work ( but this is slightly complex than I explained , polygons with holes are tricky ) this might also raise issues in other geometry operations too if you are doing any : probably splitting To test this theory : I Tried fixing up the geometry & Here is the output RawExport_geojson_uid_e9cccffa-1aa7-4ce8-b139-09214bdca977.zip |
Thanks boss man! You definitely saved me some work, so I really appreciate it 😁 That's an interesting analysis for sure! So ideally we should do a lot more preprocessing of the geom before passing to raw-data-api. Do you use ST_RemoveSmallParts to move the holes? |
@spwoodcock Yes , Correct !! |
@Sujanadh I assigned you if thats ok 🙏 SummaryProblem
Solution
In the end we need to be able to flexibly handle user AOI input, normalise to Polygon with no holes, and pass that to raw-data-api for data extract generation. |
Although the above is definitely nice to have, the actual error was something else for now!! This is the issue in osm-rawdata: https://github.com/hotosm/osm-rawdata/blob/1cd905f4aeaa794a162210fb5f8d12da4932629d/osm_rawdata/postgres.py#L762 We shouldn't be doing a unary_union of geoms in a FeatureCollection |
The issue isn't due to unary_union, it does its work perfectly dissolving all inner polygons (but not holes) generating exterior ring as polygon. The actual issue is generated due to convex hull. The holes inside polygon also doesn't affect that much in generating osm-extracts, only if those holes doesn't contain any data inside or else they will be left out. In above case, those holes doesn't contain any data extracts within them so it won't create a problem. But it's best to dissolve those holes to avoid any possible discrepancies. Why convex hull is creating problem? |
Excellent breakdown Sujan 🙌 Thanks for digging into this more deeply! Hopefully an easy fix then 😁 |
Describe the bug
While generating the map features from osm, the features are not exactly clipped by AOI but rather map features outside of AOI to few buffer distance is visible.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
the users should be provided option to choose either they want to perfectly clip the map features by AOI. May be a toggle on/off button to specify.
Screenshots

Additional context

Had a talk with Kshitiz, he shared about https://api-prod.raw-data.hotosm.org/v1/redoc#tag/Extract/operation/get_osm_current_snapshot_as_file_snapshot__post
if you use usestwithin = True , it will return only the features which are inside the geometry
it is false by default so will give you the features that are intersected in that area , this will work for buildings but for roads might not make sense because it will return the roads that are exactly inside polygon
The text was updated successfully, but these errors were encountered: