示例#1
0
 /**
  * Given an object or a string, return a Geometry
  *
  * @param mixed $input The GeoJSON string or object
  *
  * @return object Geometry
  */
 public function read($input)
 {
     if (is_string($input)) {
         $input = json_decode($input);
     }
     if (!is_object($input)) {
         throw new FOX_exception(array('numeric' => 1, 'text' => "Invalid input parameter. Must be an object.", 'data' => $input, 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => null));
     }
     if (!is_string($input->type)) {
         throw new FOX_exception(array('numeric' => 2, 'text' => "Invalid input parameter 'type' specifier. Must be a string.", 'data' => $input, 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => null));
     }
     // Check to see if it's a FeatureCollection
     if ($input->type == 'FeatureCollection') {
         $geoms = array();
         foreach ($input->features as $feature) {
             $geoms[] = $this->read($feature);
         }
         return FOX_geo::geometryReduce($geoms);
     }
     // Check to see if it's a Feature
     if ($input->type == 'Feature') {
         return $this->read($input->geometry);
     }
     // It's a geometry - process it
     return $this->objToGeom($input);
 }
示例#2
0
 public function geomFromXML()
 {
     $geometries = array();
     $geometries = array_merge($geometries, $this->parseWaypoints());
     $geometries = array_merge($geometries, $this->parseTracks());
     $geometries = array_merge($geometries, $this->parseRoutes());
     if (empty($geometries)) {
         throw new FOX_exception(array('numeric' => 1, 'text' => "Invalid GPX data string", 'data' => $geometries, 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => null));
     }
     return FOX_geo::geometryReduce($geometries);
 }
示例#3
0
 public function geomFromXML()
 {
     $geometries = array();
     $geometries = array_merge($geometries, $this->parsePoints());
     $geometries = array_merge($geometries, $this->parseLines());
     $geometries = array_merge($geometries, $this->parsePolygons());
     $geometries = array_merge($geometries, $this->parseBoxes());
     $geometries = array_merge($geometries, $this->parseCircles());
     if (empty($geometries)) {
         throw new FOX_exception(array('numeric' => 1, 'text' => "Invalid or empty GeoRSS data", 'data' => $geometries, 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => null));
     }
     return FOX_geo::geometryReduce($geometries);
 }
示例#4
0
 public function geomFromXML()
 {
     $geometries = array();
     $geom_types = FOX_geo::geometryList();
     $placemark_elements = $this->xmlobj->getElementsByTagName('placemark');
     if ($placemark_elements->length) {
         foreach ($placemark_elements as $placemark) {
             foreach ($placemark->childNodes as $child) {
                 // Node names are all the same, except for MultiGeometry, which maps to GeometryCollection
                 if ($child->nodeName == 'multigeometry') {
                     $node_name = 'geometrycollection';
                 } else {
                     $node_name = $child->nodeName;
                 }
                 if (array_key_exists($node_name, $geom_types)) {
                     $function = 'parse' . $geom_types[$node_name];
                     $geometries[] = $this->{$function}($child);
                 }
             }
         }
     } else {
         // The document does not have a placemark, try to create a valid geometry from the root element
         if ($this->xmlobj->documentElement->nodeName == 'multigeometry') {
             $node_name = 'geometrycollection';
         } else {
             $node_name = $this->xmlobj->documentElement->nodeName;
         }
         if (array_key_exists($node_name, $geom_types)) {
             $function = 'parse' . $geom_types[$node_name];
             $geometries[] = $this->{$function}($this->xmlobj->documentElement);
         }
     }
     return FOX_geo::geometryReduce($geometries);
 }
示例#5
0
 public function boundary()
 {
     if ($this->isEmpty()) {
         return new LineString();
     }
     if ($this->geos()) {
         return $this->geos()->boundary();
     }
     $components_boundaries = array();
     foreach ($this->components as $component) {
         $components_boundaries[] = $component->boundary();
     }
     return FOX_geo::geometryReduce($components_boundaries);
 }