def CreateGeometricNetwork(dataset, nome, netFeatures, tolerance): try: arcpy.CreateGeometricNetwork_management(dataset, nome, netFeatures, tolerance) print u"Rede Geometrica criada com sucesso" except Exception as ex: print u"ERRO GN:", nome, ex.message
def StreetNetworkCheck(): print checkfile arcpy.env.workspace = checkfile print topo geonet = fd + "\Street_Network" #print geonet if arcpy.Exists(geonet): print "Street Geometric Network Already Exists" else: arcpy.RemoveFeatureClassFromTopology_management(topo, "RoadCenterline") arcpy.CreateGeometricNetwork_management( fd, "Street_Network", "RoadCenterline SIMPLE_EDGE NO", "#", "#", "#", "#", "#") arcpy.FindDisconnectedFeaturesInGeometricNetwork_management( fd + "/RoadCenterline", "Roads_Disconnected") StreetLogfile = reviewpath + "/KDOTReview/" + ntpath.basename( ng911) + ".log" arcpy.VerifyAndRepairGeometricNetworkConnectivity_management( geonet, StreetLogfile, "VERIFY_ONLY", "EXHAUSTIVE_CHECK", "0, 0, 10000000, 10000000")
def recheck_orientation(self, geometry_name, geometry_folder, networkLine): arcpy.env.overwriteOutput = True geodatabaseTopage = geodatabase() geodatabasePath = geodatabaseTopage.path(geometry_folder) print("Recréation du réseau géométrique") if arcpy.Exists(geodatabasePath + "/" + networkLine + "_BUILDERR"): arcpy.Delete_management(geodatabasePath + "/" + networkLine + "_BUILDERR") arcpy.Delete_management(geometry_folder + geometry_name) arcpy.CreateGeometricNetwork_management( geometry_folder, geometry_name, networkLine + " SIMPLE_EDGE NO;" + networkLine + "_summit SIMPLE_JUNCTION YES", "0.001", "#", "#", "#", "PRESERVE_ENABLED") print("Ajout de l'exutoire") arcpy.MakeFeatureLayer_management( geometry_folder + networkLine + "_summit", 'lyr') arcpy.SelectLayerByLocation_management( 'lyr', 'INTERSECT', geometry_folder + networkLine + "_Exutoire") arcpy.CalculateField_management('lyr', 'AncillaryRole', "2", "PYTHON_9.3", "#") arcpy.SelectLayerByAttribute_management('lyr', "CLEAR_SELECTION") arcpy.Delete_management("lyr") print("Calcul du sens d'écoulement") arcpy.SetFlowDirection_management(geometry_folder + geometry_name, "WITH_DIGITIZED_DIRECTION") arcpy.TraceGeometricNetwork_management( geometry_folder + "/" + geometry_name, geometry_name, geometry_folder + networkLine + "_Exutoire", "TRACE_UPSTREAM") arcpy.MakeFeatureLayer_management( geometry_folder + networkLine + "_notUpstream", 'lyr_notUpstream') return arcpy.GetCount_management('lyr_notUpstream').__str__()
for fd in fds: #------------------------------------------------------------------------------- #Make Water Geom Network if (fd == wFDS): print 'Making ' + wFDS + ' Geom Net' ##arcpy.AddMessage('Making Geom Net for: ' + wFDS) logging.info('Making Geom Net for: ' + wFDS) in_feature_dataset = wFDS out_name = wFDS + '_Net' in_source_feature_classes = water_in_source_features arcpy.CreateGeometricNetwork_management( in_feature_dataset, out_name, in_source_feature_classes, snap_tolerance, weights, weight_associations, z_snap_tolerance, preserve_enabled_values) ##arcpy.AddMessage('Made Geom Net for: ' + wFDS) print 'Made Geom Net for: ' + wFDS ##logging.info('Made Geom Net for: ' + wFDS) #------------------------------------------------------------------------------- #Make Recycled Geom Network elif (fd == rFDS): print 'Making ' + rFDS + ' Geom Net' ##arcpy.AddMessage('Making Geom Net for: ' + rFDS) logging.info('Making Geom Net for: ' + rFDS) in_feature_dataset = rFDS
def makeGeom(featureDataset): try: arcpy.AddMessage('Making Geom Net for: ' + featureDataset) #print 'Making Geom Net for: ' + featureDataset # WATER GEOM NETWORK if featureDataset == nameOfWaterDataset: #Make Water Geom Network print 'Making ' + featureDataset + ' Geom Net' in_feature_dataset = featureDataset out_name = 'Water_Net' in_source_feature_classes = 'wControlValve SIMPLE_JUNCTION NO;wFitting SIMPLE_JUNCTION NO;wHydrant SIMPLE_JUNCTION NO;wMain COMPLEX_EDGE NO;wMeter SIMPLE_JUNCTION NO;wPump SIMPLE_JUNCTION NO;wService COMPLEX_EDGE NO;wSystemValve SIMPLE_JUNCTION NO' snap_tolerance = snapTolerance weights = '' weight_associations = '' z_snap_tolerance = '' preserve_enabled_values = preserveEnabled arcpy.CreateGeometricNetwork_management( in_feature_dataset, out_name, in_source_feature_classes, snap_tolerance, weights, weight_associations, z_snap_tolerance, preserve_enabled_values) arcpy.AddMessage('Made Water Geom Net') print 'Made Water Geom Net' # RECYCLED GEOM NETWORK elif featureDataset == nameOfRecycledDataset: #Make Recycled Geom Network print 'Making ' + featureDataset + ' Geom Net' in_feature_dataset = featureDataset out_name = 'Recycled_Net' in_source_feature_classes = 'rControlValve SIMPLE_JUNCTION NO;rFitting SIMPLE_JUNCTION NO;rMain COMPLEX_EDGE NO;rMeter SIMPLE_JUNCTION NO;rPump SIMPLE_JUNCTION NO;rService COMPLEX_EDGE NO;rSystemValve SIMPLE_JUNCTION NO' snap_tolerance = snapTolerance weights = '' weight_associations = '' z_snap_tolerance = '' preserve_enabled_values = preserveEnabled arcpy.CreateGeometricNetwork_management( in_feature_dataset, out_name, in_source_feature_classes, snap_tolerance, weights, weight_associations, z_snap_tolerance, preserve_enabled_values) arcpy.AddMessage('Made Recycled Geom Net') print 'Made Recycled Geom Net' # SEWER GEOM NETWORK elif featureDataset == nameOfSewerDataset: #Make Sewer Geom Network print 'Making ' + featureDataset + ' Geom Net' in_feature_dataset = featureDataset out_name = 'Sewer_Net' in_source_feature_classes = 'ssCleanOut SIMPLE_JUNCTION YES;ssControlValve SIMPLE_JUNCTION YES;ssFitting SIMPLE_JUNCTION YES;ssGravityMain COMPLEX_EDGE NO;ssLateral COMPLEX_EDGE NO;ssManhole SIMPLE_JUNCTION YES;ssPressurizedMain COMPLEX_EDGE NO;ssPump SIMPLE_JUNCTION YES;ssServiceConnection SIMPLE_JUNCTION NO;ssSystemValve SIMPLE_JUNCTION YES' snap_tolerance = snapTolerance weights = '' weight_associations = '' z_snap_tolerance = '' preserve_enabled_values = preserveEnabled arcpy.CreateGeometricNetwork_management( in_feature_dataset, out_name, in_source_feature_classes, snap_tolerance, weights, weight_associations, z_snap_tolerance, preserve_enabled_values) arcpy.AddMessage('Made Sewer Geom Net') print 'Made Sewer Geom Net' except: arcpy.AddMessage('FAILED to create Geom net for ' + featureDataset) print 'FAILED to create Geom net for ' + featureDataset
def transport_spatial_validation(estamap_version, with_patch=False): logging.info('environment') em = gis.ESTAMAP(estamap_version) arcpy.env.XYTolerance = '0.01 Meters' fgdb_name = 'TransportSpatialValidation_{}.gdb'.format('withPatch' if with_patch else 'exclPatch') fgdb = os.path.join(em.path, 'Routing', fgdb_name) if not os.path.exists(os.path.join(em.path, 'Routing')): logging.info('creating Routing folder: {}'.format(os.path.join(em.path, 'Routing'))) os.makedirs(os.path.join(em.path, 'Routing')) logging.info('creating fgdb: {}'.format(os.path.join(em.path, 'Routing', fgdb_name))) if arcpy.Exists(os.path.join(em.path, 'Routing', fgdb_name)): arcpy.Delete_management(os.path.join(em.path, 'Routing', fgdb_name)) arcpy.CreateFileGDB_management(out_folder_path=os.path.join(em.path, 'Routing'), out_name=fgdb_name) logging.info('creating feature dataset') arcpy.CreateFeatureDataset_management(out_dataset_path=os.path.join(em.path, 'Routing', fgdb_name), out_name='FD', spatial_reference=arcpy.SpatialReference(3111)) logging.info('importing ROAD') arcpy.FeatureClassToFeatureClass_conversion(in_features=os.path.join(em.sde, 'ROAD'), out_path=os.path.join(em.path, 'Routing', fgdb_name, 'FD'), out_name='ROAD') road_count = arcpy.GetCount_management(os.path.join(em.path, 'Routing', fgdb_name, 'FD', 'ROAD')).getOutput(0) logging.info('ROAD records: {}'.format(road_count)) logging.info('importing ROAD_INFRASTRUCTURE') arcpy.FeatureClassToFeatureClass_conversion(in_features=os.path.join(em.sde, 'ROAD_INFRASTRUCTURE'), out_path=os.path.join(em.path, 'Routing', fgdb_name, 'FD'), out_name='ROAD_INFRASTRUCTURE') road_infrastructure_count = arcpy.GetCount_management(os.path.join(em.path, 'Routing', fgdb_name, 'FD', 'ROAD_INFRASTRUCTURE')).getOutput(0) logging.info('ROAD_INFRASTRUCTURE records: {}'.format(road_infrastructure_count)) in_source_feature_classes = 'ROAD SIMPLE_EDGE NO;ROAD_INFRASTRUCTURE SIMPLE_JUNCTION NO' if with_patch: in_source_feature_classes = in_source_feature_classes + ';ROAD_PATCH SIMPLE_EDGE NO' logging.info('importing ROAD_PATCH') arcpy.FeatureClassToFeatureClass_conversion(in_features=os.path.join(em.sde, 'ROAD_PATCH'), out_path=os.path.join(em.path, 'Routing', fgdb_name, 'FD'), out_name='ROAD_PATCH', where_clause='"MERGE_TRANSPORT" = 1') road_patch_count = arcpy.GetCount_management(os.path.join(em.path, 'Routing', fgdb_name, 'FD', 'ROAD_PATCH')).getOutput(0) logging.info('ROAD_PATCH records: {}'.format(road_patch_count)) ## logging.info('importing ROAD_INFRASTRUCTURE_PATCH') ## arcpy.MakeFeatureLayer_management(in_features=os.path.join(em.sde, 'ROAD_INFRASTRUCTURE_PATCH'), ## out_layer='in_memory\\road_infrastructure_patch_layer', ## where_clause='"MERGE_TRANSPORT" = 1') ## arcpy.FeatureClassToFeatureClass_conversion(in_features='in_memory\\road_infrastructure_patch_layer', ## out_path=os.path.join(em.path, 'Routing', fgdb_name, 'FD'), ## out_name='ROAD_INFRASTRUCTURE_PATCH') logging.info('creating geometric network: {}'.format(os.path.join(em.path, 'Routing', fgdb_name, 'FD', 'geonet'))) arcpy.CreateGeometricNetwork_management(in_feature_dataset=os.path.join(em.path, 'Routing', fgdb_name, 'FD'), out_name='geonet', in_source_feature_classes=in_source_feature_classes, preserve_enabled_values='PRESERVE_ENABLED') ## arcpy.AddEdgeEdgeConnectivityRuleToGeometricNetwork_management(in_geometric_network=os.path.join(em.path, 'Routing', fgdb_name, 'FD', 'geonet'), ## in_from_edge_feature_class="ROAD", ## from_edge_subtype="ROAD", ## in_to_edge_feature_class="ROAD", ## to_edge_subtype="ROAD", ## in_junction_subtypes="'ROAD_INFRASTRUCTURE : ROAD_INFRASTRUCTURE'", ## default_junction_subtype="ROAD_INFRASTRUCTURE : ROAD_INFRASTRUCTURE") ## ## arcpy.AddEdgeJunctionConnectivityRuleToGeometricNetwork_management(in_geometric_network=os.path.join(em.path, 'Routing', fgdb_name, 'FD', 'geonet'), ## in_edge_feature_class="ROAD", ## edge_subtype="ROAD", ## in_junction_feature_class="ROAD_INFRASTRUCTURE", ## junction_subtype="ROAD_INFRASTRUCTURE", ## default_junction="DEFAULT", ## edge_min="", ## edge_max="", ## junction_min="", ## junction_max="") ## ## # DC by: find dc function ## ## logging.info('finding disconnected: ROAD') ## arcpy.FindDisconnectedFeaturesInGeometricNetwork_management(in_layer=os.path.join(em.path, 'Routing', fgdb_name, 'FD', 'ROAD'), ## out_layer='in_memory\\ROAD_disconnected') ## if arcpy.Exists('in_memory\\ROAD_disconnected'): ## fdc_road_count = arcpy.GetCount_management('in_memory\\ROAD_disconnected').getOutput(0) ## logging.info('found ROAD disconnected: {}'.format(fdc_road_count)) ## ## arcpy.FeatureClassToFeatureClass_conversion(in_features='in_memory\\ROAD_disconnected', ## out_path=os.path.join(em.path, 'Routing', fgdb_name), ## out_name='ROAD_disconnected') ## ## logging.info('finding disconnected: ROAD_INFRASTRUCTURE') ## arcpy.FindDisconnectedFeaturesInGeometricNetwork_management(in_layer=os.path.join(em.path, 'Routing', fgdb_name, 'FD', 'ROAD_INFRASTRUCTURE'), ## out_layer='in_memory\\ROAD_INFRASTRUCTURE_disconnected') ## if arcpy.Exists('in_memory\\ROAD_INFRASTRUCTURE_disconnected'): ## fdc_road_infrastructure_count = arcpy.GetCount_management('in_memory\\ROAD_INFRASTRUCTURE_disconnected').getOutput(0) ## logging.info('found ROAD_INFRASTRUCTURE disconnected: {}'.format(fdc_road_infrastructure_count)) ## ## arcpy.FeatureClassToFeatureClass_conversion(in_features='in_memory\\ROAD_INFRASTRUCTURE_disconnected', ## out_path=os.path.join(em.path, 'Routing', fgdb_name), ## out_name='ROAD_INFRASTRUCTURE_disconnected') # DC by: tracing logging.info('creating starting point') arcpy.CreateFeatureclass_management(out_path=os.path.join(em.path, 'Routing', fgdb_name), out_name='StartingPoint', geometry_type='POINT', spatial_reference=arcpy.SpatialReference(3111)) with arcpy.da.InsertCursor(in_table=os.path.join(em.path, 'Routing', fgdb_name, 'StartingPoint'), field_names=['SHAPE@']) as ic: pt = arcpy.Point(2497133.064, 2409284.931) ic.insertRow((pt,)) logging.info('Tracing Geometric Network...') arcpy.TraceGeometricNetwork_management(in_geometric_network=os.path.join(em.path, 'Routing', fgdb_name, 'FD', 'geonet'), out_network_layer='in_memory\\geonet_trace_output', in_flags=os.path.join(em.path, 'Routing', fgdb_name, 'StartingPoint'), in_trace_task_type='FIND_DISCONNECTED', in_trace_ends='NO_TRACE_ENDS', in_trace_indeterminate_flow='NO_TRACE_INDETERMINATE_FLOW', in_junction_weight_range_not='AS_IS', in_edge_weight_range_not='AS_IS') logging.info('Trace Complete. Checking counts and export.') group_layer = arcpy.mapping.Layer('in_memory\\geonet_trace_output') for layer in arcpy.mapping.ListLayers(group_layer): if not layer.isGroupLayer: layer_count = arcpy.GetCount_management(layer).getOutput(0) if int(layer_count) > 0: logging.info('found disconnected in layer: {}'.format(layer.name)) logging.info('count disconnected: {}'.format(layer_count)) arcpy.FeatureClassToFeatureClass_conversion(in_features=layer, out_path=os.path.join(em.path, 'Routing', fgdb_name), out_name=layer.name + '_disconnected_ALL') if arcpy.Exists(os.path.join(em.path, 'Routing', fgdb_name, 'ROAD_disconnected_ALL')): logging.info('Export ROAD disconnected UNNAMED') arcpy.FeatureClassToFeatureClass_conversion(in_features=os.path.join(em.path, 'Routing', fgdb_name, 'ROAD_disconnected_ALL'), out_path=os.path.join(em.path, 'Routing', fgdb_name), out_name='ROAD_disconnected_UNNAMED', where_clause="ROAD_NAME = 'UNNAMED'") logging.info('Export ROAD disconnected NAMED Victoria') arcpy.FeatureClassToFeatureClass_conversion(in_features=os.path.join(em.path, 'Routing', fgdb_name, 'ROAD_disconnected_ALL'), out_path=os.path.join(em.path, 'Routing', fgdb_name), out_name='ROAD_disconnected_NAMED_VIC', where_clause='''ROAD_NAME <> 'UNNAMED' and ( (LEFT_LOCALITY not like '%(NSW)%' or RIGHT_LOCALITY not like '%(NSW)%') AND (LEFT_LOCALITY not like '%(SA)%' or RIGHT_LOCALITY not like '%(SA)%') ) ''') logging.info('Export ROAD disconnected NAMED Interstate') arcpy.FeatureClassToFeatureClass_conversion(in_features=os.path.join(em.path, 'Routing', fgdb_name, 'ROAD_disconnected_ALL'), out_path=os.path.join(em.path, 'Routing', fgdb_name), out_name='ROAD_disconnected_NAMED_INTERSTATE', where_clause='''ROAD_NAME <> 'UNNAMED' and ( (LEFT_LOCALITY like '%(NSW)%' or RIGHT_LOCALITY like '%(NSW)%') OR (LEFT_LOCALITY like '%(SA)%' or RIGHT_LOCALITY like '%(SA)%') ) ''') logging.info('clean up trace group layer') arcpy.Delete_management('in_memory\\geonet_trace_output')
for row in cursor: row[0] = i cursor.updateRow(row) i += 1 edit.stopEditing(True) #Compute segment length if 'LENGTH' not in flist: print('Compute segment length...') arcpy.AddGeometryAttributes_management(outsnsplit, 'LENGTH', 'meters') #----------------------------- Create geometric network ------------------------------------- in_source_feature_classes = "{} SIMPLE_EDGE NO".format(os.path.split(outsnsplit)[1]) if not arcpy.Exists(geonetout): print('Create geometric network...') arcpy.CreateGeometricNetwork_management(netftdat, os.path.split(geonetout)[1], in_source_feature_classes) else: print('{} already exists. Skipping...'.format(geonetout)) ######################################################################################################################## # DCI ANALYSIS ######################################################################################################################## #Set flow direction of geometric network, a pre-requisite for tracing arcpy.SetFlowDirection_management(geonetout, flow_option = "WITH_DIGITIZED_DIRECTION") #For each segment, identify connected reaches with dams as barriers #Get start point of each reach arcpy.FeatureVerticesToPoints_management(outsnsplit, netp, point_location='START') segdic = defaultdict(list) #dictionary to contain segment ID as key and SUBREACH_ID of corresponding reaches as values #Iterate over each reach print('Find connected reaches...')
def check_orientation(self, geometry_name, geometry_folder, networkLine, file_laisse=""): geodatabaseTopage = geodatabase() geodatabasePath = geodatabaseTopage.path(geometry_folder) arcpy.env.overwriteOutput = True if arcpy.Exists(geodatabasePath + "/" + networkLine + "_BUILDERR"): arcpy.Delete_management(geodatabasePath + "/" + networkLine + "_BUILDERR") # Sélection des entités en jointure avec la laisse ou de celles qui ont l'altitude la plus basse print("Création du fichier de l'exutoire") arcpy.MakeFeatureLayer_management(geometry_folder + networkLine, 'lyr') print file_laisse if file_laisse != "": arcpy.SelectLayerByLocation_management( 'lyr', 'INTERSECT', file_laisse, selection_type="NEW_SELECTION") if file_laisse == "" or arcpy.GetCount_management('lyr') == 0: print "le compte est : " + arcpy.GetCount_management( 'lyr').__str__() print "merci d'indiquer le fichier des laisses" return "" # Création du fichier de l'éxutoire à partir de cette sélection arcpy.FeatureVerticesToPoints_management( 'lyr', geometry_folder + networkLine + "_Exutoire", "END") # Suppression du layer arcpy.SelectLayerByAttribute_management('lyr', "CLEAR_SELECTION") arcpy.Delete_management("lyr") # Ecriture de la table des sources et des puits print("Création de la table des puits et cuvettes") arcpy.FeatureVerticesToPoints_management( geometry_folder + networkLine, geometry_folder + networkLine + "_summit", "DANGLE") # Création du réseau géométrique print("Construction du réseau géométrique") arcpy.CreateGeometricNetwork_management( geometry_folder, geometry_name, networkLine + " SIMPLE_EDGE NO;" + networkLine + "_summit SIMPLE_JUNCTION NO", "0.001", "#", "#", "#", "PRESERVE_ENABLED") print("Suppression des éléments non connectés") arcpy.gp.TraceGeometricNetwork( geometry_folder + geometry_name, "lyr", geometry_folder + networkLine + "_Exutoire", "FIND_DISCONNECTED") arcpy.CopyFeatures_management( "lyr/" + networkLine, geometry_folder + networkLine + "_disconnected") arcpy.CopyFeatures_management( "lyr/" + networkLine + "_summit", geometry_folder + networkLine + "_summit_disconnected") arcpy.DeleteFeatures_management("lyr/" + networkLine) arcpy.DeleteFeatures_management("lyr/" + networkLine + "_summit") arcpy.Delete_management("lyr") print("Recréation du réseau géométrique") arcpy.Delete_management(geometry_folder + geometry_name) arcpy.CreateGeometricNetwork_management( geometry_folder, geometry_name, networkLine + " SIMPLE_EDGE NO;" + networkLine + "_summit SIMPLE_JUNCTION YES", "0.001", "#", "#", "#", "PRESERVE_ENABLED") print("Ajout de l'exutoire") arcpy.MakeFeatureLayer_management( geometry_folder + networkLine + "_summit", 'lyr') arcpy.SelectLayerByLocation_management( 'lyr', 'INTERSECT', geometry_folder + networkLine + "_Exutoire") arcpy.CalculateField_management('lyr', 'AncillaryRole', "2", "PYTHON_9.3", "#") arcpy.SelectLayerByAttribute_management('lyr', "CLEAR_SELECTION") arcpy.Delete_management("lyr") print("Calcul du sens d'écoulement") arcpy.SetFlowDirection_management( geometry_folder + "/" + geometry_name, "WITH_DIGITIZED_DIRECTION")