pyrosm icon indicating copy to clipboard operation
pyrosm copied to clipboard

Decoded coordinates do not match OSM map

Open tpwrules opened this issue 6 months ago • 0 comments

Describe the bug Coordinates decoded from a .pbf file are ~0.1m off from those in the OSM database and those decoded by other programs.

To Reproduce Steps to reproduce the behavior:

  1. Load a file
  2. Examine a point feature's coordinate
  3. Note that it's off in sixth decimal place compared to what OSM and GDAL say for the same file

Expected behavior I expect the coordinates to be decoded and reproduced in Python exactly.

Environment:

  • OS: Ubuntu
  • Python package source (PyPi, conda, ...): custom build with Nix
  • Versions of Python, Java Development Kit, Python modules: v0.6.2 and master, geopandas v1.0.1, GDAL 3.9.3

Test data and/or script/notebook

Using this small PBF downloaded from BBBike extractor: pyrosm_test.pbf.zip and examining arbitrary node 623850466 (though this happens with all the ones in the file and all the points in other files I've looked at)

API response at the time of writing:

<osm version="0.6" generator="openstreetmap-cgimap 2.0.1 (2703706 spike-06.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
<node id="623850466" visible="true" version="6" changeset="147037319" timestamp="2024-02-03T23:36:42Z" user="Gamer2000" uid="13929699" lat="26.0914866" lon="-80.4410082">
<tag k="power" v="tower"/>
</node>
</osm

GDAL output:

$ ogrinfo pyrosm_test.pbf points | grep -A 3 623850466
OGRFeature(points):623850466
  osm_id (String) = 623850466
  other_tags (String) = "power"=>"tower"
  POINT (-80.4410082 26.0914866)

GDAL through geopandas output:

import geopandas as gpd
d = gpd.read_file("pyrosm_test.pbf", layer="points")
print(list(list(d[d["osm_id"] == "623850466"]["geometry"])[0].coords)[0][::-1])
# prints (26.091486600000003, -80.4410082)

pyrosm output

from pyrosm import OSM
osm = OSM("pyrosm_test.pbf")
d = osm.get_data_by_custom_criteria({"power": ["tower"]}, filter_type="keep", keep_nodes=True)
print(list(list(d[d["id"] == 623850466]["geometry"])[0].coords)[0][::-1])
# prints (26.09148597717285, -80.44100952148438)

GDAL both through CLI and through geopandas matches the official API with the same file (and at the documented seven decimal precision) whereas pyrosm is inexplicably off in the second to last digit and displays the false impression of much more precision.

tpwrules avatar Jun 28 '25 23:06 tpwrules