[Geoserver-users] adding layers to Geoserver-WMS with REST api

Hi there,
i am new to geoserver and i am trying to use the rest api to add automatically layers to a geoserver WMS instance. I have the REST extension installed.
if i run the examples i found:
I create the workspace:
curl -u user:pwd -v -XPOST -H "Content-type: text/xml" -d "<workspace><name>test</name></workspace>" http://localhost:8080/geoserver/rest/workspaces
I test it and see that is ok with:
curl -XGET http://localhost:8080/geoserver/rest/workspaces/test.xml
Then i try to load a shapefile:
curl -u user:pwd -v -XPUT -H "Content-type: application/zip" --data-binary @c:\data\spain.zip http://localhost:8080/geoserver/rest/workspaces/test/datastores/sp/spain.shp
And i test that the datastore is created with:
curl -XGET http://localhost:8080/geoserver/rest/workspaces/test/datastores/sp.xml

After this, i chek and i have a new folder in the data_dir/data/sp folder within my geoserver installation that contains the content of the zip file. If i stop-start geoserver of i reload the data i dont see that i have a new layer in the WMS with this new datastore, my question is: is there still something i have to do to create a new layer with this data? do i have to do something else to change the WMS capabilities?

thanks in advance
Laura

--
Laura Díaz Sánchez
Centro de Visualización Interactiva (CeVI) http://www.cevi.uji.es
Geographic Information research group: http://www.geoinfo.uji.es
Department of Information Systems
Universitat Jaume I
Av. Vicente Sos Baynat s/n. 12071
Castellón, Spain

I notice one of your urls is a bit off. The url you PUT the zipped shapefile to:

http://localhost:8080/geoserver/rest/workspaces/test/datastores/sp/spain.shp

Should actually be:

http://localhost:8080/geoserver/rest/workspaces/test/datastores/sp/file.shp

That is probably why the layer is not getting created. Try changing it and let us know if it works.

-Justin

Laura Díaz wrote:

Hi there,
i am new to geoserver and i am trying to use the rest api to add automatically layers to a geoserver WMS instance. I have the REST extension installed.
if i run the examples i found:
I create the workspace:
curl -u user:pwd -v -XPOST -H "Content-type: text/xml" -d "<workspace><name>test</name></workspace>" http://localhost:8080/geoserver/rest/workspaces
I test it and see that is ok with:
curl -XGET http://localhost:8080/geoserver/rest/workspaces/test.xml
Then i try to load a shapefile:
curl -u user:pwd -v -XPUT -H "Content-type: application/zip" --data-binary @c:\data\spain.zip http://localhost:8080/geoserver/rest/workspaces/test/datastores/sp/spain.shp
And i test that the datastore is created with:
curl -XGET http://localhost:8080/geoserver/rest/workspaces/test/datastores/sp.xml

After this, i chek and i have a new folder in the data_dir/data/sp folder within my geoserver installation that contains the content of the zip file. If i stop-start geoserver of i reload the data i dont see that i have a new layer in the WMS with this new datastore, my question is: is there still something i have to do to create a new layer with this data? do i have to do something else to change the WMS capabilities?

thanks in advance
Laura

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

Hi,
thanks for your response. I have resolved my problem: First of all i have upgraded my geoserver and the restconfig extension with the nigthly build.
Then i create the workspace and then i put the zip file containing the shapefiles:
curl -u user:pwd -v -XPOST -H "Content-type: text/xml" -d "<workspace><name>test</name></workspace>" http://localhost:8080/geoserver/rest/workspaces
curl -u user:pwd -v -XPUT -H "Content-type: application/zip" --data-binary @c:\data\country.zip http://localhost:8080/geoserver/rest/workspaces/test/datastores/world/file.shp

When putting the file i saw in the log file the following message:
16 abr 14:08:12 ERROR [geoserver.global] - Could not load feature type test:country java.lang.NullPointerException
        at org.geotools.referencing.CRS.decode(CRS.java:419)
        at org.geotools.referencing.CRS.decode(CRS.java:348)
        at org.vfny.geoserver.global.FeatureTypeInfo.getSRS(FeatureTypeInfo.java:1009) ETC.

So, i guessed i had to have the PRJ file belonging to the shape within the zip file, so i zipped a shp file with prj and error solved, now the feature type is created and the layer
available in the WMS and WFS.

Just a couple of things,
1) is there a way using the restconfig to set a title for the layer?
2) in the WFS capabilities the layer has set the default SRS to "urn:x-ogc:def:crs:EPSG:4326", is this correct? or shouldnt it be just EPSG:4326?, if this is the normative sorry for the question and it is a problem of the WFS client i am using.

thanks again for your time.
Laura

Justin Deoliveira escribió:

I notice one of your urls is a bit off. The url you PUT the zipped shapefile to:

http://localhost:8080/geoserver/rest/workspaces/test/datastores/sp/spain.shp

Should actually be:

http://localhost:8080/geoserver/rest/workspaces/test/datastores/sp/file.shp

That is probably why the layer is not getting created. Try changing it and let us know if it works.

-Justin

Laura Díaz wrote:
  

Hi there,
i am new to geoserver and i am trying to use the rest api to add automatically layers to a geoserver WMS instance. I have the REST extension installed.
if i run the examples i found:
I create the workspace:
curl -u user:pwd -v -XPOST -H "Content-type: text/xml" -d "<workspace><name>test</name></workspace>" http://localhost:8080/geoserver/rest/workspaces
I test it and see that is ok with:
curl -XGET http://localhost:8080/geoserver/rest/workspaces/test.xml
Then i try to load a shapefile:
curl -u user:pwd -v -XPUT -H "Content-type: application/zip" --data-binary @c:\data\spain.zip http://localhost:8080/geoserver/rest/workspaces/test/datastores/sp/spain.shp
And i test that the datastore is created with:
curl -XGET http://localhost:8080/geoserver/rest/workspaces/test/datastores/sp.xml

After this, i chek and i have a new folder in the data_dir/data/sp folder within my geoserver installation that contains the content of the zip file. If i stop-start geoserver of i reload the data i dont see that i have a new layer in the WMS with this new datastore, my question is: is there still something i have to do to create a new layer with this data? do i have to do something else to change the WMS capabilities?

thanks in advance
Laura

--
Laura Díaz Sánchez
Centro de Visualización Interactiva (CeVI) http://www.cevi.uji.es
Geographic Information research group: http://www.geoinfo.uji.es
Department of Information Systems
Universitat Jaume I
Av. Vicente Sos Baynat s/n. 12071
Castellón, Spain

Laura Díaz wrote:

Hi,
thanks for your response. I have resolved my problem: First of all i have upgraded my geoserver and the restconfig extension with the nigthly build.
Then i create the workspace and then i put the zip file containing the shapefiles:
curl -u user:pwd -v -XPOST -H "Content-type: text/xml" -d "<workspace><name>test</name></workspace>" http://localhost:8080/geoserver/rest/workspaces
curl -u user:pwd -v -XPUT -H "Content-type: application/zip" --data-binary @c:\data\country.zip http://localhost:8080/geoserver/rest/workspaces/test/datastores/world/file.shp

When putting the file i saw in the log file the following message:
16 abr 14:08:12 ERROR [geoserver.global] - Could not load feature type test:country java.lang.NullPointerException
        at org.geotools.referencing.CRS.decode(CRS.java:419)
        at org.geotools.referencing.CRS.decode(CRS.java:348)
        at org.vfny.geoserver.global.FeatureTypeInfo.getSRS(FeatureTypeInfo.java:1009) ETC.

So, i guessed i had to have the PRJ file belonging to the shape within the zip file, so i zipped a shp file with prj and error solved, now the feature type is created and the layer
available in the WMS and WFS.

Great! Glad it worked.

Just a couple of things,
1) is there a way using the restconfig to set a title for the layer?

The best way to do this now would be to update the description of the feature type or coverage with a PUT request. The following will set the title:

curl -XPUT http://…/geoserver/rest/workspaces/<ws>/datastores/<ds/
    featuretypes/<ft> -H 'Content-type: text/xml' -d '<featureType><description>...</description></featureType>'

2) in the WFS capabilities the layer has set the default SRS to "urn:x-ogc:def:crs:EPSG:4326", is this correct? or shouldnt it be just EPSG:4326?, if this is the normative sorry for the question and it is a problem of the WFS client i am using.

Yes, this is more or less mandated by the WFS 1.1 specification. Out of curiosity what client are you using?

thanks again for your time.
Laura

Justin Deoliveira escribió:

I notice one of your urls is a bit off. The url you PUT the zipped shapefile to:

http://localhost:8080/geoserver/rest/workspaces/test/datastores/sp/spain.shp

Should actually be:

http://localhost:8080/geoserver/rest/workspaces/test/datastores/sp/file.shp

That is probably why the layer is not getting created. Try changing it and let us know if it works.

-Justin

Laura Díaz wrote:
  

Hi there,
i am new to geoserver and i am trying to use the rest api to add automatically layers to a geoserver WMS instance. I have the REST extension installed.
if i run the examples i found:
I create the workspace:
curl -u user:pwd -v -XPOST -H "Content-type: text/xml" -d "<workspace><name>test</name></workspace>" http://localhost:8080/geoserver/rest/workspaces
I test it and see that is ok with:
curl -XGET http://localhost:8080/geoserver/rest/workspaces/test.xml
Then i try to load a shapefile:
curl -u user:pwd -v -XPUT -H "Content-type: application/zip" --data-binary @c:\data\spain.zip http://localhost:8080/geoserver/rest/workspaces/test/datastores/sp/spain.shp
And i test that the datastore is created with:
curl -XGET http://localhost:8080/geoserver/rest/workspaces/test/datastores/sp.xml

After this, i chek and i have a new folder in the data_dir/data/sp folder within my geoserver installation that contains the content of the zip file. If i stop-start geoserver of i reload the data i dont see that i have a new layer in the WMS with this new datastore, my question is: is there still something i have to do to create a new layer with this data? do i have to do something else to change the WMS capabilities?

thanks in advance
Laura

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

Just a couple of things,
1) is there a way using the restconfig to set a title for the layer?

The best way to do this now would be to update the description of the feature type or coverage with a PUT request. The following will set the title:

curl -XPUT http://…/geoserver/rest/workspaces/<ws>/datastores/<ds/
    featuretypes/<ft> -H 'Content-type: text/xml' -d '<featureType><description>...</description></featureType>'

Oops, my apologies. There is a title on resources. So replace description with title. Sorry about that.

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

Hi,
thanks for the help. I was doing the tests with gvSIG

laura

Justin Deoliveira escribió:

Just a couple of things,
1) is there a way using the restconfig to set a title for the layer?

The best way to do this now would be to update the description of the feature type or coverage with a PUT request. The following will set the title:

curl -XPUT http://…/geoserver/rest/workspaces/<ws>/datastores/<ds/
    featuretypes/<ft> -H 'Content-type: text/xml' -d '<featureType><description>...</description></featureType>'

Oops, my apologies. There is a title on resources. So replace description with title. Sorry about that.

--
Laura Díaz Sánchez
Centro de Visualización Interactiva (CeVI) http://www.cevi.uji.es
Geographic Information research group: http://www.geoinfo.uji.es
Department of Information Systems
Universitat Jaume I
Av. Vicente Sos Baynat s/n. 12071
Castellón, Spain