To create a GeoServer client use the GeoServer::build method.
It will give you back a configured client instance.
As of now the client can handle 1 workspace at time by design.
use OneOffTech\GeoServer\GeoServer;
use OneOffTech\GeoServer\Auth\Authentication;
/**
* Geoserver URL
*/
$url = 'http://localhost:8600/geoserver/';
/**
* Define a workspace to use
*/
$workspace = 'your-workspace';
$authentication = new Authentication('geoserver_user', 'geoserver_password');
$geoserver = GeoServer::build($url, $workspace, $authentication);Once you have a client instance, you can verify the GeoServer version number using version()
// assuming to have a GeoServer instance in the $geoserver variable
$version = $geoserver->version();
// => 2.13.0The client can create the configured workspace if not available.
To do so call createWorkspace():
$workspace = $geoserver->createWorkspace();
// => \OneOffTech\GeoServer\Models\WorkspaceIn case the creation goes well or the workspace already exists, a Workspace instance is returned.
The workspace() method retrieve the details of the configured workspace
$workspace = $geoserver->workspace();
// => \OneOffTech\GeoServer\Models\WorkspaceA datastore is a container of vector data. A workspace can have multiple data stores.
You can retrieve all defined datastores using the datastores() method:
$datastores = $geoserver->datastores();
// => array of \OneOffTech\GeoServer\Models\DataStoreOr retrieve a datastores by name:
$datastore = $geoserver->datastore($name);
// => \OneOffTech\GeoServer\Models\DataStoreYou cal also delete a data store via:
$result = $geoserver->deleteDatastore($name);
// => true || falseA coveragestore is a container of raster data. A workspace can have multiple coverage stores.
You can retrieve all defined coverage stores using the coveragestores() method:
$coveragestores = $geoserver->coveragestores();
// => array of \OneOffTech\GeoServer\Models\CoverageStoreOr retrieve a coveragestores by name:
$coveragestore = $geoserver->coveragestore($name);
// => \OneOffTech\GeoServer\Models\CoverageStoreYou cal also delete a coverage store via:
$result = $geoserver->deleteCoveragestore($name);
// => true || falseUploading a file to a GeoServer instance is done via the upload method.
The client recognizes the format and create a correct store type, e.g. shapefiles lead to a
datastore creation. To do so the file path must be wrapped in a GeoFile object.
See Supported files for knowing what the library can handle
use OneOffTech\GeoServer\GeoFile;
$file = GeoFile::load('path/to/shapefile.shp');
// => OneOffTech\GeoServer\GeoFile{
// + mimeType
// + extension
// + format
// + type
// + name
// + originalName
// }
// it will throw OneOffTech\GeoServer\Exception\UnsupportedFileException in case the file cannot be recognizedFrom a GeoFile instance the file mimeType, format and type (vector or raster, OneOffTech\GeoServer\GeoType) can be discovered.
The format is used to specify the content of the file, as in some cases Geographic files do not have a standard mime type.
For example a Shapefile mime type is application/octet-stream, which means a binary file.
The originalName attribute contains the original filename. By default originalName and name are equals,
but the name can be changed, by using the name($value) method. The name will be used as the store name inside GeoServer.
Once obtained a GeoFile instance, the method upload() can be used to really upload the file to the GeoServer:
use OneOffTech\GeoServer\GeoFile;
$file = GeoFile::load('path/to/shapefile.shp');
$feature = $geoserver->upload($file);
// OneOffTech\GeoServer\Models\ResourceFor file character encoding please refer to File Character Encoding
Once uploaded, the return value will be an instance of the OneOffTech\GeoServer\Models\Resource.
It contains the details extracted by the GeoServer, like the bounding box.
OneOffTech\GeoServer\Models\Resource has two sub-classes:
OneOffTech\GeoServer\Models\FeatureA feature type is a vector based spatial resource or data set that originates from a data storeOneOffTech\GeoServer\Models\CoverageA coverage is a raster data set which originates from a coverage store.
As a helper method, given a GeoFile instance, is possible to verify that a corresponding Feature or Coverage is present.
use OneOffTech\GeoServer\GeoFile;
$file = GeoFile::load('path/to/shapefile.shp');
$exists = $geoserver->exist($file);
// true || falseThe identification currently uses the name assigned to the GeoFile
As a helper method, given a GeoFile instance, is possible to delete the corresponding Feature or Coverage in the Geoserver.
use OneOffTech\GeoServer\GeoFile;
$file = GeoFile::load('path/to/shapefile.shp');
$removed = $geoserver->remove($file);
// true || falseThe identification currently uses the name assigned to the GeoFile
The client can upload, retrieve and delete styles defined within the configured workspace
To upload a style, a StyleFile instance representing the file on disk is required.
Once the instance is obtained use the uploadStyle method on a GeoServer client instance.
The style will be uploaded as part of the workspace styles.
use OneOffTech\GeoServer\StyleFile;
$file = StyleFile::from('/path/to/style.sld');
// => OneOffTech\GeoServer\StyleFile{
// + name
// + originalName
// + mimeType
// + extension
// }
// it will throw OneOffTech\GeoServer\Exception\UnsupportedFileException in case the file cannot be recognized
// You can change the style name before uploading it to avoid collision. By default the filename will be used.
$file->name('my_custom_style');
$style = $geoserver->uploadStyle($file);
// => OneOffTech\GeoServer\Models\StyleThe client let you retrieve a style by its name
$style = $geoserver->style('style_name');
// => OneOffTech\GeoServer\Models\StyleThe name must be equal to the one given for the upload. It might not be the file name
You can also retrieve all styles defined in the workspace
$styles = $geoserver->styles();
// => array of OneOffTech\GeoServer\Models\StyleStyle removal is performed by giving the style name to the removeStyle method.
The method will return the details of the deleted style.
$style = $geoserver->removeStyle('style_name');
// => OneOffTech\GeoServer\Models\Stylethe
$style->existsattribute will be set tofalseafter deletion