[OpenLayers-Users] How to use OpenLayers requesting WFS withSpatial Operations

Kris Geusebroek kgeusebroek at xebia.com
Mon Apr 27 02:11:41 EDT 2009


Hi,

After having a WFS layer initially loaded you can do something like this to set a different filter and reload the layer:

		var newFilter = new OpenLayers.Filter.Comparison(
			{
				type: OpenLayers.Filter.Comparison.EQUAL_TO,
				property: 'LABEL',
				value: label
			}
		);
		var combinedFilter=new OpenLayers.Filter.Logical({
			type:OpenLayers.Filter.Logical.AND,
			filters:[originalFilter,newFilter]
		});

		wfsLayer.filter = combinedFilter;
		wfsLayer.refresh({force:true});

Hope this helps

Cheers Kris	

-----Original Message-----
From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] On Behalf Of Ingo Weinzierl
Sent: Monday, April 27, 2009 7:54 AM
To: users at openlayers.org
Subject: Re: [OpenLayers-Users] How to use OpenLayers requesting WFS withSpatial Operations

Hi Myeonghun,



On Saturday 25 April 2009 08:03:24 Myeong Hun Jeong wrote:
> Hi Roald,
> There are two things I want to know.
> 1. How to send WFS requests to server with openlayers? I know the way 
> to load WFS layers when I initialize map, but after loading layers, I 
> don't know how to request WFS with Spatial Operations in OpenLayers.

I am not quite sure if really got what you mean. But, you should be able to create a new layer and add it to the map on pressing a button. Something like the code below:

// create a button which calls myFunction var button = new OpenLayers.Control.Button({
    trigger: myFunction
});
panel.addControls([button]);

// myFunction which creates a new WMS layer and adds it to the map function myFunction() {
	var layer = new OpenLayers.Layer.WMS(
        	layername,
        	url, 
        	{
            		isBaseLayer: true,
            		layers: layername
        	}	
    	);

	map.addLayers([layer]);
}


>
> 2. I also want to know the way to display a WFS layer on my map that 
> automatically requests the correct features within the BBOX of the 
> viewport?

Have a look at this example: 
http://openlayers.org/dev/examples/strategy-bbox.html

>
> Thanks in advance.
>
> Best Regrards,
> Myeonghun Jeong.
>
>
>
> 2009/4/25 Roald de Wit <roald.dewit at lisasoft.com>
>
> > Hi Myeonghun Jeong,
> >
> > Can you explain what you try to do? Do you want to display a WFS 
> > layer on your map that automatically requests the correct features 
> > within the BBOX of the viewport or do you want to have control over 
> > what BBOX you send to the WFS server and send your WFS 'manually'?
> >
> > Maybe it is good to have a look at some examples (type WFS in the 
> > search
> > box): [1].
> >
> > Regards, Roald
> >
> > [1] http://www.openlayers.org/dev/examples/
> >
> > Myeong Hun Jeong wrote:
> >> Dear list.
> >>
> >> I want to know how to use openlayers when I request WFS with 
> >> Spatial Operations.
> >>
> >> For example, at GeoServer Demo Request page, I can fin 
> >> WFS_getFeatureBBox01.1.url and WFS_getFeatureBBox01.1.xml samples.
> >>
> >> So, the request is that
> >>
> >>
> >> 
> >>http://localhost:8888/geoserver/wfs?request=GetFeature&version=1.0.0
> >>&typ
> >>eName=topp:states&propertyName=STATE_NAME,PERSONS&BBOX=-75.102613,40
> >>.2125
> >>97,-72.361859,41.512517<
> >> 
> >>http://localhost:8888/geoserver/wfs?request=GetFeature&version=1.0.0
> >>&typ
> >>eName=topp:states&propertyName=STATE_NAME,PERSONS&BBOX=-75.102613,40
> >>.2125
> >>97,-72.361859,41.512517>
> >>
> >>
> >>
> >> or
> >>
> >> http://localhost:8888/geoserver/wfs
> >>
> >> <wfs:GetFeature service="WFS" version="1.1.0"
> >>
> >>  xmlns:topp="http://www.openplans.org/topp"
> >>
> >>  xmlns:wfs="http://www.opengis.net/wfs"
> >>
> >>  xmlns:ogc="http://www.opengis.net/ogc"
> >>
> >>  xmlns:gml="http://www.opengis.net/gml"
> >>
> >>  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> >>
> >>  xsi:schemaLocation="http://www.opengis.net/wfs
> >>
> >>                      http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
> >>
> >>  <wfs:Query typeName="topp:states">
> >>
> >>    <wfs:PropertyName>topp:STATE_NAME</wfs:PropertyName>
> >>
> >>    <wfs:PropertyName>topp:PERSONS</wfs:PropertyName>
> >>
> >>    <ogc:Filter>
> >>
> >>      <ogc:BBOX>
> >>
> >>        <ogc:PropertyName>the_geom</ogc:PropertyName>
> >>
> >>        <gml:Envelope srsName="
> >> http://www.opengis.net/gml/srs/epsg.xml#4326">
> >>
> >>           <gml:lowerCorner>-75.102613 40.212597</gml:lowerCorner>
> >>
> >>           <gml:upperCorner>-72.361859 41.512517</gml:upperCorner>
> >>
> >>        </gml:Envelope>
> >>
> >>      </ogc:BBOX>
> >>
> >>   </ogc:Filter>
> >>
> >>  </wfs:Query>
> >>
> >> </wfs:GetFeature>
> >>
> >>
> >> But when I use openlayers, how to request thses requests exactly?
> >>
> >> For instance, when I request GetFeatureInfo with openlayers.
> >>
> >> // support GetFeatureInfo
> >>
> >>            map.events.register('click', map, function (e) {
> >>
> >>                document.getElementById('nodelist').innerHTML = 
> >> "Loading... please wait...";
> >>
> >>                var url =  map.layers[0].getFullRequestString(
> >>
> >>                    {
> >>
> >>                        REQUEST: "GetFeatureInfo",
> >>
> >>                        EXCEPTIONS: "application/vnd.ogc.se_xml",
> >>
> >>                        BBOX: map.getExtent().toBBOX(),
> >>
> >>                        X: e.xy.x,
> >>
> >>                        Y: e.xy.y,
> >>
> >>                        INFO_FORMAT: 'text/html',
> >>
> >>                        QUERY_LAYERS: map.layers[0].params.LAYERS,
> >>
> >>                        FEATURE_COUNT: 50,
> >>
> >>                        WIDTH: map.size.w,
> >>
> >>                        HEIGHT: map.size.h
> >>
> >>                    },
> >>
> >>                    "http://localhost:8888/geoserver/wms"
> >>
> >>                );
> >>
> >>                OpenLayers.loadURL(url, '', this, setHTML, setHTML);
> >>
> >>                OpenLayers.Event.stop(e);
> >>
> >>            });
> >>
> >>        }
> >>
> >>
> >>
> >> Please, give me a piece of information.
> >>
> >>
> >> Best regards,
> >>
> >> Myeonghun Jeong.

I hope this was helpful.

Regards, Ingo


-- 
Ingo Weinzierl				              OpenPGP key: 0x2D2E2573
http://www.intevation.de/
Intevation GmbH, Neuer Graben 17, 49074 Osnabrück; AG Osnabrück, HR B 18998
Geschäftsführer:   Frank Koormann,  Bernhard Reiter,  Dr. Jan-Oliver Wagner



More information about the Users mailing list