1

I'm rendering maps into SVG files, and I'd like to put geographic metadata into those files, as described in section 7.13 and 7.14 of the SVG spec, but I'm uncertain about how to interpret the <svg:transform> element.

My primary use case for this is to eventually get the information into a GeoTIFF file. Since I have full control over the rendering chain, I could convey this information by any sneaky means that I care to invent, but since there is a documented way of doing it...

Let's take a concrete example:

I'm drawing my map on A4-sized paper, and I have set up the viewBox so that the viewBox coordinate system gives me 90 units per inch. In other words, the top left corner of the paper is at (0, 0) and the lower right corner is at (744, 1052).

My geographic data is in EPSG:3006 (SWEREF99TM, more or less equivalent to EPSG:32633), so a typical point P could be (660000, 6612000). Possibly, those coordinates should be flipped, but that's a separate can of worms -- this is what works with PostGIS, so it is what I have.

I want a scale of 1:50000, and the lower left corner of the map at (655000, 6606000). This puts my point P roughly at the centre of the page.

I want a sane coordinate system on my page, so I wrap the entire map in

<g transform="translate(0 1052) scale(1 -1)">

thus putting the origin at lower left, and Y axis upwards.

I then compute coordinates for my point in this coordinate system:

x = ( 660000 -  655000) / 50000 * 90 / 0.0254 = 354
y = (6612000 - 6606000) / 50000 * 90 / 0.0254 = 425

And finally I draw my point as a small circle

<circle cx="354" cy="425" radius="3" />

(In reality, I keep a few more decimals.)

Now, what should I put in <svg:transform> to describe this? Should I describe the transform from geographic coordinates to the actual numbers written into the file, i.e.

scale(0.0709) translate(-655000 -6606000) 

or should I describe the transform to viewBox space

translate(0 1052) scale(1 -1) scale(0.0709) translate(-655000 -6606000)

or something completely different?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.