I have an OpenLayers 3 application. When using a box to select features from GeoServer WFS layer (request=GetFeature) I get inaccurate results see image below. The layer is served from a PostGIS DB. However I have the same data in a shapefile served via the same GeoServer and when I change to that layer I get only one feature selected in the same example like the picture below.

Any help here would be good as I am not sure where the problem is it seems to me that the problem is in PostGIS but not sure. Any idea even how to troubleshoot this further would help.

BTW. This happens randomly in many locations this is not the only problem spot. And it seems to happen more on as I zoom in closer.

enter image description here

The query passed to PostGIS looks like this:

WHERE  "the_geom" && ST_GeomFromText('POLYGON (

Picture below shows that the query is not doing an intersection (which is what I expect) but rather an intersect with features' extents. The green BBOX selected those three yellow lines above it.

How do I change/fix this?

How do I get GeoServer to use ST_Intersects function?

enter image description here

  • what is the projection used? Is it the same in the wfs request and the postgis table
    – pavlos
    Oct 26, 2015 at 20:18
  • 3857 and it is the same across the board
    – Srdjan
    Oct 26, 2015 at 20:21
  • I just noticed that almost anywhere I click the feature on the right gets selected. So even thought this happens in different places it seems to always pick up the same extra feature(s).
    – Srdjan
    Oct 26, 2015 at 20:28
  • try to rebuild your spatial index. maybe import the "working" shapefile into Postgis and try with that........ good luck
    – pavlos
    Oct 26, 2015 at 20:43
  • 2
    Bbox is making a fast && query from spatial index as you have seen and features get selected if their bounding boxes intersect with the bbox in query. For accurate and slower results use Intersects filter instead. Use cql_filter or OGC style XML filter for that.
    – user30184
    Oct 27, 2015 at 4:41

1 Answer 1


They seem to be parts of a MULTILINESTRING.

Check the types of geometry in your geom columns by :

SELECT distinct ST_GeometryType(geom) from roads

And amend where necessary - assuming that was the problem.


To eliminate thats a db end error try and select the features using the same BBOX straight from the database:

select count(geom) from table lateral where geom && ST_MakeEnvelope(lrx, lry, urx,ury, 3857);

If you get the indented number of results you can deduct then that the error is not in the database.

  • my column in PostGIS is Linestring the_geom geometry(LineString,3857),
    – Srdjan
    Oct 26, 2015 at 20:22
  • this is the query being executed by Geoserver WHERE "the_geom" && ST_GeomFromText('POLYGON ( ... Is it possible this query is going against feature extents rather then looking for features that intersect? See how that line is angled and the bbox would be within its bounds.
    – Srdjan
    Oct 26, 2015 at 21:35
  • BTW tried the ST_MakeEnvelope suggestions and get the same result
    – Srdjan
    Oct 26, 2015 at 21:46
  • if you can id the query from the logs that is actually being executed; by all means use that to debug.
    – nickves
    Oct 26, 2015 at 22:01
  • It would be safe to say that gs, postgis works correctly. '&&' filters against bbox of features; so double check that the polygon inside st_geomfromtext is your intended bbox. Also you could use bbox geom to check where it intersects with that rogue geometry.
    – nickves
    Oct 26, 2015 at 22:03

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.