PHP code example of lowem / geoserver-php

1. Go to this page and download the library: Download lowem/geoserver-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lowem / geoserver-php example snippets


composer 


use Lowem\GeoserverPHP\Workspaces;
use Lowem\GeoserverPHP\CoverageStores;

      $workspace = new Workspaces("http://192.168.160.137:8080/geoserver");
      $workspace->setBasicAuth("admin", "geoserver");
      $result = "";
      try {
        $result = $workspace->getAll();
      } catch (HTTPRequestException $e) {
        echo $e->getCustomMessage();
      }
      print_r($result);
      

      $workspace = new Workspaces("http://192.168.160.137:8080/geoserver");
      $workspace->setBasicAuth("admin", "geoserver");
      try {
        $workspace->create("Test1");
      } catch (HTTPRequestException $e) {
      echo $e->getCustomMessage();
      }
      

      $workspace = new Workspaces("http://192.168.160.137:8080/geoserver");
      $workspace->setBasicAuth("admin", "geoserver");
      $result = "";
      try {
        $result = $workspace->get("Test1");
      } catch (HTTPRequestException $e) {
        echo $e->getCustomMessage();
      }
      print_r($result);
      

      $workspace = new Workspaces("http://192.168.160.137:8080/geoserver");
      $workspace->setBasicAuth("admin", "geoserver");
      try {
        $workspace->update("Test1", "Test12");
      } catch (HTTPRequestException $e) {
        echo $e->getCustomMessage();
      }
      

      $workspace = new Workspaces("http://192.168.160.137:8080");
      $workspace->setBasicAuth("admin", "geoserver");
      try {
        $workspace->delete("Test12", TRUE);
      } catch (HTTPRequestException $e) {
        echo $e->getCustomMessage();
      }
      

      $coverageStore = new CoverageStores("http://192.168.160.137:8080/geoserver");
      $coverageStore->setBasicAuth("admin", "geoserver");
      $result = "";
      try {
        $result = $coverageStore->getAll("World_Claim");
      } catch (HTTPRequestException $e) {
        echo $e->getCustomMessage();
      }
      print_r($result);
      

      $coverageStore = new CoverageStores("http://192.168.160.137:8080/geoserver");
      $coverageStore->setBasicAuth("admin", "geoserver");
      try {
        $coverageStore->create([
          "name" => "TestCoverStore2",
          "description" => "This is a test store",
          "workspace" => "Test1",
          "enabled" => "true",
          "type" => "GeoTIFF"
        ]);
      } catch (HTTPRequestException $e) {
        echo $e->getCustomMessage();
      }
      

      $coverageStore = new CoverageStores("http://192.168.160.137:8080/geoserver");
      $coverageStore->setBasicAuth("admin", "geoserver");
      $result = "";
      try {
        $result = $coverageStore->get("Test1", "TestCoverStore2");
      } catch (HTTPRequestException $e) {
        echo $e->getCustomMessage();
      }
      print_r($result);
      

      $coverageStore = new CoverageStores("http://192.168.160.137:8080/geoserver");
      $coverageStore->setBasicAuth("admin", "geoserver");
      try {
        $coverageStore->update("Test1", "TestCoverStore2", [
          "name" => "TestCover"
        ]);
      } catch (HTTPRequestException $e) {
        echo $e->getCustomMessage();
      }
      

      $coverageStore = new CoverageStores("http://192.168.160.137:8080/geoserver");
      $coverageStore->setBasicAuth("admin", "geoserver");
      try {
        $coverageStore->geoTiffUpload("Test1", "test10", "C:\Users\LoweM\Downloads\wc2.1_2.5m_prec_2010-2018\wc2.1_2.5m_prec_2010-03.tif");
      } catch (HTTPRequestException $e) {
        echo $e->getCustomMessage();
      }
      

      $dataStore = new DataStores($this->baseURL);
      $dataStore->setBasicAuth("admin", "geoserver");
      try {
        $dataStore->shapeFileUpload("acme", "nyc_roads5", "/Users/LoweM/Downloads/nyc_roads.zip");
      } catch (HTTPRequestException $e) {
        echo $e->getCustomMessage();
      }