ArangoDB导入OSM路网失败求助:节点无法展开、无边缘显示
Hey there! Let’s get your OSM road network imported properly into ArangoDB so you can run those algorithm analyses. I’ll break this down into clear, actionable steps based on the osm-2-graph tool you’re using.
1. Pre-Import: Verify Your JSON Files
The osm-2-graph tool outputs JSON Lines (jsonl) format—each line is a separate node or edge document. Double-check your files:
nodes.json: Each line should look like{"_key": "1234", "lat": 43.73, "lon": 7.42, ...}edges.json: Each line must include_fromand_tofields pointing to node keys, e.g.,{"_key": "5678", "_from": "nodes/1234", "_to": "nodes/9012", "highway": "residential", ...}
If your files are wrapped in a top-level array ([{}, {}, ...]), you’ll need to convert them to jsonl first—arangoimp won’t parse array-format JSON correctly for bulk imports.
2. Create Database & Collections (Critical!)
Before importing, set up your database and collections in ArangoDB:
- Create a new database (e.g.,
monaco_osm) via the web UI or ArangoShell. - Create a vertex collection named
nodes(for OSM nodes). - Create an edge collection named
edges—this is non-negotiable! Edge collections are specifically designed to store relationships between vertices, and ArangoDB won’t recognize edges stored in regular collections.
You can also create collections directly via arangoimp using flags (see below), but doing it manually first helps avoid mistakes.
3. Run arangoimp Commands
Use these exact commands to import your files. Replace placeholders like your_password with your actual ArangoDB credentials, and adjust file paths as needed.
Import Nodes
arangoimp \ --file /path/to/your/nodes.json \ --collection nodes \ --type jsonl \ --server.database monaco_osm \ --server.username root \ --server.password your_password
Import Edges
The --create-collection-type edge flag is key here—it ensures the collection is treated as an edge collection:
arangoimp \ --file /path/to/your/edges.json \ --collection edges \ --type jsonl \ --server.database monaco_osm \ --server.username root \ --server.password your_password \ --create-collection-type edge
4. Validate the Import
After running the commands, confirm the data is correctly imported using ArangoShell:
- Check node count:
db.nodes.count() - Check edge count:
db.edges.count() - Verify edge references: Run a quick query to ensure edges point to existing nodes:
Look for validdb.edges.limit(5).toArray()_fromand_tovalues (e.g.,nodes/1234) that match node keys in thenodescollection.
5. Fix the Global Network View
If you still don’t see edges in the web UI’s network view:
- Open the Graphs section in the ArangoDB web UI.
- Create a new graph (e.g.,
monaco_road_network). - Add the
nodescollection as the vertex collection. - Add the
edgescollection as the edge collection (make sure it’s selected as an edge type). - Save the graph and open its network view—you should now see nodes connected by edges.
Common Pitfalls to Avoid
- Mismatched collection names: Ensure the
_from/_tovalues in edges exactly match the vertex collection name (e.g.,nodes/1234notnode/1234). - Incorrect file format: Always use
jsonltype for osm-2-graph outputs—arangoimp defaults to this, but double-check the--typeflag. - Permission issues: Make sure the user running
arangoimphas write access to the target database and collections.
内容的提问来源于stack exchange,提问作者user3478108

