Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WCS vignette with error. #114

Open
ecor opened this issue Jan 19, 2024 · 4 comments
Open

WCS vignette with error. #114

ecor opened this issue Jan 19, 2024 · 4 comments

Comments

@ecor
Copy link

ecor commented Jan 19, 2024

I rerun automatically all the chunks of the WCS vignette and the following error occurs (SEE BELOW) , when the SpatRast object should have been returned. Is it an issue of the WCS URL used?
Thank you
Best
Emanuele @ecor

R version 4.3.0 (2023-04-21) -- "Already Tomorrow"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

Restarting R session... > knitr::opts_chunk$set(echo = TRUE,eval=TRUE) > > library(ows4R) Loading ISO 19139 XML schemas... Loading ISO 19115 codelists... > > WCS <- WCSClient$new("https://ows.rasdaman.org/rasdaman/ows", "2.1.0", logger = "INFO") [ows4R][INFO] OWSGetCapabilities - Fetching https://ows.rasdaman.org/rasdaman/ows?service=WCS&version=2.1.0&request=GetCapabilities \|=============================================================================================================\| 100% > caps <- WCS$getCapabilities() > chla <- caps$findCoverageSummaryById("AverageChloroColorScaled", exact = T) > chla_des <- cov$getDescription() Error in cov$getDescription : object of type 'closure' is not subsettable > chla Inherits from: Public: attrs: list BoundingBox: list clone: function (deep = FALSE) CoverageId: AverageChloroColorScaled CoverageSubtype: ReferenceableGridCoverage CoverageSubtypeParent: NULL defaults: list element: AbstractObject encode: function (addNS = TRUE, geometa_validate = TRUE, geometa_inspire = FALSE, ERROR: function (text) getBoundingBox: function () getClass: function () getClassName: function () getCoverage: function (bbox = NULL, crs = NULL, time = NULL, elevation = NULL, getCoverageStack: function (time = NULL, elevation = NULL, bbox = NULL, filename_handler = NULL, getDescription: function () getDimensions: function () getId: function () getNamespaceDefinition: function (recursive = FALSE) getSubtype: function () getSubtypeParent: function () getWGS84BoundingBox: function () INFO: function (text) initialize: function (xmlObj, capabilities, serviceVersion, owsVersion, logger = NULL) isFieldInheritedFrom: function (field) logger: function (type, text) loggerType: INFO namespace: OWSNamespace, R6 verbose.debug: FALSE verbose.info: TRUE WARN: function (text) WGS84BoundingBox: list wrap: FALSE Private: capabilities: WCSCapabilities, OWSCapabilities, OGCAbstractObject, R6 description: NULL dimensions: NULL fetchCoverageSummary: function (xmlObj, serviceVersion, owsVersion) fromComplexTypes: function (value) owsVersion: 2.0 system_fields: verbose.info verbose.debug loggerType wrap element names ... url: https://ows.rasdaman.org/rasdaman/ows version: 2.1.0 xmlElement: AbstractObject xmlExtraNamespaces: NULL xmlNamespacePrefix: OWS xmlNodeToCharacter: function (x, ..., indent = "", tagSeparator = "\n") Restarting R session... > knitr::opts_chunk$set(echo = TRUE,eval=TRUE) > > library(ows4R) > > WCS <- WCSClient$new("https://ows.rasdaman.org/rasdaman/ows", "2.1.0", logger = "INFO") [ows4R][INFO] OWSGetCapabilities - Fetching https://ows.rasdaman.org/rasdaman/ows?service=WCS&version=2.1.0&request=GetCapabilities \|=============================================================================================================\| 100% > caps <- WCS$getCapabilities() > chla <- caps$findCoverageSummaryById("AverageChloroColorScaled", exact = T) > chla_des <- WCS$describeCoverage("AverageChloroColorScaled") [ows4R][INFO] WCSClient - Fetching coverageSummary description for 'AverageChloroColorScaled' ... [ows4R][INFO] WCSDescribeCoverage - Fetching https://ows.rasdaman.org/rasdaman/ows?service=WCS&version=2.1.0&coverageId=AverageChloroColorScaled&request=DescribeCoverage \|=============================================================================================================\| 100% Loading required package: sf Linking to GEOS 3.10.2, GDAL 3.4.3, PROJ 8.2.0; sf_use_s2() is FALSE > chla_dims <- chla$getDimensions() [ows4R][INFO] WCSCoverageSummary - Fetching Coverage envelope dimensions by CRS interpretation Unknown IO errorfailed to load external entity "http://crs.rasdaman.com/def/crs-compound?1=http://crs.rasdaman.com/def/crs/OGC/0/AnsiDate&2=http://crs.rasdaman.com/def/crs/EPSG/0/4326" Error : 1: Unknown IO error2: failed to load external entity "http://crs.rasdaman.com/def/crs-compound?1=http://crs.rasdaman.com/def/crs/OGC/0/AnsiDate&2=http://crs.rasdaman.com/def/crs/EPSG/0/4326" [ows4R][ERROR] WCSCoverageSummary - Error during CRS interpretation for srsName = 'http://crs.rasdaman.com/def/crs-compound?1=http://crs.rasdaman.com/def/crs/OGC/0/AnsiDate&2=http://crs.rasdaman.com/def/crs/EPSG/0/4326' > chla_time_instants <- chla_dims[[1]]$coefficients > cov_data <- chla$getCoverage( + bbox = OWSUtils$toBBOX(-10, -9, 40, 42), + time = chla_dims[[1]]$coefficients[[1]] + ) [ows4R][INFO] WCSCoverageSummary - Fetching Coverage envelope dimensions by CRS interpretation Unknown IO errorfailed to load external entity "http://crs.rasdaman.com/def/crs-compound?1=http://crs.rasdaman.com/def/crs/OGC/0/AnsiDate&2=http://crs.rasdaman.com/def/crs/EPSG/0/4326" Error : 1: Unknown IO error2: failed to load external entity "http://crs.rasdaman.com/def/crs-compound?1=http://crs.rasdaman.com/def/crs/OGC/0/AnsiDate&2=http://crs.rasdaman.com/def/crs/EPSG/0/4326" [ows4R][ERROR] WCSCoverageSummary - Error during CRS interpretation for srsName = 'http://crs.rasdaman.com/def/crs-compound?1=http://crs.rasdaman.com/def/crs/OGC/0/AnsiDate&2=http://crs.rasdaman.com/def/crs/EPSG/0/4326' ....\|-- lowerCorner: "2002-07-01T00:00:00.000Z" 40 -10 ....\|-- upperCorner: "2015-05-01T00:00:00.000Z" 42 -9[ows4R][INFO] WCSCoverageSummary - Fetching Coverage envelope dimensions by CRS interpretation Unknown IO errorfailed to load external entity "http://crs.rasdaman.com/def/crs-compound?1=http://crs.rasdaman.com/def/crs/OGC/0/AnsiDate&2=http://crs.rasdaman.com/def/crs/EPSG/0/4326" Error : 1: Unknown IO error2: failed to load external entity "http://crs.rasdaman.com/def/crs-compound?1=http://crs.rasdaman.com/def/crs/OGC/0/AnsiDate&2=http://crs.rasdaman.com/def/crs/EPSG/0/4326" [ows4R][ERROR] WCSCoverageSummary - Error during CRS interpretation for srsName = 'http://crs.rasdaman.com/def/crs-compound?1=http://crs.rasdaman.com/def/crs/OGC/0/AnsiDate&2=http://crs.rasdaman.com/def/crs/EPSG/0/4326' [ows4R][INFO] WCSGetCoverage - Fetching https://ows.rasdaman.org/rasdaman/ows?service=WCS&version=2.1.0&coverageId=AverageChloroColorScaled&subset=ansi(2002-07-01T00:00:00.000Z,2015-05-01T00:00:00.000Z)&subset=Lat(40,42)&subset=Lon(-10,-9)&format=image/tiff&request=GetCoverage \|=============================================================================================================\| 100% [ows4R][ERROR] WCSGetCoverage - Error while executing request 'GetCoverage' Warning: `/tmp/Rtmp3MwsDg/AverageChloroColorScaled_40,-10,42,-9.tif' not recognized as a supported file format. (GDAL error 4)Error: [rast] cannot open this file as a SpatRaster: /tmp/Rtmp3MwsDg/AverageChloroColorScaled_40,-10,42,-9.tif
@eblondel
Copy link
Owner

Thanks i will check. They mave have changed something in the Rasdaman test service I used for the Vignette.

@eblondel
Copy link
Owner

Something goes wrong in Rasdaman test server that is used in the examples. I've contacted their team.

@ecor
Copy link
Author

ecor commented Jan 20, 2024

Thank you and compliments for your package.

@falkmielke
Copy link

Hello!
I stumbled upon this issue when using ows4R with a new version of one of our local service API's, and thought the findings might be relevant to you and others.
The issue is that this specific API switched from returning geoTIFFs directly in version 1.0.0 to packing them in an mht container for version 2.0.1 (see here).

This is the API: https://geo.api.vlaanderen.be/DHMV/wcs?request=GetCapabilities
This affects queries with version=2.0.1 && format=image/tiff (yes, you get MHT despite asking for a tiff!)

When querying the latest version, ows4R received a file, as does the direct query, yet on my OS and browser the file had no extension.
I also receive a couple of error messages and warnings:
- Start tag expected, '<' not found
- cannot open this file as SpatRaster:&#x2026;
- The raw file is not recognized as being in a supported file format. (GDAL error 4)

In fact, neither GDAL, nor terra/sf/python::rasterio, nor qgis were able to handle the file. When connecting qgis to the web service, it falls back to version 1.0.0.

The tif is contained within that MHT, and my colleague @hansvancalster figured out here how to extract it.

Here a working example:

require("httr")
require("stringr")
require("readr")
require("assertthat")


base_url = "https://geo.api.vlaanderen.be"
endpoint = "/DHMV/wcs"
url <- parse_url("https://geo.api.vlaanderen.be/DHMV/wcs")

# the query parameters which worked in QGIS
url$query <- list(
  SERVICE = "WCS",
  VERSION = "2.0.1",
  REQUEST = "GetCoverage",
  FORMAT = "image/tiff",
  COVERAGEID = "DHMVII_DTM_1m",
  SUBSET = "x,http://www.opengis.net/def/crs/EPSG/0/EPSG:31370(148000,149000)",
  SUBSET = "y,http://www.opengis.net/def/crs/EPSG/0/EPSG:31370(208000,209000)",
  SCALEFACTOR = "1",
  CRS = "EPSG:31370",
  RESPONSE_CRS = "EPSG:31370"
)

request <- build_url(url)


# get wcs data
mht_file <- tempfile(fileext = ".mht")

print(request)
print(mht_file)

response <- GET(url = request,
          write_disk(mht_file))

unpack_mht <- function(mht_filepath) {
  lines_raw <- read_lines_raw(mht_filepath)
  lines_char <- suppressWarnings(read_lines(mht_filepath))
  raw_vector <- read_file_raw(mht_filepath)

  #assert_that(any(str_detect(lines_char, "image/tiff")))
  start <- which(str_detect(lines_char, "^II\\*"))
  end <- length(lines_raw) - 1
  pos_start <- length(unlist(lines_raw[1:(start - 1)])) + start
  pos_end <- length(raw_vector) - (length(lines_raw[end + 1]) + 1)

  tif <- raw_vector[pos_start:pos_end]
  tif_path <- str_replace(mht_filepath, "mht", "tif")
  write_file(
    tif,
    tif_path
  )
  return(tif_path)
}

tif_file <- unpack_mht(mht_file)

require("terra")
raster <- rast(tif_file)
plot(raster, col = gray.colors(256))

Cheers,

Falk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants