tomalrussell / snkit

spatial networks toolkit (python)
MIT License
31 stars 10 forks source link

network.to_file and network.from_file methods #47

Closed thomas-fred closed 1 year ago

thomas-fred commented 2 years ago

Some way of serializing a network to and from disk?

tomalrussell commented 2 years ago

Suggest a thin wrapper over geopandas.GeoDataFrame.to_file / geopandas.read_file with conventional layer names of nodes and edges for the two dataframes:

def to_file(network, fname):
  network.nodes.to_file(fname, layer='nodes')
  network.edges.to_file(fname, layer='edges')

def read_file(fname):
  nodes = geopandas.read_file(fname, layer='nodes')
  edges = geopandas.read_file(fname, layer='edges')
  return Network(nodes, edges)
thomas-fred commented 2 years ago

Yep that looks good to me. Maybe pass through kwargs to the geopandas methods, too?

It's a shame that parquet files don't seem to have a layer concept. I've been using them in open-gira, but having to write nodes and edges to separate files.

tomalrussell commented 1 year ago

Closed by 4be5de2