예제 #1
0
 public static function getBody($dataObj)
 {
     $kml = KMLFormatter::getBody($dataObj);
     return Gisconverter::kmlToWkt($kml);
 }
예제 #2
0
 public static function getBody($dataObj)
 {
     // Get the KML and transform it to GeoJSON
     $kml = KMLFormatter::getBody($dataObj);
     return Gisconverter::kmlToWkt($kml);
 }
예제 #3
0
 /**
  * gets segment by segmentStopElevation
  *
  * @param PDO $pdo pointer to PDO connection
  * @param int $segmentStopElevation stop elevation to trail-search for
  * @return mixed segment found or null if not found
  * @throws PDOException when mySQL related errors occur
  * @throws RangeException when range is invalid
  * @throws Exception for other exception
  */
 public static function getSegmentBySegmentStopElevation(PDO &$pdo, $segmentStopElevation)
 {
     //sanitize the int before searching
     try {
         $segmentStopElevation = Filter::filterInt($segmentStopElevation, "segment stop", false);
     } catch (InvalidArgumentException $invalidArgument) {
         throw new PDOException($invalidArgument->getMessage(), 0, $invalidArgument);
     } catch (RangeException $range) {
         throw new RangeException($range->getMessage(), 0, $range);
     } catch (Exception $exception) {
         throw new Exception($exception->getMessage(), 0, $exception);
     }
     //create query template
     $query = "SELECT segmentId, ST_AsWKT(segmentStop) AS segmentStop, ST_AsWKT(segmentStart) AS segmentStart, segmentStartElevation, segmentStopElevation FROM segment WHERE segmentStopElevation = :segmentStopElevation";
     $statement = $pdo->prepare($query);
     //binds segmentStopElevation to placeholder
     $parameters = array("segmentStopElevation" => $segmentStopElevation);
     $statement->execute($parameters);
     //build an array of segments
     $segments = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $segmentStartJSON = Gisconverter::wktToGeojson($row["segmentStart"]);
             $segmentStopJSON = Gisconverter::wktToGeojson($row["segmentStop"]);
             $segmentStartGenericObject = json_decode($segmentStartJSON);
             $segmentStopGenericObject = json_decode($segmentStopJSON);
             $segmentStart = new Point($segmentStartGenericObject->coordinates[0], $segmentStartGenericObject->coordinates[1]);
             $segmentStop = new Point($segmentStopGenericObject->coordinates[0], $segmentStopGenericObject->coordinates[1]);
             $segment = new Segment($row["segmentId"], $segmentStart, $segmentStop, $row["segmentStartElevation"], $row["segmentStopElevation"]);
             $segments[$segments->key()] = $segment;
             $segments->next();
         } catch (Exception $e) {
             //if the row couldn't be converter, rethrow it
             throw new PDOException($e->getMessage(), 0, $e);
         }
     }
     return $segments;
 }
예제 #4
0
#!/usr/bin/php
<?php 
require_once 'vendor/autoload.php';
use Symm\Gisconverter\Gisconverter;
$decoder = new Symm\Gisconverter\Decoders\WKT();
$geometry = $decoder->geomFromText('MULTIPOLYGON(((10 10,10 20,20 20,20 15,10 10)))');
# create a geometry from a given string input
print $geometry->toGeoJSON();
# output geometry in GeoJSON format
print PHP_EOL . PHP_EOL;
print $geometry->toKML();
# output geometry in KML format
print PHP_EOL . PHP_EOL;
#ok, you get the idea. Now, let's use helper functions
print Gisconverter::geojsonToKml('{"type":"LinearRing","coordinates":[[3.5,5.6],[4.8,10.5],[10,10],[3.5,5.6]]}');
print PHP_EOL . PHP_EOL;
print Gisconverter::geojsonToWkt('{"type":"LinearRing","coordinates":[[3.5,5.6],[4.8,10.5],[10,10],[3.5,5.6]]}');
print PHP_EOL . PHP_EOL;
print Gisconverter::kmlToWkt('<Polygon><outerBoundaryIs><LinearRing><coordinates>10,10 10,20 20,20 20,15 10,10</coordinates></LinearRing></outerBoundaryIs></Polygon>');
print PHP_EOL . PHP_EOL;
print Gisconverter::kmlToGeojson('<Polygon><outerBoundaryIs><LinearRing><coordinates>10,10 10,20 20,20 20,15 10,10</coordinates></LinearRing></outerBoundaryIs></Polygon>');
print PHP_EOL . PHP_EOL;
print Gisconverter::kmlToGpx('<LineString><coordinates>3.5,5.6 4.8,10.5 10,10</coordinates></LineString>');
print PHP_EOL . PHP_EOL;