1

I am trying to add an external WFS as a datasource to my geoserver via REST API. I already added a new workspace and WFS datasource.

Now I want to publish a layer from that WFS on geoserver. The same works for WMS, but seems to be a bit different and poorly documented for WFS services.

I tried to request

PUT http://myhost.com/geoserver/rest/workspaces/my_workspace/datastores/my_datastore/layers

the following content as proposed in this post:

<layer>
  <name>my_layer</name>
  <type>VECTOR</type>
  <defaultStyle>
    <name>point</name>
  </defaultStyle>
  <resource class="featureType">
    <name>myFeature</name>
  </resource>
</layer>

This doesn't work out for me, I get a 500: Cannot cast org.geoserver.catalog.impl.LayerInfoImpl to org.geoserver.catalog.DataStoreInfo.

Now I am not sure, if it is required to create a FeatureType for the layer in advance. I added the layer manually via geoserver UI where it automatically detects the feature type from the WFS layer. I would like the same behaviour via the REST API.

Can anyone lead me towards the correct approach?

EDIT:

Maybe that will work, once I have created the featuretype. Just tried to get the featureType description from my manually created layer to adapt it. But there is a lot information I would have to put into the featuretype.xml manually just from the original WFS. I tried to insert the DescribeFeatureType output from the original WFS into this request:

POST /geoserver/rest/workspaces/my_workspace/datastores/my_datastore/featuretypes

But it complains about the syntax because the xsd:schema tags

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

Not sure, if this is the expected FeatureType syntax?

  • Once you have created one using the GUI try doing a GET on it using REST this should show all the required information. The try modifying this template. – Ian Turton Aug 25 '15 at 14:50
  • Thanks for that hint. Just tried that and updated my question. – ulrich Aug 25 '15 at 15:10
2

You have to create a FeatureType before you can create a Layer (i.e. publish it). If you have already created a test layer then fetch the feature type of that one (like http://geoserver.ianturton.com/rest/workspaces/topp/datastores/bgs/featuretypes/test_uk_625k_mapped_feature.xml) but you should be able to delete quite a lot of that and leave it for GeoServer to fill in.

<featureType>
  <name>test_uk_625k_mapped_feature</name>
  <nativeName>test_uk_625k_mapped_feature</nativeName>
  <namespace>
    <name>topp</name>
    <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://geoserver.ianturton.com/rest/namespaces/topp.xml" type="application/xml"/>
  </namespace>
  <title>uk_625k_mapped_feature</title>
  <description>net.opengis.wfs20.impl.AbstractTypeImpl@1f89241 (value: Just for testing, lang: &lt;unset&gt;)</description>
  <keywords>
    <string>uk_625k_mapped_feature</string>
    <string>features</string>
  </keywords>
  <nativeCRS class="projected">PROJCS[&quot;OSGB 1936 / British National Grid&quot;, 
  GEOGCS[&quot;OSGB 1936&quot;, 
    DATUM[&quot;OSGB 1936&quot;, 
      SPHEROID[&quot;Airy 1830&quot;, 6377563.396, 299.3249646, AUTHORITY[&quot;EPSG&quot;,&quot;7001&quot;]], 
      TOWGS84[446.448, -125.157, 542.06, 0.15, 0.247, 0.842, -20.489], 
      AUTHORITY[&quot;EPSG&quot;,&quot;6277&quot;]], 
    PRIMEM[&quot;Greenwich&quot;, 0.0, AUTHORITY[&quot;EPSG&quot;,&quot;8901&quot;]], 
    UNIT[&quot;degree&quot;, 0.017453292519943295], 
    AXIS[&quot;Geodetic longitude&quot;, EAST], 
    AXIS[&quot;Geodetic latitude&quot;, NORTH], 
    AUTHORITY[&quot;EPSG&quot;,&quot;4277&quot;]], 
  PROJECTION[&quot;Transverse_Mercator&quot;, AUTHORITY[&quot;EPSG&quot;,&quot;9807&quot;]], 
  PARAMETER[&quot;central_meridian&quot;, -2.0], 
  PARAMETER[&quot;latitude_of_origin&quot;, 49.0], 
  PARAMETER[&quot;scale_factor&quot;, 0.9996012717], 
  PARAMETER[&quot;false_easting&quot;, 400000.0], 
  PARAMETER[&quot;false_northing&quot;, -100000.0], 
  UNIT[&quot;m&quot;, 1.0], 
  AXIS[&quot;Easting&quot;, EAST], 
  AXIS[&quot;Northing&quot;, NORTH], 
  AUTHORITY[&quot;EPSG&quot;,&quot;27700&quot;]]</nativeCRS>
  <srs>EPSG:27700</srs>
  <nativeBoundingBox>
    <minx>-132576.78915711527</minx>
    <maxx>743466.6249987332</maxx>
    <miny>-15669.960592884949</miny>
    <maxy>1248847.1762802668</maxy>
    <crs class="projected">EPSG:27700</crs>
  </nativeBoundingBox>
  <latLonBoundingBox>
    <minx>-11.801005644638966</minx>
    <maxx>4.349696858682689</maxx>
    <miny>49.5245056714837</miny>
    <maxy>61.11839723246307</maxy>
    <crs>GEOGCS[&quot;WGS84(DD)&quot;, 
  DATUM[&quot;WGS84&quot;, 
    SPHEROID[&quot;WGS84&quot;, 6378137.0, 298.257223563]], 
  PRIMEM[&quot;Greenwich&quot;, 0.0], 
  UNIT[&quot;degree&quot;, 0.017453292519943295], 
  AXIS[&quot;Geodetic longitude&quot;, EAST], 
  AXIS[&quot;Geodetic latitude&quot;, NORTH]]</crs>
  </latLonBoundingBox>
  <projectionPolicy>FORCE_DECLARED</projectionPolicy>
  <enabled>true</enabled>
  <store class="dataStore">
    <name>bgs</name>
    <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://geoserver.ianturton.com/rest/workspaces/topp/datastores/bgs.xml" type="application/xml"/>
  </store>
  <maxFeatures>0</maxFeatures>
  <numDecimals>0</numDecimals>
  <overridingServiceSRS>false</overridingServiceSRS>
  <skipNumberMatched>false</skipNumberMatched>
  <circularArcPresent>false</circularArcPresent>
  <attributes>
    <attribute>
      <name>uuid</name>
      <minOccurs>1</minOccurs>
      <maxOccurs>1</maxOccurs>
      <nillable>true</nillable>
      <binding>java.lang.String</binding>
    </attribute>
    <attribute>
      <name>lex</name>
      <minOccurs>1</minOccurs>
      <maxOccurs>1</maxOccurs>
      <nillable>true</nillable>
      <binding>java.lang.String</binding>
    </attribute>
    <attribute>
      <name>rcs</name>
      <minOccurs>1</minOccurs>
      <maxOccurs>1</maxOccurs>
      <nillable>true</nillable>
      <binding>java.lang.String</binding>
    </attribute>
    <attribute>
      <name>lex_rcs</name>
      <minOccurs>1</minOccurs>
      <maxOccurs>1</maxOccurs>
      <nillable>true</nillable>
      <binding>java.lang.String</binding>
    </attribute>
    <attribute>
      <name>the_geom</name>
      <minOccurs>0</minOccurs>
      <maxOccurs>1</maxOccurs>
      <nillable>true</nillable>
      <binding>com.vividsolutions.jts.geom.Geometry</binding>
    </attribute>
  </attributes>
</featureType>

Experiment and when it works update the documentation for the next person along.

  • your link requires authentication. maybe you can post a part of the file structure. – ulrich Aug 25 '15 at 15:32
  • Thanks for this information, which was crucial to get the turn. Nevertheless, I posted as separate answer to explain my workflow. – ulrich Aug 26 '15 at 8:14
2

Finally, iant's answer led me to the goal. For completeness I post what I have done:

After creating the datasource, main information on the WFS layers are known to geoserver. So I only had to do

POST /geoserver/rest/workspaces/my_workspace/datastores/my_datastore/featuretypes

with the name of the WFS layer, I wanted to publish

<featureType><name>layer_name_from_remote_wfs</name></featureType>

All additional information is created by geoserver itself, even the corresponding layer ist created automatically, so we are done at this point.

This was quite confusing to me, as the geoserver DescribeFeatureType output from the new layer found at

http://host/geoserver/my_workspace/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&featureType

responds with an xsd-schema, which seems to be the expected output. But I also can request

http://host/geoserver/rest/workspaces/my_workspace/datastores/my_datastore/featuretypes/my_layername.xml

which returns the featuretype description in xml format including additional information about the datasource.

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.