For one of my side projects, I’m making a map of San Diego County and adorning it with various features. I’m using d3 (because I’m obsessed with d3 this month), so my map needs to be represented with GeoJSON. If you don’t know about GeoJSON, it is basically a list of vertices of your region as (longitude, latitude) pairs.

One of the important features of San Diego County is that it shares a border with Mexico. The border with Mexico is linear (at least in some map projections), but it does not fall exactly on a latitude line.

One of the other important features of San Diego County is that it shares a border with the Pacific Ocean. The ocean is very large and mostly non-linear, and the public domain shapefiles from the US Census only show the ocean for some fixed distance away from the coast. The polygon is also clipped at the Mexican border.

(Gee it would be nice if I included an image to show what I’m talking about, but right now all of my map files are kind of broken.)

My goal here is to edit the GeoJSON (list of vertices) so that the ocean polygon extends linearly along the Mexican border, has a vast blue region representing So Much Ocean, and then comes back, linearly, along the Orange County border.

So the problem is: If a set of (longitude, latitude) points that are already in the GeoJSON file (i.e. the Mexican border) lie along the same line in (x, y) space when transformed to the Mercator projection, how can I extrapolate that line out into the ocean? Where can I find some sort of inverse-Mercator function to take the desired points in my image and map them back to (longitude, latitude) pairs?