-
Notifications
You must be signed in to change notification settings - Fork 192
Interacting with a StructuredGridCoverageReader
With branch 1.6.x a new entity has been created to deal with StructuredGridCoverageReaders.
This is the base manager that interacts with a StructuredGridCoverageReader
via REST
calls.
Below you can find its constructor. The parameters are pretty much self-explaining.
public GeoServerRESTStructuredGridCoverageReaderManager(URL restURL, String username, String pw);
Here below an example of initialization to talk to aloca instance of GeoServer.
String RESTURL = "http://localhost:8080/geoserver";
String RESTUSER = "admin";
String RESTPW = "geoserver";
GeoServerRESTStructuredGridCoverageReaderManager manager =
new GeoServerRESTStructuredGridCoverageReaderManager(new URL(RESTURL), RESTUSER, RESTPW);
We are now going to provide samples for the common operations to be performed when interacting with a StructuredGridCoverageReader using a GeoServerRESTStructuredGridCoverageReaderManager.
It is possible to upload a Zip file containing the configuration for the mosaic together with at least 1 branule (internal or external to the Zip itself) via the GeoServerRESTStructuredGridCoverageReaderManager (for more info you can check the GeoServer documentation).
The following does an upload of a Zip file to create a mosaic for a certain number of GeoTiff files.
boolean create=manager.create("it.geosolutions", "mosaic","/path/to/mosaic.zip"));
The method returns true
when it succeeds and false
otherwise.
To get access to the Index Schema for a certain StructuredCoverage, the following method can be used:
RESTStructuredCoverageIndexSchema indexFormat = manager.getGranuleIndexSchema("myWorkspace", "myCoverageStore", "myCoverage");
This is a sample XML REST schema representation for a certain index schema:
<Schema>
<attributes>
<Attribute>
<name>the_geom</name>
<minOccurs>0</minOccurs>
<maxOccurs>1</maxOccurs>
<nillable>true</nillable>
<binding>com.vividsolutions.jts.geom.Polygon</binding>
</Attribute>
<Attribute>
<name>location</name>
<minOccurs>0</minOccurs>
<maxOccurs>1</maxOccurs>
<nillable>true</nillable>
<binding>java.lang.String</binding>
</Attribute>
<Attribute>
<name>imageindex</name>
<minOccurs>0</minOccurs>
<maxOccurs>1</maxOccurs>
<nillable>true</nillable>
<binding>java.lang.Integer</binding>
</Attribute>
<Attribute>
<name>time</name>
<minOccurs>0</minOccurs>
<maxOccurs>1</maxOccurs>
<nillable>true</nillable>
<binding>java.sql.Timestamp</binding>
</Attribute>
<Attribute>
<name>elevation</name>
<minOccurs>0</minOccurs>
<maxOccurs>1</maxOccurs>
<nillable>true</nillable>
<binding>java.lang.Double</binding>
</Attribute>
<Attribute>
<name>fileDate</name>
<minOccurs>0</minOccurs>
<maxOccurs>1</maxOccurs>
<nillable>true</nillable>
<binding>java.sql.Timestamp</binding>
</Attribute>
<Attribute>
<name>updated</name>
<minOccurs>0</minOccurs>
<maxOccurs>1</maxOccurs>
<nillable>true</nillable>
<binding>java.sql.Timestamp</binding>
</Attribute>
</attributes>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/myWorkspace/coveragestores/myCoverageStore/coverages/myCoverage/index/granules.xml" type="application/xml"/>
</Schema>
To add a granule to an existing coverage store which refers to an ImageMosaic you need to do the following:
boolean added = manager.createOrHarvestExternal("it.geosolutions", "myCoverageStore", "imagemosaic", "/data/newSampleFile.nc");
To get all granules from myCoverage:
RESTStructuredCoverageGranulesList granulesList = manager.getGranules("myWorkspace", "myCoverageStore", "myCoverage", null, null, null);
To get only 10 granules from myCoverage, starting from an offset of 20:
RESTStructuredCoverageGranulesList granulesList = manager.getGranules("myWorkspace", "myCoverageStore", "myCoverage", null, 20, 10);
To get only the granules from myCoverage, having depth = 100 and time = 20081101T0000000:
RESTStructuredCoverageGranulesList granulesList = manager.getGranules("myWorkspace", "myCoverageStore", "myCoverage", "depth = 100 AND time='20081101T0000000'", null, null);
To get a granule by ID (as an instance 43):
RESTStructuredCoverageGranulesList granulesList = manager.getGranuleById("myWorkspace", "myCoverageStore", "myCoverage", "43");
To remove all granules from myCoverage, related to file having location = /data/sampleFile.tif, using a CQL filter.
final String fileLocation = "/data/sampleFile.tif";
boolean result = manager.removeGranulesByCQL("myWorkspace", "myCoverageStore", "myCoverage", "location = '" + fileLocation + "'");
To remove a specific granule from myCoverage, specified by ID (as an instance 43).
boolean result = manager.removeGranuleById("myWorkspace", "myCoverageStore", "myCoverage", "43");
Basic operations may be also performed through existing Reader and Publishers classes.
public GeoServerRESTReader(URL restURL, String username, String pw);
String RESTURL = "http://localhost:8080/geoserver";
String RESTUSER = "admin";
String RESTPW = "geoserver";
GeoServerRESTReader reader = new GeoServerRESTReader(RESTURL, RESTUSER, RESTPW);
To get a StructuredCoverage Index Schema:
RESTStructuredCoverageIndexSchema indexFormat = reader.getGranuleIndexSchema("myWorkspace", "myCoverageStore", "myCoverage");
To get only the 10 granules from myCoverage, having depth = 100 and time = 20081101T0000000, starting from offset 20:
RESTStructuredCoverageGranulesList granulesList = reader.getGranules("myWorkspace", "myCoverageStore", "myCoverage", "depth = 100 AND time='20081101T0000000'", 20, 10);
public GeoServerRESTPublisher(URL restURL, String username, String pw);
String RESTURL = "http://localhost:8080/geoserver";
String RESTUSER = "admin";
String RESTPW = "geoserver";
GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(RESTURL, RESTUSER, RESTPW);
To add a granule to myCoverageStore which refers to an ImageMosaic:
boolean added = publisher.createOrHarvestExternal("it.geosolutions", "myCoverageStore", "imagemosaic", "/data/newSampleFile.nc");
To remove all granules from myCoverage, related to file having location = /data/sampleFile.tif, using a CQL filter.
final String fileLocation = "/data/sampleFile.tif";
boolean result = publisher.removeGranulesByCQL("myWorkspace", "myCoverageStore", "myCoverage", "location = '" + fileLocation + "'");
To remove a specific granule from myCoverage, specified by ID (as an instance 43).
boolean result = publisher.removeGranuleById("myWorkspace", "myCoverageStore", "myCoverage", "43");