POST
|
Hi all, I would like to write a collection of RGB rasters located in a folder to a single pdf, with one raster per image. I see that a methodology is outlined here: https://community.esri.com/t5/python-questions/export-multiple-raster-into-single-pdf-using-arcpy/td-p/507608 However, this is for arcmap 10.x. I am wanting to go through a collection of rasters, loading each one individually into a layout, and then print the layout to a pdf, and then remove the raster before adding the next. Is it possible to do this in Arcgis Pro / arcpy? If anyone could point me in the right direction, I would greatly appreciate it.
... View more
01-19-2023
11:09 AM
|
0
|
2
|
235
|
POST
|
The issue was that I had previously used arcpy.management.Clip to trim a raster with a shapefile, and this resulted in the cell size being, not 30 m, but something like 29.96 and 29.954. Downstream tools used different combination of these values to assign cell size and that is where the problem occurred.
... View more
08-24-2022
05:32 AM
|
0
|
0
|
562
|
POST
|
Okay, here is some minimal code, along with the file that is causing me problems. import arcpy
from arcpy import env
from arcpy import Raster
arcpy.CheckOutExtension("Spatial")
from arcpy.sa import *
arcpy.ResetEnvironments()
arcpy.env.overwriteOutput = True
arcpy.env.snapRaster = arcpy.sa.Raster(file)
arcpy.env.cellSize = file
rast = arcpy.sa.Raster(file)
desc = arcpy.Describe(rast)
xmin = desc.extent.XMin
xmax = desc.extent.XMax
ymin = desc.extent.YMin
ymax = desc.extent.YMax
print("xmin: %s \nxmax: %s \nymin: %s \nymax: %s" % (xmin, xmax, ymin, ymax))
arcpy.env.extent = arcpy.Extent(xmin, ymin, xmax, ymax)
red = arcpy.sa.Raster(file + '\B3')
NIR = arcpy.sa.Raster(file + '\B4')
tmp1 = 0.1 - red ## This is where some problems are happening
tmp2 = 0.06 - NIR
### get cell size
cllsizeX = arcpy.management.GetRasterProperties(Raster(file),"CELLSIZEX")
print("cell size X = " + cllsizeX.getOutput(0))
cllsizeY = arcpy.management.GetRasterProperties(Raster(file),"CELLSIZEY")
print("cell size Y = " + cllsizeY.getOutput(0))
### Now this is smaller than the image cell size
cllsizeX = arcpy.management.GetRasterProperties(NIR,"CELLSIZEX")
print("cell size X = " + cllsizeX.getOutput(0))
cllsizeY = arcpy.management.GetRasterProperties(NIR,"CELLSIZEY")
print("cell size Y = " + cllsizeY.getOutput(0))
### Same as NIR
cllsizeX = arcpy.management.GetRasterProperties(red,"CELLSIZEX")
print("cell size X = " + cllsizeX.getOutput(0))
cllsizeY = arcpy.management.GetRasterProperties(red,"CELLSIZEY")
print("cell size Y = " + cllsizeY.getOutput(0))
### Now this larger than NIR. GRRRR
cllsizeX = arcpy.management.GetRasterProperties(tmp1,"CELLSIZEX")
print("cell size X = " + cllsizeX.getOutput(0))
cllsizeY = arcpy.management.GetRasterProperties(tmp1,"CELLSIZEY")
print("cell size Y = " + cllsizeY.getOutput(0)) I don't understand how the multiband raster can have cell sizes that are different than the underlying bands. This seems to be the case, but is not the case in R or QGIS. Any help would be appreciated.
... View more
08-23-2022
08:25 AM
|
0
|
1
|
569
|
POST
|
Thanks for the suggestion, but that didn't do the trick. The issue is that the y cell size is slightly larger on the output raster, when compared to the input raster. Here is the code that I have used to try to remedy the situation: ### get and set extent of raster
file = "image.tif"
import arcpy
from arcpy import env
from arcpy import Raster
arcpy.CheckOutExtension("Spatial")
from arcpy.sa import *
arcpy.ResetEnvironments()
arcpy.env.overwriteOutput = True
arcpy.env.snapRaster = arcpy.sa.Raster(file)
arcpy.env.cellSize = file
rast = arcpy.sa.Raster(file)
desc = arcpy.Describe(rast)
xmin = desc.extent.XMin
xmax = desc.extent.XMax
ymin = desc.extent.YMin
ymax = desc.extent.YMax
print("xmin: %s \nxmax: %s \nymin: %s \nymax: %s" % (xmin, xmax, ymin, ymax))
arcpy.env.extent = arcpy.Extent(xmin, ymin, xmax, ymax)
red = arcpy.sa.Raster(file + '\B3')
NIR = arcpy.sa.Raster(file + '\B4')
tmp1 = 0.1 - red
tmp2 = 0.06 - NIR
denom = arcpy.sa.Power(tmp1,2) + arcpy.sa.Power(tmp2,2)
BAI = arcpy.sa.Divide(1, denom)
desc = arcpy.Describe(BAI)
xmin = desc.extent.XMin
xmax = desc.extent.XMax
ymin = desc.extent.YMin
ymax = desc.extent.YMax
print("xmin: %s \nxmax: %s \nymin: %s \nymax: %s" % (xmin, xmax, ymin, ymax))
BAI.save(r"D:\test.tif")
### get cell size
cllsize = arcpy.management.GetRasterProperties(template,"CELLSIZEX")
print(cllsize.getOutput(0))
cllsize = arcpy.management.GetRasterProperties(BAI,"CELLSIZEX")
print(cllsize.getOutput(0))
cllsize = arcpy.management.GetRasterProperties(template,"CELLSIZEY")
print(cllsize.getOutput(0))
cllsize = arcpy.management.GetRasterProperties(BAI,"CELLSIZEY")
print(cllsize.getOutput(0)) Even after attempting to set the cell size and extent, the output raster is not the same as the input raster. Any other suggestions?
... View more
08-23-2022
06:09 AM
|
0
|
0
|
574
|
POST
|
Hi all, I was not aware of the BAI function ins Spatial Analyst, and so I had written the burned area index into a function. However, the results shifted the raster cells and I am not sure why. Here is the example of the code I used in raster calculator: 1/((0.1 - Power("LS5_c1_19920425.tif_B3",2)) + Power("LS5_c1_19920425.tif_B4",2)) where files "..B3.tif" and "..B4.tif" are the red and NIR bands from landsat imagery. When I use the BAI function in spatial analyst, the alignment is correct. I don't see what in the code that I have would lead to a shift in the raster cells. Any help would be appreciated.
... View more
08-19-2022
01:15 PM
|
0
|
4
|
662
|
POST
|
For the purposes of the tool, ObjectID is not important, but I can see that in many cases it would be important.
... View more
08-16-2022
06:37 AM
|
0
|
0
|
197
|
POST
|
Hi John, Where are you in the process? Do you have a shapefile with the values? If so, you can import the shapefile attribute table as a numpy array and then use do it within python. Something kind of like this. from sklearn.metrics import confusion_matrix
shp = 'path\\to\\shapefile.shp'
truth = arcpy.da.TableToNumPyArray(shp,'truth')
model = arcpy.da.TableToNumPyArray(shp,'model')
cm =confusion_matrix(model, truth)
... View more
08-15-2022
09:51 AM
|
0
|
0
|
352
|
POST
|
When I exported a tif of the sentinel imagery, the resolution was 10 M. I think that when you are looking at it as a web service, the resolution is lower for speed.
... View more
08-15-2022
08:57 AM
|
0
|
0
|
6519
|
POST
|
Did you go through all the steps identified here? https://doc.arcgis.com/en/imagery/workflows/tutorials/using-image-services-in-arcgis-pro.htm I just loaded the imagery and it may be that you have to do some post-processing to get higher resolution images. When I simply load, only the RGB bands are available.
... View more
08-15-2022
08:25 AM
|
0
|
0
|
6524
|
POST
|
Sorry, I don't have any information to answer that. I just went and pulled in the sentinel 2 data and it "says" it is 10 meter resolution, but it sure doesn't look like it. It does says that it is still in beta, so not sure what you could do here.
... View more
08-15-2022
08:06 AM
|
0
|
1
|
6530
|
POST
|
My understanding is that different bands have different spatial resolutions. If you are just needing RGB, then those bands should be at 10 m resolution. The 60 m res are for bands 1,9 and 10 (blue aerosol, water vapor, and SWIR-Cirrus).
... View more
08-15-2022
07:41 AM
|
0
|
0
|
6536
|
POST
|
Hi all, I am trying to understand the behavior of ExtractMultiValuesToPoints when incorporated into an Arcgis tool. I have used the function in an Arcpy standalone script, and it works just fine. However, after incorporating into a python tool, the stars have to be aligned just right for it to work. Included is a tool that I have created to extract values from a multiband raster into a new shapefile. The issues are (1) I have to rename the bands because the tool generates new names not related to the raster bands, (2) if the shapefile is linked to the tool from a GIS workspace, the names aren't carried over, (3) rasters cannot be linked to from a GIS workspace and (4) ExtractMultiValuesToPoints has no option to preserve the original file (as far as I can tell). These are really just minor annoyances, so am wondering if I am somehow doing it wrong. Thanks for any information. class Combine_labels_features(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "07 Combine labels and features"
self.description = "This tool combines the labels point shapefile (generated and QAQC'd) with the appropriate features file"
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
labels = arcpy.Parameter(
displayName="labels file",
name="labels",
datatype="GPFeatureLayer",
parameterType="Required",
direction="Input")
labels.filter.list = ["Point"]
features = arcpy.Parameter(
displayName="features (raster)",
name="features",
datatype= u'GPRasterLayer',
parameterType="Required",
direction="Input")
outfile = arcpy.Parameter(
displayName="outfile",
name="outFile",
datatype="DEType",
parameterType="Required",
direction="Output")
params = [labels,features,outfile]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""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, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
labels = parameters[0].valueAsText
infile = parameters[1].valueAsText
outfile = parameters[2].valueAsText
features = Raster(infile)
rasters = [] ### holder for raster predictors
nams = features.bandNames
names = ["B_" + str(i+1) for i in range(0,len(nams))]
for i in range(0,len(nams)):
print(nams[i])
tmplist = [infile + "\\" + nams[i],names[i]]
rasters.append(tmplist)
origNames = [field.name for field in arcpy.ListFields(labels)]
arcpy.sa.ExtractMultiValuesToPoints(labels,infile,"BILINEAR")
tmpfile = os.path.basename(tempfile.TemporaryFile().name)
arcpy.management.CopyFeatures(labels,tmpfile,'', None, None, None)
badNames = [field.name for field in arcpy.ListFields(tmpfile)]
badNames = [x for x in badNames if x not in origNames]
badNames.remove("OBJECTID")
BandKey = {badNames[i]:nams[i] for i in range(len(badNames))}
for key, value in BandKey.items():
print(key)
print(value)
arcpy.AlterField_management(tmpfile, key,value)
## add directly to initial labels. Should make copy if you want to preserve.
## ExtractMultiValuesToPoints is not behaving as it should. In Arcpy, the names from
## the original rasters carries through. Does not happen in the tool. Not sure why,
arcpy.management.CopyFeatures(tmpfile,outfile,'', None, None, None)
arcpy.Delete_management(tmpfile)
return
... View more
08-15-2022
07:08 AM
|
0
|
2
|
217
|
POST
|
I am not sure how you figured that out, but thanks a lot. I would have never arrived at this for a solution.
... View more
08-12-2022
05:32 AM
|
0
|
0
|
869
|
Title | Kudos | Posted |
---|---|---|
1 | 06-13-2022 11:03 AM | |
1 | 07-27-2022 09:10 AM | |
1 | 07-12-2022 09:45 AM | |
1 | 07-23-2020 11:22 AM | |
1 | 07-23-2020 08:53 AM |
Online Status |
Offline
|
Date Last Visited |
06-08-2023
08:07 PM
|