geofi icon indicating copy to clipboard operation
geofi copied to clipboard

Add Finnish Digital Elevation Model (DEM)

Open jlehtoma opened this issue 6 years ago • 5 comments

The Finnish Geospatial Research and Education hub provides multiple raster datasets, including the Finnish DEM (2m / 10m), over the Open Geospatial Consortium's Web Coverage Service (WCS). Develop a wrapper to access the DEM. ows4R doesn't currently support CWS, but this may change in the future.

jlehtoma avatar Aug 19 '19 09:08 jlehtoma

@jlehtoma just to let you know that ows4R now supports WCS, in case you want to test. Feel free to report any issue you would find.

eblondel avatar Oct 31 '23 22:10 eblondel

@pitkant @jlehtoma

recent geofi version 1.1.0 has set of new functions for interacting with statfi and NLS/MML OCG API FEATURES services. For instance function ogc_get_maastotietokanta() (See https://ropengov.github.io/geofi/reference/ogc_get_maastotietokanta.html and https://github.com/rOpenGov/geofi/blob/master/R/ogc_api_nls.R)

There are no function to interact with OCG API Processes which allows fetching files. (See https://www.maanmittauslaitos.fi/paikkatiedon-tiedostopalvelu)

Paikkatiedon tiedostopalvelu (OGC API Processes) tarjoaa kyselyrajapinnan, jonka kautta voi hakea Maanmittauslaitoksen avoimia paikkatietoaineistoja tiedostopaketteina. Aineistot ovat samat, joita voi hakea käyttöliittymän kautta Karttapaikka-palvelun Lataa paikkatietoaineistoja -osiosta. Aineistojen tarkemmat tiedot ovat luettavissa tuotekuvauksista.

Palvelu sopii esimerkiksi käyttöön, jossa on tarvetta hakea paikkatietoaineistoja koordinaateilla eli suorakaiteella (Bounding Box) tai polygonirajauksella. Karttapaikan Lataa paikkatietoaineistoja-osiossa nämä valinnat piirretään kartalla, mutta OGC API Processes -palvelussa koordinaatit voi syöttää kyselyparametreina. Hakuparametrit vaihtelevat aineistosta riippuen. Osaa aineistoista voi hakea myös karttalehden, kunnan tai teeman perusteella, tai koko Suomen alueelta.

See also

  • https://www.maanmittauslaitos.fi/tutkimus/teematietoa/korkeusmallit
  • https://www.maanmittauslaitos.fi/paikkatiedon-tiedostopalvelu
  • https://avoin-paikkatieto.maanmittauslaitos.fi/tiedostopalvelu/ogcproc/v1/

Back to this issue and DEM. When looking at

  • https://www.maanmittauslaitos.fi/paikkatiedon-tiedostopalvelu/tekninen-kuvaus
  • https://avoin-paikkatieto.maanmittauslaitos.fi/tiedostopalvelu/ogcproc/v1/processes

We can see that DEM (korkeusmalli) is one of the processes available, both in 2m and 10m resolution

"Korkeusmalli 2 m -tietojen hakeminen bbox-rajauksella, EPSG:3067"
"Karttalehtikohtaisten korkeusmalli 2 m -tiedostojen haku, EPSG:3067"
"Korkeusmalli 2 m -tietojen hakeminen polygon-rajauksella, EPSG:3067"

If you have any interest/energy to look into this, any input is welcome! My understanding of raster data is very limited, so I need begin with looking into the basics.

muuankarski avatar Apr 29 '25 09:04 muuankarski

Of course, you can get korkeuskayrankorkeusarvo from maastotietokanta like this

heights_helsinki <- ogc_get_maastotietokanta(
    collection = "korkeuskayrankorkeusarvo",
    bbox = "24.5,60.1,25.5,60.5",
    crs = 4326
)
mapview::mapview(heights_helsinki)

Image

Just for a future reminder, I implemented the example from here: https://www.maanmittauslaitos.fi/paikkatiedon-tiedostopalvelu/tekninen-kuvaus below using R and httr2

library(httr2)

# example from https://www.maanmittauslaitos.fi/paikkatiedon-tiedostopalvelu/tekninen-kuvaus 
# implemented in R & httr2

# Define the URL
url <- "https://avoin-paikkatieto.maanmittauslaitos.fi/tiedostopalvelu/ogcproc/v1/processes/maastokartta_rasteri_karttalehti/execution"

# api key
api_key = Sys.getenv("MML_API_KEY")

url <- paste0(url,
  "?api-key=", api_key
)

# Define the payload
payload <- list(
  id = "maastokartta_rasteri_karttalehti",
  inputs = list(
    fileFormatInput = "PNG",
    dataSetInput = "maastokartta_rasteri_10k_painovari",
    mapSheetInput = list("M5321L")
  )
)

# POST request what initiates a job
response <- request(url) %>%
  req_body_json(payload) %>%
  req_perform()

# Check the response
resp_status(response)
content <- resp_body_json(response)

# Check job status!
url <- content$links[[1]]$href
url <- paste0(url,
              "?api-key=", api_key
)
job_status <- request(url) |> 
  req_perform()
resp_status(job_status)
job_response <- resp_body_json(job_status)

# if job status is successful, you retrieve the result urls
if (job_response$status == "successful"){
 # retrieve results
  url <- job_response$links[[1]]$href
  url <- paste0(url,
                "?api-key=", api_key)
  job_results <- request(url) |> 
    req_perform()
}
resp_status(job_results)
response_results <- resp_body_json(job_results)

# Finally, you can download png file
download.file(url = response_results$results[[1]]$path, destfile = "results.png")

It results in 18MB png image like

Image

muuankarski avatar Apr 29 '25 11:04 muuankarski

@muuankarski Sounds very useful!

My experience with handling raster data is probably the same as yours, from that one CSC course on geospatial computation, but mixing raster elevation model data with vectors like municipality boundaries or boundary of Finland was something that we did during that course. It's good if there's an API to download the data from instead of using the clunky "Add to shopping cart" style Karttapaikka-service.

I think the trickiest part of that was related to having a matching CRS for both raster and vector datasets as changing the CRS / transforming raster objects does not work very well, for understandable reasons.

Maybe there could be a helper function to easily create bounding boxes for certain municipalities / regions / wellbeing service counties with st_bbox if you want to easily find out the elevation of your local municipality / region / wellbeing service county or the most relevant map sheet.

@ake123 from our group might have some time to allocate towards this.

pitkant avatar Apr 29 '25 12:04 pitkant

@pitkant function for creating bboxes is an interesting idea. I use either http://bboxfinder.com/ or like this

 helsinki <- geofi::get_municipalities() |>
   dplyr::filter(municipality_code == 91) |>
   sf::st_transform(4326)
helsinki_bbox <- paste0(sf::st_bbox(helsinki),collapse = ",")
helsinki_bbox
[1] "24.8314030638784,60.1307443052775,25.2716473572849,60.2980801229406"

Latter could be certainly made into a function, the website usage should be documented in detail.

I created a new branch ogc_processes for this work

muuankarski avatar Apr 29 '25 14:04 muuankarski