TransWikia.com

WFS GetFeature with propertyName get response without geometry

Geographic Information Systems Asked by yxyxq1984 on February 5, 2021

I have a WFS request send to a GeoServer:

http://localhost:8600/geoserver/aa/ows?service=WFS &version=2.0.0&request=GetFeature&typeNames=aa:bb&outputFormat=json&propertyName=attr1,attr2

I cannot get all features with only attr1 and attr2 value. When requesting every feature’s geometry the response is null.

When I send a similar request without propertyName parameter, the geometry is back.

I want to have both the geometry and attr1, attr2.

One Answer

In WFS geometry is also just a property. If you do not use PropertyName parameter then all the parameters are included but if you use PropertyName then you must include into the request all the (non-mandatory) parameters that you want .

Compare

http://demo.geo-solutions.it/geoserver/wfs?service=WFS&version=2.0.0&request=GetFeature&TypeNames=states&count=2&PropertyName=STATE_NAME&outputformat=application/json

and

http://demo.geo-solutions.it/geoserver/wfs?service=WFS&version=2.0.0&request=GetFeature&TypeNames=states&count=2&PropertyName=STATE_NAME,the_geom&outputformat=application/json

The name of the geometry property is checked with the DescribeFeatureType request

http://demo.geo-solutions.it/geoserver/wfs?service=WFS&version=2.0.0&request=DescribeFeatureType&TypeName=states

You can see below that for this feature type the name of the geometry property is "the_geom". You can also see that all properties are nillable=true and minOccurs="0" so they are not included in the result set if they are not requested. If some properties in a WFS service are not-nillable or if they have minOccurs greater than zero then they are mandatory and always included in the result even if not requested with PropertyName.

<?xml version="1.0" encoding="UTF-8"?><xsd:schema xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:topp="http://www.openplans.org/topp" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.openplans.org/topp">
  <xsd:import namespace="http://www.opengis.net/gml/3.2" schemaLocation="http://demo.geo-solutions.it:80/geoserver/schemas/gml/3.2.1/gml.xsd"/>
  <xsd:complexType name="statesType">
    <xsd:complexContent>
      <xsd:extension base="gml:AbstractFeatureType">
        <xsd:sequence>
          <xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:MultiSurfacePropertyType"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="STATE_NAME" nillable="true" type="xsd:string"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="STATE_FIPS" nillable="true" type="xsd:string"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="SUB_REGION" nillable="true" type="xsd:string"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="STATE_ABBR" nillable="true" type="xsd:string"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="LAND_KM" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="WATER_KM" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="PERSONS" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="FAMILIES" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="HOUSHOLD" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="MALE" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="FEMALE" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="WORKERS" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="DRVALONE" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="CARPOOL" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="PUBTRANS" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="EMPLOYED" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="UNEMPLOY" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="SERVICE" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="MANUAL" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="P_MALE" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="P_FEMALE" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="SAMP_POP" nillable="true" type="xsd:double"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:element name="states" substitutionGroup="gml:AbstractFeature" type="topp:statesType"/>
</xsd:schema>

Answered by user30184 on February 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP