1

I have been trying to publish a zipped up shapefile to GeoServer.

For background, I am using DotSpatial to create a Line shapefile based on uploaded points. Once I have created the shapefile, I compress all files generated (shp, prj, dbf, shx). Then I want to publish it to GeoServer

I am able to create a Workspace and DataStore using a web request. When I tried adding the zipped up shapefile, all shapefiles are placed in the data\ folder.

No featuretype.xml or or layer.xml file is created under the workspace folder. The datastore.xml does get created.

The error I get back is:

500 Server Error

It worked at some point but is now not working and I haven't changed the code.

  Dim localShapeFile() As Byte = readLocalShapeFile(zipUri) ' read file bytes

  Dim sUrl As String = "http://localhost:8080/geoserver/rest/workspaces/" & workspace & "/datastores/" & dsname & "/file.shp"

  Dim request As WebRequest = WebRequest.Create(sUrl)
  request.ContentType = "application/zip"
  request.Method = "PUT"
  request.Credentials = New NetworkCredential("admin", "geoserver")
  Dim requestStream As Stream = request.GetRequestStream
  requestStream.Write(localShapeFile, 0, localShapeFile.Length)
  requestStream.Close()
  Dim response As WebResponse = request.GetResponse ' error is produced here
0

What version of GeoServer are you using?

There's some documentation here, which uses a different method than what you have above.

And there's another example here, with a working solution.

Regarding your specific problem, a 500 error is a server error. I'd check the GeoServer logs to see what it's complaining about. That'll put you on the right track. (Stick the logs in here, if you can't make sense of them.)

  • 1
    I used the second option. It was a template for what I was trying to do, only after much research, it appears using PostGIS using that method works. The only problem I am having now is getting the Declared SRS correct. It is coming in as 'EPSG:404000'. I want to change it to 'EPSG:4326' using the REST API but am having trouble finding a solution that works. – Gary Whitcher Jul 20 '17 at 22:23
  • If you feel that this question is answered, can you mark mine as the answer, please. Ask another question about the SRS. – Alex Leith Jul 20 '17 at 23:05
0

If you want to publish single shapefile layer then use this code:

def layer_publish(self):
    print ("Publishing Layer. wait..")
 url = "http://localhost:8080/geoserver/rest/workspaces/cite/datastores/Shapefile/featuretypes"
    payload ="<featureType>"\
             "<name>"layername"</name>"\
             "<type>VECTOR</type>" \
             "<srs>EPSG:3857</srs>"\
             "<projectionPolicy>FORCE_DECLARED</projectionPolicy>"\
             "<enabled>true</enabled>"\
             "<defaultStyle>"\
             "<name>line</name>"\
             "</defaultStyle>"\
             "<resource class='featureType'>"\
             "<name>"layername"</name>"\
             "</resource>"\
             "<attribution>"\
             "<logoWidth>0</logoWidth>"\
             "<logoHeight>0</logoHeight>"\
             "</attribution>"\
             "</featureType>"

    headers = {'Content-Type': 'text/xml'}
    auth = ('admin', 'geoserver')
    response = requests.post(url, headers=headers, data=payload, auth=auth)
    if response.status_code == 201:
        print ("Layer Publish Successfully.")

Remember onething if your data is raster(Geotiff,ImageMosaic etc) then you have to create coveragestore for it. If your data is vector (Shapefiles) then you have to create featuretypes for it.

I hope this will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.