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– Ian Turton2015年08月25日 14:50:27 +00:00Commented Aug 25, 2015 at 14:50
-
Thanks for that hint. Just tried that and updated my question.ulrich– ulrich2015年08月25日 15:10:06 +00:00Commented Aug 25, 2015 at 15:10
2 Answers 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
responds with an xsd-schema, which seems to be the expected output. But I also can request
which returns the featuretype description in xml format including additional information about the datasource.
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: <unset>)</description>
<keywords>
<string>uk_625k_mapped_feature</string>
<string>features</string>
</keywords>
<nativeCRS class="projected">PROJCS["OSGB 1936 / British National Grid",
GEOGCS["OSGB 1936",
DATUM["OSGB 1936",
SPHEROID["Airy 1830", 6377563.396, 299.3249646, AUTHORITY["EPSG","7001"]],
TOWGS84[446.448, -125.157, 542.06, 0.15, 0.247, 0.842, -20.489],
AUTHORITY["EPSG","6277"]],
PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]],
UNIT["degree", 0.017453292519943295],
AXIS["Geodetic longitude", EAST],
AXIS["Geodetic latitude", NORTH],
AUTHORITY["EPSG","4277"]],
PROJECTION["Transverse_Mercator", AUTHORITY["EPSG","9807"]],
PARAMETER["central_meridian", -2.0],
PARAMETER["latitude_of_origin", 49.0],
PARAMETER["scale_factor", 0.9996012717],
PARAMETER["false_easting", 400000.0],
PARAMETER["false_northing", -100000.0],
UNIT["m", 1.0],
AXIS["Easting", EAST],
AXIS["Northing", NORTH],
AUTHORITY["EPSG","27700"]]</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["WGS84(DD)",
DATUM["WGS84",
SPHEROID["WGS84", 6378137.0, 298.257223563]],
PRIMEM["Greenwich", 0.0],
UNIT["degree", 0.017453292519943295],
AXIS["Geodetic longitude", EAST],
AXIS["Geodetic latitude", 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– ulrich2015年08月25日 15:32:15 +00:00Commented Aug 25, 2015 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– ulrich2015年08月26日 08:14:35 +00:00Commented Aug 26, 2015 at 8:14
Explore related questions
See similar questions with these tags.