Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
2  
Try viewing the geometries in another program, such as QGIS. This way the problem can be narrowed down a bit. –  Mike T Aug 3 '11 at 21:39
    
Have you tried specifying a CRS for the linestring geometries? –  underdark Aug 4 '11 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 Aug 4 '11 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. –  Martin Lee Aug 4 '11 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? –  Martin Lee Aug 5 '11 at 7:26
show 1 more comment

2 Answers 2

up vote 1 down vote accepted

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).

share|improve this answer
    
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. –  Martin Lee Aug 4 '11 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. –  iant Aug 4 '11 at 15:41
    
Could you please elaborate on that? How can I construct a style with a named geometry in it? –  Martin Lee Aug 6 '11 at 16:43
    
add comment

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);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.