0

The coordinates from a line feature class are stored in a networkx multigraph differently. Some coordinates have 9 decimal places, others 10 decimal places. It seems to be random. I need a stable number of decimal places so that I can use the coordinates from a given list of stations as input parameters for the nx.shortest_path function.

# Create geopandas dataframe from geodatabase feature class
railroad= gdp.read_file(path_to_gdb, layer = 'railroad')

Multipart to singlepart linestring

railroad = railroad.explode()

Create network

G = momepy.gdf_to_nx(railroad, approach="primal")

print (G.nodes)

The coordinates of the nodes look like this

NodeView(((2682601.1939999983, 1248221.1190000102), (2683267.109000005, 1247948.7130000032), (2683347.7720000036, 1247916.077999998), (2682777.5089999996, 1250770.3490000032)...

Is there a way to control the precision of coordinates with networkx? Or even a better way to access the nodes than with the coordinates?

TobKug
  • 51
  • 5
  • I found the solution by using Shawn's function for rounding coordinates, https://gis.stackexchange.com/questions/321518/rounding-coordinates-to-five-decimals-in-geopandas – TobKug Oct 13 '23 at 13:10

0 Answers0