Skip to main content
Made title more concise
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

How can you make Making RasterToASCII_conversion observe environment setting for output cell size?

Added CheckoutExtension to enable Spatial Analyst tools
Source Link
jbaums
  • 745
  • 5
  • 19

I have two rasters (an ESRI grid and an IMAGINE image) that differ in projection, extent and cell size. I want to convert the IMAGINE to an ASCII, and want it to have the extent, cell size and projection of the ESRI grid. I've set global environment variables (extent, output CRS, cell size, snap raster) to match the values in the ESRI grid, and the ASCII that results from RasterToASCII_conversion has the correct projection and extent, but ignores the cell size setting.

However, if I use the Raster and ApplyEnvironment tools (see code below) from the Python console, the output is as expected (correct cell size, extent, etc).

import arcpy
arcpy.env.extent = 'c:/path/to/grid'
arcpy.env.cellSize = 'c:/path/to/grid'
arcpy.env.outputCoordinateSystem = 'c:/path/to/grid'
arcpy.env.snapRaster = 'c:/path/to/grid'
r = arcpy.Raster('c:/path/to/imagine')
arcpy.CheckoutExtension('Spatial')
rclip = arcpy.sa.ApplyEnvironment(r)
rclip.save('c:/path/to/outfile')

While I could do the above and then convert the resulting grid to ASCII, I'd prefer to do the whole procedure without using Spatial Analyst. Is this possible?

I'm using ArcGIS 10.

I have two rasters (an ESRI grid and an IMAGINE image) that differ in projection, extent and cell size. I want to convert the IMAGINE to an ASCII, and want it to have the extent, cell size and projection of the ESRI grid. I've set global environment variables (extent, output CRS, cell size, snap raster) to match the values in the ESRI grid, and the ASCII that results from RasterToASCII_conversion has the correct projection and extent, but ignores the cell size setting.

However, if I use the Raster and ApplyEnvironment tools (see code below) from the Python console, the output is as expected (correct cell size, extent, etc).

import arcpy
arcpy.env.extent = 'c:/path/to/grid'
arcpy.env.cellSize = 'c:/path/to/grid'
arcpy.env.outputCoordinateSystem = 'c:/path/to/grid'
arcpy.env.snapRaster = 'c:/path/to/grid'
r = arcpy.Raster('c:/path/to/imagine')
rclip = arcpy.sa.ApplyEnvironment(r)
rclip.save('c:/path/to/outfile')

While I could do the above and then convert the resulting grid to ASCII, I'd prefer to do the whole procedure without using Spatial Analyst. Is this possible?

I'm using ArcGIS 10.

I have two rasters (an ESRI grid and an IMAGINE image) that differ in projection, extent and cell size. I want to convert the IMAGINE to an ASCII, and want it to have the extent, cell size and projection of the ESRI grid. I've set global environment variables (extent, output CRS, cell size, snap raster) to match the values in the ESRI grid, and the ASCII that results from RasterToASCII_conversion has the correct projection and extent, but ignores the cell size setting.

However, if I use the Raster and ApplyEnvironment tools (see code below) from the Python console, the output is as expected (correct cell size, extent, etc).

import arcpy
arcpy.env.extent = 'c:/path/to/grid'
arcpy.env.cellSize = 'c:/path/to/grid'
arcpy.env.outputCoordinateSystem = 'c:/path/to/grid'
arcpy.env.snapRaster = 'c:/path/to/grid'
r = arcpy.Raster('c:/path/to/imagine')
arcpy.CheckoutExtension('Spatial')
rclip = arcpy.sa.ApplyEnvironment(r)
rclip.save('c:/path/to/outfile')

While I could do the above and then convert the resulting grid to ASCII, I'd prefer to do the whole procedure without using Spatial Analyst. Is this possible?

I'm using ArcGIS 10.

typo corrected
Source Link
jbaums
  • 745
  • 5
  • 19

I have two rasters (an ESRI grid and an IMAGINE image) that differ in projection, extent and cell size. I want to convert the IMAGINE to an ASCII, and want it to have the extent, cell size and projection of the ESRI grid. I've set global environment variables (extent, output CRS, cell size, snap raster) to match the values in the ESRI grid, and the ASCII that results from RasterToASCII_conversion has the correct projection and extent, but ignores the cell size setting.

However, if I use the Plus toolRaster and ApplyEnvironment tools (see code below) from the ArcCatalog Python console, the output is as expected (correct cell size, extent, etc).

import arcpy
from arcpy import *
from arcpy.sa import *
arcpy.env.extent = 'c:/gis_temppath/grid1'to/grid'
arcpy.env.cellSize = 'c:/gis_temppath/grid1'to/grid'
arcpy.env.outputCoordinateSystem = 'c:/gis_temppath/grid1'to/grid'
arcpy.env.workspacesnapRaster = 'c:/gis_temp'path/to/grid'
imagine1r = arcpy.Raster('c:/gis_temppath/grid2.img'to/imagine')
out1rclip = Plusarcpy.sa.ApplyEnvironment(imagine1, 0r)
out1rclip.save('c:/gis_temppath/output'to/outfile')

While I could do the above and then convert the resulting grid to ASCII, I'd prefer to do the whole procedure without using Spatial Analyst. Is this possible?

I'm using ArcGIS 10.

I have two rasters (an ESRI grid and an IMAGINE image) that differ in projection, extent and cell size. I want to convert the IMAGINE to an ASCII, and want it to have the extent, cell size and projection of the ESRI grid. I've set global environment variables (extent, output CRS, cell size, snap raster) to match the values in the ESRI grid, and the ASCII that results from RasterToASCII_conversion has the correct projection and extent, but ignores the cell size setting.

However, if I use the Plus tool (see code below) from the ArcCatalog Python console the output is as expected (correct cell size, extent, etc).

import arcpy
from arcpy import *
from arcpy.sa import *
arcpy.env.extent = 'c:/gis_temp/grid1'
arcpy.env.cellSize = 'c:/gis_temp/grid1'
arcpy.env.outputCoordinateSystem = 'c:/gis_temp/grid1'
arcpy.env.workspace = 'c:/gis_temp'
imagine1 = 'c:/gis_temp/grid2.img'
out1 = Plus(imagine1, 0)
out1.save('c:/gis_temp/output')

While I could do the above and then convert the resulting grid to ASCII, I'd prefer to do the whole procedure without using Spatial Analyst.

I'm using ArcGIS 10.

I have two rasters (an ESRI grid and an IMAGINE image) that differ in projection, extent and cell size. I want to convert the IMAGINE to an ASCII, and want it to have the extent, cell size and projection of the ESRI grid. I've set global environment variables (extent, output CRS, cell size, snap raster) to match the values in the ESRI grid, and the ASCII that results from RasterToASCII_conversion has the correct projection and extent, but ignores the cell size setting.

However, if I use the Raster and ApplyEnvironment tools (see code below) from the Python console, the output is as expected (correct cell size, extent, etc).

import arcpy
arcpy.env.extent = 'c:/path/to/grid'
arcpy.env.cellSize = 'c:/path/to/grid'
arcpy.env.outputCoordinateSystem = 'c:/path/to/grid'
arcpy.env.snapRaster = 'c:/path/to/grid'
r = arcpy.Raster('c:/path/to/imagine')
rclip = arcpy.sa.ApplyEnvironment(r)
rclip.save('c:/path/to/outfile')

While I could do the above and then convert the resulting grid to ASCII, I'd prefer to do the whole procedure without using Spatial Analyst. Is this possible?

I'm using ArcGIS 10.

added ArcGIS version details
Source Link
jbaums
  • 745
  • 5
  • 19
Loading
edited tags
Link
scw
  • 16.4k
  • 6
  • 65
  • 101
Loading
Source Link
jbaums
  • 745
  • 5
  • 19
Loading