Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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:)

mxd=arcpy.mapping.MapDocument("CURRENT")

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

list=getValueList('my_shp_file', 'typeID')
lyr=arcpy.mapping.Layer('my_shp_file')
where_clause='"typeID"='

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

Thanks for suggestions! Rok

share|improve this question
    
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

1 Answer 1

up vote 2 down vote accepted

Just use Layer object do something like:

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

It works great!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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