Sunday, 23 December 2018

openlayers 2 - adding non spatial attributes using geoserver


I am using Openlayers + geoext to perform transaction operations in postgis database using geoserver . i can insert spatial data into postgis but cannot insert other data like road name, road type in my road database.


the openlayers generates this code during transaction



service="WFS" 
version="1.1.0"
xsi:schemaLocation="http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">




xmlns:gml="http://www.opengis.net/gml"
srsName="EPSG:4326">


85.292019896027 27.722567213659 85.303131631935 27.72224973549 85.303290371019 27.72478956084










in geoserver demo i add fid and id so that it looks as


service="WFS" 
version="1.1.0"
xsi:schemaLocation="http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">



xmlns:gml="http://www.opengis.net/gml"
srsName="EPSG:4326">


85.292019896027 27.722567213659 85.303131631935 27.72224973549 85.303290371019 27.72478956084






**650
400**





and i get what i want. my question is how can i post the 2nd request (with id and fid) instead of first using openlayers and/or geoext?



Answer



i don't know the answer to this question, but if someone is stuck in same situation. i suggest that you extract the geometry of feature and assign it to an html element. then access the value of same element and use php to insert it to database along with other attributes. it works for simple geometries but is a tedious task, still it is a solution.


My code is like this


var draw = new OpenLayers.Control.DrawFeature(
vector, //layer
OpenLayers.Handler.Path, //Handler
{ multi:true,
type: OpenLayers.Control.TYPE_TOGGLE,

//handlerOptions : {maxVertices: 5}
}//options
);
draw.events.register("featureadded",'' , FeatureAdded);
function FeatureAdded(object){
//alert('feature added');
var oFeature = object.feature;
oFeature.state = OpenLayers.State.INSERT;
**document.getElementById('geometry').value = oFeature.geometry;
//alert(oFeature.geometry);

}

map.addControl(draw);

the sql statement is like this in postgis


INSERT INTO table_name VALUES (ST_GeographyFromText('value of the element(geometry)',SRID))

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...