problem with create a RasterLayer object from file using R

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

problem with create a RasterLayer object from file using R

soshi
Hi everybody,
I got error, but I didn't understand. because I tested in R software.
actually I get a raster image (TXT file as input-MTL is Metadata for raster images)
I tested without wps, it runs correctly: mtlFile : it gets MTL file
myImg read all bands of raster images

R process:
# calculate NDVI for raster ,
#wps.des: NDVI, NDVI for raster;
#wps.in: input, text/plain;


library(RStoolbox);
library(sp);
library(raster);
library(ggplot2);

# import separate Landsat files into single RasterStack
mtlFile = input


myImg = stackMeta(mtlFile, quantity = "all", category = "image", allResolutions = FALSE)
x = raster(myImg)

NDVI <- function(myImg, NIR, Red){
  ndvi <- (myImg[[NIR]] - myImg[[Red]]) / (myImg[[NIR]] + myImg[[Red]])
  return(ndvi)
}

# in Landsat8 imagery, band 5 is NIR and band 4 is red
output_ndvi <- NDVI(myImg, 5, 4)


f = writeRaster(output_ndvi, filename="output_ndvi.tif", overwrite=TRUE);

output = "output_ndvi.tif"

#wps.out: output, application/geotiff;

and request:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<wps:Execute service="WPS" version="1.0.0"
        xmlns:wps="http://www.opengis.net/wps/1.0.0"
        xmlns:ows="http://www.opengis.net/ows/1.1"
        xmlns:xlink="http://www.w3.org/1999/xlink"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0
  http://schemas.opengis.net/wps/1.0.0/wpsExecute_request.xsd">
        <ows:Identifier>org.n52.wps.server.r.NDVI</ows:Identifier>
        <wps:DataInputs>
                <wps:Input>
                        <ows:Identifier
                                xmlns:ns1="http://www.opengis.net/ows/1.1">input</ows:Identifier>
                        <wps:Reference xlink:href="http://localhost:8080/satellite_image/LC08_L1TP_043032_20170623_20170630_01_T1_MTL.txt" mimeType="text/plain" />
                </wps:Input> 
        </wps:DataInputs>
        <wps:ResponseForm>
                <wps:RawDataOutput mimeType="application/geotiff">
                        <ows:Identifier>output</ows:Identifier>
                </wps:RawDataOutput>
        </wps:ResponseForm>
</wps:Execute> 

response:

<ows:ExceptionReport xmlns:ows="http://www.opengis.net/ows/1.1" version="1.0.0">
<ows:Exception exceptionCode="RemoteComputationError">
<ows:ExceptionText>
An R error occured while executing R script: Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", : Cannot create a RasterLayer object from this file. (file does not exist)
</ows:ExceptionText>
</ows:Exception>
<ows:Exception exceptionCode="JAVA_StackTrace">
<ows:ExceptionText>
org.n52.wps.server.ExceptionReport: An R error occured while executing R script: Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", : Cannot create a RasterLayer object from this file. (file does not exist) at org.n52.wps.server.r.util.RExecutor.executeScript(RExecutor.java:191) at org.n52.wps.server.r.GenericRProcess.run(GenericRProcess.java:242) at org.n52.wps.server.request.ExecuteRequest.call(ExecuteRequest.java:685) at org.n52.wps.server.request.ExecuteRequest.call(ExecuteRequest.java:92) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)
</ows:ExceptionText>
</ows:Exception>
<ows:Exception exceptionCode="JAVA_RootCause"/>
</ows:ExceptionReport>

how Can I solve the problem?
thanks in advance...
Reply | Threaded
Open this post in threaded view
|

Re: problem with create a RasterLayer object from file using R

BenjaminPross
When R reads the MTL file, the tif and other files specified in the file must be present in the workspace.

E.g.:

....
    FILE_NAME_BAND_1 = "LC08_L1TP_139045_20170304_20170316_01_T1_B1.TIF"
    FILE_NAME_BAND_2 = "LC08_L1TP_139045_20170304_20170316_01_T1_B2.TIF"
    FILE_NAME_BAND_3 = "LC08_L1TP_139045_20170304_20170316_01_T1_B3.TIF"
    FILE_NAME_BAND_4 = "LC08_L1TP_139045_20170304_20170316_01_T1_B4.TIF"
    FILE_NAME_BAND_5 = "LC08_L1TP_139045_20170304_20170316_01_T1_B5.TIF"
    FILE_NAME_BAND_6 = "LC08_L1TP_139045_20170304_20170316_01_T1_B6.TIF"
    FILE_NAME_BAND_7 = "LC08_L1TP_139045_20170304_20170316_01_T1_B7.TIF"
    FILE_NAME_BAND_8 = "LC08_L1TP_139045_20170304_20170316_01_T1_B8.TIF"
    FILE_NAME_BAND_9 = "LC08_L1TP_139045_20170304_20170316_01_T1_B9.TIF"
    FILE_NAME_BAND_10 = "LC08_L1TP_139045_20170304_20170316_01_T1_B10.TIF"
    FILE_NAME_BAND_11 = "LC08_L1TP_139045_20170304_20170316_01_T1_B11.TIF"
    FILE_NAME_BAND_QUALITY = "LC08_L1TP_139045_20170304_20170316_01_T1_BQA.TIF"
    ANGLE_COEFFICIENT_FILE_NAME = "LC08_L1TP_139045_20170304_20170316_01_T1_ANG.txt"
    METADATA_FILE_NAME = "LC08_L1TP_139045_20170304_20170316_01_T1_MTL.txt"
    CPF_NAME = "LC08CPF_20170101_20170331_01.02"
    BPF_NAME_OLI = "LO8BPF20170304042138_20170304055856.01"
    BPF_NAME_TIRS = "LT8BPF20170225090252_20170313050703.01"
    RLUT_FILE_NAME = "LC08RLUT_20150303_20431231_01_12.h5"
....

This is not the case when you execute the script as WPS process. Just the MTL file is present in the workspace then.  I don't see an easy solution for this.. How did you download the different files, all together in a zip file?
Reply | Threaded
Open this post in threaded view
|

Re: problem with create a RasterLayer object from file using R

soshi
thanks anyway,
actually I downloaded from https://libra.developmentseed.org/ only Landsat 8 ..