Home > Blockchain >  Aligning Natural Earth Geojson and Raster to render in D3
Aligning Natural Earth Geojson and Raster to render in D3

Time:03-22

I am trying to render the world map with elevation data using D3.

For this I use Natural Earth 50m land geojson : result

I tried to first project and then cut, or to use Pseudo-Mercator or Mercator when projection, but nothing works.. Anyone have an idea ?

CodePudding user response:

A Mercator is usually clipped at roughly 85 degrees North/South (~85.05113 N/S) - as further than this you get a map that is taller than it is wide, and one that gets much much taller for every extra degree north/south included in the extent..

D3 clips features using this limit:

The spherical Mercator projection. Defines a default projection.clipExtent such that the world is projected to a square, clipped to approximately ±85° latitude.

The northern bounds are fine, but the southern bounds of the geojson is -89.998926 degrees which you use to cut the image. But as D3 clips the geojson, your stretching the image by a different amount as compared with the geojson, hence the issue you see.

The solution should be to clip the image to a bounds that is representative of the limits of what D3 will render for a Mercator (85.05113 degrees south) not the limits of the data itself.

I haven't looked up how faithfully gdal implements EPSG:3395 as the definition provides for a projected bounds of 80 degrees south and 84 degrees north - though looking at the image, this doesn't appear to be an issue.

You can also use the cleaner fitSize methods for D3 projections (d3v4 ):

 projection.fitSize([width,height],geojsonObject)

Which will set scale and translate for you given a provided width/height.

  • Related