Update of "ISO Metadata"
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview

Artifact ID: b83318c7694593630b2d46799d461e7f4bba49b8
Page Name:ISO Metadata
Date: 2013-03-18 16:09:35
Original User: sandro
Parent: 10379c7a117ca5ae09ba45608532b769da59c500 (diff)
Content

back to XmlBlob main page

ISO Metadata - Intro

Starting since version 4.1.0 SpatiaLite will support ISO Metadata; all metadata documents exactly are XML Documents, so the whole ISO Metadata implementation simply is a further specialized extension based on XmlBLOB.
Several different standard specifications are collectively grouped under the generic name of ISO Metadata; the common core reference is always based on ISO 19115 / 19139, but many further specialized extensions exist: one of the best known being e.g. the INSPIRE EU Initiative.

DB Tables implementing ISO Metadata

SELECT CreateIsoMetadataTables();
The CreateIsoMetadataTables() SQL function will attempt to create all DB Tables required in order to enable ISO Metadata support.
Any attempt to directly create or otherwise manipulate these Tables is strongly discouraged; you are always expected to properly invoke CreateIsoMetadataTables(), which will correctly define all required Primary / Foreign Key constraints, as will create all validating Triggers expected to support these Tables.
SELECT CreateIsoMetadataTables( 1 );
Please note: CreateIsoMetadataTables() will optionally accept a single (boolean) argument intended to choose between strict and relaxed Triggers alternative implementations:
Important notice: oldest versions of libxml2 aren't able to support a successful Schema validation for ISO Metadata documents. Using the most recent 2.9.0 version of this library seems to be an absolute pre-requisite.
  • all pre-built binaries for Windows released by SpatiaLite itself surely support libxml2 2.9.0, and can be thus safely used in strict mode.
  • while building on Linux it's very probable that you'll encounter a system pre-packaged libxml2 corresponding to some obsolete version: in this case duly switching to relaxed mode is strongly suggested.

the ISO_metadata table

This table is specifically intended to store all ISO Metadata documents:

the ISO_metadata_reference table

This table is specifically intended to represent any possible reference joining ISO Metadata documents and geographic features stored within the same DB (layers, coverages, features, tiles and so on):

A practical tutorial by real examples

In this example we'll use the samples contained into the xml-samples/iso-metadata folder.
export "SPATIALITE_SECURITY=relaxed"
For didactic simplicity we'll use the unsafe SQL functions supporting direct access to external files stored into the file-system.
Remember: you have to explicitly set the SPATIALITE_SECURITY=relaxed environment variable in order to enable all unsafe SQL Import/Export functions.
SELECT CreateIsoMetadataTables();
-----
1
And we'll suppose that the ISO Metadata supporting tables have been created in strict mode, i.e. always requiring a successful XML Schema validation.
SELECT RegisterIsoMetadata( 'dataset', 
  XB_Create( XB_LoadXML( 'C:/xml-samples/iso-metadata/inspire-data-example.xml' ) ) );
-----
0
The RegisterIsoMetadata() SQL function inserts a registration into the ISO_metadata table. Any attempt aimed to directly perform any INSERT or UPDATE SQL statement on behalf of ISO_metadata is strongly discouraged; always using the abstract function RegisterIsoMetadata() is warmly recommended, and will preserve long-term compatibility against subsequent releases. Anyway this first attempt was unsuccessful: we've get a 0 result, this meaning failure.
There is very simple reason accounting for this failure: we've missed to perform any XML Schema validation; and accordingly to this the safety Trigger has then rejected this first attempt.
SELECT RegisterIsoMetadata( 'dataset', 
  XB_Create( XB_LoadXML( 'C:/xml-samples/iso-metadata/inspire-data-example.xml' ),
    1, 1 ) );
-----
1
This second attempt is finally successful, because this time we've correctly invoked XB_Create() asking for full XML Schema validation.
SELECT RegisterIsoMetadata( 'dataset', 
  XB_Create( XB_LoadXML( 'C:/xml-samples/iso-metadata/inspire-data-example.xml' ),
    1, 1 ) );
-----
0
Anyway a second attempt to insert yet another time the same Metadata document will be rejected; this is because a uniqueness constraint forbids to insert two documents declaring the same fileId value.
SELECT RegisterIsoMetadata( 'dataset', 
  XB_Create( XB_LoadXML( 'C:/xml-samples/iso-metadata/db_topografico_iso19139.xml' ),
    1, 1 ) );
-----
1

SELECT RegisterIsoMetadata( 'dataset', 
  XB_Create( XB_LoadXML( 'C:/xml-samples/iso-metadata/unita_volumetrica_iso19139.xml' ),
    1, 1 ), 2 );
-----
1

SELECT RegisterIsoMetadata( 'dataset', 
  XB_Create( XB_LoadXML( 'C:/xml-samples/iso-metadata/unita_insediativa_iso19139.xml' ),
    1, 1 ), 'f0780c41-023d-41be-9ed4-f79bdb4a7886' );
-----
1
Please note: the RegisterIsoMetadata() function can be also invoked in order to update an already defined Metadata document; in this case you simply have to pass the corresponding id as the third argument.
Alternatively, if the Metadata document to be replaced/updated declares an internal <fileIdentifier> tag value, you can pass the fileID value as the third argument.
In any case both fileId and parentId will be correctly updated so to exactly correspond to the internal tags declared within the XML documents itself; you can safely rely on this, because a couple of Triggers will always take care to ensure a strict correspondence.


SELECT *
FROM ISO_metadata_view;
idmd_scopetitleabstract geometryfileIdentifierparentIdentifiermetadataschema_validatedmetadata_schema_uri
0undefinedNULLNULL NULLNULLNULLBLOB sz=4 UNKNOWN type-1NULL
1dataset Image2000 Product 1 (nl2) Multispectral IMAGE2000 product 1 individual orthorectified scenes ... BLOB sz=141 GEOMETRY029097fd-2ef2-487c-a5ca-6ec7a3dbac53 NULLXmlBLOB-ISOmetadata sz=4423 (XMLsz=18026) SchemaValidated 1 http://schemas.opengis.net/iso/19139/20060504/gmd/gmd.xsd
2datasetUnita' Insediativa Aree adibite all'installazione ... BLOB sz=141 GEOMETRYcd76c9a2-8138-4e7e-ad6b-2e105c37e65c cc27d885-2795-4998-9bae-6f6872b181ce XmlBLOB-ISOmetadata sz=7355 (XMLsz=58098) SchemaValidated 1http://www.isotc211.org/2005/gmd/gmd.xsd

The ISO_metadata table is supported by a corresponding VIEW (not surprisingly) named ISO_metadata_view.
Please note: a default row identified by id=0 is always defined in the ISO_metadata table (being automatically created by CreateIsoMetadata()); its intended scope is the one to define kind-of universal-placeholder allowing to define undefined/unknown metadata references still preserving full relational integrity.

If you are curious enough, you'll quickly discover that this VIEW exactly corresponds to the original table, and that its added values is in that further title, abstract, geometry(*), fileId(*), parentId(*), schema_validated and metadata_schema_uri columns are made immediately available.
(*)Please note: the geometry, fileId and parentId columns are always directly exposed in the base table; all them are immediately set by appropriate Triggers, so to always correspond to the actual tag-values internally declared by the XML document itself.
The following SQL functions, once invoked on behalf of the XmlBLOB payload (metadata), will immediately extract the corresponding values from within the XML document: XB_GetTitle(), XB_GetAbstract(), XB_GetGeometry(), XB_GetFileId(), XB_GetParentId(), XB_IsSchemaValidated() and XB_GetSchemaURI().


advanced SQL functions supporting ISO Metadata

SELECT GetIsoMetadataId( 'cd76c9a2-8138-4e7e-ad6b-2e105c37e65c' );
-----
2
The GetIsoMetadataId() SQL function will return the internal id value corresponding to some fileId; if no corresponding Metadata document exists, then ZERO will be returned.
UPDATE ISO_metadata
SET metadata = XB_SetParentId ( metadata , 'new-parent-id' )
WHERE id = 2;
-----
1

UPDATE ISO_metadata
SET metadata = XB_SetParentId ( metadata , 'another-parent-id' )
WHERE id = GetIsoMetadataId( 'cd76c9a2-8138-4e7e-ad6b-2e105c37e65c' );
-----
1
The XB_SetFileId() and XB_SetParentId() SQL functions are respectively intended to change the <fileIdentifier> or <parentIdentifier> tag values internally declared within the XML document itself; the supporting Triggers will then take care to immediately make visible this change in the corresponding table/column values.
Please note:
UPDATE ISO_metadata
SET metadata = XB_AddParentId ( metadata , CreateUUID() , 
    'gmd' , 'http://www.isotc211.org/2005/gmd' , 
    'gco' , 'http://www.isotc211.org/2005/gco' )
WHERE id = 1;
-----
1
The XB_AddFileId() and XB_AddParentId() SQL functions are respectively intended to insert a <fileIdentifier> <parentIdentifier> tag values internally declared within the XML document itself; the supporting Triggers will then take care to immediately make visible this change in the corresponding table/column values.
Please note: Remember:

Metadata references

A very common misconception about metadata is the one based on this false assumption: 1 layer = 1 metadata document.
Reality is much more complex than this, and happily enough ISO 19115 defines a sophisticated hierarchical model, based on parent/child chains of ISO Metadata documents.
You can learn more about all this by reading the appropriate Wiki page



back to XmlBlob main page