TransWikia.com

How to obtain an extent of a whole shapefile?

Geographic Information Systems Asked by user21816 on July 12, 2021

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.

2 Answers

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))

Correct answer by Barbarossa on July 12, 2021

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

Answered by Tigerwoulds on July 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP