I am new to ArcPy and was trying to get a new layer from two shapefiles. The new layer would only have the data if the two layers intersect and one of the attributes ("VEGETATION") = "NV".
import arcpy
import numpy
#Locations
arcpy.env.workspace = "c:\Users\C\Desktop\GIS\Geodatabases"
LClocation = "c:\Users\C\Desktop\GIS\Geodatabases\ex_LandCover.shp"
RBveglocation = "c:\Users\C\Desktop\GIS\Geodatabases\ex_RedBluffVegetation.shp"
a_RBVeg = arcpy.MakeFeatureLayer_management(RBveglocation, "VEGETATION")
a_LC = arcpy.MakeFeatureLayer_management(LClocation, "LU_CODE")
updateveg = arcpy.SelectLayerByLocation_management(a_RBVeg,'INTERSECT', a_LC, 0, 'NEW_SELECTION')
query = '"VEGETETATION" = "NV"'
updatevegQ = arcpy.SelectLayerByAttribute_management(a_RBVeg, "SUBSET_SELECTION", query)
arcpy.CopyFeatures_management(updatevegQ,'updateveg4')
-
2I would try the Intersect tool followed by the Select (not Select Layer By Attributes) tool.PolyGeo– PolyGeo ♦2021年04月05日 10:39:54 +00:00Commented Apr 5, 2021 at 10:39
1 Answer 1
1
Start by adding a r in front of all paths, for example
arcpy.env.workspace = r"c:\Users\C\Desktop\GIS\Geodatabases"
(raw strings). Or some characters might be interpreted as a tab / newline / etc. and the path wont work.
2
When you do
a_RBVeg = arcpy.MakeFeatureLayer_management(RBveglocation, "VEGETATION")
a_RBVeg will be a result object, not the layer. The layer is called "VEGETATION"
or you can also use a_RBVeg.getOutput(0)
So arcpy.SelectLayerByLocation_management(a_RBVeg, ...
wont work.