Exemplo n.º 1
0
def get_route_distance(a_list, b_list, ND):
    distance_list = []
    arcpy.MakeRouteLayer_na(ND, route_f, "Length")
    for x1y1 in a_list:
        for x2y2 in b_list:
            try:
                route_leng = get_length_route([x1y1, x2y2])
            except:
                route_leng = 99999
            distance_list.append(route_leng)
    minimum_distance = min(distance_list)
    return minimum_distance
Exemplo n.º 2
0
def get_dist(points, current_id, buffer_id):
    if points[0] == points[
            1]:  # if both the snapped connecting node and the point being tested is the same
        return [], 0
    arcpy.MakeFeatureLayer_management(new_l, "newlf")
    arcpy.MakeRouteLayer_na(B1_ND, B1_route, "Length")
    # print current_id
    # print buffer_id
    point = arcpy.Point()
    pointGeometryList = []
    for pt in points:
        point.X = pt[0]
        point.Y = pt[1]
        pointGeometry = arcpy.PointGeometry(point).projectAs(sr_g)
        pointGeometryList.append(pointGeometry)
    arcpy.CopyFeatures_management(pointGeometryList, m)
    arcpy.AddLocations_na(B1_route, "Stops", m, "Name Name #", "", "", "",
                          "MATCH_TO_CLOSEST", "CLEAR", "NO_SNAP", "",
                          "INCLUDE", "")  # just in case
    try:
        arcpy.Solve_na(B1_route, "SKIP", "TERMINATE", "")
    except:
        return {}, 99999
    #arcpy.Solve_na(B1_route, "SKIP", "TERMINATE", "")

    arcpy.SelectData_management(B1_route, "Routes")
    arcpy.FeatureToLine_management(B1_route + "/Routes", feature, "",
                                   "ATTRIBUTES")
    arcpy.AddField_management(feature, "curr_id", "LONG")
    arcpy.AddField_management(feature, "buffer_id", "LONG")
    arcpy.CalculateField_management(feature, "curr_id", current_id, "PYTHON")
    arcpy.CalculateField_management(feature, "buffer_id", buffer_id, "PYTHON")
    arcpy.SelectLayerByLocation_management("newlf", "WITHIN", feature)
    _list_ = [f[0] for f in arcpy.da.SearchCursor("newlf", '_ID_')]
    return _list_, ([
        f[0] for f in arcpy.da.SearchCursor(feature, 'SHAPE@LENGTH', "", sr_p)
    ][0]) / 1604.34
Exemplo n.º 3
0
newoldnodesconversion = 'M:/RAIL/OngoingWork/new_old_node_conversion.csv'

o = "C:\\GIS\\o.shp"  #temporary files
d = "C:\\GIS\\d.shp"
m = "C:\\GIS\\m.shp"
temp = "C:\\GIS\\teemp.shp"
temp1 = "C:\\GIS\\teemp1.shp"
temp2 = "C:\\GIS\\teemp2.shp"

B1_ND = "M:/RAIL/OngoingWork/newconnections/railway_ln/Rail2_ND.nd"
feature = "M:/RAIL/OngoingWork/newconnections/intermediate/feature_unlocked.shp"  #i guess this is just a temporary layer/ no worries

arcpy.CheckOutExtension("Network")
arcpy.BuildNetwork_na(B1_ND)  #because the Rail2_ND file may have been changed
print("Network Rebuilt")
arcpy.MakeRouteLayer_na(B1_ND, "Route", "Length")

allnodes = Dbf5(all_nodes + '.dbf').to_dataframe()
Links_Final2 = Dbf5(linksfinal + '.dbf').to_dataframe()


#creates a dictionary of two columns
def get_dictionary(columnA, columnB, dataframe_name):
    dict = {}
    for i in range(len(Links_Final2)):
        dict[dataframe_name[columnA][i]] = []
        dict[dataframe_name[columnB][i]] = []
    for i in range(len(dataframe_name)):
        dict[dataframe_name[columnA][i]].append(dataframe_name[columnB][i])
        dict[dataframe_name[columnB][i]].append(dataframe_name[columnA][i])
    return dict
Exemplo n.º 4
0
new_n = new_nodes_shp
old_l = old_links_shp
new_l = new_links_clipped
old_ns = snapped_old_nodes
new_ngt = "../../RAIL11/RAIL/gis/allnodes.shp"
empty = "C:/gis/empty.shp"
empty_memory = "in_memory/e1"
memory_1 = "in_memory/m1"
memory_2 = "in_memory/m2"

arcpy.CopyFeatures_management(empty, empty_memory)

arcpy.env.overwriteOutput = True  # overwrite files if its already present
arcpy.CheckOutExtension("Network")
arcpy.BuildNetwork_na(B1_ND)
arcpy.MakeRouteLayer_na(B1_ND, B1_route, "Length")
arcpy.MakeFeatureLayer_management(new_l, "newlf")


# how far is the nearest node (old network)
def get_near_node_dict(nodelayer):
    arcpy.Project_management(nodelayer, temp1, arcpy.SpatialReference(102039))
    fid_id_dict = {
        row.getValue("FID"): row.getValue("_ID_")
        for row in arcpy.SearchCursor(temp1)
    }
    arcpy.Near_analysis(temp1, temp1)
    near_node_dict = {
        row.getValue("_ID_"):
        [row.getValue("NEAR_Fid"),
         row.getValue("NEAR_DIST") / 1609.34]
Exemplo n.º 5
0
StopCount = arcpy.GetCount_management(stops)
intCount = int(StopCount.getOutput(0))
lastRow = intCount - 1  #This is used to get the last FID row in the stops shapefile.

Query = """{0} = 0 or {0} = {1}""".format(
    arcpy.AddFieldDelimiters(stops, "FID"), lastRow
)  #Equates to "FID" = 0 or "FID" = N-1, where N = # of rows. This query is used to select origin/destination points.

stopsLayer = arcpy.MakeFeatureLayer_management(stops, "stops.lyr")
selectedStops = arcpy.SelectLayerByAttribute_management(
    "stops.lyr", "NEW_SELECTION", Query)
pointBarriers = outBarriersName

Route = arcpy.MakeRouteLayer_na(NetworkDataset, RouteName, "Length",
                                "USE_INPUT_ORDER", "PRESERVE_BOTH",
                                "NO_TIMEWINDOWS", "Length", "ALLOW_UTURNS",
                                "Oneway", "NO_HIERARCHY", "#",
                                "TRUE_LINES_WITH_MEASURES")

arcpy.AddLocations_na(Route, "Stops", selectedStops)
arcpy.AddLocations_na(Route, "Point Barriers", pointBarriers)
arcpy.Solve_na(Route, "SKIP")  #Skip invalid locations.

outRouteLayer = arcpy.SaveToLayerFile_management(
    Route, RouteName,
    "RELATIVE")  #Save route as layer file to user-specified location.
arcpy.AddMessage("Route layer created successfully. Route is located at:" +
                 " " + RouteName)

arcpy.CheckInExtension("Spatial")
Exemplo n.º 6
0
# uncomment the next line to overwrite existing files with output
#arcpy.env.overwriteOutput = True

# Check out the extension
arcpy.CheckOutExtension("Network")

# Define the variables. Check to make sure that the file paths match your own
busStops = r'C:\Projects\SanFrancisco.gdb\SanFrancisco\Bus_Stops'
networkDataset = r'C:\Projects\SanFrancisco.gdb\Chapter7Results\street_network'
networkLayer = "streetRoute"
impedance = "Length"
routeLayerFile = "C:\Projects\{0}.lyr".format(networkLayer)

# Make a route layer
arcpy.MakeRouteLayer_na(networkDataset, networkLayer, impedance)
print 'layer created'

# Search the bus stops feature class and add the geometry to the layer
sql = "NAME = '71 IB' AND BUS_SIGNAG = 'Ferry Plaza'"
with arcpy.da.SearchCursor(busStops, ['SHAPE@', 'STOPID'], sql) as cursor:
    for row in cursor:
        stopShape = row[0]
        print row[1]
        arcpy.AddLocations_na(networkLayer, 'Stops', stopShape, "", "")

# Solve the network layer
arcpy.Solve_na(networkLayer, "SKIP")

# Save the layer to file
arcpy.SaveToLayerFile_management(networkLayer, routeLayerFile, "RELATIVE")
Exemplo n.º 7
0
def solve_network(config_json):
    # This function creates a network dataset from a template,
    # builds the network, adds the nearest station points as stops,
    # and solves for the least-cost route

    # check network analyst license
    arcpy.CheckOutExtension("network")
    print('Network Analyst License Confirmed!')

    # set directory and path for network geodatabase
    config_data = read_config_json(config_json)
    project_dir = config_data['directories']['project_dir']
    save_dir = config_data['directories']['save_dir']
    direction_save_name = config_data['filenames']['direction_save_name']
    gdb_dir = project_dir + r'/Data'
    gdb_name = r'Bikeshare_GDB'
    gdb_path = gdb_dir + r'/' + gdb_name + r'.gdb'
    feature_dataset_name = 'Bikeshare'
    gdb_feature_path = gdb_path + r'/' + feature_dataset_name

    # set arcpy workspace
    arcpy.env.workspace = gdb_path

    # create network dataset from template
    arcpy.CreateNetworkDatasetFromTemplate_na(
        (project_dir + r'/Bikeshare_ND_template.xml'),      # network dataset template location
        gdb_feature_path                                    # feature dataset for network
    )

    # build network dataset
    arcpy.BuildNetwork_na(gdb_feature_path + r'/Bikeshare_ND')

    # create layer for least-cost route analysis
    arcpy.MakeRouteLayer_na(
        "Bikeshare_ND",             # input network dataset
        "Route",                    # output route analysis layer
        "Time",                     # impedance attribute
    )

    # add nearest station routing points
    arcpy.AddLocations_na(
        "Route",                    # input route analysis layer
        "Stops",                    # "Stops" analysis sub-layer
        "Bike_Stations_Intersect",  # input features table
        "Name Name #",              # field mapping
        "5000 Meters",              # search tolerance
        "ORIG_FID",                 # sort field
    )

    # solve the routing problem
    arcpy.Solve_na(
        "Route",                    # input route analysis layer
    )

    # export bike route as feature
    arcpy.FeatureClassToGeodatabase_conversion(
        r"Route\Routes",
        gdb_feature_path
    )

    print('Network Route Complete!')

    # export route directions
    arcpy.Directions_na(
        "Route",                                            # input route analysis layer
        "TEXT",                                             # export format
        (save_dir + r'/' + direction_save_name + r'.txt'),  # export path
        "Meters",                                           # distance units
        "REPORT_TIME",                                      # write travel time
        "Minutes"                                           # travel time units
    )
    print('Route Directions Exported!')
print("verificação variavéis ok")

# Listar inputs (lista de locais)

#talhao = arcpy.ListFeatureClasses("talhao*","point") 

talhao = arcpy.ListFeatureClasses()



for fc in talhao:

# Processo: Make Route Layer

	arcpy.MakeRouteLayer_na (network, "analise_rota", "Length", "FIND_BEST_ORDER", "PRESERVE_BOTH", "NO_TIMEWINDOWS", "", "ALLOW_UTURNS", "", "NO_HIERARCHY", "", "TRUE_LINES_WITH_MEASURES", "")
   


# Processo: adicionar locais

	#arcpy.AddLocations_na  ('analise_rota', "stops", fc, "", "5000 Meters", "", "estrada SHAPE;junction NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "estrada #;junction #")

	arcpy.AddLocations_na  ('analise_rota', "stops", fc, "", "5000 Meters", "",[["estrada","SHAPE"],["junction","NONE"]], "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "estrada #;junction #")

	
# Processo : checkout de extensão

	arcpy.CheckOutExtension("Network")

# Processo : Solve
Exemplo n.º 9
0
# Created on: 2018-05-09 13:15:55.00000
#   (generated by ArcGIS/ModelBuilder)
# Usage: model_script <Route__3_> 
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy

# Local variables:
Navigation_ND = "U:\\GEOG_469\\Routing.gdb\\Navigation\\Navigation_ND"
POI = "U:\\GEOG_469\\Routing.gdb\\POI"
Solve_Succeeded = "true"

# Process: Make Route Layer
arcpy.MakeRouteLayer_na(Navigation_ND, "Route", "Walktime", "FIND_BEST_ORDER", "PRESERVE_BOTH", "NO_TIMEWINDOWS", "", "ALLOW_UTURNS", "'Avoid High';'Prefer Low';'Avoid Medium'", "NO_HIERARCHY", "", "TRUE_LINES_WITH_MEASURES", "")

# Process: Convert InteriorSpace_Points feature class to a layer
arcpy.MakeFeatureLayer_management(POI, "classrooms")

# Create a new geodatabase in your folder
# Process: Convert Merged Schedule Excel Table to a Table in ArcMap
arcpy.env.workspace = "U:\GEOG_469"
arcpy.ExcelToTable_conversion("schedule_ID_excel.xlsx","schedule.dbf")

#IMPORTANT!!!! manually add field to schedule table, name the field as "walk_time".

# Process: Get a list of Sorted and Paired Classroom ID
spaceID_list = [r[0] for r in arcpy.da.SearchCursor("schedule", "space")]

walktime_list = []
Exemplo n.º 10
0
import pandas

arcpy.env.overwriteOutput = True

ND = "./output/highway_ln1_ND.nd"
snapped_dumm = "C:/GIS/dumm.shp"
fips = 'C:/Users/pankaj/Desktop/RAIL/gis/standards/FIPS.shp'
alllinks = "./output/highway_ln1.shp"
feature = "C:/GIS/feature.shp"  # i guess this is just a temporary layer/ no worries

arcpy.Copy_management(fips, snapped_dumm)

# snap FIPS to nearest links
arcpy.Snap_edit(snapped_dumm, [[alllinks, "EDGE", "100 Miles"]])
arcpy.MakeRouteLayer_na(
    ND, "Route", "resist"
)  # update the network dataset if required (this is not required generally)

# temporary files
m = "C:/GIS/m.shp"
sr = arcpy.SpatialReference(102005)


#make arrangements for both distance and time
def get_dist_AB(fips_a, fips_b):
    arcpy.Select_analysis(snapped_dumm, m,
                          'FIPS = {0} OR FIPS = {1}'.format(fips_a, fips_b))
    arcpy.AddLocations_na("Route", "Stops", m, "Name Name #",
                          "5000 Kilometers", "",
                          "B1 SHAPE;B1_ND_Junctions SHAPE", "MATCH_TO_CLOSEST",
                          "CLEAR", "NO_SNAP", "5 Meters", "INCLUDE",