The problem becomes visible if the use_nodecache.py example is run with an osm file that contains nodes with negative ints.
» ./use_nodecache.py map_minimal.osm cache
Traceback (most recent call last):
File "/osmgj/./use_nodecache.py", line 31, in <module>
osmium.apply(reader, lh, WayHandler(idx))
File "/osmgj/./use_nodecache.py", line 17, in way
locations.append(idx.get(n.ref)) # note that cache is used here
^^^^^^^^^^^^^^
TypeError: get(): incompatible function arguments. The following argument types are supported:
1. (self: osmium.index.LocationTable, id: int) -> osmium.osm._osm.Location
Invoked with: <osmium.index.LocationTable object at 0x7f675e724170>, -138468
When using a fix positive nonexistent id like 100 a KeyError is raised.
To me it looks like the problem is here. The osmium lib uses unsigned integers and even ensures this with enable_if.
using LocationTable =
osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>;
using IndexFactory =
osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>;
py::class_<LocationTable>(m, "LocationTable")
.def("set", &LocationTable::set, py::arg("id"), py::arg("loc"))
.def("get", &LocationTable::get, py::arg("id"))
# Set up the OSM handler
node_cache = UnsingedLocationTableWrapper(osmium.index.create_map('flex_mem'))
handler_create_json = OSMHandler(node_cache)
> handler_read_node_cache = osmium.NodeLocationsForWays(node_cache)
E TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
E 1. osmium._osmium.NodeLocationsForWays(arg0: osmium::index::map::Map<unsigned long, osmium::Location>)
E
E Invoked with: <osmgj.UnsingedLocationTableWrapper object at 0x7f2586e1da90>
I have tried to use a python wrapper, but at some points the c/c++ structs are expected and my wrapping code is not accepted.
As Python only knows about ints and has not notion of unsigned and the osmium lib requires unsigned this library should do a conversion && check if the value is in the rage or raise a ValueError (too big/small).
Or offer some other mechanic to allow the usage of negative integers.
The problem becomes visible if the
use_nodecache.pyexample is run with an osm file that contains nodes with negative ints.When using a fix positive nonexistent id like 100 a
KeyErroris raised.To me it looks like the problem is here. The osmium lib uses unsigned integers and even ensures this with
enable_if.I have tried to use a python wrapper, but at some points the c/c++ structs are expected and my wrapping code is not accepted.
As Python only knows about ints and has not notion of unsigned and the osmium lib requires unsigned this library should do a conversion && check if the value is in the rage or raise a ValueError (too big/small).
Or offer some other mechanic to allow the usage of negative integers.