1

I'm not a GIS person; this is really just a side task, so I probably have terminology/strategy incorrect; I would ask that you please bear with me. I have the following requirements for a Qt-based C++ application that I'm working on:

  • Display a tiled map (e.g. OpenStreetMaps). I have this working well.

  • Allow the overlay of other vector data on top of the map (as a test, I have a shapefile of world boundaries I got from Natural Earth.

Preprocessing of the vector data is possible in my application, so I decided to convert the EPSG:4326-projected Natural Earth shapefile to an SVG file (which I can render most easily in my application). I have done so using Kartograph. Its configuration looks like this:

{
   "layers": [{
       "src": "ne_10m_admin_0_countries.shp",
       "class": "world_boundaries"
   }],
   "proj": {
       "id": "proj4",
       "projstr": "+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs "
   },
   "bounds": {
       "mode": "bbox",
       "data": [-180, -85.0511, 180, 85.0511]
   }
}

I believe this should take the input shapefile, reproject it to Spherical Mercator (which should match the projection of the OSM tiles), and generate a corresponding SVG. This all "works," but the projection of the SVG file seems to be a bit off, it seems. When I overlay the SVG features atop the OSM image tiles, they don't quite line up, like this:

enter image description here

The black one-pixel-wide lines are rendered from the SVG. I'm wondering if there's something conceptually that I'm doing wrong in the preprocessing steps. I think that I'm rendering the SVG tiles correctly (I'm treating the SVG document as a square image that is 360 degrees wide and 170.1022 degrees tall and just slicing out the square portion of that image that corresponds to each tile that I need). However, since GIS isn't my job, I'm sure my ignorance could be leading me astray somewhere.

  • 2
    What is the input spatial reference of the input shapefile? It looks like a datum conflict.. how did you reproject? what utility and what parameters? Are you rendering with the same origin? Seeing as you're this close then done something right. – Michael Stimson Feb 18 '15 at 3:58
  • @MichaelMiles-Stimson: The input shape file's projection is GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]] according to its .prj file. I used Kartograph.py as I described above, using the config file that I gave in the OP. I believe I'm using the same origin (which I assume is -180 degrees longitude and 85.0511 degrees latitude). – Jason R Feb 18 '15 at 4:14
  • Have you viewed the data in a GIS program like QGIS (free to download & use) to see if it's the data or your applications' rendering that causes the disparity? I'm not familiar with Kartography.py, I would use GDAL_Warp (which comes with QGIS). – Michael Stimson Feb 18 '15 at 4:19
  • I will take a look at that. I wasn't aware that GDAL could write SVG files; that's why I had chosen the tool I'm using now. – Jason R Feb 18 '15 at 4:35
  • 1
    Easiest would be to use ogr2ogr (gdal is for rasters) to reproject natural earth to epsg:3857 and then SVG it. I think you issue is you told the conversion tool your data was already in spherical mercator, but I've never used it so that may be right. – Ian Turton Feb 18 '15 at 8:30
1

I decided to try some alternative tools to see if I had a problem in my workflow. At the suggestion of one of the commenters above, I instead did the following:

  • I used ogr2ogr to reproject the input shapefile into EPSG:3857.
  • I then used shp2svg to convert the Spherical Mercator shapefile to an SVG.

This resulted in an SVG file that rendered properly in my application. I'm assuming there must be either a bug in Kartograph, or I may have been driving it incorrectly. I think I was using it correctly, but its documentation isn't as detailed as it could be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.