Friday 24 August 2018

arcmap - Using SQL query with ArcPy?



I'm creating a tool that when you type in the city name it will select the city, zoom in and label it. I have the zoom and label working but can't figure out the SQL Query needed to select the city I type in the tool in ArcMap. My code in below.


I'm still new at this


import arcpy as ARCPY

def citySelect():

mxd = ARCPY.mapping.MapDocument("CURRENT")
df = ARCPY.mapping.ListDataFrames(mxd)[0]
city = ARCPY.GetParameter(0)
cities = ("N:/Lab13/Lab13/cities.lyr")

ARCPY.SelectLayerByAttribute_management("cities", "NEW_SELECTION",''' "CITY_NAME" = ' city ' ''')
print city[0]
layers = arcpy.mapping.ListLayers(mxd, "", df)
citiesLayer = layers[0]
df.zoomToSelectedFeatures()
citiesLayer.showLabels =True
ARCPY.RefreshActiveView()

citySelect()


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...