I have problems trying to extract the osm area from an "openstreetmap" file and using "osm_import":
"osm_import" works fine when using an osm file extracted from the "openstreetmap" website but... does not work when using "osmosis" to extract the area you want to use, from a pbf file (download.geofabrik.de / large area data)
- because when doing so, "Osmosis" cuts the data according to the coordinates you request but does not check that the "node_id" data needed to use the "way" expression is in the truncated part of the file! which means that the resulting file does not contain some "node_id" variables which make "osm_import" announce an error: "Invalid source /obj/geo1/osm_import1/read_in_map_data.
(Error: Python error: Traceback (most recent call last):
File "", line 329, in
File "", line 190, in build
KeyError: '4355555387'
). "
A solution would probably be to check that "node_id" exists when "way" needs it and if "not" ignore this data and move on to the next one?
The code is in python and should be "easily" modifiable by a programmer...but I am not a python programmer! Thanks for any help!
SideFxLabs - osm_import bug ?
575 1 0- oniregoc
- Member
- 5 posts
- Joined: May 2024
- Offline
- oniregoc
- Member
- 5 posts
- Joined: May 2024
- Offline
Hello ! found the solution !
at line 192 until line "polys = poly" replace code by :
Hope it help someone !
at line 192 until line "polys = poly" replace code by :
for node_id in way.nodes: try: node_id print(node_id) node = self.nodes[node_id] pos_xy = self.get_relative_coordinates([float(node.lat), float(node.lon)]) positions.append((pos_xy[0], 0, pos_xy[1])) latlongs.append([float(node.lat), float(node.lon)]) points = geo.createPoints(positions) poly = geo.createPolygon() for x, point in enumerate(points): point.setAttribValue("latitude", latlongs[x][0]) point.setAttribValue("longitude", latlongs[x][1]) if ONLY_CLOSE_BUILDING_SHAPES: if "building" not in way.tags and "buildingpart" not in way.tags and "building_part" not in way.tags: poly.setIsClosed(0) else: if not closed: poly.setIsClosed(0) if READ_BUILDING_COLORS: if "buildingcolour" in way.tags: rgb = QColor(way.tags["buildingcolour"]) Cd = [rgb.red()/255.0, rgb.green()/255.0,rgb.blue()/255.0] poly.setAttribValue("Cd", Cd ) poly.setAttribValue("hou_id", way.id) poly.setAttribValue("hou_way", 1) for tag in way.tags: clean_value = way.tags[tag] try: if tag == "name": poly.setAttribValue("hou_name", clean_value) else: poly.setAttribValue(tag, clean_value) except: pass for point in points: poly.addVertex(point) polys[way.id] = poly except: pass
Hope it help someone !
-
- Quick Links