def Custom_Erase(inFeature1, inFeature2, outFeature): # Instead of erase, might try a union, then selection for only the features # that do not have their centers within the 2nd feature class, # or that are not entirely within the 2nd feature class, # then output the selected features. # MakeFeatureLayer, Union, SelectByLocation, CopyFeatures. tempUnionFeatureClass = r'in_memory\UnionTemp' unionList = list() unionList.append(inFeature1) unionList.append(inFeature2) Union_analysis(unionList, tempUnionFeatureClass, "ALL") tempUnionLayer = MakeFeatureLayer_management(tempUnionFeatureClass, "UnionLayer") tempFeature2 = MakeFeatureLayer_management(inFeature2, "Feature2") SelectLayerByLocation_management(tempUnionLayer, "HAVE_THEIR_CENTER_IN", tempFeature2) SelectLayerByLocation_management(tempUnionLayer, "WITHIN", tempFeature2, "0 Feet", "ADD_TO_SELECTION") CopyFeatures_management( tempUnionLayer, r'\\gisdata\ArcGIS\GISdata\GDB\CCL_Scratch_Boundary.gdb\TempUnionSelection' ) SelectLayerByAttribute_management(tempUnionLayer, "SWITCH_SELECTION") CopyFeatures_management( tempUnionLayer, r'\\gisdata\ArcGIS\GISdata\GDB\CCL_Scratch_Boundary.gdb\TempUnionSelectionSwitch' ) CopyFeatures_management(tempUnionLayer, outFeature)
def Annually(): #arcpy.MakeFeatureLayer_management(CPMSlyr, 'CPMS', ProjectSelect) MakeFeatureLayer_management(CPMSlyr, 'CPMS') MakeFeatureLayer_management(CountyLyr, 'County') MakeFeatureLayer_management(HPMSlyr, 'HPMS') MakeFeatureLayer_management(MPOLyr, 'MPO') MakeFeatureLayer_management(CONGDistlyr, 'CONG') #make the polygon analysis layer for Districts, Counties, and MPOs Union_analysis("CONG #;MPO #;County #", ws + "/Polygons", "ALL", "1 feet", "GAPS")
union_sectors = [] if len(v1_sectors) != 0: writeShp(v1_sectors, 'v1_sectors.shp') union_sectors.append('v1_sectors.shp') if len(v2_sectors) != 0: writeShp(v2_sectors, 'v2_sectors.shp') union_sectors.append('v2_sectors.shp') if len(v1_sectors) == 0: if len(v2_sectors) == 0: writeShp(dealt_obs, 'dealtobs.shp') CopyFeatures_management('cover_shp.shp', 'cover_1_shp.shp') Erase_analysis('cover_1_shp.shp', 'dealtobs.shp', 'cover_shp.shp') print 'end of loop, no sectors' #raw_input() else: Union_analysis(union_sectors, 'sectors.shp') writeShp(dealt_obs, 'dealtobs.shp') Union_analysis(['sectors.shp', 'other_sector.shp'], 'union_2.shp') Dissolve_management('union_2.shp', 'union_2_dissol.shp') Erase_analysis('union_2_dissol.shp', 'dealtobs.shp', 'cover_shp.shp') print "end of loop" #raw_input() else: Union_analysis(union_sectors, 'sectors.shp') writeShp(dealt_obs, 'dealtobs.shp')
missing_poly = Polygon(missing_piece) cutting_box_1, cutting_box_2 = cutting_box(isl1, isl2, cover_shp, facil_coords[0]) cutbox = [x for x in (cutting_box_1, cutting_box_2) if cent_dist_clip_obs[0][1].centroid.intersects(x)] other_cutbox = [x for x in (cutting_box_1, cutting_box_2) if x not in cutbox] saveShp([cutbox[0]], 'polygon', path, 'cutbox_0') saveShp(other_cutbox, 'polygon', path, 'othercutbox') Intersect_analysis(['cover_shp.shp', 'cutbox_0.shp'], 'initial_sector.shp') Intersect_analysis(['cover_shp.shp', 'othercutbox.shp'], 'other_sector.shp') #intial_sector = cover_shp.intersection(cutbox[0]) #saveShp([intial_sector], 'polygon', path, 'intial_sector') #other_sector = cover_shp.intersection(other_cutbox[0]) #saveShp([other_sector], 'polygon', path, 'other_sector') saveShp([missing_poly], 'polygon', path, 'missing_poly') Union_analysis(['other_sector.shp', 'missing_poly.shp'], 'union.shp') Dissolve_management('union.shp', 'union_dissol.shp') v1_sLines = [isl1] v2_sLines = [isl2] v1_overlap = [list(v1_esps[-1][1][1].coords)[-1] ,list(v2_esps[-1][1][1].coords)[-1]] v2_overlap = [list(v2_esps[-1][1][1].coords)[-1] ,list(v1_esps[-1][1][1].coords)[-1]] v2_esps.remove(v2_esps[0]) v1_esps.remove(v1_esps[0]) v1_sectors = [] v2_sectors = [] #what about area between esp1 esp2 and obstacle? it must be included while len(v1_esps) != 0: if v1_remain_dis <= 0: break
def MakeSniceBoundaries(): from arcpy import (FeatureClassToFeatureClass_conversion, AddField_management, CalculateField_management, Clip_analysis, SelectLayerByAttribute_management, gp, RasterToPolygon_conversion, Dissolve_management, FeatureToPoint_management, SpatialJoin_analysis, env, Union_analysis, DeleteRows_management) env.overwriteOutput = 1 SNIC = r'\\gisdata\arcgis\GISdata\Connection_files\ArcGIS103\sql2008\RO@sqlgisprod_GIS_cansys.sde\GIS_CANSYS.SHARED.SNIC' FeatureClassToFeatureClass_conversion(SNIC, "in_memory", "DAS1", "", "#", config_keyword="") AddField_management("DAS1", "DAS", "Text", "#", "#", "4") CalculateField_management( "DAS1", "DAS", "[SNICE_DISTRICT] & [SNICE_AREA] & [SNICE_SUB_AREA]", "VB", code_block="") gp.EucAllocation_sa("DAS1", "in_memory/EucAllo_Subarea", "", "", "1E-03", "DAS", "", "") RasterToPolygon_conversion("EucAllo_Subarea", "in_Memory/DAS_Poly", "SIMPLIFY", "Value") Dissolve_management("DAS1", "in_memory/DAS_Dissolve", "DAS", "", "SINGLE_PART", "DISSOLVE_LINES") FeatureToPoint_management("DAS_Dissolve", "in_memory/DAS_Dissolve_FeatureToPoint", "INSIDE") SpatialJoin_analysis("DAS_Poly", "DAS_Dissolve_FeatureToPoint", "in_memory/SNICE_AREA", "JOIN_ONE_TO_ONE", "KEEP_ALL", "", "CONTAINS", "", "") #this is the time to look at the in memory process and edit any null DAS values, and review the changes #for some reason, SNICE boudary will not clip, it results in no values. May be a projection issue or a extent issue Clip_analysis( r"in_memory/SNICE_AREA", r"Database Connections/GISPROD_Shared.sde/SHARED.STATE_BOUNDARY", r"in_memory/SNICE_AREA_CLIP") #for workaround Union the Euclidean Allocation areas and the state boundary, then select results outside state boundary and delete them Union_analysis( "in_memory/SNICE_AREA #;'Database Connections/SDEPROD_SHARED.sde/SHARED.STATE_BOUNDARY' #", "in_memory/SNICE_AREA_Union", "ALL", "", "GAPS") SelectLayerByAttribute_management( "SNICE_AREA_Union", "NEW_SELECTION", """"FID_STATE_BOUNDARY" = -1 OR "FID_SNICE_AREA" = -1""") DeleteRows_management("SNICE_AREA_Union") AddField_management("SNICE_AREA_Union", "D", "Text", "#", "#", "1") AddField_management("SNICE_AREA_Union", "A", "Text", "#", "#", "1") AddField_management("SNICE_AREA_Union", "S", "Text", "#", "#", "1") CalculateField_management("SNICE_AREA_Union", "D", "Left( [DAS],1)", "VB", "") CalculateField_management("SNICE_AREA_Union", "A", "Mid( [DAS],2, 1)", "VB", "") CalculateField_management("SNICE_AREA_Union", "S", "Right( [DAS], 1)", "VB", "") Dissolve_management("SNICE_AREA_Union", "in_memory/KDOT_SNICE_District", "D", "", "MULTI_PART", "DISSOLVE_LINES") Dissolve_management("SNICE_AREA_Union", "in_memory/KDOT_SNICE_Area", "D;A", "", "MULTI_PART", "DISSOLVE_LINES") Dissolve_management("SNICE_AREA_Union", "in_memory/KDOT_SNICE_SubArea", "D;A;S", "", "MULTI_PART", "DISSOLVE_LINES")