2

I am using postgis for my project along with geoserver and openlayers. I give user an html form with drop down menu list of available layers(each layer corresponds to a table in db).The user can select any layer , based on which I am retrieving the fields of that particular from db to insert the values. As soon as the user inputs data and clicks on submit then the data should be inserted into db.

Inserting data into db is a trivial thing as far as you know the order in which to insert into the db. But I have tables with different number of fields and in different order. I want to know how can I insert values into particular table when I don't know the order in which I have to store.

I shall explain with an example:

Table 1 of layer1: id,name,point Table 2 of layer2: id,polygon,name,area

When user selects layer1 in dropdown menu , the form will provide you id,name,point text fields in that order to insert data. If the user selects layer2 then form will give you id,polygon,name,area text fields in that order. Suppose say user has selected layer1 then after inserting the values into text fields and submitting , the php file should perform a query "insert into (id,name,point) values('$_post[id]','$_post[name]','st_geomfromtext('POINT($_post[point])',4326));"

Same way for inserting into layer2 the query should be "insert into (id,polygon,name,area) values('$_post[id]','st_geomfromtext('POINT($_post[point])',4326),'$_post[name]','$_post[area]');"

But how can I know that I have to use only this particular query??? I can know the table name from hidden field.

For now my php file is like this:

$tablename=$_POST[tablename]; if($tablename=='layer1') { perform query1; } else if($tablename=='layer2') { perform query2; }

But this works only if I know the tables already present. Is there anyway to write the php file provided I know only the table name but no idea of table description in db?? (I can get the table description through a query if I want).

1 Answer 1

3

Since you have already installed GeoServer why not use a WFS-T request to handle your database writes. Then the question of how to write the code becomes moot as there is good, well defined and tested code already there. OpenLayers provides a WFS-T object to help you build the request on the client too. For an example with a form to add attributes see http://dev4.mapgears.com/bdga-mapfish/bdgaWFS-T.html

5
  • I have developed everything using WMS since I was getting some crossdomain probelm due to WFS.. I think changing everything to WFS is not a better solution at this point of time. Jun 12, 2011 at 19:49
  • 2
    Just add a proxy to overcome the crossdomain problem - the advantage of using WFS-T is that your WMS layers will update automatically.
    – Ian Turton
    Jun 12, 2011 at 20:14
  • That sounds good,I have many layers in the layerswitcher, so if I want to add a point to a layer say layer1 then should I check only layer1 and then add??? In other way,Suppose if I add a point when all the layers in layerswitcher are checked, then to which layer will the point get added??? Jun 12, 2011 at 20:36
  • surely you have to have some way to specify which layer is to be modified other than the layerswitcher? otherwise I think you need to rethink your interface.
    – Ian Turton
    Jun 12, 2011 at 20:48
  • @iant The link no longer exists
    – Vidar
    Jan 3, 2016 at 22:04

Your Answer

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

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