Automating GIS Metadata Conversion

Any sysadmin working in an earth-science organization may find themselves learning the skills of the programmers around them in order to help out with everyday tasks. This is one such example, where automating conversion of the XML metadata proved helpful to GIS analysts and sysadmins alike.

FGDC to ISO-19115 Conversion on Import (GeoNetwork)

  1. Download the csdgm2iso19115-2.xslt stylesheet from the FGDC website.
  2. Replace root element “gmi:MI_Metadata” with “gmd:MD_Metadata”
    ( this is the root element: <xsl:template match=”/”>
    so right beneath that, place <gmd:md_metadata> )
  3. Completely remove the gmi namespace to allow compatibility with GeoNetwork
  4. Under this element, <xsl:stylesheet>, add the following so Saxon can use the necessary types.
    xmlns:saxon=”” saxon:allow-all-built-in-types=”yes”
  5. Save the file, then copy it to /usr/local/geonetwork/web/geonetwork/xsl/conversion/import/FGDC_to_ISO19115.xsl

This will allow you to select FGDC_to_ISO19115 from the Stylesheet drop-down menu in your GeoNetwork web interface when you import files. When this is selected, GeoNetwork can import directories of FGDC metadata and automatically convert them to ISO19115.

For the lazy, you can find the above file, FGDC_to_ISO19115.xsl, pre-edited and ready for use with GeoNetwork.

Alternatively, if you prefer to use the command-line, run the new stylesheet through Saxon:

java -jar /usr/local/geonetwork/web/geonetwork/WEB-INF/lib/saxon- -s:$INPUTFILE -xsl:$SOMEPATH/csdgm2iso19115-geonetwork.xslt -o:$OUTPUTFILE

Here is an example of using the above command in a bash script to automate conversion of entire directories of FGDC metadata.

# a metadata translation helper script
# takes FGDC metadata and converts to ISO-19115 standard
# USAGE:  ./xml_convert <input[file|dir]> <outputfile>

function run_saxon() {
    java -jar /usr/local/geonetwork/web/geonetwork/WEB-INF/lib/saxon- -s:$inputfile -xsl:$HOME/scripts/csdgm2iso19115-geonetwork.xslt -o:$output

# process a single file
if [ -f "$1" ]; then
    run_saxon $inputfile $output

# process a directory of files 
elif [ -d "$1" ]; then
    # create output dir
    [ -d $2 ] || mkdir -p $2

    # if this option is selected, all files will be output to a single directory
    if [ "$3" == "--single_dir" ]; then
        # run saxon on each xml file in the input dir, translate, then output to specified dir
        for inputfile in $( find $1 -iname *.xml ); do
            filename=`basename $inputfile`
            echo "Converting: $inputfile -> $output"
            run_saxon $inputfile $outputfile
        # same as above, but keep directory structure
        for inputfile in $( find $1 -iname *.xml ); do
            filename=`basename $inputfile`
            filepath=`dirname $inputfile`

            # create an output path with the same name as the input path
            [ -d "$2/$filepath" ] || mkdir -p "$2/$filepath"

            echo "Converting: $inputfile -> $output"
            run_saxon $inputfile $outputfile
    # print usage info
    echo "error: incorrect parameters given"
    echo "USAGE:  xml_convert <input[file|dir]> <outputfile>"
    echo "        xml_convert <input[file|dir]> <outputfile> --single_dir, to output all files to a single directory"

Leave a reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>