#Import arcpy and set workspace
import arcpy
import arcpy.mapping
arcpy.env.workspace = "P:\CoWetlandTools\maps\distribution_maps_Johns_pytest"
import arcpy.sa
specieslist = ['Achillea millefolium', 'Acroptilon repens', 'Actinea osterhoutii', 'Adenocaulon bicolor', 'Adoxa moschatellina', 'Ageratina herbacea', 'Agoseris �?agrestis', 'Agoseris �?montana', 'Agoseris agrestis', 'Agoseris attenuata', 'Agoseris aurantiaca', 'Agoseris frondifera', 'Agoseris glauca']
for X in specieslist:
#select counties each species is known to occur
#Create Loop and List to run processing for
arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "NEW_SELECTION", "X in "str(specieslist)" > 0")
#Export selected to jpeg
mxd = arcpy.mapping.MapDocument(r"CURRENT")
arcpy.mapping.ExportToJPEG(mxd, r"P:\CoWetlandTools\maps\"X in str(specieslist)".jpg")
#clear selected attributes
arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "CLEAR_SELECTION")
#finished
print "Finished"
arcpy.env.workspace = r"P:\CoWetlandTools\maps\distribution_maps_Johns_pytest" #"r" at beginning of path string
where = "X in ('" + '\',\''.join(specieslist) + "')"
#Import arcpy and set workspace
import arcpy
import arcpy.mapping
arcpy.env.workspace = r"P:\CoWetlandTools\maps\distribution_maps_Johns_pytest"
import arcpy.sa
specieslist = ['Achillea millefolium', 'Acroptilon repens', 'Actinea osterhoutii', 'Adenocaulon bicolor', 'Adoxa moschatellina', 'Ageratina herbacea', 'Agoseris �?agrestis', 'Agoseris �?montana', 'Agoseris agrestis', 'Agoseris attenuata', 'Agoseris aurantiaca', 'Agoseris frondifera', 'Agoseris glauca']
for X in specieslist:
#select counties each species is known to occur
#Create Loop and List to run processing for
arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "NEW_SELECTION", "'Achillea millefolium' in ('"+'\',\''.join(specieslist)+"') > '0'")
#Export selected to jpeg
mxd = arcpy.mapping.MapDocument(r"CURRENT")
arcpy.mapping.ExportToJPEG(mxd, r"P:\CoWetlandTools\maps\"'Achillea millefolium' in ('"+'\',\''.join(specieslist) + "').jpg")
#clear selected attributes
arcpy.SelectLayerByAttribute_management ("counties_edited_datamergetest", "CLEAR_SELECTION")
#finished
print "Finished"# where "SpecField" LIKE '%Achillea millefolium%') where = '\"%s\" LIKE \'%%%s%%\' % (SpecField,X)
My data is structured with counties as rows and individual species as columns with the presence/absence indicated by a 1 or 0. So in order to run the code for all species I am trying to select the values > 0 within the column of a species, export a jpeg with those counties selected, clear the selection, and then move to the next column (species) until it runs for all species.
where = '\"%s\" > 0' % X
I started with a simple polygon shapefile of counties and then merged the attribute table with a spreadsheet of all species of interest formatted like stated above. Would it be better to have the species as rows and counties as columns or in a single column with them comma-delimited per species? If so is there an easy way to do this?
tv = arcpy.MakeTableView(SpecCounty,"tv")
arcpy.SelectLayerByAttribute(tv,"","SPECIES = \'%s\'" % X)
# KEEP_COMMON will unselect non-matching rows
arcpy.AddJoin("County_poly","COUNTY",tv,"COUNTY","KEEP_COMMON")
#
# .. make your plot here ..
#
# Now remove the join (this clears the selection for the next loop)
joinName = gp.Describe("County_poly").Name
arcpy.RemoveJoin("County_poly",joinName)