cyipt / acton

Active Transport Options for New Developments
https://cyipt.github.io/acton/
GNU General Public License v3.0
3 stars 2 forks source link

Fixing invalid geometry #27

Closed joeytalbot closed 4 years ago

joeytalbot commented 4 years ago

When I make a tmap of the Leeds accessibility stats, the map shows up ok but this message also appears:

> tm_shape(reszone) +
+   tm_polygons(col = "FoodPTt") +
+   tm_shape(sites) +
+   tm_dots()
Warning message:
The shape reszone is invalid. See sf::st_is_valid 

There is only one polygon that has invalid geometry is this is it: http://rpubs.com/joeytalbot/invalid_geometry

Is this worth fixing, and if so what would be the best way to do it?

mem48 commented 4 years ago

https://r-spatial.github.io/lwgeom/reference/valid.html This always works, but be careful in what has been changes ot make it valid.

Robinlovelace commented 4 years ago

Well spotted, that's definitely invalid and worth fixing. Just to clarify, is that a zone in the PCT? Worth fixing 'upstream' if so but for now you could use something like QGIS to fix the geometry or try st_make_valid() function described here: https://www.r-spatial.org/r/2017/03/19/invalid.html

I don't think this issue affects the output or 'MVP' so would prioritise other things for now, will be great to get an overview map of Leeds with the following layers visualised (in fact I may make an overview issue from this):

mvl22 commented 4 years ago

Bear in mind that if you are using ST_Simplify (i.e. Douglas-Peucker algorithm), that can result in invalid geometries.

Robinlovelace commented 4 years ago

Yes, I recommend the mapshaper approach which uses a better and faster algorithm. Details: https://geocompr.robinlovelace.net/geometric-operations.html#simplification

joeytalbot commented 4 years ago

Yes it comes from get_pct_zones().

I've tried using st_make_valid and the resulting object is listed as valid, but in mapview() the polygon looks exactly the same as it did before.

Robinlovelace commented 4 years ago

Interesting. Minor bug in data provided by government (the geometries were not made by us).

mem48 commented 4 years ago

Invalid geometires are often visually fine see the example pictures https://shapely.readthedocs.io/en/latest/manual.html

mem48 commented 4 years ago

Also do you know the x = st_buffer(x, 0) trick?