Extent to xy coordinate- arcpy

4087
1
Jump to solution
01-08-2015 01:10 AM
Yaron_YosefCohen
Occasional Contributor II

Hellow

i try to extent to xy coordinate with arcpy? i using this code:

import arcpy, os, sys
from arcpy import env

env
.workspace = r"C:\Project"
pnt
= '178434 ,662446'
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 = pnt
  
print 'extent'
  mxd
.save()
del mxd

but i get en error: ValueError: Invalid string value for Extent argument

any help would be great

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
AnthonyGiles
Frequent Contributor

Your extent needs to be a rectangle so you would need to find out the width and height of your data frame to be able to create an AOI from your point,  i.e. if your point is the bottom left corner:

xmapdistance = df.extent.XMax - df.extent.XMin

ymapdistance = df.extent.YMax - df.extent.YMin

extentxmin = 178434

extentxmax = 178434 + xmapdistance

extentymax = 662446

extentymin = 662446 + ymapdistance

df.panToExtent(arcpy.Extent(extentxmin,extentymax,extentxmin,extentymax))

View solution in original post

1 Reply
AnthonyGiles
Frequent Contributor

Your extent needs to be a rectangle so you would need to find out the width and height of your data frame to be able to create an AOI from your point,  i.e. if your point is the bottom left corner:

xmapdistance = df.extent.XMax - df.extent.XMin

ymapdistance = df.extent.YMax - df.extent.YMin

extentxmin = 178434

extentxmax = 178434 + xmapdistance

extentymax = 662446

extentymin = 662446 + ymapdistance

df.panToExtent(arcpy.Extent(extentxmin,extentymax,extentxmin,extentymax))