2

I've created a lovely route map in CartoDB, but one of the lines crosses the dateline (from Colorado to Guam, FWIW) and finds its way there by hitting the dateline north of Alaska, bouncing back around past Greenland to the dateline, bouncing again ... you get the idea.

I tried to manually draw a line that crosses the dateline and found that it gets cut off right at the dateline, no matter what I do.

See for yourself: http://cdb.io/1k1vod6

Is there a way to draw a poly line that crosses the dateline in the Pacific?

  • my understanding is that you need make two geoms from this type of lines to make them work (split at dateline ) – simplexio Feb 3 '14 at 14:03
  • So, two rows? One with an arc to the dateline, one connecting Guam to the dateline? – Amanda Feb 3 '14 at 16:18
  • yes, or one line with multilinestring – simplexio Feb 4 '14 at 7:59
2

This is a great question and one that I have a part answer too. The problem is a combination of the database and the rendering. Maybe there are smarter simpler answers, but here goes.

The best solution is to create a MultiLineString that contains one linestring to the east of the dateline and one to the west. It also depends a bit on projection. I've gone ahead and created a plpgsql function that can do it for you in EPSG:3857 / Webmercator. What it does is finds the point along the line between two points that WOULD hit the dateline, then splits the line into the two segments.

Here it is at work, http://cdb.io/1dnMhq5

To use it, give the function your start and end points,

SELECT 
  AXH_CrossDateLine(
     cdb_latlng( 24, -158), 
     cdb_latlng(-38,  145)
  ) AS the_geom_webmercator

But you'll see, even though I put in WGS84 it spits out Webmercator. If you put in webmercator, it will spit out webmercator faster :)

The function is here, https://gist.github.com/andrewxhill/8795878. You can load it into your account by executing it from any SQL panel one time.

Perhaps we'll try to make some version of this part of CartoDB in the future.

  • Ah, note. This works for Webmercator. Great circle will need a variation of this. – andrewxhill Feb 4 '14 at 1:37
  • Mostly works (the lines don't meet but this is a start). So my next challenge is to transform this into Great Circle, but I think I can wrap my head around that. – Amanda Feb 4 '14 at 15:04
  • Super interested on this. I am working on this visualization jatorre-cloud.cartodb.com/viz/… – jatorre Feb 8 '14 at 14:43
  • I used this for solving the problem on [this map] (jatorre-cloud.cartodb.com/viz/…) – jatorre Feb 9 '14 at 23:16

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.