0

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')
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 5, 2021 at 10:26
1
  • 2
    I would try the Intersect tool followed by the Select (not Select Layer By Attributes) tool. Commented Apr 5, 2021 at 10:39

1 Answer 1

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.

answered Apr 5, 2021 at 12:23

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.