[GIS] How to clip a vector feature to the extent of an existing raster dataset using arcpy

arcgis-10.0arcpycliprastervector

I have a clipped raster dataset with polylines (from the contour tool) overlayed (see attached). I am trying to clip the polylines to the extent of the raster dataset, which seems simple enough, but I've tried multiple things and can't seem to get it to work. I will eventually need to code this using arcpy but I think for now, just a nudge in the right direction as to which tool will accomplish this will help me for now.

Thanks.

P.S. I am using ArcInfo 10.0

clipPolylinesToRasterExtent

Best Answer

You can use the dataset extent as a polygon geometry with the clip tool, as in the Using geometries in geoprocessing tools example.

import arcpy

pnt_array = arcpy.Array()
extent = arcpy.Raster(in_raster).extent
pnt_array.add(extent.lowerLeft)
pnt_array.add(extent.lowerRight)
pnt_array.add(extent.upperRight)
pnt_array.add(extent.upperLeft)

poly = arcpy.Polygon(pnt_array)

arcpy.Clip_analysis(in_lines, poly, "out_dataset")