1

This is the standard MKT expression (here also translated to Proj.4 string) of Albers conicEqualArea for official Statistical Grid of Brazil:

PROJCS["Conica_Equivalente_de_Albers_Brasil",
    GEOGCS["GCS_SIRGAS2000",
        DATUM["D_SIRGAS2000",
            SPHEROID["Geodetic_Reference_System_of_1980",6378137,298.2572221009113]],
        PRIMEM["Greenwich",0],
        UNIT["Degree",0.017453292519943295]],
    PROJECTION["Albers"],
    PARAMETER["standard_parallel_1",-2],
    PARAMETER["standard_parallel_2",-22],
    PARAMETER["latitude_of_origin",-12],
    PARAMETER["central_meridian",-54],
    PARAMETER["false_easting",5000000],
    PARAMETER["false_northing",10000000],
    UNIT["Meter",1]]

The DATUM is the WGS 84 ("SIRGAS2000" is a alias for it).

How to translate all details to the D3.js v5 parametrization?

I try the obvious, as center and parallels, but it was not sufficient

var projection = d3.geoConicEqualArea()
  .parallels([-2,-22])  // IS IT?
  .scale(815)
  //.rotate([??,??]) // HERE THE PROBLEM... 
  .center([-54, -12])  // IS IT?

PS: where the D3 documentation for it? The D3 source-code of geoConicEqualArea() have no clues.

Peter Krauss
  • 13,174
  • 24
  • 167
  • 304
  • There is no official documentation that speaks specifically to creating a D3 projection from a projection definition. – Andrew Reid Oct 28 '19 at 15:10

1 Answers1

1

The parts that translate to a d3 Albers projection are as follows:

    PROJECTION["Albers"],
    PARAMETER["standard_parallel_1",-2],
    PARAMETER["standard_parallel_2",-22],
    PARAMETER["latitude_of_origin",-12],
    PARAMETER["central_meridian",-54],

You have the parallels, now you need to rotate. Also note, for any D3 projection, the rotation is applied to the centering coordinates. Generally, you'll want to rotate on the x and center on the y:

d3.geoAlbers()
 .parallels([-2,-22])
 .center([0,-12])
 .rotate([54,0])
 .translate([width/2,height/2])
 .scale(k)

I've rotated in the opposite direction along the x axis (rotated the earth under me so that I'm overtop of the central meridian, hence my rotation by -x). I've then centered on the y. Lastly I translate so that the intersection of the central longitude and meridian is centered in the map and apply a scale value that is appropriate.

If I want to center on a different area but keep the projection the same, I can modify projection.center(), but keep in mind that the coordinates provided here are relative to the rotation. I can also use projection.fitSize() or projection.fitExtent(), both of which set 'translate' and 'scale' values for the projection. None of center/scale/translate change the distortion in the D3 projection.

Of course this isn't a true replication of your projection as the coordinate space units are pixels, you will remain unable to measure distances in meters directly without some extra work.

See also

Andrew Reid
  • 37,021
  • 7
  • 64
  • 83
  • Important to remember that [`d3.geoAlbers()`](https://github.com/d3/d3-geo/blob/master/src/projection/albers.js) is an alias for `geoConicEqualArea()`, is it? – Peter Krauss Oct 28 '19 at 17:01
  • I am [implementing an illustration here as open gist](https://bl.ocks.org/ppKrauss/raw/e6c12bf84e732ca4cbf0694808619cad/)... My aim is to compare maps in "Mercator vs Albers" and make sense to use your suggestion of `projection.fitExtent()`, but I not see how to fit both in the same scale, center and area... It is possible? – Peter Krauss Oct 28 '19 at 20:58
  • Not sure if I follow - you want to use fitSize/fitExtent to replicate the visual in the link? – Andrew Reid Oct 28 '19 at 21:21
  • Yes, use it as more precise and *automatic fit* to the box/grid, turning the figures more comparable... I can post another question if you prefere. – Peter Krauss Oct 28 '19 at 23:05
  • I could mock something up this evening (a bit busy for the immediate future) - though as long as projection type, rotation, and parallels (if applicable) are set, then fitSize/fitExtent on each projection will set projection translate and scale appropriately (center does not matter: center/translate are both shifts - one in degrees prior to projection, the other in pixels after projection). – Andrew Reid Oct 28 '19 at 23:44
  • 1
    Something like [this](https://bl.ocks.org/Andrew-Reid/0ebddf4724a1658e43da01a5feff859b)? – Andrew Reid Oct 29 '19 at 02:52