How to use WFS GetFeature to return data like wmsgetfeatureinfo?

1.7k views Asked by At

Hello, right now I am working with Openlayers.Control.getfeature using wfs protocol to return attribute when I click one of the features in my map. I know I can use wmsgetfeatureinfo to return attributes but my server administrator disabled access to it's own machine so I cannot access the geoserver using proxy.

Is there some way I can use wfs getfeature to return attributes like wmsgetfeatureinfo?

Here is one of the responses from wfs getfeature

<?xml version="1.0" encoding="UTF-8"?>
<wfs:FeatureCollection
    numberOfFeatures="1"
    timeStamp="2013-12-19T05:57:11.434Z"
    xsi:schemaLocation="http://localhost:8080/geoserver/kabupaten http://127.0.0.1:8080/geoserver/wfs?service=WFS&amp;version=1.1.0&amp;request=DescribeFeatureType&amp;typeName=kabupaten%3Adesa http://www.opengis.net/wfs http://127.0.0.1:8080/geoserver/schemas/wfs/1.1.0/wfs.xsd" 
    xmlns:ogc="http://www.opengis.net/ogc"
    xmlns:provinsi="http://localhost:8080/geoserver/provinsi"
    xmlns:wfs="http://www.opengis.net/wfs"
    xmlns:pusat="http://localhost:8080/geoserver/pusat"
    xmlns:ccrom="http://localhost:8080/geoserver/ccrom"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:kabupaten="http://localhost:8080/geoserver/kabupaten"
    xmlns:ows="http://www.opengis.net/ows"
    xmlns:gml="http://www.opengis.net/gml"
    xmlns:xlink="http://www.w3.org/1999/xlink">
<gml:featureMembers>
    <kabupaten:desa gml:id="desa.38888">
    <kabupaten:the_geom>
    <gml:MultiSurface srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
        <gml:surfaceMember>
            <gml:Polygon srsDimension="2">
                <gml:exterior>
                    <gml:LinearRing srsDimension="2">
                        <gml:posList>
                            110.59745283700005 -7.748368004999975 110.59713305000008 -7.748094082999955
                            110.59648326600006 -7.748150648999967 110.59648297300004 -7.748150464999981           
                            [...]
                            110.59745742400008 -7.748371934999966 110.59745283700005 -7.748368004999975
                        </gml:posList>
                    </gml:LinearRing>
                </gml:exterior>
            </gml:Polygon>
        </gml:surfaceMember>
    </gml:MultiSurface>
    </kabupaten:the_geom>
    <kabupaten:PROVNO>33</kabupaten:PROVNO>
    <kabupaten:KABKOTNO>10</kabupaten:KABKOTNO>
    <kabupaten:KECNO>070</kabupaten:KECNO>
    <kabupaten:DESANO>001</kabupaten:DESANO>
    <kabupaten:IDSP2010>3310070001</kabupaten:IDSP2010>
    <kabupaten:PROVINSI>JAWA TENGAH</kabupaten:PROVINSI>
    <kabupaten:KABKOT>KLATEN</kabupaten:KABKOT>
    <kabupaten:KECAMATAN>KALIKOTES</kabupaten:KECAMATAN>
    <kabupaten:DESA>JIMBUNG</kabupaten:DESA>
    <kabupaten:KERENTANAN>2</kabupaten:KERENTANAN>
    <kabupaten:IKA>0.18</kabupaten:IKA>
    <kabupaten:IKS>-0.22</kabupaten:IKS>
    <kabupaten:BANJIR>4</kabupaten:BANJIR>
    <kabupaten:KEKERINGAN>6</kabupaten:KEKERINGAN>
    </kabupaten:desa>
</gml:featureMembers>
</wfs:FeatureCollection>
1

There are 1 answers

1
dkakoti On

You can use OpenLayers.Protocol.WFS.fromWMSLayer(layer) where layer is the wms layer from your geoserver

control = new OpenLayers.Control.GetFeature({
    protocol: OpenLayers.Protocol.WFS.fromWMSLayer(layer),
    box: true,
    hover: true,
    multipleKey: "shiftKey",
    toggleKey: "ctrlKey"
});

and add this control to your map. I think You can not show the result as popup. But you can get the feature info and can add to another vector layer. Here is the example