예제 #1
0
 public function testToString()
 {
     $decoder = new Symm\Gisconverter\Decoders\WKT();
     $geom = $decoder->geomFromText('POINT(10 10)');
     $this->assertEquals($geom->toWKT(), (string) $geom);
     $geom = $decoder->geomFromText(' POINT  ( 10  10 ) ');
     $this->assertEquals($geom->toWKT(), (string) $geom);
 }
예제 #2
0
 public function validate_wkt($value)
 {
     if (empty($value)) {
         return TRUE;
     }
     if (!is_string($value)) {
         return FALSE;
     }
     $decoder = new Symm\Gisconverter\Decoders\WKT();
     try {
         $decoder->geomFromText($value);
     } catch (Symm\Gisconverter\Exceptions\InvalidText $itex) {
         return FALSE;
     }
     return TRUE;
 }
예제 #3
0
 /**
  * Handles getting of column
  * Overriding this method to handle WKT Geometry value
  *
  * @param   string $column Column name
  * @throws Kohana_Exception
  * @return mixed
  */
 public function get($column)
 {
     // Decode WKT value
     if (array_key_exists($column, $this->_object) and $column == 'value' and is_string($this->_object[$column])) {
         $decoder = new Symm\Gisconverter\Decoders\WKT();
         try {
             $geometry = $decoder->geomFromText($this->_object[$column]);
             if ($geometry instanceof Symm\Gisconverter\Geometry\Point) {
                 return array('lon' => $geometry->lon, 'lat' => $geometry->lat);
             }
         } catch (Symm\Gisconverter\Exceptions\InvalidText $itex) {
             // noop - continue to return raw value
         }
         // continue to return raw value
     }
     return parent::get($column);
 }
예제 #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;