Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have been writing some python code to automatically add data layers from PostGIS to GeoServer and attach a suitable SLD as default. I got this working using the following code:

store=("<dataStore><name>data</name><connectionParameters><host>localhost</host><port>5432</port><database>case</database><schema>public</schema><user>" + postgisusername + "</user><passwd>" + postgispassword + "</passwd><dbtype>postgis</dbtype></connectionParameters></dataStore>")

c = pycurl.Curl()
c.setopt(c.VERBOSE, 1)
c.setopt(c.HTTPHEADER, ['Content-type: text/xml'])
c.setopt(c.USERPWD, username + ":" + password)
c.setopt(c.URL, 'http://localhost:8080/geoserver/rest/workspaces/test/datastores')
c.setopt(c.CUSTOMREQUEST, "POST")
c.setopt(c.POSTFIELDS, store)
c.perform()
c.close()


sldname='<style><name>DataLine</name><filename>DataLine.sld</filename></style>'

c = pycurl.Curl()
c.setopt(c.VERBOSE, 1)
c.setopt(c.HTTPHEADER, ['Content-type: text/xml'])
c.setopt(c.USERPWD, username + ":" + password)
c.setopt(c.URL, 'http://localhost:8080/geoserver/rest/styles')
c.setopt(c.CUSTOMREQUEST, "POST")
c.setopt(c.POSTFIELDS, sldname)
c.perform()
c.close()

filesize = os.path.getsize("Data Line.sld")
f = open("Data Line.sld", 'rb')

c = pycurl.Curl()
c.setopt(c.VERBOSE, 1)
c.setopt(c.HTTPHEADER, ['Content-type: application/vnd.ogc.sld+xml'])
c.setopt(c.USERPWD, username + ":" + password)
c.setopt(c.INFILESIZE, filesize)
c.setopt(c.URL, 'http://localhost:8080/geoserver/rest/styles/DataLine')
c.setopt(c.PUT, 1)
c.setopt(c.INFILE, f)
c.perform()
c.close()
f.close()

sldtolayer='<layer><defaultStyle><name>DataLine</name></defaultStyle><enabled>true</enabled></layer>'

c = pycurl.Curl()
c.setopt(c.VERBOSE, 1)
c.setopt(c.HTTPHEADER, ['Content-type: text/xml'])
c.setopt(c.USERPWD, username + ":" + password) 
c.setopt(c.URL, 'http://localhost:8080/geoserver/rest/layers/dataline')
c.setopt(c.CUSTOMREQUEST, "PUT")
c.setopt(c.POSTFIELDS, sldtolayer)
c.perform()
c.close()

This works very well for all SLDs where I am not referencing an external graphic such as an SVG for symbology. I moved a folder of SVGs into the styles folder within the data directory and restarted the OpenGeo Suite, to make sure it knew the SVGs existed.

However, the code creates a blank SLD within GeoServer.

The error message I receive is a Java Unknown Source error and external graphic location.

I know this SLD works if I load through the GUI, so it must be something going on through the REST API.

Can anyone help?

thanks

share|improve this question
    
Can you add the specific Java error and stack trace? –  CHenderson Jan 20 '13 at 21:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.