Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kartograph python script generates SVG with incorrect lat/long coords

I have modified this question to reflect some progress on discovering the problem. I am using the following python code to generate an SVG of the continental USA. The shapefile is irrelevant, as the problem I describe occurs regardless of what shapefile I use. The script is really simple. I basically just take a shapefile for the US and use a bounding box to exclude Hawaii and Alaska.

from kartograph import Kartograph

K = Kartograph()

blah={
    "layers": [
        {
        "id":"mylayer",
        "src":"/Users/austinc/Documents/shapefiles/states_21basic/states.shp",
        }
    ],
    "bounds":{
        "mode":"bbox",
        "data":[-130,25,-65,50],
    },
    "proj":{
        "id":"mercator"
    }
}

K.generate(blah,outfile='/Users/austinc/Desktop/mymap.svg')

The problem is that the svg generated by this code has incorrect coordinates associated with it. When I use javascript to try to map points on it, the points appear at the correct latitude, but are off by roughly 100 degrees of longitude.

When I use a pre-made SVG from Kartograph, I do not have this problem (I have not tried cropping away Alaska and Hawaii yet). So something about my python script is causing this but I don't understand what.

FIXED: The comment below got me thinking that maybe this was something to do with the projection. I removed the part of the python script that draws the graph as a mercator projection and this fixed everything. I'm not sure I understand why but if you are having a similar issue and find this question: try changing your projection or not using a projection at all.

like image 666
AustinC Avatar asked Nov 17 '13 16:11

AustinC


1 Answers

It might be that the coordinate system used in your SVG file doesn't coincide with latitudes and longitudes. You might need to know what projection was used for generating the SVG file, and computing latitudes and longitudes by using the inverse of that projection. Maybe also try to see if the same problem occurs with the ready-to-use maps provided by Kartograph.

like image 190
user2314737 Avatar answered Nov 02 '22 22:11

user2314737