I want to calculate the width of a shapefile or the distance btw 2 shapefiles

698
3
10-08-2013 06:55 AM
OLANIYANOLAKUNLE
Occasional Contributor II
I want to calculate the width of a polygon feature or get the distance between two line features. All I have for the first scenario is how to calculate the length, I want to be able to use arcpy to get the width of a polygon feature and pass the result into a what if statement. I want to use arcpy to get the distance between two line features and pass the result into a what if statement. Any suggestion(s)?
Tags (2)
0 Kudos
3 Replies
DarrylKlassen
New Contributor III
You could cursor through each of the geometries of the 2 features you are interested in and get the X,Y coordinates of each of the vertex's in both features.  Then using some basic TRIG - get the distance between each vertex in both datasets.  This link shows how to read XY coordinates of polylines and polygons using Arcpy:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001t000000
0 Kudos
DarrenWiens2
MVP Honored Contributor
Similarly, you can get XMin, Ymax, etc. from the Describe Dataset Extent object:

import arcpy

# Create a Describe object from the shapefile
#
desc = arcpy.Describe("C:/data/centerlines.shp")

# Print dataset properties
#
print "Dataset Type: " + desc.datasetType

extent = desc.Extent
print "Extent:"
print "  %s: %f, %s: %f, %s: %f, %s: %f" % ("XMin", extent.XMax, "XMax", extent.XMax, 
                                            "YMin", extent.YMin, "YMax", extent.YMax)
print "MExtent: " + desc.MExtent
print "ZExtent: " + desc.ZExtent

SR = desc.spatialReference
print SR.name
0 Kudos
NeilAyres
MVP Alum
The geometry methods are very useful.
like :
 dist = geom1.distanceTo(geom2)


See the Café Python page for some useful tips.
http://arcpy.wordpress.com/

Cheers,
Neil
0 Kudos