9

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

12

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")
  • Thank you!! Before I saw this post, I was able to at least manually do it within Arc, but it sure seems like my way is slightly convoluted. I created a dummy shapefile and then constructed a polygon with the editor tools which outlined the boundary of the raster data. Then I ran the clip tool on the polylines using this dummy shapefile as what it should clip them too. I got an error, but then I used feature to polygon and used the result of this as the shapefile for the polylines to be clipped to and it worked!! I will need arcpy so thanks for that!! :-) – niklas24 Mar 25 '12 at 2:08
2

There is a simple way to do this.

First get the extent of the raster image.

set it as environment extent property

Then use the copy feature instead of clip analysis , for example

arcpy.env.extent = arcpy.Extent(-107.0, 38.0, -104.0, 40.0)
...some code here to ...
arcpy.CopyFeatures_management(shapefile,outFeatureClass)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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