[gdal-dev] Re: [SpatiaLite-Users] Spatialite_gml tool and Inspire Administrative units dataset

Even Rouault even.rouault at mines-paris.org
Sun Jan 1 13:08:31 EST 2012

Le dimanche 01 janvier 2012 15:27:34, Jukka Rahkonen a écrit :
> Hi,
> I have been playing with a datasets that follows the Inspire
> definitions for the Administrative Units data set.  Data are in GML
> 3.2 format and the dataset contain administrative units both as
> polygons and linestrings. In addition, also the reference points for
> the administrational units are present. So there are three layers all
> together.
> FME can find all the layers without problems. GDAL v 1.9.0 is also
> doing rather good work and ogr2ogr finds the polygon layer and
> linestring layer and can convert data for example into Spatialite
> format.

You can also fetch the reference points, but it is a bit more involved since 
OGR has not native support for multiple geometries per layer. In the case the 
GML parser finds several GML geometry elements for a single feature, it only 
reports the last one (arbitrary choice, but based on experience it is often 
the most interesting one...)

There are 2 different ways of doing this :

1) Remove inspire_au.gfs that has been generated previously and run "ogrinfo 
inspire_au_bak.xml --config GML_FETCH_ALL_GEOMETRIES YES". This option isn't 
really documented as it is a bit experimental, but seems to work with your 
file. The resulting AdministrativeUnit layer will have geometries of type 
GEOMETRYCOLLECTION. The first element of the geometry collection will be a 
MULTIPOINT with the reference points, and the second element the MULTIPOLYGON 
with the area of the unit. A bit of further processing would then be needed to 
split the 2 components. For example :

# fetch the points and polygons into a single geometrycollection, and split it 
immediately in 2 features, one with the points, the other with the polygons
$ ogr2ogr AdministrativeUnit.sqlite inspire_au.xml -explodecollections -f 

# extract the points
$ ogr2ogr AdministrativeUnit_points.sqlite AdministrativeUnit.sqlite  -f 
SQLite -dsco SPATIALITE=YES  -sql "select * from administrativeunit where 

# extract the polygons
$ ogr2ogr AdministrativeUnit_polygons.sqlite AdministrativeUnit.sqlite  -f 
SQLite -dsco SPATIALITE=YES  -sql "select * from administrativeunit where 
nln AdministrativeUnit_polygons

2) Or edit the inspire_au.gfs that is generated by a normal run of ogrinfo to 
add the <GeometryType> and <GeometryElementPath> elements in the definition of 
the AdministrativeUnit class, so it looks like :

    <GeometryType>4</GeometryType> <!-- multipoint -->
    <GeometryElementPath>location</GeometryElementPath> <!-- 'location' 
contains the reference points -->

The next run of ogrinfo will report the reference points in the 
AdministrativeUnit layer. It is however impossible currently to get both the 
points and the polygon in a single run.

More information about the gdal-dev mailing list