How to create RGeo polygon in Ruby from WKT when the polygon has errors
gis, mysql, polygon, rgeo, ruby
Solution
Try this:
RGeo::Geos.factory(:srid => 4326).parse_wkt(wkt_string)
Problem
I'm working with a MySQL database with polygons stored in WKT format. Many polygons in the database have duplicate points (e.g. in the below example, the point -122.323502 47.600959 is repeated three times). When attempting to call RGeo::Cartesian::Factory.parse_wkt() on these polygons, the result is nil. How can I create RGeo objects from these polygons, without modifying the polygon data. ``` poly = "MULTIPOLYGON(((-122.362163 47.618641,-122.344621 47.592555,-122.332017 47.592458,-122.32748 47.59241,-122.326109 47.592652,-122.324738 47.592895,-122.323147 47.593478,-122.321412 47.59411,-122.320826 47.594984,-122.320669 47.596296,-122.321149 47.598627,-122.323502 47.600959,-122.323502 47.600959,-122.323502 47.600959,-122.324071 47.601688,-122.320757 47.601688,-122.32073 47.604262,-122.320767 47.607663,-122.320746 47.609703,-122.320723 47.611938,-122.320714 47.612812,-122.320772 47.614075,-122.320799 47.618495,-122.362163 47.618641)))" parsed_poly = RGeo::Cartesian::Factory.new().parse_wkt(poly) =>nil ```