I have a car with a GPS (WGS84) and a camera (who shot the road) fixed on it. I would like to know is there is a way to get the transformation from a OSM node to the GPS Cartesian coordinate fixed on the car ? So that I can get easily project the coordinate of the GPS into the picture (from the camera) coordinate.

I don't know if this is a problem of map matching because I don't want to match a trajectory (like for example https://mapmatching.3scale.net/) but I just want to get the node next to the car and then have the transformation between the two.

Do you have an idea ?

  • What coordinate system are you using on your camera/GPS? Nowdays GPS units can do pretty much any common spatial reference - projected or geographic. The question is what tool are you going to use to transform your node? ArcGis, OGR, MapInfo... it really isn't the sort of thing that you'd like to do without a library. Jun 10, 2015 at 4:16
  • Sorry, I've edited my post. This is Cartesian coordinate.Hum actually I don't know, I'm new in this field and I would like to know if we can do that and in which way ? Thanks
    – lilouch
    Jun 10, 2015 at 5:02
  • If you haven't already done so download QGIS - one of the best open source (free) GIS packages, it will help a lot. Openstreetmap is Spherical Mercator wiki.openstreetmap.org/wiki/EPSG:3857, your GPS is probably WGS84 (but that's by no means a certainty)... if you open in QGIS with the Open Layers plugin you can view your data with the OpenStreetMap data, the hardest part is communicating with your camera/GPS (I have no experience there). Jun 10, 2015 at 5:22
  • Okey I'll but the visualization is not a problem for me. I used some tools from OSM to visualize the nodes and the way, but now my problem is to get the transformation between two gps coordinate...Not easy.
    – lilouch
    Jun 10, 2015 at 5:37
  • No, there's a lot of maths. GDAL/QGIS uses PROJ.4 (trac.osgeo.org/proj) which is open source.. are you coding this or are you trying to get an out of the box solution? If coding, what language (python, C, C++, C#, VB.net, VB6, Java...)? Jun 10, 2015 at 22:05

1 Answer 1


Firstly I would convert OSM to a shapefile, it makes it easier to use and protects against 'black spots'.

Here's a bit of code to get you started:

// GDALAllRegister(); // More recent versions don't separate OGR from GDAL
// READ http://www.gdal.org/ogr_apitut.html FOR MORE INFO
char* BasePath = ""; // FILL IN FULL PATH TO SHAPE FILE
OGRDataSource *hDS = NULL;
OGRSFDriver   *Driver = NULL;
hDS = OGRSFDriverRegistrar::Open(BasePath,FALSE,&Driver);
OGRLayer *Layer = hDS->GetLayerByName("Polyline");
OGRSpatialReference* LayerSR = Layer->GetSpatialRef();

OGRSpatialReference WGS84 = OGRSpatialReference(0);

// create a query geometry, YourX, YourY need to be in the same spatial reference
// as the osm data. This limits the features returned to just the ones near the X,Y
OGRPoint pt;
OGRGeometry* QueryGeom = pt.Buffer(SutableDistance); // make a buffer of the point

// now the layer will only return intersecting features..
Layer->ResetReading(); // initialize
int pCnt = Layer->GetFeatureCount();
if (pCnt > 0)
    OGRFeature* pFeat;

    while ((pFeat = Layer->GetNextFeature()) != NULL)
        OGRGeometry* pGeom =  pFeat->GetGeometryRef(); // get the geometry for the feature..
        pGeom->transformTo(&WGS84);// Now the geometry is in WGS84
        // READ http://stackoverflow.com/questions/18747370/how-to-extract-vertexes-of-geometries-in-esri-shapefiles-using-ogr-library-with

After you have broken down the line into vertices it's pythagorean to find the closest vertex. You need to know which way you're headed to decide what the next one is (with the line direction or against it)... to get sensible distances you would need to project both points to a projected coordinate system like UTM, Lamberts or Albers.. the parameters for these depend on where you are but a mathematical formula can decide which parameters is most appropriate.

Your Answer

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

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