Beispiel #1
0
 /**
  * Convert the geometry to geohash.
  * @return string the geohash or null when the $geometry is not a Point
  * @param Point $geometry
  * @see GeoAdapter::write()
  */
 public function write(Geometry $geometry, $precision = NULL)
 {
     if ($geometry->isEmpty()) {
         return '';
     }
     if ($geometry->geometryType() === 'Point') {
         return $this->encodePoint($geometry, $precision);
     } else {
         // The geohash is the hash grid ID that fits the envelope
         $envelope = $geometry->envelope();
         $geohashes = array();
         $geohash = '';
         foreach ($envelope->getPoints() as $point) {
             $geohashes[] = $this->encodePoint($point, 1.0E-7);
         }
         $i = 0;
         while ($i < strlen($geohashes[0])) {
             $char = $geohashes[0][$i];
             foreach ($geohashes as $hash) {
                 if ($hash[$i] != $char) {
                     return $geohash;
                 }
             }
             $geohash .= $char;
             $i++;
         }
         return $geohash;
     }
 }
Beispiel #2
0
 /**
  * Serialize geometries into a GPX string.
  *
  * @param Geometry $geometry
  *
  * @return string The GPX string representation of the input geometries
  */
 public function write(Geometry $geometry, $namespace = FALSE)
 {
     if ($geometry->isEmpty()) {
         return NULL;
     }
     if ($namespace) {
         $this->namespace = $namespace;
         $this->nss = $namespace . ':';
     }
     return '<' . $this->nss . 'gpx creator="geoPHP" version="1.0">' . $this->geometryToGPX($geometry) . '</' . $this->nss . 'gpx>';
 }
Beispiel #3
0
 /**
  * Serialize geometries into a WKT string.
  *
  * @param Geometry $geometry
  *
  * @return string The WKT string representation of the input geometries
  */
 public function write(Geometry $geometry)
 {
     // If geos is installed, then we take a shortcut and let it write the WKT
     if (GeoPHP::geosInstalled()) {
         $writer = new GEOSWKTWriter();
         $writer->setTrim(TRUE);
         return $writer->write($geometry->geos());
     }
     if ($geometry->isEmpty()) {
         return strtoupper($geometry->geometryType()) . ' EMPTY';
     } else {
         if ($data = $this->extractData($geometry)) {
             return strtoupper($geometry->geometryType()) . ' (' . $data . ')';
         }
     }
 }