Sunday 22 May 2016

gdal - How do I split polygons that cross the dateline?



I have a dataset of country borders which I obtained from:


http://thematicmapping.org/downloads/world_borders.php/


I have that dataset in both shp and SQL, but I'll put out there that I don't feel that affects my problem; however, please let me know if it does/can.


Because I'll be displaying those borders in something that uses Google Maps, I've got a problem. That problem is that countries whose polygons cross 180 degrees are displaying extremely weird in Google Maps. Either it's splitting them completely wrong, taking them all the way across the map, whatever the weirdness might be.


So, I thought I can simply address this by splitting the polygons of the countries that cross the line so that no country contains a polygon that presents a problem. Examples of such countries/regions would be Russia and Antarctica.


I therefore invoked the following: ogr2ogr -wrapdateline -t_srs EPSG:4326 new countryBorders.sql


I got: ERROR 1: TopologyException: found non-noded intersection between LINESTRING (-59.7742 -72.9003, -59.8494 -73.2331) and LINESTRING (0 -73.1221, -89.3211 -73.0542) at -59.8141 -73.0766 ERROR 1: TopologyException: found non-noded intersection between LINESTRING (-59.7742 -72.9003, -59.8494 -73.2331) and LINESTRING (180 -73.2589, -89.3211 -73.0542) at -59.8141 -73.0766


A few questions:


1: am I even doing this the right way? for example, I find it odd that I have to provide ogr2ogr the same srs as of the input. Is that translation even needed? Is that even the right SRS to use? I obtained that SRS from taking the .prj file and looking it up on this site:


http://prj2epsg.org/search



2: all I want is for a few of the polygons of those few troublesome countries to get split so they don't cause any more problems. -wrapdateline seemed like the perfect solution ... maybe it's not?


I'm completely open to advice, suggestions, references, whatever.


I am perfectly willing to redo this dataset in another projection, run a one-time query against it to redo it so it is more compatible with displaying on Google Maps, anything at all. I'd love any advice. It doesn't have to involve my most probably incorrect approach outlined above.


Thanks so much in advance!




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...