Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am implementing gs:Nearest WPS process available in GeoServer using openlayers in OpenGeo Suite SDK. I am trying to implement this process as a openlayers plugin to hook into my custom web mapping application.Though there is many tutorial on how to implement JTS:Split and JTS:Buffer process there is no tutorial for any other wps process.This Process Require Feature collection or Vector Layer as a input.

Firebug Error Geometry.CLASS_NAME undefined i think this is because I am not able to collect all the features from the vector layer.

So How can I create a vector layer using OpenLayers.Layer.Vector????

var test = Ext.extend(gxp.plugins.Tool, {

ptype: 'myapp_test',

/** Initialization of the plugin */
init: function(target) {
    test.superclass.init.apply(this, arguments);

    // Create a WPSClient instance for use with the local GeoServer
    this.wpsClient = new OpenLayers.WPSClient({
        servers: {
            local: '/geoserver/wps'
        }
    });



    // Add action buttons when the viewer is ready
    target.on('ready', function() {
        // Get a reference to the vector layer from app.js
        this.layer = target.getLayerRecordFromMap({
            name: 'sketch',
            source: 'ol'
        }).getLayer();
      //I am not getting Feature Collection or can not create Vector layer
       this.layer2 = new OpenLayers.Layer.Vector("parks", {
                strategies: [new OpenLayers.Strategy.Fixed()],
                projection: new OpenLayers.Projection("EPSG:4326"),
                protocol: new OpenLayers.Protocol.WFS({
                    version: "1.1.0",
                    url:  "/geoserver/wfs",
                    featurePrefix: "medford",
                    featureType: "parks",
                    featureNS: "http://medford.opengeo.org"
                })
            });

        // Some defaults
        var actionDefaults = {
            map: target.mapPanel.map,
            enableToggle: true,
            toggleGroup: this.ptype,
            allowDepress: true
        };

        this.addActions([

            // Action for splitting by drawing a line
            new GeoExt.Action(Ext.apply({
                text: 'TEST',
                control: new OpenLayers.Control.DrawFeature(
                    this.layer, OpenLayers.Handler.Point, {
                    eventListeners: {
                        featureadded: this.nearf,
                        scope: this
                    }
                })
            }, actionDefaults))
        ]);
    }, this);
},

/** Handler function for splitting geometries */
   nearf: function(evt) {
 var wkt = new OpenLayers.Format.WKT();
 var pt=wkt.write(evt.feature);
//var f =JSON.parse(this.request.responseText);
//var myline = OpenLayers.Geometry.fromWKT('point(117 22)');
 var g = new OpenLayers.Format.GeoJSON(); 
 var f=g.read(this.request.responseText);
 this.wpsClient.execute({
                server: 'local',
                process: 'gs:Nearest',
                inputs: {features:this.layer2, point:pt},
                success: this.addResult
            });

},

/** Helper function for adding process results to the vector layer */
addResult: function(outputs) {
    alert('Hello World');
}
});

Ext.preg(test.prototype.ptype, test);
share|improve this question
add comment

1 Answer 1

Not sure but try these:
- write the whole url
- change version to 1.0.0
- you need another parameter, the geometryName. It is the name of the geometrycolumn which contains the geometries, or if it is a shapefile, then it is called "the_geom"
- I think you don't need the featurePrefix

So like this:

 this.layer2 = new OpenLayers.Layer.Vector("parks", {
                strategies: [new OpenLayers.Strategy.Fixed()],
                projection: new OpenLayers.Projection("EPSG:4326"),
                protocol: new OpenLayers.Protocol.WFS({
                    version: "1.0.0", 
                    url:  "http://localhost:8080/geoserver/wfs",
                    //featurePrefix: "medford",
                    featureType: "parks",
                    featureNS: "http://medford.opengeo.org",
                    geometryName: "the_geom"
                })
            });

I hope it helps.
One more comment: I actually tried to implement the very same nearest process from geoserver but somehow I didn't succeed. So I simply sent a POST request to the server then it was ok. Here is some clue how this is done.
Please comment if it worked

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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