Example #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(FOX_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;
     }
 }
Example #2
0
 /**
  * Serialize geometries into a WKT string.
  *
  * @param Geometry $geometry
  *
  * @return string The WKT string representation of the input geometries
  */
 public function write(FOX_geometry $geometry)
 {
     // If geos is installed, then we take a shortcut and let it write the WKT
     if (FOX_geo::geosInstalled()) {
         $writer = new GEOSWKTWriter();
         $writer->setTrim(true);
         return $writer->write($geometry->geos());
     }
     if ($geometry->isEmpty()) {
         return strtoupper($geometry->geometryType()) . ' EMPTY';
     } else {
         $data = $this->extractData($geometry);
         if ($data) {
             return strtoupper($geometry->geometryType()) . ' (' . $data . ')';
         } else {
             return null;
         }
     }
 }