[OpenLayers-Users] Re: Get Features from a WMS Layer

Xurxo Mendez sonxurxo at gmail.com
Tue May 24 01:55:00 EDT 2011


Hi,

if you just want to get the features in browser memory (that is, get them
into a JavaScript variable) you can fetch them issuing an XHR to GeoServer
rather than using a Vector layer that your map will not display at all (BTW,
if you finally use that approach be sure that you use
OpenLayers.Strategy.Fixed if you want to load all features - using BBOX will
load only those in the map viewport). Note that this way you are just
issuing a request to a server, there is nothing specifically related to WFS,
features, GIS or anything. You can then use a Format.WFS to parse the
features.

OpenLayers provides some facilities to perform cross-browser XHR. It would
be, for example:

var processResponse = function(response) {
  // Do your stuff here, typically with response.responseText, something
like
  // var features = new OpenLayers.Format.WFS().read(response.responseText);
  // I didn't test it !!
}
OpenLayers.Request.issue({
  url: 'http://localhost:8081/geoserver/wfs',
  method: 'GET',
  params: {
    service: 'WFS',
    version: '1.0.0',
    request: 'GetFeature',
    typeName: 'MyMap:MyLayer',
    success: processResponse
  }
});

Best regards,

Xurxo Méndez Pérez

http://blog.sonxurxo.com
http://www.sonxurxo.com



2011/5/24 IvanBell <Ivan.Bell at cca.com>

> One final thing before I sleep. The following query (typed directly into
> the browser) returns the layer's features:
>
> http://localhost:8081/geoserver/wfs?service=wfs&version=1.1.0&request=GetFeature&typeName=MyMap:MyLayer
>
>  Executing the query above returns the following:
>
>
> <wfs:FeatureCollection numberOfFeatures="22" timeStamp="2011-05-23T23:26:16.950-04:00" xsi:schemaLocation="http://localhost:8081/MyMap http://localhost:8081/geoserver/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=MyMap%3AMyLayer http://www.opengis.net/wfs http://localhost:8081/geoserver/schemas/wfs/1.1.0/wfs.xsd">
>    <gml:featureMembers>
>       <MyMap:MyLayer gml:id="MyLayer.1">
>          <MyMap:the_geom>
>             <gml:MultiSurface srsDimension="2" srsName="urn:x-ogc:def:crs:EPSG:68156405">
>                <gml:surfaceMember>
>                   <gml:Polygon>
>                      <gml:exterior>
>                         <gml:LinearRing>
>                            <gml:posList>3492.0015869140625 -3363.049072265625 2556.0007934570312 -3363.0496215820312 2566.0004272460938 -4540.960388183594 1848.4064331054688 -4534.499755859375 1848.4064331054688 -5648.319641113281 2556.0016479492188 -5648.319641113281 2556.0016479492188 -6855.0450439453125 3478.28564453125 -6845.04638671875 3492.0015869140625 -6846.075744628906 3503.0972900390625 -5607.562316894531 4951.1680908203125 -5596.262756347656 4938.001708984375 -4642.6566162109375 3512.1845703125 -4641.047546386719 3492.0015869140625 -3363.049072265625</gml:posList>
>                         </gml:LinearRing><
>                      /gml:exterior>
>                   </gml:Polygon>
>                </gml:surfaceMember>
>             </gml:MultiSurface>
>          </MyMap:the_geom>
>          <MyMap:Id>2</MyMap:Id>
>       </MyMap:MyLayer>
>    <MyMap:MyLayer gml:id="MyLayer.2">
>       <MyMap:the_geom>
>          <gml:MultiSurface srsDimension="2" srsName="urn:x-ogc:def:crs:EPSG:68156405">
>             <gml:surfaceMember>
>                <gml:Polygon>
>                   <gml:exterior>
>                      <gml:LinearRing>
>                         <gml:posList>
>                            3522.3305053710938 1036.248291015625 2586.3297119140625 1036.2476806640625 2596.3291015625 -141.6632080078125 1878.7352905273438 -135.20257568359375 1878.7352905273438 -1249.0225830078125 2586.330322265625 -1249.0225830078125 2586.330322265625 -2455.747802734375 3508.6143188476562 -2445.7493286132812 3522.3305053710938 -2446.7785034179688 3533.4263305664062 -1208.2650756835938 4981.4970703125 -1196.965576171875 4968.330505371094 -243.359375 3542.5133056640625 -241.75048828125 3522.3305053710938 1036.248291015625</gml:posList>
>                         </gml:LinearRing>
>                      </gml:exterior>
>                   </gml:Polygon>
>                </gml:surfaceMember>
>             </gml:MultiSurface>
>          </MyMap:the_geom>
>          <MyMap:Id>2</MyMap:Id>
>       </MyMap:MyLayer>
>    <MyMap:MyLayer gml:id="MyLayer.3">
>       <MyMap:the_geom>
>          <gml:MultiSurface srsDimension="2" srsName="urn:x-ogc:def:crs:EPSG:68156405">
>             <gml:surfaceMember>
>                <gml:Polygon>
>                   <gml:exterior>
>                      <gml:LinearRing>
>                         <gml:posList>
>                            -734.0172119140625 5564.245300292969 -2226.5150146484375 5537.9622802734375 -2226.0020751953125 4616.246276855469 -749.6724853515625 4581.516906738281 -749.6724853515625 3374.7916870117188 -557.3804931640625 3364.8572998046875 140.07470703125 3363.828125 151.17047119140625 4473.9202880859375 915.5023193359375 4485.219909667969 902.335693359375 5642.824890136719 168.80548095703125 5643.652526855469 149.22967529296875 6830.244079589844 -543.664306640625 6846.854919433594 -733.727294921875 6869.757080078125 -734.0172119140625 5564.245300292969</gml:posList>
>                         </gml:LinearRing>
>                      </gml:exterior>
>                   </gml:Polygon>
>                </gml:surfaceMember>
>             </gml:MultiSurface>
>          </MyMap:the_geom>
>          <MyMap:Id>2</MyMap:Id>
>       </MyMap:MyLayer>
>    </gml:featureMembers>
> </wfs:FeatureCollection>
>
>  So, executing the query directly to the map server (i.e., GeoServer)
> works. What is the equivalent "new OpenLayers.Layer.Vector" call and the
> corresponding "featureType" and "featureNS"?
> Up the Irons!!!
>
> ------------------------------
> View this message in context: Re: Get Features from a WMS Layer<http://osgeo-org.1803224.n2.nabble.com/Get-Features-from-a-WMS-Layer-tp6396039p6397114.html>
>
> Sent from the OpenLayers Users mailing list archive<http://osgeo-org.1803224.n2.nabble.com/OpenLayers-Users-f1822463.html>at Nabble.com.
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110524/424ebc88/attachment-0001.html


More information about the Users mailing list