Skip to content

Instantly share code, notes, and snippets.

@tomkralidis
Last active September 20, 2022 00:48
Show Gist options
  • Save tomkralidis/b4e1a25132831ab0a7da98433d0d4c59 to your computer and use it in GitHub Desktop.
Save tomkralidis/b4e1a25132831ab0a7da98433d0d4c59 to your computer and use it in GitHub Desktop.
OGC API Features - Part 4: Transactions example

OGC API Features - Part 4: Transactions examples

Overview

Examples of OGC API transactions using OGC API - Features - Part 4: Create, Replace, Update and Delete in the context of OGC API - Records metadata management.

curl

# insert metadata
curl -v -H "Content-Type: application/geo+json" -XPOST http://localhost:8000/collections/metadata:main/items -d @foorecord.json
# update metadata
curl -v -H "Content-Type: application/geo+json" -XPUT http://localhost:8000/collections/metadata:main/items/foorecord -d @foorecord.json
# delete metadata
curl -v -XDELETE http://localhost:8000/collections/metadata:main/items/foorecord

OWSLib

import json

from owslib.ogcapi.records import Records

record_data = 'sample-record.json'

url = 'http://localhost:8000'
collection_id = 'metadata:main'

r = Records(url)

cat = r.collection(collection_id)

with open(record_data) as fh:
    data = json.load(fh)

identifier = data['id']

r.collection_item_delete(collection_id, identifier)

# insert metadata
r.collection_item_create(collection_id, data)

# update metadata
r.collection_item_update(collection_id, identifier, data)

# delete metadata
r.collection_item_delete(collection_id, identifier)
{
"id": "foorecord",
"conformsTo": [
"http://www.opengis.net/spec/ogcapi-records-1/1.0/req/record-core"
],
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-141,
42
],
[
-141,
84
],
[
-52,
84
],
[
-52,
42
],
[
-141,
42
]
]
]
},
"properties": {
"identifier": "3f342f64-9348-11df-ba6a-0014c2c00eab",
"title": "title in English",
"description": "abstract in English",
"themes": [
{
"concepts": [
"kw1 in English",
"kw2 in English",
"kw3 in English"
]
},
{
"concepts": [
"FOO",
"BAR"
],
"scheme": "http://example.org/vocab"
},
{
"concepts": [
"kw1",
"kw2"
]
}
],
"providers": [
{
"name": "Environment Canada",
"individual": "Tom Kralidis",
"positionName": "Senior Systems Scientist",
"contactInfo": {
"phone": {
"office": "+01-123-456-7890"
},
"email": {
"office": "+01-123-456-7890"
},
"address": {
"office": {
"deliveryPoint": "4905 Dufferin Street",
"city": "Toronto",
"administrativeArea": "Ontario",
"postalCode": "M3H 5T4",
"country": "Canada"
},
"onlineResource": {
"href": "https://www.ec.gc.ca/"
}
},
"hoursOfService": "0700h - 1500h EST",
"contactInstructions": "email",
"url": {
"rel": "canonical",
"type": "text/html",
"href": "https://www.ec.gc.ca/"
}
},
"roles": [
{
"name": "pointOfContact"
}
]
},
{
"name": "Environment Canada",
"individual": "Tom Kralidis",
"positionName": "Senior Systems Scientist",
"contactInfo": {
"phone": {
"office": "+01-123-456-7890"
},
"email": {
"office": "+01-123-456-7890"
},
"address": {
"office": {
"deliveryPoint": "4905 Dufferin Street",
"city": "Toronto",
"administrativeArea": "Ontario",
"postalCode": "M3H 5T4",
"country": "Canada"
},
"onlineResource": {
"href": "https://www.ec.gc.ca/"
}
},
"hoursOfService": "0700h - 1500h EST",
"contactInstructions": "email",
"url": {
"rel": "canonical",
"type": "text/html",
"href": "https://www.ec.gc.ca/"
}
},
"roles": [
{
"name": "distributor"
}
]
}
],
"language": "en",
"type": "dataset",
"created": "2011-11-11",
"recordUpdated": "2000-09-01",
"rights": "Copyright (c) 2010 Her Majesty the Queen in Right of Canada"
},
"links": [
{
"rel": "canonical",
"href": "https://example.org/data",
"type": "WWW:LINK",
"title": "my waf"
},
{
"rel": "service",
"href": "https://example.org/wms",
"type": "OGC:WMS",
"title": "roads"
}
],
"time": {
"interval": [
"1950-07-31",
null
],
"resolution": "P1Y"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment