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 writing a Openlayers map app, and wondering whether there's a better practice to query which features of which vector layers intersect with a given bounds..

It's certainly not a good idea to iterate features...

thanks for any replies!

UPDATE

In this scenario, vector layers are already added to map, so I assume I don't need to request features from remote GeoServer again... then'll just do intersect check on the fly

share|improve this question
    
I have exactly the same problem... –  user13402 Dec 7 '12 at 13:40
add comment

2 Answers

up vote 0 down vote accepted

Your best approach is probably to set up a unit test with the maximum number of expected features and run it multiple times in a few different browsers to get an accurate idea of how long exactly it will take. You can base it on an OpenLayers unit test (see here for more details on setting one up) or an example such as this one.

JavaScript is getting surprisingly fast, and intersections even on a large number of features may be unnoticeable to a user.

A few factors will affect this:

  • the number of features in the map at anyone time, although you'll probably notice slow loading / panning times before you even get to querying the features
  • the type of geometry you are querying. If it is a point OpenLayers simply checks if the other point has the same coordinates. If it is a polygon then it loops through each vertex to see if it falls in the other polygon.

There are a few other options before you start looping through geometries. You could get the bounds of each geometry, and seeing which of these intersect to filter out many of the features, before comparing the remaining geometries.

I've also found the distanceTo function to be useful, though this could be slower than intersects.

share|improve this answer
add comment

If fetching features from Geoserver WFS you can issue a WFS request with a CQL geometric filter like those described here:

http://docs.geoserver.org/stable/en/user/tutorials/cql/cql_tutorial.html#geometric-filters

You should issue one request per layer. I'm pretty sure Mapserver also has something like that, but I can't recall the correct syntax right now.

CQL/ECQL operators are described here.

share|improve this answer
    
thanks, good suggestion! In my app, I already added a WFS vector layer into map, so I suppose I don't need to request features from GeoServer again per intersection calculation. do you know whether there's better way to deal with feature intersection process for existing layers other than iterate each feature? thank you a lot! –  Simon Dec 6 '11 at 15:41
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.