|
POST
|
Does your internet connection pass through a proxy that requires authentication? The MODIS Import Tool uses the python urllib module to download the images. The urllib documentation notes that: Proxies which require authentication for use are not currently supported; this is considered an implementation limitation.
... View more
12-26-2011
11:39 AM
|
0
|
0
|
578
|
|
POST
|
Just make two copies of the parameter variable. >>> param1a=param1b=arcpy.GetParameterAsText(1)
>>> print param1a
Some Parameter
>>> print param1b
Some Parameter
>>> print param1a==param1b
True
>>> param1a='Something else'
>>> print param1a==param1b
False
... View more
12-19-2011
02:37 PM
|
0
|
0
|
683
|
|
POST
|
fieldvalue=' '.join(fieldvalue.strip().split())
#in case fieldvalue=='', change empty string to space to avoid "Field is not Nullable" error
if not fieldvalue: fieldvalue=' '
... View more
12-19-2011
10:43 AM
|
0
|
0
|
4528
|
|
POST
|
It is better practice to store the return value from a function/method in a variable if you are going to use it more than once rather than repeatedly calling the function method. param1=arcpy.GetParameterAsText(1)
for i in range(10):
if i >=param1: #eg use a variable instead of calling GetParameterAsText 10x
dosomething()
... View more
12-19-2011
10:12 AM
|
0
|
0
|
683
|
|
POST
|
Do I loop for rows and cols? Depends on the type of raster you are using. Some rasters are tiled internally and it is much more efficient to access by tiles or blocks. Geodatabase rasters have 128x128 pixel tiles (by default), GRIDS are 256x4 (col then row), tiffs can be tiled or untiled (safest to process one row at a time). Here is some code to process by tile (the commented out stuff is arcpy related that I can't test as I'm not at back work until January). ncols=67000
nrows=58000
cellsize=2
xmin=0
ymax=58000
## ^^ Get all this info from your original raster
tile_size=(128,128) #GDB rasters=(128,128), tif=(ncols,1), GRID=(256,4)
ntiles = 4 #no. of tiles to process at a time
#arcpy.env.Extent=in_raster
#arcpy.env.outputCoordinateSystem=in_raster
#arcpy.env.cellSize=in_raster
#new_raster=arcpy.CreateRasterDataset(out_path, out_name, cellsize, pixel_type,
# spatial_reference)
for row in range(0,nrows,tile_size[1]):
for col in range(0,ncols,tile_size[0]*ntiles):
colend=min([ncols,col+tile_size[0]*ntiles-1])
rowend=min([nrows,row+tile_size[1]-1])
xstart=xmin+(cellsize*col)
ystart=ymax-(cellsize*(rowend+1))
print 'Processing cols',col,':',colend
print 'Processing rows',row,':',rowend
print 'Extracting lower left corner:',xstart,ystart
#array=RasterToNumPyArray (in_raster, arcpy.Point(xmin,ystart), ncols, step)
#Do your processing
#out_raster=NumPyArrayToRaster(array, arcpy.Point(xmin,ystart), cellsize, cellsize)
#arcpy.Mosaic_management(out_raster,new_raster)
... View more
12-18-2011
12:13 PM
|
0
|
0
|
3428
|
|
POST
|
Sorry, I'm not at work so don't have access to ArcGIS to test an example. I think the mosaic tool will do what you need though: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Mosaic_To_New_Raster/001700000098000000/ or http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000097000000
... View more
12-17-2011
12:14 PM
|
0
|
0
|
3428
|
|
POST
|
You can specify what part of the raster to extract to a numpy array - RasterToNumPyArray(in_raster, lower_left_corner, ncols, nrows). http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/NumPyArrayToRaster/000v00000130000000/ So you could loop through and process a few rows at a time.
... View more
12-17-2011
01:53 AM
|
0
|
0
|
3427
|
|
POST
|
That's because your raster is too big to fit in memory. A 67000*58000 (1 band) 8 bit raster is 4GB, 16 bit is 7GB and 32 bit is 14GB... If you must use numpy, you will have to clip out smaller sections/tiles of your raster, convert to numpy array, process each tile separately and then convert back to raster and mosaic. Looking at the commented out section of your code, you don't need to use numpy at all, all those operations can be done in spatial analyst map algebra.
... View more
12-16-2011
12:07 PM
|
0
|
0
|
3427
|
|
POST
|
I've had trouble with ZonalStats using objectid fields previously. Try using another field of SmallInteger or Integer type, no floating points (i.e. Double) or text. You also need to make sure that the ArcGIS ScratchWorkspace environment setting (or the Windows %TEMP% environment variable) points to a path without spaces as ArcGIS writes temporary grids there and will fail with a very unhelpful error message if the path has spaces.
... View more
12-07-2011
03:26 PM
|
0
|
0
|
1522
|
|
POST
|
Note: indentation is correct just didn't copy correctly If you use the CODE tag (the "#" button in the editor toolbar above where you type your post) than the indentation will be preserved.
... View more
12-04-2011
02:15 PM
|
0
|
0
|
558
|
|
POST
|
I've been practicing recently with numpy for certain tasks. It works nicely (using indices) for returning the row and column numbers for small and medium-sized rasters, up to a few thousand cells on a side. When I work with large rasters (10000-by-10000 or larger), I get a Python Memory Error. It seems that numpy is not an option for doing computations with data for large rasters. Check out pytables or numpy.memmap Is there a practical procedure out there for returning row and column numbers for large rasters? I've seen suggestions for using fishnet or flowaccumulation, but am guessing that the steps involved would make for verrry slow processing. import arcgisscripting
gp = arcgisscripting.create(9.3) #This works in ArcGIS 10 for backwards compatibility.
#Make sure extent and cellsize are set in the arcgisscripting environment...
expr='$$rowmap'
output=r'C;\Temp\rowmap'
result=gp.SingleOutputMapAlgebra(expr,output)
... View more
12-01-2011
11:48 PM
|
0
|
0
|
1226
|
|
POST
|
From the ArcGIS 10 Help page on the raster calculator: Note: The Raster Calculator tool is intended for use in the ArcGIS Desktop application only as a GP tool dialog box or in ModelBuilder. It is not intended for use in scripting and is not available in the ArcPy Spatial Analyst module. However, you can use map algebra operators and functions directly in python. E.g. from arcpy.sa import *
import arcpy
arcpy.CheckOutExtension("Spatial")
landmask=Raster(r'C:\SomeDirectory\landmask')
bathymetry=Raster(r'C:\SomeDirectory\bathy')
masked_bathymetry=Con(IsNull(landmask), bathymetry, 70000)
masked_bathymetry.save(r'C:\SomeDirectory\maskbath')
... View more
11-30-2011
05:44 PM
|
0
|
0
|
1373
|
|
POST
|
Con means 'conditional', it's basically an if/else statement - see the Con reference. IsNull means just that, it determines which cells in the input raster have no data and which do - see IsNull reference. So the raster calculator statement I gave you above means: If a landmask cell has no data (is not land) then assign the value of the bathymetry raster (from the cell at the same coordinates) to the output raster, otherwise assign 70000 to that cell.
... View more
11-27-2011
02:00 PM
|
0
|
0
|
1373
|
|
POST
|
Convert "oceancl" featureclass to raster with the same cell size and registration as the DEM. Use a raster calculator expression something like the following which will keep all DEM values where there is no ocean and insert "0" where there is: Con(IsNull(oceanraster), dem, 0)
... View more
11-24-2011
03:39 PM
|
0
|
0
|
587
|
|
POST
|
You can use a ToolValidator class. This is set in the script tool properties dialog in the Validation tab. Something like: class ToolValidator:
"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog."""
def __init__(self):
"""Setup arcpy and the list of tool parameters."""
import arcpy
self.params = arcpy.GetParameterInfo()
def initializeParameters(self):
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""
names=set() #Sets only handle unique values
rows = arcpy.SearchCursor('Rivers','','','NAME')
for row in rows:
names.add(row.getValue('NAME'))
for param in self.params:
if param.name == 'RiverName':
param.filter.list=list(names)
break
return
def updateParameters(self):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
... View more
11-10-2011
01:02 PM
|
0
|
0
|
416
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 07-30-2025 03:00 PM | |
| 1 | 06-10-2025 08:06 PM | |
| 5 | 05-20-2025 07:56 PM | |
| 1 | 05-04-2025 10:34 PM | |
| 5 | 04-22-2025 09:04 PM |