3

I am trying to find out the counties that don't contain any stores in ArcGIS using Python. Basically, I have a point layer (representing the stores) and a polygon layer (counties). I have managed to write some code to find out the counties that DO contain the stores (it was pretty simple actually). The code is below.

import arcpy
arcpy.env.overwriteOutput = True
path="C:/Users/XARDAS/Documents/ArcGIS/Packages/Romania1000k_9E5B7FEC-6005-4D3A-81EA-E95FAACEF69E/v101/ro1mil.gdb"
arcpy.MakeFeatureLayer_management(path+"/Counties", "Counties_lyr")
arcpy.MakeFeatureLayer_management(path+"/Stores", "Stores_lyr")
arcpy.SelectLayerByAttribute_management("Stores_lyr", "NEW_SELECTION","Type=1")
arcpy.SelectLayerByLocation_management("Counties_lyr","INTERSECT","Stores_lyr",0,"NEW_SELECTION")

So this gives me the counties that have stores but I would like to somehow inverse the intersection for the program to give me the ones that don't have any stores. I have thought about just deleting the selected counties but I don't think that it would be too nice.

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Jun 6, 2017 at 23:24
2

1 Answer 1

6

After selecting the points using select by location, you need to switch the selection using again select by attribute. I Added variables to easily track each step. You need to do something like this:

import arcpy
arcpy.env.overwriteOutput = True
path="C:/Users/XARDAS/Documents/ArcGIS/Packages/Romania1000k_9E5B7FEC-6005-4D3A-81EA-E95FAACEF69E/v101/ro1mil.gdb"
country_lyr = arcpy.MakeFeatureLayer_management(path+"/Counties", "Counties_lyr")
stores_lyr = arcpy.MakeFeatureLayer_management(path+"/Stores", "Stores_lyr")
att_Select = arcpy.SelectLayerByAttribute_management("Stores_lyr", "NEW_SELECTION","Type=1")
loc_Select = arcpy.SelectLayerByLocation_management("Counties_lyr","INTERSECT","Stores_lyr",0,"NEW_SELECTION")
switch_att_Select = arcpy.SelectLayerByAttribute_management(loc_Select, "SWITCH_SELECTION")
answered Jun 7, 2017 at 0:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.