LocalData / localdata-api

API/server for LocalData
http://localdata.com/
BSD 3-Clause "New" or "Revised" License
20 stars 14 forks source link

Automatically correct rings that are too small #307

Open hampelm opened 8 years ago

hampelm commented 8 years ago

We sometimes get errors like this:

Mar 02 07:34:36 localdata-app app/web.2: { [Error: First argument geometry could not be converted to GEOS: IllegalArgumentException: Invalid number of points in LinearRing found 3 - must be 0 or >= 4] 

We can probably detect and fix these errors (by removing the offending broken ring). Is it worth any performance hit?

Low priority for now, as these are fairly rare. They do take time to fix manually, so an automated solution would be preferable.

prashtx commented 8 years ago

If these start cropping up more often, this could be a job for the task system. We could have a regular, repeated task that detects and removes or repairs invalid geometries. If it can record state, then it could notice that there are no new rows (most of the time) and quickly exit. Alternatively the API could queue up a task when it detects an invalid-geometry error. Potentially the originally API request would fail with a 500 status. If it's a request for a large area of parcels, then it's a shame for it to fail on account of one bad geometry. But this would not require the task to maintain state over time.

We had a bunch of bad geometries when running an older version of postgres+postgis. At that time, it was easy to accidentally import bad geometries and difficult to root them out, so I had to perform some binary searches to hone in on the bad rows. If that's still how we'd need to do it, then it would be expensive to perform regularly, so an on-demand or stateful approach would be really helpful.