import arcpy mxd = arcpy.mapping.MapDocument("C:/Rafiq_GIS/PYTHONTESTING/2011/2011_CountyComm/Data/DataPrep.mxd") for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name == "CountyCommission_TriCounty": layer.definitionQuery = "[DISTRICT] = '1' AND [COUNTY] = 'ORANGE'" arcpy.SelectLayerByLocation_management("BusRoutes_Ridership","INTERSECT","CountyCommission_TriCounty","","NEW_SELECTION") arcpy.CopyFeatures_management("BusRoutes_Ridership","C:/Rafiq_GIS/PYTHONTESTING/2011/2011_CountyComm/Data/Orange/Or_Com1.shp")
import arcpy mxd = arcpy.mapping.MapDocument("C:/Rafiq_GIS/PYTHONTESTING/2011/2011_CountyComm/Data/DataPrep.mxd") for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name == "CountyCommission_TriCounty": lyr.definitionQuery = "DISTRICT" = '1' AND "COUNTY" = 'ORANGE' arcpy.SelectLayerByLocation_management("BusRoutes_Ridership","INTERSECT","CountyCommission_TriCounty","","NEW_SELECTION") arcpy.CopyFeatures_management("BusRoutes_Ridership","C:/Rafiq_GIS/PYTHONTESTING/2011/2011_CountyComm/Data/Orange/Or_Com1.shp")
rbasaria;87366 wrote:
Hi. Ive been trying to figure out how to accomplish this, but Ive run into some trouble. Im not sure if I am coding this correctly. My goal, overall, is to select features from a layer that intersect with features from another layer. The features in this second layer need to be defined by a definition query that I do not want to manually change. The selected features will then be exported to a new shapefile. I have been able to get the script to select and export, but I cannot get it to create the definition query. Any assistance will be greatly appreciated. Here is the
import arcpy from arcpy import env import os inzones = (.../RevisedGroundZones) for lyr in inzones: if lyr.name == "RevisedGroundZones": lyr.definitionQuery = ' "Grounds_GSC_Zones" = \'2\''
I've been trying to use a definition query just like rbasaria, and have used the syntax that clm42 suggested, but keep running into trouble. For now, I just want to be able to query out various zones from a larger map, and then run further geoprocessing functions on them.import arcpy from arcpy import env import os inzones = (.../RevisedGroundZones) for lyr in inzones: if lyr.name == "RevisedGroundZones": lyr.definitionQuery = ' "Grounds_GSC_Zones" = \'2\''
When running it from the python window in ArcMap, I get an error message that says AttributeError: 'str' object has no attribute 'name' and when I run it as a script tool in ArcCatalog, I get an error saying that there is no definition Query function for 'lyr'
Any help would be very appreciated, thanks!