Importing and Exporting Systems

Importing and Exporting Systems#

  1. All Infrasys systems can be serialized and deserialized using the to_json and from_json methods.

  2. The DistributionSystem class can also be exported to GeoDataFrame and GeoJSON formats using the to_gdf and to_geojson methods.

We start by loading a sample distribution system.

from gdm.distribution import DistributionSystem
from gdmloader.constants import GCS_CASE_SOURCE
from gdmloader.source import SystemLoader

gdm_loader = SystemLoader()
gdm_loader.add_source(GCS_CASE_SOURCE)

distribution_system: DistributionSystem = gdm_loader.load_dataset(
    source_name=GCS_CASE_SOURCE.name,
    system_type=DistributionSystem,
    dataset_name="p5r",
)
distribution_system.name = "P5R"

The DistributionSystem can be serialized to disk using the to_json method. If the model already exists, set the overwrite parameter to True. Serialization ensures no loss of information. The JSON file can be deserialized using the from_json method.

distribution_system.to_json("test.json", overwrite=True)
system = DistributionSystem.from_json("test.json")

The DistributionSystem can also be exported in GeoDataFrame and GeoJSON formats.

Warning

Limited model information is exported in these formats. Model deserialization is not supported for these formats.

system.to_gdf(“test.csv”) system.to_geojson(“test.geojson”)

system.to_gdf("test.csv")
system.to_geojson("test.geojson")
2025-10-28 17:31:15.754 | INFO     | gdm.distribution.distribution_system:to_geojson:577 - Exporting GeoJSON to test.geojson