Hi Patrick,

That is a good point; working with curl actually helped. The following
works:

curl \
http://localhost:8080/geoserver/rest/workspaces/workspace_name/datastores/datastore_name/featuretypes
\
--header 'content-type: application/xml' \
--user user:password \
--data \
'<featureType>\
<name>pub_layer</name>\
<nativeName>layer</nativeName>\
<title>LAYER</title>\
</featureType>'

It is not clear in the documentation what the <name> and <nativeName> tags
represent. Using the above data in the post Geoserver interprets
<nativeName>layer</nativeName> as the table which is used in the PostGIS
database therefore the value within the tags should be the same as the table
name in PostGIS. If the <nativeName>layer</nativeName> is not used in the
POST payload then Geoserver expects the <name></name> to include a value
which is the same as the table name in the PostGIS database which in my
original post it wasn't.

Going back to Python the right answer to my question is the following:

import requests
from requests.auth import HTTPBasicAuth

def
create_feature_type(layer_name,store_name,workspace_name,table_name,user,password):

    headers = {'Content-Type': 'application/xml'}
    url =
'http://localhost:8080/geoserver/rest/workspaces/{0}/datastores/{1}/featuretypes'.format(workspace_name,store_name)
    
    post_data = """<featureType>"""\
                +"""<name>{}</name>""".format(layer_name)\
                +"""<nativeName>{}</nativeName>""".format(table_name)\
                +"""<title>{}</title>""".format(table_name.upper())\
                +"""</featureType>"""

    r =
requests.post(url,headers=headers,auth=HTTPBasicAuth(user,password),data=post_data)

    return r.status_code

def main():

    #Assumes workspace and data store have been created before running the
following function and
    #a table named 'table_name' is located into the database.
   
create_feature_type('pub_table_name','test_store','test_workspace','table_name','admin','passwd')

if __name__ == "__main__":
    main()

Cheers for your help,
D.



--
View this message in context: 
http://osgeo-org.1560.x6.nabble.com/Create-layer-REST-API-issues-tp5317197p5317683.html
Sent from the GeoServer - User mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Reply via email to