Here is my case: I have a layer of features (buildings from a city) that is populated with polygons. This polygons have attributes : street name and postal code
In the project I have another layer of features, that is populated with points. Each point has similar attributes : street name and postal code. For each polygon we must add a point that has the same values.
ex: we have a polygon whit attributes > - Street_name> Main Street - postal code> 96
after this polygon is drawn and it's attributes are updated I am required to create a point feature (the other layer) that has the same attributes - Street_name> Main Street - postal code> 96
What i need to do > sometimes my team forgets to add the point feature, and the project is quite big. Can I write some code in python or use some tools to detect if every polygon has an equivalent point feature?
ex: i created and updated attributes for the polygon - Street_name> Main Street - postal code> 96 but i forgot to add the point feature with the same attributes, or made an typo (main street becomes Main Stret)
the tool should scan all the database , all the polygons and all the point features, compare they'r values and finally display (or store in a new layer) the polygons that don't have an equivalent point feature.
Answer
Doing a Spatial Join is probably the easiest... There is probably a more effecient way of doing this, but this should work... you'll need to check the field names for the WHERE clause in the MakeFeatureLayer part
Notice that I used forward slashes instead of back slashes... this is not a typo... this works on Windows (even though it doesn't look right) and saves you from having to use \\ all the time...
import arcpy
# Make Feature Layers
arcpy.MakeFeatureLayer_management("C:/YourPath/AddressPoints.shp", "lyr_MyAddressPoints")
arcpy.MakeFeatureLayer_management("C:/YourPath/AddressPolygons.shp", "lyr_MyAddressPolygons")
# Do a spatial join
inputFC = "lyr_MyAddressPolygons"
joinFC = "lyr_MyAddressPoints"
outputFC = "C:/YourPath/AddressPolygonsSpatialJoin.shp"
arcpy.SpatialJoin_analysis(inputFC, joinFC, outputFC)
# Make a new Feature Layer that just contains the ones that need fixed
arcpy.MakeFeatureLayer_management("C:/YourPath/AddressPolygonsSpatialJoin.shp", "lyr_MySpatialJoinLayer", "(\"STREET\" <> \"STREET_1\") OR (\"POSTALCODE\" <> \"POSTALCODE_1\")")
# Create a new shapefile (or FGDB) with just the polygons that need fixed
arcpy.CopyFeatures_management("lyr_MySpatialJoinLayer", "C:/YourPath/PolygonsThatNeedFixed.shp")
No comments:
Post a Comment