I'm using arcmap 10.1 and have one shp with many polygons with different typeID. I want to make a serie of maps showing each typeID on an individual map. Since I have many typeIDs I want to use arcpy. And here is the problem. I don't know which arcpy function to use to select only one typeID and remove all the others; and then repeat this step for all IDs.

SOLUTION: Here is my code after I fixed it. Now it works:)


def getValueList (inputTable, field):
    values = set()
    rows = arcpy.SearchCursor(inputTable)
    for row in rows:
    return sorted(values)

list=getValueList('my_shp_file', 'typeID')

for type in list:
    arcpy.mapping.ExportToJPEG(mxd, "C:\\my_location\\"+str(type)+".jpg")

Thanks for suggestions! Rok

  • If you have a layer file in your mxd pointing to your shapefile you can get to it's definition query and set it to be typeID="value" and then save. I'm not sure how set() works but you'll probably want to ensure your list is unique. help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… – Justin Oct 28 '12 at 20:16

Just use Layer object do something like:

where_clause = "'" + my_field + " = " + typeID + "'"
if yourLayer.supports("DEFINITIONQUERY"):
    yourLayer.definitionQuery = where_clause

It works great!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.