AnsweredAssumed Answered

Check layer in specific area using python

Question asked by yaron148 on Nov 8, 2015
Latest reply on Nov 11, 2015 by timothy_hales-esristaff

Hi ,

i try to check if layer "openSpace" are in area coordinate with this code:

 

import arcpy
from arcpy import env

area= '178000 672000 190000 655000' 
env.workspace = r"C:\Project"
for mxdname in arcpy.ListFiles("*.mxd"):
    print mxdname
    mxd = arcpy.mapping.MapDocument(r"C:\Project\\" + mxdname)
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] 
    df.extent = area
    desc = arcpy.Describe(r"C:\Project\layers\openSpace.shp")
    if (map_Y_Max > layer_Y_max) and (map_X_Max > layer_X_max) and (map_Y_Min < layer_Y_min) and (map_X_Min < layer_X_min):
        print "layer is inside map extent"
    else:
        print "layer is outside map extent"
    mxd.save()
del mxd

 

but i get an error:

>>> 
antiquities.mxd
Traceback (most recent call last):
  File "C:\Users\yaron.KAYAMOT\Desktop\check if every layer in df extent_geonet.py", line 15, in <module>
    if (map_Y_Max > layer_Y_max) and (map_X_Max > layer_X_max) and (map_Y_Min < layer_Y_min) and (map_X_Min < layer_X_min):
NameError: name 'map_Y_Max' is not defined
>>> 

i don't understand what my mistake because the layer extent is:

1.jpg

thanks for any help.

Outcomes