Last active
March 24, 2022 14:48
-
-
Save jbdesbas/3d2705b0a1a9622f4354feefc68578dc to your computer and use it in GitHub Desktop.
Insert geonetwork mtd into PG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TABLE xml_mtd ("xml" xml); | |
| /*COPY distant XML file (with removing line feed) */ | |
| COPY xml_mtd FROM PROGRAM 'curl "https://www.geo2france.fr/geonetwork/srv/api/records/6ea5c1bd-b10b-4f7e-9139-2f878c63fc74/formatters/xml?attachment=true&approved=true" | tr -d "\n" '; | |
| /*Extract relevant data*/ | |
| WITH ns AS ( | |
| SELECT ARRAY[ | |
| ARRAY['gmd', 'http://www.isotc211.org/2005/gmd'], | |
| ARRAY['gco', 'http://www.isotc211.org/2005/gco'], | |
| ARRAY['srv', 'http://www.isotc211.org/2005/srv'], | |
| ARRAY['gmx', 'http://www.isotc211.org/2005/gmx'], | |
| ARRAY['gts', 'http://www.isotc211.org/2005/gts'], | |
| ARRAY['gsr', 'http://www.isotc211.org/2005/gsr'], | |
| ARRAY['gmi', 'http://www.isotc211.org/2005/gmi'], | |
| ARRAY['gml', 'http://www.opengis.net/gml'], | |
| ARRAY['xlink', 'http://www.w3.org/1999/xlink'] | |
| ] AS ns | |
| ), | |
| xmldata AS ( | |
| SELECT "xml" FROM xml_mtd | |
| ) | |
| SELECT | |
| (xpath('//gmd:fileIdentifier/gco:CharacterString/text()', "xml", ns)::TEXT)::uuid AS jdd_uuid, | |
| (xpath('//gmd:contact/gmd:CI_ResponsibleParty/gmd:organisationName//*/text()', "xml", ns))[1]::TEXT AS contact_org, | |
| (xpath('//gmd:contact/gmd:CI_ResponsibleParty//gmd:electronicMailAddress//*/text()', "xml", ns))[1]::TEXT AS contact_email, | |
| (xpath('//gmd:identificationInfo//*/gmd:title//*/text()', "xml", ns))[1]::TEXT AS title, | |
| (xpath('//gmd:abstract//*/text()', "xml", ns))[1]::TEXT AS abstract | |
| FROM ns, xmldata; | |
| /* | |
| jdd_uuid |contact_org |contact_email |title |abstract | | |
| ------------------------------------+---------------+------------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |
| 6ea5c1bd-b10b-4f7e-9139-2f878c63fc74|Picardie Nature|data@picardie-nature.org|Atlas mammifères des Hauts-de-France|Picardie Nature, le GON et la CMNF ont entrepris la réalisation d’un Atlas régional des mammifères regroupant les mammifères terrestres, marin et chauves-souris.L’objectif de cette démarche est de recenser, entre 2010 et 2020, les mammifères des Hauts-de-| | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment