Hi Jonathan,
have you tried forming curl requests programmatically?
You can publish a postgis layer to GeoServer by sending an HTTP request
(e.g. using curl) with a bit of XML as parameter.
Below is the docstring of a python function to send such an HTTP request
that worked with PostGIS 1.4 on Postgres 8.3 and GS 2.0.1 in June 2010:
"""Publish postGIS tables (from converted shapefiles) as GeoServer layers
using
the GS REST plugin. From a given tablename of a postGIS table, form and
send
the REST command that configures this table as a layer in GeoServer (GS
URL,
workspace, data store hardcoded for now).
Assume that a metadata sidecar file in FGDC standard exists in a local
directory (location hardcoded) and link the GS layer to it.
Attach keywords (parameter) to GS layer.
Output (cURL command):
'curl -u MY_USER:MY_PASSWORD -XPOST -H "Content-type: application/xml"
-d "<featureType>
<name>MY_NAME</name>
<title>MY_TITLE</title>
<abstract>
Shapefile MY_NAME, stored in PostGIS, hosted on GeoServer.
</abstract>
<keywords>
<string>MY_KEYWORD_ONE</string><string>MY_KEYWORD_TWO</string>
</keywords>
<metadataLinks>
<metadataLink>
<type>application/xml</type>
<metadataType>FGDC</metadataType>
<content>
http://10.20.200.211:8080/geoserver/www/md/MY_NAME.shp.xml
</content>
</metadataLink>
</metadataLinks></featureType>"
MY_GS_INSTANCE/rest/workspaces/MY_WS/datastores/MY_DS/featuretypes)'
"""
(The whole code is at Bitbucket [1] and serves to import shapefiles into
postgis and publish them to GS.)
First, install curl [2] and form the above request with the correct
parameters for one of your postgis layers.
Note to self: make sure your postgis layers are registered in the
geometry_columns table, especially if you created them by hand, see [3]
If that works, install Mercurial [4] to download the code by running this on
your commandline (assuming you're on a Windows machine):
> cd \my\work\dir\shpload
> hg clone https://bitbucket.org/florianm/shpload
This should download two scripts into your folder at \my\work\dir\shpload.
"shpload.py" holds the functions
- to convert shape files into pgsql,
- to run the pgsql against your postgis database, and
- to publish the postgis tables to GeoServer using curl to send HTTP
requests to the GeoServer REST API.
"shlorp.py" holds the configuration (location of your postgis db etc.) and
runs the three functions of shpload.py on your shapefiles or postgis tables.
To run it, install Python (2.*) and the packages specified in the "import"
section of shpload.py, then type at the commandline:
> cd \my\work\dir\shpload
> python shlorp.py
You can either modify shlorp.py to match your needs or use the shpload
functions from another python script.
If you start from postgis tables in schema "public", you'll need the list of
table names to form the curl request - e.g. on the command line:
> psql DBNAME DBUSER
(enter password)
DBNAME# SELECT table_name FROM information_schema.tables WHERE table_schema
~ 'public';
DBNAME# \q
Let me know how you go, and feel free to commit any improvements back into
bitbucket!
Cheers,
Florian
[1] http://bitbucket.org/florianm/shpload/
[2] http://curl.haxx.se/download.html
[3]
http://postgis.refractions.net/docs/ch04.html#Manual_Register_Spatial_Column
[4] http://mercurial.selenic.com/wiki/Download
On Tue, Jul 12, 2011 at 8:38 AM, Diaz, Jonathan F. <[email protected]
> wrote:
> Hello list, ****
>
> ** **
>
> I need a little help figuring out how I can programmatically publish a
> PostGIS table as a layer.****
>
> I am creating tables in a PostGIS database and populating them with simple
> features in Java using GeoTools. I would like to then publish the table as a
> layer on GeoServer. I manually setup the database as a datastore already. I
> looked at the rest interface API and while I see how I can add a new
> featuretype, I don’t see how I can add a new layer. ****
>
> ** **
>
> Thanks,****
>
> Jonathan****
>
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Geoserver-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geoserver-users