[OpenLayers-Users] wfs feature geometry based on one attribute
value
Lehtonen, Mika
mika at digikartta.net
Thu Dec 11 10:35:17 EST 2008
Alexandre Dube kirjoitti:
>>
>>
>> I have my data in PostGIS and I mean features that aren't shown in my
>> map. Or actually they are shown, but through wms. I am already
>> fetching some attributes after geometry comparison through wfs
>> GetFeature, but I was wondering whether there would some other ways
>> to do that.
>
> Could you share an example of this ? I would like to see how you do it.
>
> Alexandre
Sure,
it ain't no rocket science. I'm using GeoServer and PostGIS. I have
about 3000 polygons in my wfs service and I need to get some attributes
out of those I choose using wms-layer as a reference. The choosing tool
is sort of a buffer tool (choose all features which are entirely or
partially inside the circle). First I do the GetFeature.( I'll try to
incorporate only the essential parts..)
function buffer(e) {
var url = wfs.getFullRequestString({
SERVICE: 'WFS',
VERSION: '1.0.0',
REQUEST: 'GetFeature',
OUTPUTFORMAT: 'json',
PROPERTYNAME: 'the_geom,attr1',
MAXFEATURES: 1000,
TYPENAME: 'ns:layername',
SRSNAME: 'EPSG:900913',
CQL_FILTER: 'INTERSECT(the_geom,'+ buffergeometry +')'
},
"http://host.domain/geoserver/wfs"
);
OpenLayers.loadURL(url,'',this,bufferUpdate);
Event.stop(e);
};
Then I dig the attributes I need out of the response:
function bufferUpdate (response) {
g = new OpenLayers.Format.JSON();
resp = g.read(response.responseText);
attrdata = new Array();
for (i in resp.features) {
attrdata[i] = resp.features[i].properties.attr1; }
}
I hope I included all the parts needed. Anyway after this I have an
array of attributes (attr1) of the chosen geometries. I guess CQL_FILTER
is Geoserver specific and JSON isn't mandatory format in wfs compliant
server, but of course there could be used standard FILTER and GML output
with 'getElementsByTagName' or similar.
- mika -
More information about the Users
mailing list