Select to view content in your preferred language

Create an outline of a raster grid

598
1
07-18-2013 01:46 AM
ShaneCarey
Deactivated User
Hi,

I have a raster grid and I need to create a outline from the grid, some areas have No data and I was going to try create an outline using contour, but this will not work for areas of No data.

Any ideas would be appreciated,

Cheers
Thanks
Tags (2)
0 Kudos
1 Reply
JamesCrandall
MVP Frequent Contributor
You can use the Extent of the raster to get the lower-left, lower-right, upper-left, and upper-right points and just add these to a new polyline or polygon feature class.


inputRaster = r"C:\MyRaster"
desc = arcpy.Describe(inputRaster)
ext = desc.extent

ll = ext.lowerLeft
ul = ext.upperLeft
lr = ext.lowerRight
ur = ext.upperRight

arcpy.CreateFeatureclass_management(r"C:\Documents\ArcGIS\Default.gdb","extentoutput", "POLYGON")

outFC = r"C:\Documents\ArcGIS\Default.gdb\extentoutput"

array = arcpy.Array([ll, ul, ur, lr])
pg = arcpy.Polygon(array)

with arcpy.da.InsertCursor(outFC, ["SHAPE@"]) as cursor:
    cursor.insertRow([pg])



Edit:  If you want it as a polyline output FC, then be sure to add the starting point at the end to "close" the polyline as a bounding box:


inputRaster = r"C:\MyRaster"
desc = arcpy.Describe(inputRaster)
ext = desc.extent

ll = ext.lowerLeft
ul = ext.upperLeft
lr = ext.lowerRight
ur = ext.upperRight

arcpy.CreateFeatureclass_management(r"C:\Documents\ArcGIS\Default.gdb","extentoutput", "POLYLINE")

outFC = r"C:\Documents\ArcGIS\Default.gdb\extentoutput"

array = arcpy.Array([ll, ul, ur, lr, ll])
pl = arcpy.Polyline(array)

with arcpy.da.InsertCursor(outFC, ["SHAPE@"]) as cursor:
    cursor.insertRow([pl])

0 Kudos