Select to view content in your preferred language

Raster Extent

3450
2
11-29-2011 04:25 PM
by Anonymous User
Not applicable
Original User: luke.kaim

This is part of the code that I have. I basically want to create a raster from a feature with the same extents as another raster. It makes the raster, but does not change the extents to the other raster. Can you look at the code to see what I am missing? Also does raster calculator not work in python?


import arcpy, sys, os, re
from arcpy import env

arcpy.env.overwriteOutput = True
arcpy.env.workspace = "C:\\Users\\Luke Kaim\\Documents\\university_of_maine\\research4\\test2"

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")


#Raster
IDW20meter2 = "IDW20meter2"
#feature
APPROACH_POLYGON_Project_shp = "APPROACH_POLYGON_Project.shp"
#layer
PolygonFeature = "PolygonFeature"

# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(APPROACH_POLYGON_Project_shp, PolygonFeature, "", "", "FID FID VISIBLE NONE;Shape Shape VISIBLE NONE;OBJL OBJL VISIBLE NONE;CONDTN CONDTN VISIBLE NONE;OBJNAM OBJNAM VISIBLE NONE;INFORM INFORM VISIBLE NONE;SCAMIN SCAMIN VISIBLE NONE;SORDAT SORDAT VISIBLE NONE;SORIND SORIND VISIBLE NONE;DSNM DSNM VISIBLE NONE;ArbNumber ArbNumber VISIBLE NONE")


# get the extents of the raster
Bottom = arcpy.GetRasterProperties_management(IDW20meter2,"BOTTOM")
Top = arcpy.GetRasterProperties_management(IDW20meter2,"TOP")
Left = arcpy.GetRasterProperties_management(IDW20meter2,"LEFT")
Right = arcpy.GetRasterProperties_management(IDW20meter2,"RIGHT")
#User specified XMin, YMin, XMax, YMax values.
# set env to those extents I think
arcpy.env.extent = arcpy.Extent(Left, Bottom, Right, Top)


Ftoraster3 = "Ftoraster3"
FinRast_r = "finRast"
FinishedRasterACSII_TXT = "FinishedRasterACSII_TXT.TXT"

print "test"
# Process: Feature to Raster
arcpy.FeatureToRaster_conversion(PolygonFeature, "FID", Ftoraster3, "20")
print "finished"

# Process: Raster Calculator
arcpy.gp.RasterCalculator_sa("Con(IsNull(\"Ftoraster3\"),\"idw20meter2\", -1)", FinRast_r)


# Process: Raster to ASCII
arcpy.RasterToASCII_conversion(FinRast_r, FinishedRasterACSII_TXT)


Any ideas?
0 Kudos
2 Replies
by Anonymous User
Not applicable
Original User: luke.kaim

Is what I am trying to do not make sense?

Thank you,
Luke Kaim

Thank you
Luke Kaim (SIE)
Lucas.Kaim@maine.edu
(914)263-7866
�??Everything should be made as simple as possible, but no simpler�?� (Albert Einstein).
0 Kudos
AnthonyTimpson2
Regular Contributor
It makes sense to me.. I dont have code that does what you are trying to do but i do have a snippet for zooming to the extent of a polygon. It strikes me as somewhat similar in principle...



xmin, ymin, xmax, ymax  = row.shape.extent.XMin, row.shape.extent.YMin,                                                                          row.shape.extent.XMax, row.shape.extent.YMax
       
df = arcpy.mapping.ListDataFrames(mxd)[0]
newExtent = df.extent
newExtent.XMin, newExtent.YMin, newExtent.XMax, newExtent.YMax = xmin, ymin, xmax, ymax
df.extent = newExtent
arcpy.RefreshActiveView()
0 Kudos