POST
|
It sounds like I will need to spend some time working out how to do this in GDAL.... thanks for the replies!
... View more
01-26-2012
03:31 PM
|
0
|
0
|
491
|
POST
|
I am still having difficulties converting a numpy array to a raster. I have created a raster for my cell sizes and have found the latitude min and longitude min for the lower_left_corner and use the following code: from numpy import * myarray=genfromtxt("E:/test/rasterise/myfile.txt") mylon=genfromtxt("E:/test/rasterise/LATout.txt") mylat=genfromtxt("E:/test/rasterise/LONout.txt") corner=arcpy.Point(139.8, -39.2) myRaster=arcpy.NumPyArrayToRaster(myarray, corner, mylon, mylat) but I receive an error message: Runtime error <type 'exceptions.TypeError'>: Argument x_cell_size: Expected a numeric value, Raster instance or path name. however the documentation says that you can use a raster for the cell size. Not sure where I am going wrong here. Any feedback will be greatly appreciated.
... View more
01-24-2012
06:53 PM
|
0
|
5
|
2901
|
POST
|
Hi All, I need to run a process in python on a huge array but I first need to create a mask using a shapefile. Does anyone know how I could do this or any examples I could follow? Once I have created the mask this is what I would like to do temparray=numpyarraycoveringtemperatureofwholestate shapefile=forestedregions.shp forestedregionsasarray=convert shapefile to array of 0's and 1's?? newarray=ma.masked_values(temparray,forestregionsasarray) meantemperatureofforestedregions=MA.mean(newarray) print meantemperatureofforestedregions Any ideas of functions I could use, examples I could follow? Thanks
... View more
11-03-2011
09:13 PM
|
0
|
0
|
745
|
POST
|
Thanks for the feedback, especially the point/corner idea. I eventually found lower left corner (print LONmin() LATmin() for netcdf file) and cell size (simply by printing all the lats and lons in python and then minusing one from the other, not the prettiest method but it gave me what I needed) but I seem to still be producing an upside down raster! I have tried numpy.flipud and from the documentation this appears to be the best method but the results are strange lines. Maybe to solve this problem I need to go back to the original array? Is there some way I should write my array to a file that will make it easier to import into arcmap as a raster? I am currently using savetxt("myfile.txt", myarray) any feedback will be greatly appreciated.
... View more
10-25-2011
06:05 PM
|
0
|
0
|
711
|
POST
|
I would like to use arcpy.NumPyArrayToRaster to import a numpy array and use in arcGIS10 as a raster. This function works fine except I did not enter the lower left corner (in map units) and the x and y cell size, therefore my image was upside down! Is there a simple command I can run in python on my numpy array to find out what the lower left corner is?? thanks
... View more
10-04-2011
07:15 PM
|
0
|
6
|
2825
|
POST
|
In case some one else is doing this I have ended up just using SUM in cell statistics. I convert the category I am interested in to a binary and then sum. What I really wanted though was to be able to have various classes assigned and to add them depending on what class. e.g. If cell = 6 then convert is to a 1 if cell = anything but 6 convert it to 0 then sum rasters to produce an output image with the frequency of that category and then repeat this for each other category. if cell =5 then convert to a 1 else convert to 0 and sum
... View more
06-27-2011
02:54 PM
|
0
|
0
|
236
|
POST
|
I posted this to spatial analyst but thought it might be more appropriate here. I have reclassified many raster to be only 0's and 1's and I would like to sum the 1's together and output a new raster which is basically a count of those rasters. I have used the code from a thread in spatial analyst so I am open to different tools to do this processing. When I run the code I do receive an output but it is wrong and python keeps crashing each time I try to run it so I don't receive an error message. Can someone please tell me what I am doing wrong. Thanks
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
import os
# Set environment settings
arcpy.env.workspace = "D:/sumrasters/rasterimgs"
outputfolder="D:/sumrasters/output_sumRaster"
datapath="D:/reclass/sumrasters/rasterimgs"
arcpy.env.overwriteOutput = 1
arcpy.CheckOutExtension('Spatial')
arcpy.env.scratchWorkspace = r"c:\temp\scratch.gdb"
#create a list of rasters in the workspace
rasters = arcpy.ListRasters("*","IMG")
i = 0
#loop through rasters in list
for raster in rasters:
print rasters
#sum rasters together
if i == 0:
outSUM = arcpy.Raster(raster)
i += 1
else:
outSUM = outSUM + raster
i += 0
#save final output to the current workspace
outSUM.save(os.path.join(outputfolder,"sumRas.img"))
print "end of processing"
... View more
06-20-2011
06:13 PM
|
0
|
1
|
380
|
POST
|
I have reclassified a raster to be only 0's and 1's and I would like to sum the 1's together. I have used the code from this thread but my output is not correct and python keeps shutting down each time I run it so I do not even get an error message. Can someone please tell me what I am doing wrong. Thanks
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
import os
# Set environment settings
arcpy.env.workspace = "D:/sumrasters/rasterimgs"
outputfolder="D:/sumrasters/output_sumRaster"
datapath="D:/DSE_work/reclass/sumrasters/rasterimgs"
arcpy.env.overwriteOutput = 1
arcpy.CheckOutExtension('Spatial')
arcpy.env.scratchWorkspace = r"c:\temp\scratch.gdb"
#create a list of rasters in the workspace
rasters = arcpy.ListRasters("*","IMG")
i = 0
#loop through rasters in list
for raster in rasters:
print rasters
#sum rasters together
if i == 0:
outSUM = arcpy.Raster(raster)
i += 1
else:
outSUM = outSUM + raster
i += 0
#save final output to the current workspace
outSUM.save(os.path.join(outputfolder,"sumRas.img"))
print "end of processing"
... View more
06-19-2011
09:56 PM
|
0
|
0
|
693
|
POST
|
I am trying to do something similar and have followed the link posted above. I am getting an error: Runtime error <type 'exceptions.IndexError'>: list index out of range The code I am working on is trying to change the symbology of one file, I actually need it to work on many files. Can someone help me with the code below to make this happen! Thanks
import arcpy
mxd = arcpy.mapping.MapDocument(r"D:\updatelayer\mxd1.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
updateLayer = arcpy.mapping.ListLayers(mxd, "FFDI_19900102", df)[0]
sourceLayer = arcpy.mapping.Layer(r"C:\Project\Data\FFDI_19900101.img.lyr")
arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True)
mxd.saveACopy(r"D:\updatelayer\test.mxd")
... View more
06-19-2011
05:22 PM
|
0
|
0
|
219
|
POST
|
Hello, I am still having trouble running makenetcdfrasterlayer and then exporting as a raster in python. My main problem is working out how to run makenetcdfrasterlayer on each dimension value (for time) and being able to export these as rasters. This is the code I have so far. Any feedback will be greatly appreciated!!
#Make a separate raster *.img file for each dimension value (time) in a netcdf file
import arcpy
from arcpy import env
from arcpy.sa import *
import os
# Set local variables
inNetCDF = r"D:/DSE_work/FFDInetcdf/FEB2009FFDI/IDZ00026_VIC_ADFD_FFDI_SFC.nc"
env.workspace="D:/DSE_work/FFDInetcdf/FEB2009FFDI"
outRasterFolder = "D:/data/FFDInetcdf/OutputRasters"
variable = "FFDI_SFC"
XDimension = "longitude"
YDimension = "latitude"
bandDimension = ""
dimensionValues = "time"
valueSelectionMethod = "BY_VALUE"
# loop through all dimension and show the values
ncFP = arcpy.NetCDFFileProperties(inNetCDF)
ncDim = ncFP.getDimensions()
for dim in ncDim:
print "dimension name is:", dim
dimsize = ncFP.getDimensionSize(dim)
for i in range(0,dimsize):
dimvalues=ncFP.getDimensionValue(dim,i)
print dimvalues
# Execute MakeNetCDFRasterLayer
arcpy.MakeNetCDFRasterLayer_md(inNetCDF,
variable,
XDimension,
YDimension,
(outRasterFolder,dimvalues), #output folder named by dimension value
bandDimension,
(dimensionValues,dimvalues), #need to feed in each day (value from the time dimension e.g time 2/02/2009)
valueSelectionMethod)
#export raster layer (from scratch workspace) to raster output folder as *.img
Rasters_List=[]
for Rasters in arcpy.ListRasters():
Rasters_List.append(Rasters)
arcpy.CopyRaster_management(outRasterFolder, ((os.path.join(outRasterFolder, "netcdf_"+rasters))), "", "", "NONE", "NONE", "")
print "end of processing"
... View more
06-15-2011
08:33 PM
|
0
|
0
|
1054
|
POST
|
help for others with the same problem, this works:
import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
import os
inputfolder="D:/reclass/reclassinputs"
env.workspace = inputfolder
outputfolder="D:/reclass/reclassoutputs"
reclassfield = "Value"
remap=RemapValue([[0,11,1],
[12,24,2],
[25,49,3],
[50,74,4],
[75,99,5],
[100,350,6]])
for raster in arcpy.ListRasters("","IMG"):
print raster
outReclassify=Reclassify(raster, reclassfield, remap, "NODATA")
outReclassify.save((os.path.join(outputfolder, "reclass_"+raster)))
print "end of processing"
... View more
06-15-2011
07:25 PM
|
0
|
0
|
253
|
POST
|
thanks for the response. I think I will take your advice.
... View more
06-15-2011
07:22 PM
|
0
|
0
|
1040
|
POST
|
thanks, but surely they will move to Python3 soon enough/eventually? I should just try and stay on top of both! that will be easy enough....
... View more
06-15-2011
03:09 PM
|
0
|
0
|
1040
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|