D3 geoEquirectangular Projection

So d3’s concept of scaling is making my head explode. That aside, I seem to be thudding my head against the wall in trying to use a projection. Or rather, to set one up.

I have a map. It’s not an Earth map, but it’s at a 2:1 ratio and thus directly mapable at a x,y => lat,lon function with scaling factor.
D3 provides a Equirectangular projection, (d3.geoEquirectangular), but when invoked, it constructs a projection such that lat/long 0,0 = 480,250. Which would be a 1.92:1 ratio, rather than 2:1.

Am i missing something? Why is the projection at this ratio? Can the ratio be fixed by some magical command that none of the documentation details?

Hi m_hutley welcome to the forum

I don’t know how many here have experience using d3, but there are a lot of members here that do maths better than I do and a lot of members that enjoy trying new things.

I’ve done a bit with QGIS and the number of possible projections is mind boggling, all attempting to display a spherical surface as a plane and all beyond my full understanding.

Anyway, are you following a tutorial or more or less trying to piece things together based on the documentation?

Evening Mittineague. EtoileLion here (long since forgotten my account :P)

It’s a combination between piecing things together based on example and documentation. I’d been wracking my brain mostly to try and understand spherical geodesic formulae in order to draw geodesic (Great Arc) lines on an SVG based on coordinate endpoints sourced from JSON via d3, rather than a Cartesian straight line. (Annnd exhale.)

Eventually realized d3 implements methods to do the math for you (namely passing a LineShape to a geoPath), which requires a Projection. It’s a 2:1 rectangular (and very large) map, so an equirectangular projection makes sense to me. I cant just apply a scale to the projection though, as scaling a 960 pixel projection up by a magnitude then exasperates the ratio difference, and my X coordinates are off by about 400 pixels by the time i’m at [180,Y].

One of those projects where the bodges just pile up on top of each other, and you’re not entirely sure WHY it works, but it works and whenever you touch it something breaks :smiley:
https://pastebin.com/ZMiBCNBa (trying to implement a replacement for line 151)

1 Like

I’ve started to copy the files to my localhost (I don’t like min files for troubleshooting / development). I get a JavaScript error and the browsers broken image icon that I’m guessing is because I need image files. I don’t need the actual images, but knowing the dimensions should be enough for replacements. i.e.
TalanisFinal-noborder.jpg and TalanisPolitics-noborder.png and any other I may have missed.

Both images are imgWidth x imgHeight (6980x3490), but I fear i’ve sent you down a rabbit hole by putting that code up, and managed to surmise my error, now that i’m not trying to solve the problem at midnight while tired…

My assumption, when i said the default projection was 1.92:1 instead of 2 to 1, was based on the center point being 480,250. What i had not accounted for is that the projection’s default does not map its top corner to 0,0, but rather 0,10 (or a rough approximation thereto: [0.4987132825899039, 10.249356641294952]). Checking the other end, it pops out at 960, 490 ([959.50128671741, 489.750643358705]), which makes the canvas actually 960x480, and the ratio actually the proper 2:1

Just… odd choices of default y coordinates throwing me completely off -_-

1 Like

I do wonder what the rationale was for that default. For the image I used the southern most bit of Tierra del Fuego isn’t initially visible. Nothing personal to any Chileans, but I guess it isn’t that big of a deal unless you’re navigating the waters. With a different map it might be more important to show all the pixels.

vs

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.