Difference between revisions of "GIS Interface"
(→GeoNetwork and GIS Metadata) |
(→Publish API) |
||
Line 81: | Line 81: | ||
To modify both data and metadata registered in the '''SDI''', one should use the instance methods exposed by the class ''GISInterface''. This grants the client a complete interaction with both '''GeoServer''' and '''GeoNetwork''' servers, assuring consistency between data and metadata. | To modify both data and metadata registered in the '''SDI''', one should use the instance methods exposed by the class ''GISInterface''. This grants the client a complete interaction with both '''GeoServer''' and '''GeoNetwork''' servers, assuring consistency between data and metadata. | ||
The following code shows how to publish a layer from a table already created on a postgis database. | The following code shows how to publish a layer from a table already created on a postgis database. | ||
− | Please note that the Database must already registered onto the '''GeoServer''' instance as a store inside the workspace the user is willing to publish the layer into. | + | Please note that the Database must already be registered onto the '''GeoServer''' instance as a store inside the workspace the user is willing to publish the layer into. |
<source lang="java"> | <source lang="java"> | ||
Line 97: | Line 97: | ||
String workspace="..."; | String workspace="..."; | ||
− | + | //Setup geoserver publishing parameters | |
GSFeatureTypeEncoder fte=new GSFeatureTypeEncoder(); | GSFeatureTypeEncoder fte=new GSFeatureTypeEncoder(); | ||
fte.setEnabled(true); | fte.setEnabled(true); | ||
Line 108: | Line 108: | ||
le.setEnabled(true); | le.setEnabled(true); | ||
− | // | + | //GCubeISOMetadata class belongs to org.gcube.spatial.data.geonetwork. Please refer to metadata generation in this page for further information |
+ | //Generate metadata for the layer to be published | ||
ScopeProvider.instance.set(scope); | ScopeProvider.instance.set(scope); | ||
− | GcubeISOMetadata meta=... | + | GcubeISOMetadata meta=new GcubeISOMetadata(); |
+ | meta.set.. | ||
+ | ... | ||
Line 121: | Line 124: | ||
We decided not to override some parameter classes like ''GSLayerEncoder'' and ''GSFeatureTypeEncoder''. So please refer to the ''geoserver-manager'' library's official documentation. | We decided not to override some parameter classes like ''GSLayerEncoder'' and ''GSFeatureTypeEncoder''. So please refer to the ''geoserver-manager'' library's official documentation. | ||
− | === | + | ===Metadata generation and publishing=== |
Publishing of GIS metadata is made using ''org.gcube.spatial.data.geonetwork'' library. The library exposes facilities to help developers define layers metadata compliant with gCube SDI policies, especially the class ''org.gcube.spatial.data.geonetwork.iso.GcubeISOMetadata''. Please refer to [[GeoNetwork library]] for further details. | Publishing of GIS metadata is made using ''org.gcube.spatial.data.geonetwork'' library. The library exposes facilities to help developers define layers metadata compliant with gCube SDI policies, especially the class ''org.gcube.spatial.data.geonetwork.iso.GcubeISOMetadata''. Please refer to [[GeoNetwork library]] for further details. | ||
Revision as of 15:34, 14 July 2016
The GIS-Interface is a java library which exposes methods to access / modify spatial data and related metadata. The library is designed to rely on GeoNetwork and GeoServer registered in the infrastructure.
The library relies on org.gcube.spatial-data.geonetwork (see GeoNetwork library) to interact with geonetwork. Interaction with GeoServer REST interface is based on functionalities exposed by geoserver-manager, developed by GeoSolutions under MIT License.
Contents
The library
The library is a maven artifact with the following coordinates :
<groupId>org.gcube.spatial.data</groupId> <artifactId>gis-interface</artifactId>
It relies on the GeoNetwork library for the interaction with GeoNetwork servers, and exploits functionalities implemented by geosolution's library :
<groupId>it.geosolutions</groupId> <artifactId>geoserver-manager</artifactId> <version>1.5.2</version>
It basically :
- Interacts with the infrastructure's IS to gather access information to both GeoServer and GeoNetwork instance(s)
- Wraps geoserver-manager functionalities for accessing/modifying data on a given Geoserver instance,
- Implements high level logic by coordinating publication of both data and metadata on the Spatial Data Infrastructure in the current scope.
The offered functionalities are accessible by instatiating the org.gcube.spatial.data.gis.GISInterface java class, via its static method
public static GISInterface get() throws Exception
Interaction with the Spatial Data Infrastructure
The library relies on the interfaces inside the package it.geosolutions.geoserver.rest to interact with the REST interface of a given GeoServer instance. While GET methods are offered to clients just by letting them access an instance of GeoServerRESTReader class, PUT (for creating, modifying and deleting purposes) methods are redefined and offered by the class GISInterface. This lets the library coordinate the modification of both data/metadata thus granting consistency inside the SDI.
GeoServer Discovery
gCube SDI storage facilities enables the use of multiple GeoServer instances. Each of these instances must be registered in the IS as ServiceEndpoint with category Gis and platform name GeoServer.
Using the library
Functionalities of this library can be exploited using org.gcube.spatial.data.gis.GISInterface instance methods. To obtain instances of this class use the static method public static GISInterface get().
Read API
GeoServerRESTReader
To access and read data from a GeoServer instance, one needs to get an instance of it.geosolutions.geoserver.rest.GeoServerRESTReader in one of the following ways :
//Use the most unload GeoServer from infrastructure, after refreshing cached list GISInterface.get().getGeoServerReader(ResearchMethod.MOSTUNLOAD, true); //Get Access to a particular GeoServer instance GISInterface.get().getGeoServerReader("url","user","password"); //Get Access to a particular GeoServer instance without authentication GISInterface.get().getGeoServerReader("url");
GeoServerDescriptor
Information on the available GeoServer instances in the current scope are mapped in GeoServerDescriptor beans that can be obtained with the following methods :
//Get full ordered set of available GeoServers GISInterface.get().getGeoServerDescriptorSet(boolean forceRefresh) //Get current selected GeoServer GISInterface.get().getCurrentGeoServerDescriptor()
Publish API
To modify both data and metadata registered in the SDI, one should use the instance methods exposed by the class GISInterface. This grants the client a complete interaction with both GeoServer and GeoNetwork servers, assuring consistency between data and metadata. The following code shows how to publish a layer from a table already created on a postgis database. Please note that the Database must already be registered onto the GeoServer instance as a store inside the workspace the user is willing to publish the layer into.
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder; import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder; ... String scope="..."; String toPublishTable="..."; String datastore="..."; String defaultStyle="..."; String workspace="..."; //Setup geoserver publishing parameters GSFeatureTypeEncoder fte=new GSFeatureTypeEncoder(); fte.setEnabled(true); fte.setLatLonBoundingBox(-180.0, -90.0, 180.0, 90.0, crs); fte.setName(toPublishTable); fte.setNativeCRS(crs); GSLayerEncoder le=new GSLayerEncoder(); le.setDefaultStyle(defaultStyle); le.setEnabled(true); //GCubeISOMetadata class belongs to org.gcube.spatial.data.geonetwork. Please refer to metadata generation in this page for further information //Generate metadata for the layer to be published ScopeProvider.instance.set(scope); GcubeISOMetadata meta=new GcubeISOMetadata(); meta.set.. ... GISInterface gis=GISInterface.get(); PublishResponse resp=gis.publishDBTable(workspace, datastore, fte, le, meta.getMetadata(), "datasets", "_none_", LoginLevel.DEFAULT);
GS Parameters
We decided not to override some parameter classes like GSLayerEncoder and GSFeatureTypeEncoder. So please refer to the geoserver-manager library's official documentation.
Metadata generation and publishing
Publishing of GIS metadata is made using org.gcube.spatial.data.geonetwork library. The library exposes facilities to help developers define layers metadata compliant with gCube SDI policies, especially the class org.gcube.spatial.data.geonetwork.iso.GcubeISOMetadata. Please refer to GeoNetwork library for further details.
Report classes
The results, status and contingent error messages of modifying operations are wrapped into the classes org.gcube.spatial.data.gis.model.report.PublishResponse and org.gcube.spatial.data.gis.model.report.DeleteReponse, both extending org.gcube.spatial.data.gis.model.report.Report class. Please refere to their javadoc pages for further information.