I am investigating using Geoserver to output new WFS layer features dynamically. We have a backend process that will be generating new WFS features periodically that will be placed in a datastore (most likely PostGIS). I plan on creating a WFS layer for the feature data in PostGIS. The idea is to have the backend process dynamically add new features into PostGIS and my expectation is that clients making WFS features requests using Geoserver will get the new feature data I am adding at runtime. Is this the case? I can't seem to find any documentation discussing what happens when the datastore's data is updated.
[GIS] Dynamically adding WFS layer features with Geoserver
geoserverwfs
Related Solutions
If you use WFS 1.0.0 the srsName
parameter is not supported, so you can’t use OpenLayers to decide in which projection you want your features returned. Therefore you'll need 1.1.0
Also you need to request the WFS in the same SRS as your basemap otherwise no features will appear as they will be outside the map's bounding box. So the srsName should be set to EPSG:900913 (not EPSG:900918 as in your question - a typo maybe?).
Finally you need to make sure that Geoserver can reproject the WFS into EPSG:900913. You can check this by issuing a request similar to:
http://localhost/geoserver/wfs?service=WFS&request=GetCapabilities&version=1.1.0
I had similar issues with MapServer rather than GeoServer, but the same principles probably apply:
http://geographika.co.uk/mapserver-openlayers-and-the-wfs-maze
You can reproject features on the client side, but this may take longer than doing it on the server. You will also need to include the Proj4JS library in your web application and the EPSG:26918 definition in your code to take this approach. You'll also need to set the layers's projection:
Proj4js.defs["EPSG:26918"] = "+proj=utm +zone=18 +ellps=GRS80 +datum=NAD83 +units=m +no_defs";
var myproj =new OpenLayers.Projection("EPSG:26918");
var wfsLayer = new OpenLayers.Layer.Vector(
"Photo Points", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.WFS({
version: "1.0.0",
url: "http://localhost/geoserver/wfs",
featureType: "Photo Point",
srsName:"EPSG:26918",
featureNS: "http://dev.geodatabase.org",
geometryName: "SHAPE"
}),
visibility: true,
projection: myproj
});
Have a look at the source in this example - http://openlayers.org/dev/examples/wfs-reprojection.html for more details. Also you may want to change the strategy to BBox or you will load all the features in in one go.
strategies: [new OpenLayers.Strategy.BBOX()]
For others who come across this question, here's what I've learned so far:
PostGIS and the geography data type appear to be red herrings.
In WFS 1.0, you can't project on the fly and the BBOX is expected to be specified in the same projection as the features.
In WFS 1.1, reprojection is supported, but by default the BBOX is interpreted as CRS84. Unlike in WMS, there is no BBOXSR parameter, but you can append a "crsuri" string to the end of your BBOX parameter specifying the CRS of the BBOX. Unfortunately, you can't just say "EPSG:32615" but have to use a CRS URI like "urn:ogc:def:crs:OGC:1.3:CRS84". The crsuri must be a valid URI, and it appears codes like "EPSG:32615" are accepted, at least by GeoServer, though the blog I found recommends the urn format shown above. I haven't yet found the spec for these URI's, so I don't know whether they're application-specific or there's some universal way to say "WGS84, UTM 15". I'd love for someone more knowledgeable to weigh in on this.
Anyway, here is the blog post where I got most of my information.
Anyone know where to find a true API reference for WFS? All I can find are the implementation spec and the documentation for various WFS server applications.
Best Answer
Yes, that's the case. The way I do it is basically exactly how you've described. I have my tables and a PostGIS View. Then on GeoServer I create a GeoServer SQL View to postgis which is basically
select * from ourpostgisview
. So as soon as anything is updated or added to the tables of course the view sees it and so does the GeoServer layer.Here is some documentation.
Creating a View in GeoServer
Parametric SQL views