5

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.

1 Answer 1

6

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>
6
  • Thank you so much. That's what I need.
    – yxyxq1984
    Commented Dec 1, 2020 at 11:55
  • One more question. It is possible to set the the_geom' attribution nillable=false? Because I saw someone don't request attribution like the_geom, still get gemetry. Or why my the_geom is nillable=true?
    – yxyxq1984
    Commented Dec 1, 2020 at 11:59
  • It is set in that way be default with GeoServers. Please explain "Because I saw someone don't request attribution like the_geom, still get gemetry.". Where did you see that? In the logs of your server? Somewhere in the internet? GeoServer is possible to configure to show nillable=false but it is a bit complicated. Manual is here docs.geoserver.org/stable/en/user/services/wfs/….
    – user30184
    Commented Dec 1, 2020 at 12:42
  • Thanks again. Yes I saw in the internet. I will check the link you mentioned.
    – yxyxq1984
    Commented Dec 1, 2020 at 13:19
  • Doesn't work for me. I request PropertyName=au:name but this WFS service still returns geometry: ign.es/wfs-inspire/…
    – abu
    Commented Aug 5, 2022 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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