Problem with decode and self-intersecting polygon
pankas87 opened this issue · 2 comments
I have a valid GeoJSON polygon which I checked using the GeoJSON Lint service.
It is displayed perfectly in Google Maps, using the data.addGeoJson() method.
But when I try to decode it using
RGeo::GeoJSON.decode(polygon_json, :json_parser => :json)
I get a nil geometry. I have tried a lot of stuff but can get it to work correctly. Here's the GeoJSON polygon I'm trying to decode
{
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-69.30999755859375,
-33.610044573695632
],
[
-69.54620361328125,
-33.89321737944087
],
[
-68.95294189453125,
-33.749464192325767
],
[
-69.1094970703125,
-33.982086259019368
],
[
-69.30999755859375,
-33.610044573695632
]
]
]
},
"type": "Feature",
"properties": {
"Campo 1 (Texto)": null,
"gx_id": "undefined-undefined-1422304622752",
"Campo 3 (Num\u00e9rico)": null,
"Campo 2 (Texto)": null
}
}
The problem is not specific to this polygon, it happens with any polygon which has lines that go over previous lines in the polygon, like this
The geoJSON representation of the polygons are created by me in JS based on user input from Google Maps Draw Tools.
Is there something wrong with my polygon coordinates? Is there anything I can do to fix this issue or is it an issue of the gem?
Thank you for reading
GeoJSON doesn't care if a polygon self-intersects, but many tools in the chain are implemented against the Simple Features standard which disallows it. Check the PostGIS documentation section on "Ensuring OpenGIS compliancy of geometries" and consider using multipolygon.
I enabled GEOS support for RGeo in my Ubuntu 12.04 install and now it works perfectly.