AnsweredAssumed Answered

Expand extent for purposes of clipping

Question asked by rastrauch Champion on Dec 9, 2015
Latest reply on Dec 13, 2015 by bixb0012

I'm wanting to clip a hydro layer (with a reselect) based on the extent of my study area extent....but expanded a bit (% to be determined). I have code that works, but it's a bit clunky. I grab the extent, create a poly, buffer, grab-new-extent, create the poly and then do my clip/query.  It's the getting the extent->poly->buffer->extent->poly that seems a bit overkill.  I'm wondering if I am missing an obvious arcpy option for expanding the extent for the clip.  Trying to keep it to arcpy and not get deep into the geometry of this one...but all suggestions will be considered.



This works:

import arcpy
from arcpy import env
import os
arcpy.env.overwriteOutput = "True"

inStudy =  r'C:\Prep.gdb\study_boundary'
srDesc = arcpy.Describe(inStudy).spatialReference
extent = arcpy.Describe(inStudy).extent
arcpy.env.outputCoordinateSystem = srDesc.PCSCode

# ---> Ugly way to do this, but it works and fairly fast.  Ok for now.
# get extent, a buff distance (1% of X), and create a temp polygon
extBuffDist = ((int(abs(extent.lowerLeft.X - extent.lowerRight.X))) * .01)

# Array to hold points for the bounding box for initial extent
origExtentPts = arcpy.Array()
origExtentPts.add(extent.lowerLeft)  # ensures polygon closes
# Create and buffer the polygon object
polygonTmp1 = arcpy.Polygon(origExtentPts)
arcpy.Buffer_analysis(polygonTmp1, "polyBuff", extBuffDist, "OUTSIDE_ONLY")

#get extent of buffered poly
extent = arcpy.Describe("polyBuff").extent
# Array to hold points for the buffer bounding box
newExtentPts = arcpy.Array()
newExtentPts.add(extent.lowerLeft) # ensures polygon closes
polygonTmp2 = arcpy.Polygon(newExtentPts)

# save to disk
#extentPoly = "extentPoly" 
arcpy.CopyFeatures_management(polygonTmp2, "extentPoly")
del polygonTmp1, polygonTmp2

hydroNHDSource = r"\\myServer\NHDH_AK.gdb\Hydrography\NHDFlowline"
hydroNHDQuery = "(GNIS_Name >= '1' AND ( FType = 566 OR FType = 460 OR FType = 558))"

arcpy.Clip_analysis(hydroNHDSource, "extentPoly", "hydroExtent")   
arcpy.MakeFeatureLayer_management("hydroExtent", "HydroReselect", hydroNHDQuery)
arcpy.Buffer_analysis("HydroReselect", "hydroBuff", 500, "FULL", "ROUND", "ALL" )
hydroBuffStudy = arcpy.Clip_analysis("hydroBuff", inStudy)