GeoServer Publishing Map Service via code

Source: Internet
Author: User

GeoServer: Code implementation bulk Publishing map service

Using GeoServer to publish a WCS service, if I have a lot of data to publish, it's obviously not going to work with the UI interface provided by GeoServer. Can you use the API provided by GeoServer to do this? GeoServer provides a rest API that allows us to operate with code. The following languages or methods are available in the user manual: Curl,php,python,java and Ruby.

Java Chapter

I first used the Java language GeoServer Manager. To create a new MAVEN project in Eclipse, add the appropriate dependency package, here is an example of reading the data:

public static Boolean read () {String Resturl ="Http://localhost/geoserver";String username = "admin"; string password =  "GeoServer"; Geoserverrestreader reader; try {reader = new geoserverrestreader (Resturl, username, password); } catch (malformedurlexception e) {e.printstacktrace (); return FALSE;} string workspace =  "whu.images"; string store =  "00n006e"; string name =  "00n006e"; Restcoverage coverage = reader.getcoverage (workspace, store, name); System.out.println (Coverage.getabstract ()); return true;}        

But I have some problems writing raster data, and the following are the class inheritance relationships of data stores:

We can see that the coverage store has no implementation class, Gsabstractcoveragestoreencoder is an abstract class, and is labeled @deprecated, so I don't know how to create a coverage store, Originally wanted to write an implementation class, and eventually gave up.

Python article

Python solved the problem later, but it was not smooth sailing.
First install the Gsconfig package, if you do not know how to install, refer to the Python module commonly used several installation methods.
After installation, the code is as follows:
as follows, using the default user name, password, default workspace, so the function of the parameters are very few, if you want to customize these, detailed view of the function description.

from geoserver.catalog import cataloggeourl =  "http://localhost/geoserver/rest" # The URL of Geoservergeocat = catalog (geourl) # Create a Catalog object store_name =  "00n010e" data =" e:/rsimageservice/ data/images/00n010e.tif "geocat.create_coveragestore (store_ Name, data)       

However, there is a problem with Create_coveragestore, which will copy your files to your data directory by default, and if you have a lot of information, you will have two copies of the data, which is a huge waste of disk space.

Later found that the Catalog class has a way to provide a create_coveragestore2, you can create a unsavedcoveragestore, the data will not be uploaded.

from geoserver.catalog import Cataloggeourl = "http://localhost/geoserver/rest"  # the url of geoservergeocat = Catalog(geourl)  # create a Catalog objectstore_name = "00N010E"data_url = "fiel:E:/RSImageService/data/images/00N010E.tif"geostore = geocat.create_coveragestore2(store_name)geostore.url = data_urlgeocat.save(geostore)

But once the program runs, it returns a server internal error 505,error code (505) from GeoServer:: Data store must is part of a workspace.

Finally wrote a method for publishing GeoTiff images (a piece of code seen from GitHub, running a bit of a problem, and then modifying it yourself). Add a Create_coveragestore3 method to the Catalog class, where the user publishes the raster data without copying the data. This requires modifying the Gsconfig source code and then recompiling it.
The Create_coveragestore3 method is as follows:

DefCreate_coveragestore3(Self, name, Data_url, Workspace=none, Overwrite=false):IfNot overwrite:Try:store = Self.get_store (name, workspace) msg ="There is already a store named" + NameIf workspace:msg + ="In" + str (workspace)Raise Conflictingdataerror (MSG)Except Failedrequesterror:# we don ' t really expect that every layer name would be takenPassIf workspaceIsnone:workspace = self.get_default_workspace () headers = { "Content-type": "Text/plain", "Accept": " Application/xml "} ext = " GeoTiff "Cs_url = URL (self.service_url, [" workspaces ", Workspace.name, " Coveragestores ", name, " external. "+ ext], { " Configure ": " First ", " Coveragename ": Name}) headers, res Ponse = Self.http.request (Cs_url, "PUT", Data_url, headers) self._cache.clear () if headers.status! = 201: raise Uploaderror (response)               

The final client calling code:

from geoserver.catalog import Cataloggeourl = "http://localhost/geoserver/rest"  # the url of geoservergeocat = Catalog(geourl)  # create a Catalog objectstore_name = "00N010E"data_url = "file:E:/RSImageService/data/images/00N010E.tif"geocat.create_coveragestore3(store_name, data_url)

If you want to publish a lot of data, traverse the folder call Create_coveragestore3.

GeoServer Publishing Map Service via code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.