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 getting error performing insert exception while performing wfs-t insert operation when i use postgres 9.1.4 and postgis 2.0. but i get successful insert when using postgres 9.0.1 and postgis 1.5(on another computer). is this some kind of bug in postgres/postgis or i am doing something wrong ?

my script is below

OpenLayers.ProxyHost= "/cgi-bin/proxy.cgi?url=";
//variables
//var host = "http://192.168.10.11";
var host = "http://localhost";
var port = ':8888';
var centerX = 85.3403;//491213.721224323//-123.1684986291807;//9497800;
var centerY = 27.70774;//5456645.24607268//49.245339757767844;//3212000;
var center = new OpenLayers.LonLat(centerX, centerY);
var range = 1.5;//10000000//.5;//10000;
var map_bound = [centerX-range,centerY-range,centerX+range,centerY+range];
var map_wd = 490;
var map_ht = 360;
var legend_wd = 100;
var legend_ht = map_ht;
var tbar_wd = map_wd + legend_wd;
var tbar_ht = 100;
var zoom = 15;

var proj_sp = new OpenLayers.Projection("EPSG:4326");

var DeleteFeature = OpenLayers.Class(OpenLayers.Control, {
    initialize: function(layer, options) {
        OpenLayers.Control.prototype.initialize.apply(this, [options]);
        this.layer = layer;
        this.handler = new OpenLayers.Handler.Feature(
            this, layer, {click: this.clickFeature}
        );
    },
    clickFeature: function(feature) {
        // if feature doesn't have a fid, destroy it
        if(feature.fid == undefined) {
            this.layer.destroyFeatures([feature]);
        } else {
            feature.state = OpenLayers.State.DELETE;
            this.layer.events.triggerEvent("afterfeaturemodified", 
                {feature: feature});
            feature.renderIntent = "select";
            this.layer.drawFeature(feature);
        }
    },
    setMap: function(map) {
        this.handler.setMap(map);
        OpenLayers.Control.prototype.setMap.apply(this, arguments);
    },
    CLASS_NAME: "OpenLayers.Control.DeleteFeature"
});

function oldBrowser() {
    var browser = navigator.appName;
    var b_version = navigator.appVersion;
    var version = parseFloat(b_version);
    var useragent = navigator.userAgent;
    switch (browser){
        case 'Microsoft Internet Explorer':
            browser = "MSIE";
            version = useragent.substr(useragent.lastIndexOf('MSIE') + 5, 3);
            if(version<10)
                return true;
            break;
        case 'Netscape':
            if (useragent.lastIndexOf('Chrome/') > 0) {
                browser = "Chrome";
                version = useragent.substr(useragent.lastIndexOf('Chrome/') + 7, 10);
            }
            else if (useragent.lastIndexOf('Firefox/') > 0) {
                browser = "Firefox";
                version = useragent.substr(useragent.lastIndexOf('Firefox/') + 8, 5);
            }
            else if (useragent.lastIndexOf('Safari/') > 0) {
                browser = "Safari";
                version = useragent.substr(useragent.lastIndexOf('Safari/') + 7, 7);
            }
            else
            { alert("undefined browser"); }
            break;
        case 'Opera':
            version = useragent.substr(useragent.lastIndexOf('Version/') + 8, 5);
            break;
    }
}

Ext.onReady(function() {    
    if(oldBrowser()){
        alert("Your browser version is pretty old."
             +"please update to latest version"
             +"performance may be reduced.");
    }

    var saveStrategy = new OpenLayers.Strategy.Save();
    /*saveStrategy.events.register("start", '', alert('saving'));
    saveStrategy.events.register("success", '', alert('save success'));
    saveStrategy.events.register("failure", '', alert('save failure'));
    */
    //map configuration
    var map_options = {
        allOverlays:true,
        maxExtent:new OpenLayers.Bounds(map_bound[0],map_bound[1],map_bound[2],map_bound[3]),
        numZoomLevels: zoom,
        controls: [new OpenLayers.Control.PanZoomBar(),
            new OpenLayers.Control.MousePosition(),
            new OpenLayers.Control.ScaleLine(),
            new OpenLayers.Control.Scale(),
            new OpenLayers.Control.Navigation()
        ],
        minScale: 50000,
        projection: "EPSG:4326"
    }
    var map = new OpenLayers.Map(map_options);
    var navi = new OpenLayers.Control.NavigationHistory();
    map.addControl(navi);
    center.transform(proj_sp, map.getProjectionObject());
    //layers configuration
    var world = new OpenLayers.Layer.WMS(
        "OpenLayers WMS"
        ,"http://localhost:8888/geoserver/wms"
        ,{layers: 'nurc:Arc_Sample'}
        ,{displayInLayerSwitcher:false}
    );

    var roadswgs = new OpenLayers.Layer.WMS(
        "roadswgs"
        ,host+port+"/geoserver/wms"
        ,{  layers: "postgis:trans_ln_8"
            ,transparent: true
        }
        //,{'reproject': true}
    );

    var portwgs = new OpenLayers.Layer.WMS(
        "airportwgs"
        ,host+port+"/geoserver/wms"
        ,{  layers: "postgis:airport_runway"
            ,transparent : true
        }
        //,{'reproject': true}
    );

    //var vector = new OpenLayers.Layer.Vector('editable');

    var vector = new OpenLayers.Layer.Vector('editable'
        ,{  strategies: [new OpenLayers.Strategy.BBOX(),saveStrategy]
            ,protocol: new OpenLayers.Protocol.WFS({
                url:  host+port+"/geoserver/wfs",
                featureType: "airport_runway",
                featureNS: "http://geoserver/postgis",
                version: "1.1.0",
                geometryName: "geom"
            })
            /*,styleMap: new OpenLayers.StyleMap({
                pointRadius: 5,
                strokeColor: "#ff005b",
                strokeWidth: 1,
                fillOpacity: 0.4,
                fillColor: '#ffffff'
            })*/
        }
    );
    alert('vector.protocol.url='+vector.protocol.url);
    var wfsroads = new OpenLayers.Layer.Vector("PostgisWFS", 
        {   strategies: [new OpenLayers.Strategy.BBOX()],
            protocol: new OpenLayers.Protocol.WFS({
                url:  host+port+"/geoserver/wfs",
                featureType: "trans_ln_8",
                featureNS: "http://geoserver/postgis",
                version: "1.1.0"                    
            })
            /*,styleMap: new OpenLayers.StyleMap({
                pointRadius: 6,
                strokeColor: "#ff005b",
                strokeWidth: 1,
                fillOpacity: 0
            })*/
        }
    );
    map.addLayers([wfsroads,roadswgs,vector,portwgs/*world,,gsat*/]);       
    //adding OSM layer
    //map.addLayer(new OpenLayers.Layer.OSM("OSM"));
    //adding google satellite layer
    map.addLayer(new OpenLayers.Layer.Google("Google Satellite",{type:G_SATELLITE_MAP, numZoomLevels: 22}));



    //mappanel configuration
    var mapPanel = new GeoExt.MapPanel({
        renderTo: 'gxmap',
        height: map_ht,
        width: map_wd,
        map: map,
        title: 'A Simple GeoExt Map',
        extent: map_bound,
        center: center,
        //zoom: zoom
    });
    //layer tree configuration
    var layerList = new GeoExt.tree.LayerContainer({
        text: 'All Layers',
        layerStore: mapPanel.layers,
        leaf: true,
        expanded: true
    });

    var layerTree = new Ext.tree.TreePanel({
        title: 'Layers',
        renderTo: 'layerTree',
        root: layerList,
        width: legend_wd,
        //height: '*',
        autoheight: true
    });

    //legend configuration
    var legendPanel = new GeoExt.LegendPanel({
        title:'Legend',
        layerStore: mapPanel.layers,
        renderTo: "legend",
        border: true,
        width: legend_wd,
        //height: legend_ht,
        autoheight: true
    });

    //editor tools
    var editor = "editor tools";
    { //snap for drawing 
    var snaproad = new OpenLayers.Control.Snapping({
        layer: vector,
        targets: [{
            layer: wfsroads,
            tolerance: 15,
            greedy: true
        }]
    });
    //snaproad.activate();
    var snapvector = new OpenLayers.Control.Snapping({
        layer: vector,
        targets: [{
            layer: vector,
            tolerance: 15,
            greedy: true
        }]
    });
    snapvector.activate();}
    { //Draw Feature control
    var draw = new OpenLayers.Control.DrawFeature(
        vector,     //layer
        OpenLayers.Handler.Path, //Handler
        {   multi:true,
            type: OpenLayers.Control.TYPE_TOGGLE,
            //handlerOptions : {maxVertices: 5}
        }//options
    );

    /*draw.featureAdded = function(feature) {
        //feature.layer.eraseFeatures([feature]);
        // cast to multilinestring
        //alert(feature.geometry);
        //feature.geometry = new OpenLayers.Geometry.MultiLineString(feature.geometry);
        //alert(feature.geometry);//feature.style.strokeColor = "#ff0000";
        feature.state = OpenLayers.State.INSERT;
        feature.layer.drawFeature(feature);
    }*/
    map.addControl(draw);
    // DrawFeature control, a "toggle" control
    var draw_ac = new GeoExt.Action({
        text: "draw",
        control: draw,
        map: map,
        // button options
        enableToggle: true,
        tooltip: "draw feature",
        toggleGroup: editor
    });}
    { //Select Feature control
    var select = new OpenLayers.Control.SelectFeature(
        vector,
        {multiple: false, hover: true,
        }
    );
    var select_ac = new GeoExt.Action({
        text: "select",
        control: select,
        map: map,
        // button options
        enableToggle: true,
        tooltip: "modify feature",
        toggleGroup: editor
    });
    }
    { //Modify Feature control
    var modify = new OpenLayers.Control.ModifyFeature(vector,{type: OpenLayers.Control.TYPE_TOGGLE});
    map.addControl(modify);
    var modify_ac = new GeoExt.Action({
        text: "modify",
        control: modify,
        map: map,
        // button options
        enableToggle: true,
        tooltip: "modify feature",
        toggleGroup: editor
    });
    }
    { //Delete Feature control
    var del = new DeleteFeature(vector, {title: "Delete Feature"});
    map.addControl(del);
    var del_ac = new GeoExt.Action({
        text: "delete",
        control: del,
        map: map,
        // button options
        enableToggle: true,
        tooltip: "delete feature",
        toggleGroup: editor
    });
    }
    { //Save Feature control
    var save_ac = new GeoExt.Action({
        text: "save",
        //icon: 'icons/icon_zoomnext.png',
        //control: saveStrategy.save(),
        onClick: function(){
            //var s=confirm('save?');
            //if(s==true){
                saveStrategy.save();
            //  alert('saved');
            //} 
            //else
            //  alert('not saved');
        },
        disabled: false,
        //deactivateOnDisable: true,
        //activateOnEnable: true,
        tooltip: "save road"
    });}
    { //Measure Feature control
    var length = new OpenLayers.Control.Measure(OpenLayers.Handler.Path, {
        eventListeners: {
            measure: function(evt) {
                alert("The length was " + evt.measure + ' ' + evt.units);
            }
        }
    });
    var area = new OpenLayers.Control.Measure(OpenLayers.Handler.Polygon, {
        eventListeners: {
            measure: function(evt) {
                alert("The area was " + evt.measure + ' sq ' + evt.units);
            }
        }
    });
    var measu_length = new GeoExt.Action({
        //text: "measu_length",
        icon: 'icons/icon_ruler.gif',
        control: length,
        map: map,
        // button options
        enableToggle: true,
        tooltip: "measu_length",
        toggleGroup: editor
    });
    var measu_area = new GeoExt.Action({
        //text: "measu_area",
        icon: 'icons/tool_measurearea.png',
        control: area,
        map: map,
        // button options
        enableToggle: true,
        tooltip: "measu_area",
        toggleGroup: editor
    });}
    { //identify Feature control
    var info = new OpenLayers.Control.WMSGetFeatureInfo({
        url: host+port+'/geoserver/wms', 
        eventListeners: {
            getfeatureinfo: function(event) {
                map.addPopup(new OpenLayers.Popup.FramedCloud(
                    "chicken", 
                    map.getLonLatFromPixel(event.xy),
                    null,
                    event.text,
                    null,
                    true
                ));
            }
        }
    });
    var identify_ac = new GeoExt.Action({
        //text: "identify",
        icon: 'icons/icon_query.gif',
        control: info,
        map: map,
        // button options
        enableToggle: true,
        tooltip: "identify",
        toggleGroup: editor
    });}
    { //pan Feature control
    var pan = new OpenLayers.Control.DragPan();
    var pan_ac = new GeoExt.Action({
        //text: "pan",
        icon: 'icons/tool_pan.gif',control: pan,
        map: map,
        // button options
        enableToggle: true,
        tooltip: "pan map",
        toggleGroup: editor
    });
    }
    {//tools simple
    var toolsbar = "tools"          //tools toolbar
    //zoom to max extent tool
    var maxext = new GeoExt.Action({
        //text: "Max Extent",       
        icon: 'icons/icon_fullextent.gif',
        control: new OpenLayers.Control.ZoomToMaxExtent(),
        map: map,
        deactivateOnDisable: true,
        activateOnEnable: true,
        tooltip: "zoom to max extent"
    });

    var zoomin = new GeoExt.Action({
        //text: "Zoom In",
        icon: 'icons/icon_zoomin.gif',
        control: new OpenLayers.Control.ZoomIn(),
        map: map,
        deactivateOnDisable: true,
        activateOnEnable: true,
        tooltip: "zoom inside",
    });

    var zoomout = new GeoExt.Action({
        //text: "Zoom Out",
        icon: 'icons/icon_zoomout.gif',
        control: new OpenLayers.Control.ZoomOut(),
        map: map,
        deactivateOnDisable: true,
        activateOnEnable:true,
        tooltip: "zoom outside",
    });

    var pan = new GeoExt.Action({
        text: "Pan",
        control: new OpenLayers.Control.Pan(),
        map: map,
        deactivateOnDisable: true,
        activateOnEnable:true,
        tooltip: "drag to move",
    });

    var prev_ext = new GeoExt.Action({
        //text: "previous",
        icon: 'icons/icon_zoomprevious.png',
        control: navi.previous,
        disabled: false,
        deactivateOnDisable: true,
        activateOnEnable: true,
        tooltip: "previous in history",
    });

    var next_ext = new GeoExt.Action({
        //text: "next",
        icon: 'icons/icon_zoomnext.png',
        control: navi.next,
        disabled: false,
        deactivateOnDisable: true,
        activateOnEnable: true,
        tooltip: "next in history"
    });

    }
    var toolbar = new Ext.Toolbar({                 //embed tool in toolbar
        renderTo: 'tools',
        width: tbar_wd,
        height: tbar_ht,
        autoWidth : true,
        autoHeight : true,
        items: [draw_ac,'-',modify_ac,'-',del_ac,'-',save_ac,'-',measu_length,'-',measu_area,'-',select_ac,'-',identify_ac,'-',pan_ac,maxext,'',zoomin,'',zoomout,'',prev_ext,'',next_ext]
    });

    // the part below is just to make the bounds show up on the page
    function updateBounds(){
        var bbox = map.getExtent().toArray();
        code = "Bounds      lower left: "+bbox[0]+','+bbox[1]+"     upper right"+bbox[2]+','+bbox[3];
        document.getElementById('bounds').innerHTML = code;
    }
    // update the bounds with each map move
    map.events.register('moveend', map, updateBounds);
    // and update the bounds on first load
    updateBounds();

});
share|improve this question

1 Answer 1

The problem is with Geoserver, neither OpenLayers nor postgresql.

  • Which version of Geoserver are you using? (to use postgis 2.0 you should use at least the 2.1.3)
  • What is the error generated by geoserver? (you can find it using Firebug, a firefox add-on to inspect the response of the WFS ajax request)

Possibile problems could be

  • Old geoserver
  • Invalid geometry, maybe you are saving the feature with a different SRID from the one defined in the postgis table
share|improve this answer
    
i am using geoserver 2.1.4 and the geometry is also valid (just a simple line and srid is also correct), the error i get is error inserting feature –  neogeomat Sep 7 '12 at 16:28
    
Mmh, could you check the geoserver log file? –  Tommaso Sep 7 '12 at 16:50
1  
PostGIS 1.5 allow to call some functions without the "ST_" prefix, while 2.0 and up it's required. Mapserver suffer this too. –  Magno C Dec 6 '12 at 19:30
1  
There is the possibility to import in postgis 2.x the legacy functions see the faq –  Tommaso Jan 8 '13 at 10:53

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.