Friday, May 9, 2014

Making off-road transportation network using ArcGIS

Objective:

To create a off-road network (walking, off-road vehicle) from scratch and incorporate into traditional transportation network.

In order to model off-road transportation methods such as walking and driving off-road vehicle, the network dataset consists of traditional road network made by Navteq, horizontal, vertical, and diagonal line segment covering the whole extent.

Data:

Raster data for weighting (such as DEM, land cover)

Procedure:

Create "Fishnet" polygon to cover the target extent
Run Polygon to Raster with desired resolution
Run Raster to Point to create nodes for the network
Run Extract Values to Point to store raster values to points
Create a table containing pairs of coordinates to be connected
import arcpy
arcpy.env.overwriteOutput = 1 # enable overwriting

try:
    # load the point featrure class
    arcpy.env.workspace = arcpy.GetParameterAsText(0)
    #fc = "C:/Users/koitaroh/Docments/ArcGIS/Default.gdb/WeightPoint_Test"
    fc = arcpy.GetParameterAsText(1)
    outtable_path = arcpy.GetParameterAsText(2)
    
    class_field = "WeightPoint"
    fields = ["OBJECTID", "grid_code", "POINT_X", "POINT_Y"]
    xcoord = 0.0
    ycoord = 0.0
    # print("INITIALIZED")

    # create a insert cursor
    cursor2 = arcpy.da.InsertCursor(outtable_path, ("weight", "origin_x", "origin_y", "destination_x", "destination_y"))
    # create a search cursor
    # select * --- where x between a+10 and a-10m AND y between b+10m and b-10 (or 11m?)
    with arcpy.da.SearchCursor(fc, fields) as cursor1:
        for row in cursor1:
            weight = row[1]
            xcoord = row[2]
            ycoord = row[3]
            cursor2.insertRow((weight, xcoord+10, ycoord, xcoord, ycoord))
            cursor2.insertRow((weight, xcoord, ycoord+10, xcoord, ycoord))
            cursor2.insertRow((weight, xcoord-10, ycoord, xcoord, ycoord))
            cursor2.insertRow((weight, xcoord, ycoord-10, xcoord, ycoord))
            cursor2.insertRow((weight, xcoord+10, ycoord-10, xcoord, ycoord))
            cursor2.insertRow((weight, xcoord+10, ycoord+10, xcoord, ycoord))
            cursor2.insertRow((weight, xcoord-10, ycoord+10, xcoord, ycoord))
            cursor2.insertRow((weight, xcoord-10, ycoord-10, xcoord, ycoord))
            #rows = arcpy.da.SearchCursor(fc, "POINT_X" between x+10 and x-10 AND "POINT_Y" between y+10 and y-10 )
        del cursor1
        del cursor2
    # if the point is not same to the original
    

    # add row to a table

    # export as a table
    
except:
    print arcpy.GetMessages(2)
https://github.com/koitaroh/Workspace/blob/master/CreateIllicitGrid.py
Run XY to Line to create polyline feature

Join the weight attributes in the table to the polyline feature
Add and calculate attributes for length, and speed
Create a new network dataset and build it
Test the performance of the network dataset

Test walking network in Yuma County

Walking network prototype (red: shortest path, blue: most efficient path)