[OpenLayers-Users] Spatial constraints of a WFS GetFeature request

Lehtonen, Mika mika at digikartta.net
Thu Jun 25 03:24:33 EDT 2009


Hi Tom,
I used the following function on top of OL2.7 just recently with some 
Geoserver 1.6 series for point data. It seemed to be acting just fine.

function fetchID(e) {
var ll = new OpenLayers.Pixel(e.xy.x-10,e.xy.y+10);
var ur = new OpenLayers.Pixel(e.xy.x+10,e.xy.y-10); //* 20x20 px "window"
var mapll = map.getLonLatFromPixel(ll).transform(new 
OpenLayers.Projection("EPSG:900913"), new 
OpenLayers.Projection("EPSG:3423"));
var mapur = map.getLonLatFromPixel(ur).transform(new 
OpenLayers.Projection("EPSG:900913"), new 
OpenLayers.Projection("EPSG:3423"));
var box = new 
OpenLayers.Bounds(mapll.lon,mapll.lat,mapur.lon,mapur.lat).toBBOX();
var url = wfslayername.getFullRequestString({
        SERVICE: 'WFS',
        SRSNAME: 'EPSG:900913',
        VERSION: '1.1.0',
        REQUEST: 'GetFeature',
        OUTPUTFORMAT: 'json',
        PROPERTYNAME: 'someNS:the_geom,someNS:ID',
        BBOX: box,
        MAXFEATURES: 1,
        TYPENAME: 'someNS:someTypeName'},
"http://domain.name/geoserver/wfs"
        );
        OpenLayers.loadURL(url,'',this,wfsJSON);
        Event.stop(e);
    };

- mika -

Tom B kirjoitti:
> Hi Andreas,
>
> Thanks for the help.  I should've mentioned that the map also has features
> that are points, and GetFeatureInfo's tolerance wasn't quite wide enough for
> how we are displaying them; that was the big impetus for using GetFeature.  
>
> Additionally, the user will be dynamically adding and removing many
> different WMS layers, and the GetFeature request needs to include all of
> those layers, so making a custom GetFeature request seemed much easier than
> using the GetFeature control.
>
> Yes, I've been using Firebug to double-check these requests; everything
> looks good as far as I can tell.  I think I might go ahead and ask the
> GeoServer list--in retrospect, it seems like that's closer to where the
> problem probably lies.
>
> Thanks again,
> Tom
>
>
>  
>
> Andreas Hocevar-2 wrote:
>   
>> Hi,
>>
>> On Wed, Jun 24, 2009 at 7:36 PM, Tom B<seileef at gmail.com> wrote:
>>     
>>> I'm trying to allows users to click on a WMS overlay and get a popup
>>> showing
>>> a list of features at the location they clicked.  It's a setup similar to
>>> http://trac.openlayers.org/wiki/GetFeatureInfo, but instead of a WMS
>>> GetFeatureInfo request, I'm using WFS GetFeature, since it allows me to
>>> make
>>> the area queried a little larger than just the single pixel that the
>>> mouse
>>> clicked.
>>>       
>> First of all, if you are using GeoServer >= 1.7.4, GetFeatureInfo is
>> smart enough to select point and line features when clicking anywhere
>> on the feature, not just the within two pixels of the center.
>>
>> Also, there is a GetFeature control that you may want to have a look
>> at: http://www.openlayers.org/dev/examples/getfeature-wfs.html
>>
>>     
>>> When I set the CQL_FILTER param to
>>> BBOX(geometry,'+left+','+bottom+','+right+','+top+')
>>>
>>> and, for example, click on a county, the result often includes
>>> neighboring
>>> counties as well, even when left==right and top==bottom.
>>>       
>> This is weird. Have you looked at the requests in Firebug to make sure
>> that what gets sent to the server is what you intended to?
>>
>>     
>>> As an alternative, I tried using INTERSECT instead of BBOX, like this:
>>> clicked_bounds = new OpenLayers.Bounds(left, bottom, right, top);
>>> geometryString = clicked_bounds.toGeometry().toString();
>>> cql_filter = 'INTERSECT(geometry,'+geometryString+')';
>>>
>>> With this, some counties show up fine when you click on them (i.e. no
>>> neighboring counties are listed), but other counties never show up in the
>>> results, regardless of where you click on them.
>>>       
>> Also weird. If you have more troubles with that, collect some sample
>> requests (e.g. by copying the request strings from the firebug
>> console), and ask on the geoserver users list.
>>
>> Regards,
>> Andreas.
>>
>>     
>>> Does any have any ideas of what might be the issue with either of these?
>>> I'm a bit lost on where to start, and I don't have the access necessary
>>> to
>>> see what queries GeoServer is making against the database.
>>>
>>> Best,
>>> Tom
>>> --
>>> View this message in context:
>>> http://n2.nabble.com/Spatial-constraints-of-a-WFS-GetFeature-request-tp3150234p3150234.html
>>> Sent from the OpenLayers Users mailing list archive at Nabble.com.
>>>
>>> _______________________________________________
>>> Users mailing list
>>> Users at openlayers.org
>>> http://openlayers.org/mailman/listinfo/users
>>>
>>>       
>>
>> -- 
>> Andreas Hocevar
>> OpenGeo - http://opengeo.org/
>> Expert service straight from the developers.
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>>
>>     
>
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090625/a41ede7e/attachment.html


More information about the Users mailing list