Create Network Dataset#

How to create network Dataset. Add some description here

import ast, os
import pandas as pd
import networkx as nx

from pyincore import IncoreClient, DataService, Dataset, NetworkDataset, NetworkUtil
client = IncoreClient()
datasvc = DataService(client)

Upload/Create Network Datasets to Data Services#

This example shows how to create network dataset by uploading a link shapefile and a node shapefile

Prerequisite#

  • meta data is json text descrbing the network dataset component

  • node file is a shapefile that contains node information of the network.

  • link file is a shapefile that contains the link information. This should include fromnode and tonode information.

  • graph file is a csv file that contains the network relationship between the link and node.

dataset_prop = {
  "title": "Test epn network",
  "dataType": "incore:epnNetwork",
  "format": "shp-network",
  "networkDataset": {
    "link": {
      "dataType": "ergo:powerLineTopo",
      "fileName": "epn_links.shp"
    },
    "node": {
      "dataType": "incore:epf",
      "fileName": "epn_nodes.shp"
    },
    "graph": {
      "dataType": "incore:networkGraph",
      "fileName": "network_graph.csv"
    }
  }
}

response = datasvc.create_dataset(dataset_prop)

if 'id' not in response:
    print("Failed to create a dataset in the data service")
else:
    dataset_id = response['id']

    print('network dataset is created with id ' + dataset_id)
    print('attching files to created dataset')

    file_dir = os.path.join(os.getcwd(), 'files')

    files = ['epn_links.shp',
             'epn_links.dbf',
             'epn_links.shx',
             'epn_links.prj',
             'epn_nodes.shp',
             'epn_nodes.dbf',
             'epn_nodes.shx',
             'epn_nodes.prj',
             'network_graph.csv']
    linkname = dataset_prop["networkDataset"]["link"]["fileName"]
    nodename = dataset_prop["networkDataset"]["node"]["fileName"]
    graphname = dataset_prop["networkDataset"]["graph"]["fileName"]

    response = datasvc.add_files_to_network_dataset(dataset_id, files, nodename, linkname, graphname)
    dataset = Dataset.from_data_service(response["id"], data_service=datasvc)