Custom cropping and generation of OSM map layers, however, the graphHopper program encountered an exception when parsing the map

Dear sir/miss,
To reduce memory consumption when loading map layers, I want to customize and crop the OpenStreetMap map, such as extracting only the railway network, deleting other layers such as buildings and roads, and saving only the railway network layer as an osm.pbf format file. I started from https://download.geofabrik.de/ The website downloaded a shapefile compressed package in the format of. shp.zip. After decompression, many layer files were obtained, such as GIS_ Osm_ Water_ A_ Free_ 1. SHP, GIS_ Osm_ Roads_ Free_ 1. SHP, GIS_ Osm_ Traffic_ Free_ 1. SHP, GIS_ Osm_ Buildings_ A_ Free_ 1. SHP and others, I only extract GIS_ Osm_ Roads_ Free_ 1. SHP layer data can be opened and displayed normally through ArcGIS and JOMS software. I load GIS through JOSM_ Osm_ Roads_ Free_ 1. Successfully saved as GIS after shp_ Osm_ Roads_ Free_ 1. OSM.PBF format file. However, the graphHopper program was unable to load the map data file with the following error:

2023-09-18 14:56:22.528 [main] INFO com.graphhopper.GraphHopper - version 8.0|2023-09-04T02:43:13Z (9,21,6,5,2,9)
2023-09-18 14:56:23.173 [main] INFO com.graphhopper.GraphHopper - No custom areas are used, custom_areas.directory not given
2023-09-18 14:56:23.189 [main] INFO com.graphhopper.GraphHopper - No country rules available
2023-09-18 14:56:23.189 [main] INFO com.graphhopper.GraphHopper - start creating graph from E:\code\c\graphhopper\data\gis_osm_railways_free_1.osm.pbf
2023-09-18 14:56:23.240 [main] INFO com.graphhopper.GraphHopper - using car|RAM_STORE|2D|no_turn_cost|nodes:9,edges:21,geometry:6,location_index:5,string_index:2,nodesCH:0,shortcuts:9, memory:totalMB:252, usedMB:15
2023-09-18 14:56:23.267 [main] INFO c.g.reader.osm.WaySegmentParser - Start reading OSM file: ‘E:\code\c\graphhopper\data\gis_osm_railways_free_1.osm.pbf’
2023-09-18 14:56:23.267 [main] INFO c.g.reader.osm.WaySegmentParser - pass1 - start
2023-09-18 14:56:23.906 [main] INFO c.g.reader.osm.WaySegmentParser - pass1 - finished, processed ways: 0, accepted ways: 0, way nodes: 0, relations: 0, totalMB:252, usedMB:159
Exception in thread “main” java.lang.RuntimeException: Could not parse OSM file: E:\code\c\graphhopper\data\gis_osm_railways_free_1.osm.pbf
at com.graphhopper.reader.osm.WaySegmentParser.readOSM(WaySegmentParser.java:406)
at com.graphhopper.reader.osm.WaySegmentParser.readOSM(WaySegmentParser.java:98)
at com.graphhopper.reader.osm.OSMReader.readGraph(OSMReader.java:177)
at com.graphhopper.GraphHopper.importOSM(GraphHopper.java:946)
at com.graphhopper.GraphHopper.process(GraphHopper.java:884)
at com.graphhopper.GraphHopper.importOrLoad(GraphHopper.java:832)
at com.graphhopper.example.RoutingExample.createGraphHopperInstance(RoutingExample.java:47)
at com.graphhopper.example.RoutingExampleTest.main(RoutingExampleTest.java:66)
Caused by: java.lang.RuntimeException: Unable to read PBF file.
at com.graphhopper.reader.osm.pbf.PbfReader.close(PbfReader.java:66)
at com.graphhopper.reader.osm.OSMInputFile.close(OSMInputFile.java:241)
at com.graphhopper.reader.osm.WaySegmentParser.readOSM(WaySegmentParser.java:405)
… 7 more
Caused by: java.lang.RuntimeException: A PBF decoding worker thread failed, aborting.
at com.graphhopper.reader.osm.pbf.PbfDecoder.sendResultsToSink(PbfDecoder.java:88)
at com.graphhopper.reader.osm.pbf.PbfDecoder.processBlobs(PbfDecoder.java:152)
at com.graphhopper.reader.osm.pbf.PbfDecoder.run(PbfDecoder.java:162)
at com.graphhopper.reader.osm.pbf.PbfReader.run(PbfReader.java:52)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalArgumentException: Invalid OSM WAY Id: -664707; Ids must not be negative
at com.graphhopper.reader.ReaderElement.(ReaderElement.java:51)
at com.graphhopper.reader.ReaderElement.(ReaderElement.java:46)
at com.graphhopper.reader.ReaderWay.(ReaderWay.java:32)
at com.graphhopper.reader.osm.pbf.PbfBlobDecoder.processWays(PbfBlobDecoder.java:254)
at com.graphhopper.reader.osm.pbf.PbfBlobDecoder.processOsmPrimitives(PbfBlobDecoder.java:337)
at com.graphhopper.reader.osm.pbf.PbfBlobDecoder.runAndTrapExceptions(PbfBlobDecoder.java:350)
at com.graphhopper.reader.osm.pbf.PbfBlobDecoder.run(PbfBlobDecoder.java:362)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
… 1 more

企业微信截图_16950215712707

This issue has been bothering me for a long time, and I look forward to your help and reply.

JOSM produces negative OSM IDs which GraphHopper cannot handle. The easiest you can do is probably downloading a pbf extract from geofabrik (instead of the shapefile) and use Osmosis or Osmium to remove everything except the railway network. Or actually just try without manipulating the file at all.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.