AnsweredAssumed Answered

How can I get a value from a field and then do a definition query to SELECT A POLYGON?

Question asked by retiredmofo65 on Jun 27, 2016
Latest reply on Jun 28, 2016 by dkwiens

Hi-

I'm trying to change the polygon selection based upon a field in it's own attribute table. I have 4 polygons in the feature class each representing a different lake levels and I would like to be able to change the polygon to the one that represents the data in the Pool_Status field. My code runs in pyscripter, but does not update the .mxd. Any help is appreciated.

Here is my code:

 

import arcpy

mxd = arcpy.mapping.MapDocument(r'\\swf-netapp1\RefGIS\FY-15_FLD_Support\Geospatial\Automation_Tools\LM_Test.mxd')

# Updates the color of the poly to reflect pool level

# Sets the field to take pool level from

df = arcpy.mapping.ListLayers(mxd, "Grapevine_Lake_Pool")

for lyr in arcpy.mapping.ListLayers(mxd, "Pool_Status", df):

            if ([Pool_Status] == "'SP'"):

                for lyr in arcpy.mapping.ListLayers(mxd):

                    if lyr.name == 'Grapevine Lake Pool':

                        lyr.definitionQuery = "NAME = 'Grapevine Lake SP'"

            elif ([Pool_Status] == "'CP'"):

                for lyr in arcpy.mapping.ListLayers(mxd):

                    if lyr.name == 'Grapevine Lake Pool':

                        lyr.definitionQuery = "NAME = 'Grapevine Lake CP'"

            elif ([Pool_Status] == "'FP'"):

                for lyr in arcpy.mapping.ListLayers(mxd):

                    if lyr.name == 'Grapevine Lake Pool':

                        lyr.definitionQuery = "NAME = 'Grapevine Lake FP'"

            elif ([Pool_Status] == "'SC'"):

               for lyr in arcpy.mapping.ListLayers(mxd):

                    if lyr.name == 'Grapevine Lake Pool':

                        lyr.definitionQuery = "NAME = 'Grapevine Lake SC'"

mxd.save()

del mxd

Outcomes