1

When using Cartodb to layer polygons (craters on Mercury) on top of a user-defined (via Mapbox) basemap, features (craters/polygons) that span the edge of the basemap are extended into bands that wrap the planet/map and exclude the crater they should encircle.

Example of crater-polygons to bands

Is there an elegant way to fix this? Here's a link to the visualisation: Edge Spanning Polygon Anomalies

1

Try to split the features that cross the dateline (-180/180 longitude) . ogr2ogr utility has an option -wrapdateline to do this.

  • Thanks @spatialthoughts. I've heard of this solution but didn't know ogr2ogr had that functionality. I fear however that splitting the polygons like that will make further processing of them in my workflow difficult; I need each polygon to be a single entity (I could add pre- and post- processing steps to my workflow around the visualisation step but I'm hope for a more 'elegant' solution). – DrJMcAuliffe Mar 17 '15 at 14:37
  • CartoDB deals with multipolygons though, so you can split them and still have them be considered a single entity – andrewxhill Mar 18 '15 at 11:55
0

There's an inelegant way to do it. If your table SQL originally looked like this and your the_geom column was original in geographic coordinates:

SELECT * FROM mytable;

You'd replace it with:

SELECT 
 cartodb_id, myattribute1, myattribute2, the_geom,
 ST_Transform(
 ST_Difference(
 ST_Difference(the_geom,
 ST_Buffer('SRID=4326;LINESTRING(180 -89, 180 89)'::geometry, 0.00001)), 
 ST_Buffer('SRID=4326;LINESTRING(-180 -89, -180 89)'::geometry, 0.00001)), 
 3857) AS the_geom_webmercator
FROM mytable

To make it more efficient, wrap the differencing step in a CASE statement and only difference geometries that meet an ST_Intersects() condition with the -180 or 180 boundary lines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.