3

I have got two shapefiles. One of them is a point shapefile and the second one is a polygon shapefile. I need to find out which of them has a larger extent and then set the environment extent to include both shapefiles.

4
  • 1
    What software ?
    – warrieka
    Sep 30, 2013 at 14:09
  • It is in ArcGIS.
    – user21816
    Sep 30, 2013 at 14:10
  • 4
    this could get you started: resources.arcgis.com/en/help/main/10.1/index.html#//…
    – Craig
    Sep 30, 2013 at 14:21
  • What ArcGIS for Desktop version are you using? Can you post your code so far, please? The edit button should be used to do this rather than as more comments.
    – PolyGeo
    Sep 30, 2013 at 19:36

2 Answers 2

10

I use a code similar to this. Try using the following code (its modified from what I use and this is untested).

# Import arcpy modules
import arcpy
from arcpy import env

def extents(fc):
    extent = arcpy.Describe(fc).extent
    west = extent.XMin
    south = extent.YMin
    east = extent.XMax
    north = extent.YMax
    width = extent.width
    height = extent.height
    return west, south, east, north, width, height

# Script arguments
shape1 = "path to shape 1"
shape2 = "path to shape 2"

# Obtain extents of two shapes
w1, s1, e1, n1, wid1, hgt1 = extents(shape1)
w2, s2, e2, n2, wid2, hgt2 = extents(shape2)

# Determine which extent is larger (I assumed in area)
area1 = wid1 * hgt1
area2 = wid2 * hgt2

larger = max(area1, area2)
print("%s is the larger shape" % larger)

XMin = min(w1, w2)
YMin = min(s1, s2)
XMax = max(e1, e2)
YMax = max(n1, n2)

# Set the extent environment
arcpy.env.extent = "%s %s %s %s" % (XMin, YMin, XMax, YMax)
print("Extent set to %s %s %s %s" % (XMin, YMin, XMax, YMax))
1
  • Shouldn't you use more than simply width and height to determine shape area? Or maybe just change the comment to: # Determine which extent is larger (I assumed in area)
    – bcollins
    Sep 30, 2013 at 21:19
1

In ArcCatalog, you can right click the shapefile > Feature extent This will give you the extent coordinates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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