I have some 3D linestrings in a postgis database, and I want to use pgrouting for calculating the shortest path with Dijkstra.

When I execute select pgr_createTopology('route2', 0.000001, 'geo3d', 'id'); , there is the error:

Geometry has Z dimension but column does not

How can I create topology with 3d linestring by pgrouting?


You can easily clone the pgr_createTopology() and create a pgr_createTopology3D() function and clone pgr_pointToId() and make pgr_pointToId3D() that supports what you want. I have done this in the past for a project that needed z-level support at intersections.

pgr_createTopology() assigns a unique ID to each node based on a tolerance distance to determine if the node is the same as another. The test and assignment are done in the call to pgr_pointToId() which you need to change to call pgr_pointToId3D() and then pgr_pointToId3D() just needs to be modified for use ST_Distance3D().


Far as i know. PgRouting uses only 2d geoms and error you mentioned comes because somewhere there is temp table or results table uses 2d geom column. To get 3d support you probably need to write your own code which created similiar edge and node tables but instead of using 2d function you need to use 3d functions.

Again. Far as i know, things may have changed in past few years. You can create mentioned edge table by yourself using extracting start and endpoint and comparing them to other lines start and endpoints, but instead of using ST_DWithin (like old assign_vertex (postgis 1.5 i think) tool used to do) you use ST_3DDWithin()

Or solution is simple and you just need to alter 'route2' table (or results table, i think it still is 'route2' table) geometry column to use geomz, but pgr_CreateTopology probably created data using only 2d information , which is no problem if your data doesn't have overlapping start and endpoints in 3d, if you have then you have a problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.