1

Is it possible to find the geometry type of a layer in a WFS, using OGR, when the layer is empty (0 features)?

3
  • Are you using an OGR (GDAL) command line utility (which one?), or C/C++ API, or Python? Give us some more information about how you're using GDAL (OGR). Does GetGeomType() (or OGR_L_GetGeomType()) work on WFS layers ( gdal.org/api/… )? – Son of a Beach Mar 15 at 3:20
  • I just tried ogrinfo "WFS:https://ahocevar.com/geoserver/wfs?service=WFS" WFSLayerMetadata and it reported: Geometry: None even when it DOES have features. So that didn't help. – Son of a Beach Mar 15 at 3:40
  • There are also servers that have "gml:GeometryPropertyType" in DescribeFeatureType and then it is not possible to know the exact geometry type without reading the data. In that case GDAL usually prints the geometry type as Unknown (any), not None. – user30184 Mar 15 at 9:10
1

I just tried:

ogrinfo -al -so http://localhost:8080/geoserver/ows?service=wfs&version=1.1.0&request=getfeature&typename=ian:states

and amongst other things it says that my geometry type is a Multi Surface.

using driver `WFS' successful.
Metadata:
  ABSTRACT=This is the reference implementation of WFS 1.0.0 and WFS 1.1.0, supports all WFS operations including Transaction.
  PROVIDER_NAME=The ancient geographes INC
  TITLE=GeoServer Web Feature Service

Layer name: ian:states
Metadata:
  KEYWORD_1=features
  KEYWORD_2=states
  TITLE=states
Geometry: Multi Surface
Feature Count: 55
Extent: (-179.149000, -14.549000) - (179.778000, 71.365000)
Layer SRS WKT:
GEOGCRS["NAD83",
    DATUM["North American Datum 1983",
        ELLIPSOID["GRS 1980",6378137,298.257222101,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    USAGE[
        SCOPE["unknown"],
        AREA["North America - NAD83"],
        BBOX[14.92,167.65,86.46,-47.74]],
    ID["EPSG",4269]]
Data axis to CRS axis mapping: 2,1
Geometry Column = geom_4269
gml_id: String (0.0) NOT NULL
pop_2018: Integer64 (0.0)
area: Real (0.0)

If you don't have to use OGR then it is as easy to just make a DescribeFeatureType request directly to the WFS Server.

curl "http://localhost:8080/geoserver/ows?service=wfs&version=1.1.0&request=describeFeatureType&typename=ian:states"

which returns:

<?xml version="1.0" encoding="UTF-8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" xmlns:ian="http://ianturton.com/ian" elementFormDefault="qualified" targetNamespace="http://ianturton.com/ian">
  <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://localhost:8080/geoserver/schemas/gml/3.1.1/base/gml.xsd"/>
  <xsd:complexType name="statesType">
    <xsd:complexContent>
      <xsd:extension base="gml:AbstractFeatureType">
        <xsd:sequence>
          <xsd:element maxOccurs="1" minOccurs="0" name="pop_2018" nillable="true" type="xsd:long"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="area" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="geom_4269" nillable="true" type="gml:MultiSurfacePropertyType"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="geom_2163" nillable="true" type="gml:MultiSurfacePropertyType"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:element name="states" substitutionGroup="gml:_Feature" type="ian:statesType"/>
</xsd:schema>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.