[Geoserver-users] Relations between features with WFS and PostGIS

Hello everyone,

I am trying to use GeoServer 1.4 with PostGIS to store features that may
have a geometric value (optional!) and also relations to other features. I
would like to insert and query these features using WFS. Playing around a
bit I encountered several questions (more detailed explanations below):

1. What is the best or standard way to define and query relations between
features?
2. Can I insert a new feature (with WFS insert) without a geometry?

First, I created a simple feature table in Postgres/PostGIS with a foreign
key to itself:

CREATE TABLE some_places (
    pid integer PRIMARY KEY,
    place_name character varying(128) NOT NULL,
    refers_to integer REFERENCES places
);
SELECT AddGeometryColumn (...,'place_geom',...);

Afterwards, I can easily define a new FeatureType within GeoServer based on
the database definitions. The refers_to element is treated as a regular int
attribute of the feature, and actually representing the id of the referenced
feature. So I am able to follow relations querying this feature id.

However, a many-to-many relationship seems impossible because I cannot span
a feature over several tables (as discussed in the 'Feature over more the on
table' thread recently).

I also found nice mechanisms in the GML simple profile spec where you can
define the feature type of the reference target. I don't think there is a
similar approach using WFS, is it?

My second problem is that I cannot insert a place without a place_geom value
although the schema and the table definition allow this. As workaround I am
currently using a constant polygon with 0.0 values but I am not so happy
about it. I guess GeoServer simply expects a geometry, tries to handle it
and consequently throws a nullpointer.

I digged through some docs and specs already but could not find the desired
information. So I would appreciate any comments or references to helpful
documents.

Thank you in advance!

Regards,
Martin

--
View this message in context: http://www.nabble.com/Relations-between-features-with-WFS-and-PostGIS-tf2971393.html#a8314570
Sent from the GeoServer - User mailing list archive at Nabble.com.

Hi Martin,

Comments inline.

Martin Gruhn-2 wrote:

Hello everyone,

I am trying to use GeoServer 1.4 with PostGIS to store features that may
have a geometric value (optional!) and also relations to other features. I
would like to insert and query these features using WFS. Playing around a
bit I encountered several questions (more detailed explanations below):

1. What is the best or standard way to define and query relations between
features?
2. Can I insert a new feature (with WFS insert) without a geometry?

First, I created a simple feature table in Postgres/PostGIS with a foreign
key to itself:

CREATE TABLE some_places (
    pid integer PRIMARY KEY,
    place_name character varying(128) NOT NULL,
    refers_to integer REFERENCES places
);
SELECT AddGeometryColumn (...,'place_geom',...);

Afterwards, I can easily define a new FeatureType within GeoServer based on
the database definitions. The refers_to element is treated as a regular int
attribute of the feature, and actually representing the id of the referenced
feature. So I am able to follow relations querying this feature id.

However, a many-to-many relationship seems impossible because I cannot span
a feature over several tables (as discussed in the 'Feature over more the on
table' thread recently).

Yes, this is not supported by GeoServer. There was some experimental
work that went on to support it, but it has yet to become part of the
core geoserver.

http://docs.codehaus.org/display/GEOS/Complex+Datastore

We are working on obtaining funding in the near future to actually
support this as part of core geoserver.

I also found nice mechanisms in the GML simple profile spec where you can
define the feature type of the reference target. I don't think there is a
similar approach using WFS, is it?

Theoretically yes, since you define wfs feature types with GML, but like
above, GeoServer does not support references between feature types.

My second problem is that I cannot insert a place without a place_geom value
although the schema and the table definition allow this. As workaround I am
currently using a constant polygon with 0.0 values but I am not so happy
about it. I guess GeoServer simply expects a geometry, tries to handle it
and consequently throws a nullpointer.

This has more to do with the underlying postgis support in geoserver.
There is no reason why a table should have to have a geometry column,
but as written it requires one. I am sure there is a jira issue open
about this somewhere, I will hunt for it.

I digged through some docs and specs already but could not find the desired
information. So I would appreciate any comments or references to helpful
documents.

Thank you in advance!

Regards,
Martin

-Justin

--
Justin Deoliveira
jdeolive@anonymised.com
The Open Planning Project
http://topp.openplans.org