[gdal-dev] Re: GML 3.1.1

Mark Overmeer mark at overmeer.net
Wed Sep 15 05:14:11 EDT 2010


* Ari Jolma (ari.jolma at gmail.com) [100915 08:51]:
> To write data into an OGR supported format (in-memory is also a
> format), you'd need to create a data source, then a layer, and then
> insert features into the layer. There are a few ways to actually do
> this. That should not be very difficult, I'd just need to know how
> that data is accessed from Geo::GML, which is in the docs I assume.

Geo::GML reader produces pure Perl, not objects or methods. It's
a nested HASH as simple as that, reflecting the data in the document.
With
    print $gml->template(PERL => $type)
you get a nicely documented example of the data you can expect.

> Enable a method to create a GDAL vector data source with the help
> of Geo::GML

The program looks like this:

   use Geo::GML ':gml321';
   use Data::Dumper;

   my ($type, $data) = Geo::GML->from('data.xml');

   print Dumper $data;

For instance, when the input file contains
 <gml:multiExtentOf xmlns:gml="http://www.opengis.net/gml/3.2">
   <gml:MultiSurface srsName="EPGS:4326">
     <gml:surfaceMembers>
       <gml:Polygon>
         <gml:exterior>
           <gml:LinearRing>
             <gml:posList count="7">
               53.477199 6.139263 53.588759 5.359165 53.695178 4.5753
               52.762039 4.224426 52.656849 4.990792 52.54677 5.753162
               53.477199 6.139263
             </gml:posList>
           </gml:LinearRing>
         </gml:exterior>
       </gml:Polygon>
     </gml:surfaceMembers>
   </gml:MultiSurface>
 </gml:multiExtentOf>

The content of %$data will become

  {
  gml_MultiSurface => {
    srsName => 'EPGS:4326',
    gml_surfaceMembers => {

#     gml__Surface => [              # in GML3.1.1 syntax
      seq_gml_AbstractSurface => [   # in GML3.2.1 syntax
        { gml_Polygon => {
            gml_interior => [],
            gml_exterior => {
              gml_LinearRing => {
                gml_posList => {
                  count => 7,
                  _ => [
                    53.477199, 6.139263,
                    53.588759, 5.359165,
                    53.695178, 4.5753,
                    52.762039, 4.224426,
                    52.656849, 4.990792,
                    52.54677,  5.753162,
                    53.477199, 6.139263
                  ]
                }
              }
            }
          }
        }
      ]
    }
  } }

Then, recursively, you have to run through the $data and translate it
into internal GDAL data structures.

Of course, you can use any simple XML parser to get such a data-structure,
however with Geo::GML, the parsing is schema controled and validated.
For instance, an element which can be repeated will always be shows as
ARRAY, even if there is just one element.  In simple parsers, you often
needs constructs like

   my @interior = ref $data->{interior} eq 'ARRAY'
                ? @{$data->{interior}}
                : defined $data->{interior}
                ? $data->{interior}
                : ();

with XML::Compile, you can do

   my @interior = @{$data->{interior} || []};
-- 
CU,
               MarkOv


More information about the gdal-dev mailing list