Skip to content
Emmanuel Blondel edited this page Aug 31, 2023 · 8 revisions

geonapi - R Interface to GeoNetwork API

R Interface to GeoNetwork API – Allows to perform programmatically from R CRUD operations (Create, Read, Update, Delete) on GeoNetwork metadata.


If you wish to sponsor geosapi, do not hesitate to contact me

Many thanks to the following organizations that have provided fundings for strenghtening the geosapi package:


Table of contents

1. Overview
2. Package status
3. Credits
4. User guide
   4.1 Installation
   4.2 Connect to GeoNetwork API
   4.3 Metadata operations
      4.3.1 Create metadata record
      4.3.2 Read a metadata record
      4.3.3 Update a metadata record
      4.3.4 Delete a metadata record
5. Issue reporting

1. Overview and vision


Until now, equivalent tools were existing for other programming languages (e.g. Java, Python) but not in R. geonapi intends to provide R native interface to the Geonetwork API, in order to facilitate publication of geographic metadata resources from R to GeoNetwork.

2. Development status


The geonapi package currently supports the GeoNetwork legacy API, covering key versions of Geonetwork, including 2.6.x, 2.10.x, 3.0.x, 3.2.x, 3.4.x, 3.6.x, 3.8.x and 4.x series.

The new Geonetwork REST API (Beta) is not supported yet.

geonapi is published on CRAN CRAN_Status_Badge. For the latest version of geonapi, use the Github version.

3. Credits


(c) 2017, Emmanuel Blondel

Package distributed under MIT license.

If you use geonapi, i would be very grateful if you can add a citation in your published work. By citing geonapi, beyond acknowledging the work, you contribute to make it more visible and guarantee its growing and sustainability. You can get the preferred citationplease use the citation provided at this link DOI

4. User guide


4.1 How to install geonapi in R

The package can be installed from CRAN:

install.packages("geonapi")

or from Github

install.packages("devtools")

Once the devtools package loaded, you can use the install_github to install geonapi. By default, package will be installed from master which is the current version in development (likely to be unstable).

require("devtools")
install_github("eblondel/geonapi")

4.2 Connect to GeoNetwork API

The main entry point of geonapi is the GNManager. To configure it, enter the following line, specifying the base URL of your GeoServer, your credentials, and the version of the GeoNetwork you use (as string):

GN <- GNManager$new(
    url = "http://localhost:8080/geonetwork", #base URL of the Geonetwork
    version = "3.6.0",
    user = "admin", pwd = "geonetwork", #credentials (ignore if you want to connect as anonymous user for metadata reading)
    logger = NULL
)

By default, the geonapi logger is deactivated. To enable the logger, specify the level of log you wish as parameter of the above R code. Two logging levels are available:

  • INFO: will print the geonapi logs. Three types of messages can be distinguished: INFO, WARN, ERROR. The latter is generally associated with a stop and indicate an blocking error for the R method executed.
  • DEBUG will print the above geonapi logs, and report all logs from HTTP requests performed with cURL

4.3 Metadata record operations

4.3.1 Create a metadata record
  mdfile <- system.file("extdata/examples", "metadata.xml", package = "geonapi")
  created = GN$insertMetadata(file = mdfile, group = "1", category = "datasets")
  config <- GNPrivConfiguration$new()
  config$setPrivileges("all", c("view","dynamic","featured"))
  GN$setPrivConfiguration(id = created, config = config)
4.3.2 Read a metadata record
  id <- "my-metadata-identifier"
  md <- GN$getMetadataByUUID(id)
4.3.3 Update a metadata record
  id <- "my-metadata-identifier"
  md <- GN$getMetadataByUUID(id)
  md$setDataSetURI("new-dataset-uri")
  metaId <- GN$get(md$fileIdentifier, by = "uuid", output = "id")
  updated <- GN$updateMetadata(id = metaId, xml = md$encode()) 
4.3.4 Delete a metadata record
  id <- "my-metadata-identifier"
  md <- GN$getMetadataByUUID(id)
  metaId <- GN$get(md$fileIdentifier, by = "uuid", output = "id")
  deleted <- GN$deleteMetadata(id = metaId)

5. Issue reporting


Issues can be reported at https://github.com/eblondel/geonapi/issues