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.

2 Answers 2


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")
  • I somewhat understand this code, but I struggle at --- (\"STREET\" <> \"STREET_1\") OR (\"POSTALCODE\" <> \"POSTALCODE_1\")") --- street should be a field in the polygons layer and street_1 should be a filed in the points layer, right? then shouldn't I use AND instead of OR to use both information? and what <> mean? lastly, the field that contains the street name in the point-feature layer is split into two columns. i can merge them with a tool, but can i concatenate them directly in this code? Commented Nov 5, 2014 at 10:22
  • 1
    When you do a SpatialJoin, it merges fields from both layers into one... therefore if you have a STREET field in polygons and a STREET field in points, it's going to change the points field name to STREET_1. Run the code, then look at the "AddressPolygonsSpatialJoin.shp" table to see the field names (make sure "Show Field Aliases" is turned off) ----- <> means "does not equal" ----- You want to use OR... you want to see all the entries where the STREET values don't match OR the POSTALCODES don't match...if you use AND then you'll only filter out where both don't match... Commented Nov 5, 2014 at 15:48
  • If the building(polygon) has the same attributes as the point feature no errors will be generated. But for this to be true the 2 features must overlap. And this causes a problem. Most of the time I will have more than one building(with the same attributes) and an corresponding feature point(only one point is required for multiple buildings). One of those buildings will have the point feature over it, so no errors will be generated for it, but for the others errors will be generated. Can it be specified that the features shouldn't overlap so that all those building come out with no errors? Commented Nov 17, 2014 at 8:17
  • 1
    With a spatial join you can specify a (optional) Search Radius, which allows you to match a polygon to a point even when they don't overlap. You would change your code to arcpy.SpatialJoin_analysis(inputFC, joinFC, outputFC, "", "", "", "", "50 Feet") However, this may not always be ideal either, depending how far apart your buildings are. Commented Nov 17, 2014 at 20:31

In ArcGIS, you can perform a spatial join on the polygon feature class (right click on the layer >> "Join >> Join data from another layer based on the spatial location" choosing the third option "Each polygon will be given attributes on the layer that fall inside....". Then, opening the attribute table, all the records that do not have a joined data are the ones with missing points. Selecting those records you can use the FeatureToPoint tool to add the missing points. By using the help tool you can easily turn it into a Python script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.