import sys, os import arcpy from arcpy import env env.overwriteOutput = True ### Set the workspace --- env.workspace = r"C:\Users\janiceb\Documents\ArcGIS\Default.gdb" ##env.workspace = r"\\skagit\dept\gis\janiceb\Projects\Health\June_2014\Septic.gdb" print env.workspace ## Parcel Layer prodParcelPolys = r"Database Connections\SQLVM3_scgis.sde\Scgis.SDEADM.Parcel_Polys" tempParcels = "Temp_Copy_of_Parcels" tempDOHParcels = "Temp_Copy_of_DOH_Parcels" ## MRA Layer prodMRAPolys = r"Database Connections\SQLVM9_Health.sde\Health.SDEADM.MarineRecoveryAreas" tempMRAs = "Temp_Copy_of_MRAs" ## Final Data to be written to file geodatabase for sharing with DOH finalDOHParcels = "ParcelsInMRA" # Make a temporary layer from the parcel feature class print(" -> Making temporary copy of the Parcel layer...") arcpy.MakeFeatureLayer_management(prodParcelPolys, tempParcels) # Make a temporary layer from the MRA feature class print(" -> Making temporary copy of the MRA layer...") arcpy.MakeFeatureLayer_management(prodMRAPolys, tempMRAs) # Select those parcels with centroid in MRA Polygons arcpy.SelectLayerByLocation_management(tempParcels, "HAVE_THEIR_CENTER_IN", tempMRAs, 5, "NEW_SELECTION") print("FYI :: Number of parcels with centroid in MRA Polygons: {0}".format(str(arcpy.GetCount_management(tempParcels).getOutput(0)))) # Dissolve the parcels in the MRA by PARCELID # This will combine parcels with duplicate parcelid values (ex: parcels divided by a road or river.) # This will give us a feature class of parcels which are located in the MRA print(" -> Dissolving by parcel id...") dissolveFields = ["PARCELID"] arcpy.Dissolve_management(tempParcels, finalDOHParcels, dissolveFields, "", "MULTI_PART", "") Total_Parcels_In_MRA = int(arcpy.GetCount_management(finalDOHParcels).getOutput(0)) print("FYI :: Number of parcels in MRA after Dissolve: {0}".format(str(Total_Parcels_In_MRA)))
Solved! Go to Solution.
env.workspace = r"\\skagit\dept\gis\janiceb\Projects\Health\June_2014\Septic.gdb"