Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using OpenLayers, Geoserver, and PostGIS. For now, everything is fine and happy. I have 2 layers showing on my map through WMS from geoserver. I am taking following steps:

Step 1: inserting data into postgis - done manually.

step 2: if it is a feature in already present layer then reloading the page add that feature on the map, but for adding the table for a layer into geoserver, I am publishing it manually.

step 3: including that layer code into JS manually

I want everything to be done automatically. Since my project is to be handed over to a client and they should be given the possibilitz to add features, layers etc. I think automation is necessary.

So I want:

Step 1: inserting data into postgis - can be achieved by providing a form to user and using a php I can insert them into postgis

Step 2: publishing of layer(selecting a style also) in geoserver - has to be done programmatically

Step 3: inserting this layer code in JS - to be done problematically.

I request your good guidance on this issue. Thank you.

share|improve this question
This can be all done in a batch file with some SQL for the PostGIS. – Mapperz Jun 6 '11 at 18:48
Do u have any links/references that might guide me further – Vikash Talanki Jun 6 '11 at 19:27
@Mapperz, Can you plz guide me how to perform this using batch files. I am still stuck up on this issue, Not finding the REST Php section to get enough guidance – Vikash Talanki Jun 12 '11 at 10:50
up vote 2 down vote accepted

I had almost the same issues as you last year, when I worked on an open-source (PostgreSQL&PostGIS database + Geoserver + Javascript frontend) WebGIS architecture.

I developed on Ubuntu and solved the automation issues using a mixture of CRONed bash scripts, which:

  1. periodically performed SQL queries to insert/modify features into the DB. Data was stored under a filesystem folder into CSV text files, which were read by the scripts and pumped into the DB.
  2. added new raster data, whenever available, calling Geoserver REST APIs

Javascript code had not to be modified because it automatically loaded all of the Geoserver layers.

Hope this kind of approach can help you...

share|improve this answer
Can you provide me ur bash scripts , so that I can go through them once – Vikash Talanki Jun 8 '11 at 19:44
...That wouldn't be very good for my company if I provided the scripts publicly, don't you think so ? That's the reason why I just posted the general ideas and not the code.. – csparpa Jun 13 '11 at 9:15

The basics for your 3 questions in one.

php to connect to postgis

    $host_str = "host=yourhost";
    $db_str = "dbname=your_db";
    $usr_str = "user=username&password=yourpassword";
    $string = $host_str." ".$db_str." ".$usr_str;
    $connection = pg_connect($string);
    if (!$connection)
      echo "Error: Cannot connect to the database <br>\n";

  echo "Connected to the database <br>\n";

Create and Add Geoserver REST request (example only)

-u admin:geoserver -XPOST -H "Content-type: text/xml" -d @/tmp/sb2.xml http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes

js file should not be needed to be updated if you set variables in your original code.

share|improve this answer
+ I do recommend the username/password and dbname (connection) are in a separate php file (only access on the server itself) - for added security in a production environment. – Mapperz Jun 8 '11 at 15:53
"js file should not be needed to be updated if you set variables in your original code".. Can you please explain this in detail... I am attaching the following code everytime I publish a new layer var wmslayer2 = new OpenLayers.Layer.WMS( "Layer2", "localhost:8080/geoserver/wms";, {'layers': 'cite:layer2', 'format':'image/png', 'transparent':'true'}, {'opacity': 1.0, 'isBaseLayer': false, 'visibility': true} ); Is there a way to automatically put this code in JS each time I publish a new layer?? – Vikash Talanki Jun 13 '11 at 5:34

Your Answer


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.