[gdal-dev] Parse GML without geometry

Steve.Toutant at inspq.qc.ca Steve.Toutant at inspq.qc.ca
Fri Dec 12 13:13:02 PST 2014


Got it! Lots of fun!
Good links for python
http://pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html#get-wfs-layer-and-iterate-over-features

Thousand thanks






Even Rouault <even.rouault at spatialys.com>@lists.osgeo.org 
Envoyé par : gdal-dev-bounces at lists.osgeo.org
2014-12-12 15:42

A
gdal-dev at lists.osgeo.org
cc
Steve.Toutant at inspq.qc.ca
Objet
Re: [gdal-dev] Parse GML without geometry








Le vendredi 12 décembre 2014 21:38:06, Steve.Toutant at inspq.qc.ca a écrit :
> thanks Kyle
> 
> I ended up with
> geom=osgeo.ogr.CreateGeometryFromGML(wfs_response)
> Returns ERROR 1: Unrecognised geometry type <FeatureCollection>
> 
> If I understand well, I think my question now is
> How do I parse the feature collection with ogr?

With the WFS driver:

ogrinfo "WFS:
http://demo.mapserver.org/cgi-bin/wfs?SERVICE=WFS&REQUEST=GetFeature&version=1.1.0&Typename=continents&maxfeatures=10&propertyname=(NA2DESC) 
" -ro -al

You can read the OGR API tutorial to see how to use a OGR datasource, 
layer, feature

Regarding gemetry or not geometry, it won't matter. Actually as generated 
by mapserver, there's a geometry column declared, but not filled. Won't be 
an issue:

$ wget "
http://demo.mapserver.org/cgi-bin/wfs?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=1.1.0&TYPENAME=continents&
" -O -

<schema
   targetNamespace="http://mapserver.gis.umn.edu/mapserver" 
   xmlns:ms="http://mapserver.gis.umn.edu/mapserver" 
   xmlns:ogc="http://www.opengis.net/ogc"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns="http://www.w3.org/2001/XMLSchema"
   xmlns:gml="http://www.opengis.net/gml"
   elementFormDefault="qualified" version="0.1" >

  <import namespace="http://www.opengis.net/gml"
          schemaLocation="
http://schemas.opengis.net/gml/3.1.1/base/gml.xsd" />

  <element name="continents" 
           type="ms:continentsType" 
           substitutionGroup="gml:_Feature" />

  <complexType name="continentsType">
    <complexContent>
      <extension base="gml:AbstractFeatureType">
        <sequence>
          <element name="msGeometry" type="gml:GeometryPropertyType" 
minOccurs="0" maxOccurs="1"/>
          <element name="NA2DESC" type="string"/>
          <element name="NA3DESC" type="string"/>
        </sequence>
      </extension>
    </complexContent>
  </complexType>

</schema>


> 
> 
> 
> 
> 
> 
> 
> Kyle Shannon <kyle at pobox.com>
> 2014-12-12 14:47
> 
> A
> Steve.Toutant at inspq.qc.ca
> cc
> GDAL Developers <gdal-dev at lists.osgeo.org>
> Objet
> Re: [gdal-dev] Parse GML without geometry
> 
> 
> 
> 
> 
> 
> 
> 
> Steve,
> 
> On Fri, Dec 12, 2014 at 12:35 PM,  <Steve.Toutant at inspq.qc.ca> wrote:
> > Hi,
> > I need to parse the GML returned by this query, to make a list of 
unique
> > value of NA2DESC tag using python
> 
> 
http://demo.mapserver.org/cgi-bin/wfs?SERVICE=WFS&REQUEST=GetFeature&versio

> n=1.1.0&Typename=continents&maxfeatures=10&propertyname=(NA2DESC)
> 
> > I could not make it with a XML parser yet. I consider using ogr API 
but
> 
> can
> 
> > I use it even if there is no geometry?
> 
> This one has a geometry, or so ogr thinks so:
> 
> kyle at kyle-workstation:~$ ogrinfo -so -al -ro
> 
"/vsicurl_streaming/http://demo.mapserver.org/cgi-bin/wfs?SERVICE=WFS&REQUE
> 
ST=GetFeature&version=1.1.0&Typename=continents&maxfeatures=10&propertyname
> =(NA2DESC)" INFO: Open of
> 
`/vsicurl_streaming/http://demo.mapserver.org/cgi-bin/wfs?SERVICE=WFS&REQUE
> 
ST=GetFeature&version=1.1.0&Typename=continents&maxfeatures=10&propertyname
> =(NA2DESC)' using driver `GML' successful.
> 
> Layer name: continents
> Geometry: Unknown (any)
> Feature Count: 10
> Extent: (-90.000000, -180.000000) - (83.627419, 180.000000)
> Layer SRS WKT:
> GEOGCS["WGS 84",
>     DATUM["WGS_1984",
>         SPHEROID["WGS 84",6378137,298.257223563,
>             AUTHORITY["EPSG","7030"]],
>         AUTHORITY["EPSG","6326"]],
>     PRIMEM["Greenwich",0,
>         AUTHORITY["EPSG","8901"]],
>     UNIT["degree",0.0174532925199433,
>         AUTHORITY["EPSG","9122"]],
>     AUTHORITY["EPSG","4326"]]
> Geometry Column = msGeometry
> gml_id: String (0.0)
> NA2DESC: String (0.0)
> NA3DESC: String (0.0)
> 
> > If ogr api is a good option, any link to examples or tutorial would be
> > appreciated since I never used the API.
> 
> API tutorials:
> 
> For gdal 2.x:
> 
> http://gdal.org/ogr_apitut.html
> 
> For gdal 1.x (the vector side is ogr):
> 
> http://gdal.org/1.11/ogr/ogr_apitut.html
> 
> > Thanks!
> > 
> > 
> > _______________________________________________
> > gdal-dev mailing list
> > gdal-dev at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/gdal-dev
> 
> kss

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
gdal-dev at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20141212/4cebc88b/attachment-0001.html>


More information about the gdal-dev mailing list