0

GIS newbie here! I have been playing around with the import I did from an OSM region (that I got from here) to postgres using the osm2pgsql conversion tool. The command I used to import was this:

osm2pgsql -c -d gis --slim --style default.style -C 10240 --flat-nodes ./bayern-latest-pgsql bayern-latest.osm.pbf

Now, everything seems to have worked and I got all the data I want, except for the geometry. When I run a query like this:

> select osm_id, ST_AsGeoJSON(way), name, from planet_osm_point;

I get back values like {"type":"Point","coordinates":[1197606.06200162,6136808.52532997]} in the st_asgeojson column. These coordinates are not what I expected (lat, lon). What am I doing wrong here?

  • It's almost certainly because your data is not in a lat/long projection. Trying to find a dupe target; I'm sure there must be one. – jpmc26 Mar 5 '18 at 23:29
  • 2
    Possible duplicate of PostGIS Unknown Coordinates Format – jpmc26 Mar 5 '18 at 23:33
  • @jpmc26 Now that you mentioned it, I just discovered the --latlong flag on the osm2pgsql tool (which I didn't use), perhaps that's the reason? – sashimiblade Mar 5 '18 at 23:35
  • @jpmc26 I'm pretty sure that was it. I looked back on the output from the initial import and saw Using projection SRS 3857 (Spherical Mercator) Output after --latlong is: Using projection SRS 4326 (Latlong) – sashimiblade Mar 5 '18 at 23:38
1

I was using the wrong projection when importing the OSM data into Postgres. By default the projection in SRS 3857 (Spherical Mercator), but by passing --latlong to osm2pgsql it uses the expected projection SRS 4326 (Latlong).

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.