6

I am reading the PostGIS in Action book now and I have a problem with one example:

  • I have created a table:

    CREATE TABLE my_geometries (id serial NOT NULL PRIMARY KEY, name varchar(20));

  • I have added some points to this table:

    SELECT AddGeometryColumn('public','my_geometries', 'my_points',-1,'POINT',2);

    INSERT INTO my_geometries (name,my_points) VALUES ('Home',ST_GeomFromText('POINT(0 0)'));

    INSERT INTO my_geometries (name,my_points) VALUES ('Pizza 1',ST_GeomFromText('POINT(1 1)')) ;

  • And some linestrings as well:

    SELECT AddGeometryColumn ('public','my_geometries', 'my_linestrings',-1,'LINESTRING',2);

    INSERT INTO my_geometries (name,my_linestrings) VALUES ('Linestring Open', ST_GeomFromText('LINESTRING(0 0,1 1,1 -1)'));

    INSERT INTO my_geometries (name,my_linestrings) VALUES ('Linestring Closed', ST_GeomFromText('LINESTRING(0 0,1 1,1 -1, 0 0)'));

The problem is that for some reason I do not see the linestrings in the OpenLayers window of GeoServer, but all the points are on their place.

The GeoServer's 'Edit layer' page for my_workspace:my_geometries shows Feature Type Details having both my_points and my_linestrings columns.

What is the problem here? How can I see both points and linestrings that I have added to my database in GeoServer's OpenLayers window?

6
  • 2
    Try viewing the geometries in another program, such as QGIS. This way the problem can be narrowed down a bit.
    – Mike T
    Commented Aug 3, 2011 at 21:39
  • Have you tried specifying a CRS for the linestring geometries?
    – underdark
    Commented Aug 4, 2011 at 0:24
  • I can only support Mike Toews suggestion about using QGIS for displaying geographical data from PostGIS. I do it a lot and it is a quick way to tell if the data source delivers as I expect.
    – Chau
    Commented Aug 4, 2011 at 6:28
  • @ Mike Toews and Chau: Some news here: QGIS shows both points and linestrings. Any ideas? @underdark: Could you please give me a reference where I can read about CRS in detail? I don't have any idea what CRS is.
    – skanatek
    Commented Aug 4, 2011 at 10:02
  • @underdark: Can I paraphrase my question? The 'PostGIS in Action' book says that "Spatial reference system (SRS) defines the spatial coordinate system". What is the difference between CRS and SRS?
    – skanatek
    Commented Aug 5, 2011 at 7:26

2 Answers 2

2

Do you have two styles for your layer? You will need to create a style to draw the points (using one geometry column) and another to draw the lines (using the other geometry column). This is because by default GeoServer will use the first geometry column as the default.

If you follow Kelso's suggestion of combining the geometries into one column you will need to look at http://docs.geoserver.org/stable/en/user/styling/sld-tipstricks/mixed-geometries.html to see how to make the SLD work the way you expect (the default will apply a point symbolizer to the line center).

4
  • I have already tried to add the 'line' style from the 'Available styles' to 'Selected styles' in the Publishing tab of my layers. This doesn't seem to work.
    – skanatek
    Commented Aug 4, 2011 at 14:18
  • It wouldn't as the default geometry for your layer is a point. You will need to construct a specific style with a named geometry in it.
    – Ian Turton
    Commented Aug 4, 2011 at 15:41
  • Could you please elaborate on that? How can I construct a style with a named geometry in it?
    – skanatek
    Commented Aug 6, 2011 at 16:43
0

While this is not a direct answer to why you can't see the linestrings in OpenLayers, you can store multiple geometries in one column, overcoming your need for two different columns. If you then wanted to separate them out, you could create a view, one selecting the lines, one selecting the points and linking these through geoserver. If you want to see both geometries, just link to my_geometries and geoserver / openlayers will display both.

To use multiple geometries in a column, use:

SELECT AddGeometryColumn('public','my_geometries', 'my_geom',-1,'GEOMETRY',2);

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.