1

Consider this example,

https://geoext.github.io/geoext2/examples/grid/feature-grid.html

It uses

protocol: new OpenLayers.Protocol.HTTP({
                url: "../data/summits.json",
                format: new OpenLayers.Format.GeoJSON()
            })

for the locations and elevations of some mountains. There are three properties: name (string), height (long), and geometry (point).

What I want to do is put the json file onto GeoServer and call it that way. I imported the file into GeoServer, and I know it works because I can see it with a WFS url. But I'm trying to load it with the code

var vecLayer = new OpenLayers.Layer.Vector("vector", {
    styleMap: new OpenLayers.StyleMap({
        'default': style
    }),
    strategies: [new OpenLayers.Strategy.Fixed() ],
    protocol: new OpenLayers.Protocol.WFS({
        readFormat: new OpenLayers.Format.GeoJSON(),
        url: "http://fakeurl.com/geoserver/wfs",
        srsName: "EPSG:4326",
        featureNS: "http://fakeurl.com/geoext/geonodeuri",
        featureType: "summits",
        outputFormat: "json",
        version: "1.1.0"
   })
});

I know that url, featureNS, and featureType are all correct because I can successfully add other shapefile vectors in the same workspace with them. I'm quite stumped as far as getting the WFS protocol to work, however. Do I need to set geometryName or something? GeoServer lists three properties, and I need all three of them. Ideally I would get the exact same result as the simple OpenLayers.Protocol.HTTP protocol.


If I put the JSON file in a web directory and do an HTTP protocol to it, it works. Which is to say,

protocol: new OpenLayers.Protocol.HTTP({
                url: "http://fakeurl/data/summits.json",
                format: new OpenLayers.Format.GeoJSON()
            })

displays just fine. However, when I link to a WFS Getfeature request, like

protocol: new OpenLayers.Protocol.HTTP({
                url: "http://fakeurl/geoserver/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=geonode:summits&maxFeatures=50",
                format: new OpenLayers.Format.GeoJSON()
            })

I get no result. But the url provided displays the JSON file in a browser. I don't understand. I just want some way of getting those contents via GeoServer, but it continues to elude me.


turns out there's something wrong with the layer itself. I can view the JSON data through a link but only if I'm logged into Geoserver. If I'm not logged in, then I get a "Could not find layer" message. So I guess that's my issue: why data imported in GeoServer it not made public (my JSON), but a layer through Geonode is.

5
  • I would guess that the easiest fix is to forget json and wipe away the outputformat line for letting GeoServer to send data in the default GML format. See the OL2 WFS examples, for example dev.openlayers.org/examples/wfs-filter.js.
    – user30184
    Commented Mar 23, 2016 at 22:02
  • I converted the JSON file into a GML formatted xml file, and loaded it directly with the HTTP protocol -- it works fine. Then I tried to use the default GeoServer WFS protocol and still nothing is shown. I have to assume that the WFS protocol and the HTTP protocol are not taking in the information in the same way. Commented Mar 24, 2016 at 3:55
  • Alright, problem solved. I'd installed a package called geoserver-geonode. A security "feature" of the package makes it so only layers uploaded through GeoNode can be served up. Since I imported the JSON file through GeoServer's import extension, it was not allowed to be served. So I installed GeoServer and GeoNode packages separately and all is fine. (I also removed the JSON formatting and just went with the default GML format, as suggested.) Commented Mar 27, 2016 at 6:40
  • WFS isn't a protocol
    – nmtoken
    Commented Apr 11, 2016 at 19:18
  • RE: WFS protocol, I was referring to the OpenLayers code protocol: new OpenLayers.Protocol.WFS Commented Apr 12, 2016 at 20:29

1 Answer 1

0

Alright, problem solved. I'd installed a package called geoserver-geonode. A security "feature" of the package makes it so only layers uploaded through GeoNode can be served up. Since I imported the JSON file through GeoServer's import extension, it was not allowed to be served. So I installed GeoServer and GeoNode packages separately and all is fine. (I also removed the JSON formatting and just went with the default GML format, as suggested.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.