public function createPolygon(UserPolygon $neighborhood, $polygonGeoJson)
 {
     $polygonArray = \Zend\Json\Json::decode($polygonGeoJson, \Zend\Json\Json::TYPE_ARRAY);
     $lineStringArray = $polygonArray['geometry']['coordinates'];
     $ring = array();
     foreach ($lineStringArray as $lineString) {
         foreach ($lineString as $point) {
             $ring[] = new Point($point[0], $point[1]);
         }
     }
     $myLineString = new LineString($ring);
     $myLineString->close();
     $neighborhood->setPolygon(new Polygon($rings = array($myLineString)));
 }
 public function getPolygon()
 {
     $filename = $this->filename;
     if (!file_exists($filename)) {
         throw new \InvalidArgumentException("{$filename} does not exist");
     }
     $jsonStr = file_get_contents($filename);
     $json = \Zend\Json\Json::decode($jsonStr);
     $counter = 1;
     $points = array();
     foreach ($json->features[0]->geometry->coordinates[0] as $point) {
         $lat = $point[1];
         $lng = $point[0];
         $points[] = new Point($lat, $lng);
     }
     $lineString = new LineString($points);
     $lineString->close();
     return new Polygon(array($lineString));
 }
 public function getPolygon()
 {
     $filename = $this->file;
     if (!file_exists($filename)) {
         throw new \InvalidArgumentException("{$filename} does not exist");
     }
     if ($this->getRegion() == null) {
         throw new \InvalidArgumentException("region must be defined");
     }
     if ($this->getWhathoodUser() == null) {
         throw new \InvalidArguementException("user must be defined");
     }
     $jsonStr = file_get_contents($filename);
     $whathoodUser = $this->getWhathoodUser();
     $json = \Zend\Json\Json::decode($jsonStr);
     $neighborhoods = array();
     $counter = 1;
     foreach ($json->kml->Document->Folder->Placemark as $n) {
         $name = $n->ExtendedData->SchemaData->SimpleData[2]->{'#text'};
         $coordinateString = $n->Polygon->outerBoundaryIs->LinearRing->coordinates;
         $array = explode(' ', $coordinateString);
         $neighborhood = new Neighborhood();
         $neighborhood->setName($name);
         $neighborhood->setRegion($this->getRegion());
         $points = array();
         foreach ($array as $point) {
             list($lng, $lat) = explode(",", $point);
             $points[] = new Point($lng, $lat);
         }
         $lineString = new LineString($points);
         $lineString->close();
         $polygon = new Polygon(array($lineString));
         $neighborhoodPolygon = new UserPolygon();
         $neighborhoodPolygon->setWhathoodUser($whathoodUser);
         $neighborhoodPolygon->setAuthority($this->isAuthority());
         $neighborhoodPolygon->setNeighborhood($neighborhood);
         $neighborhoodPolygon->setPolygon($polygon);
         $neighborhoodPolygon->setRegion($this->getRegion());
         $neighborhoods[] = $neighborhoodPolygon;
     }
     return $neighborhoods;
 }
Example #4
0
 /**
  * expects an array that conforms to a geojson object
  **/
 public static function buildPolygonFromGeoJsonArray(array $polygon_array, $srid)
 {
     if (empty($polygon_array)) {
         throw new \InvalidArgumentException("polygon_array may not be empty");
     }
     if (isset($polygon_array['geometry']['coordinates'])) {
         $lineStringArray = $polygon_array['geometry']['coordinates'];
     } else {
         if (isset($polygon_array['coordinates'])) {
             $lineStringArray = $polygon_array['coordinates'];
         }
     }
     $ring = array();
     foreach ($lineStringArray as $lineString) {
         foreach ($lineString as $point) {
             $ring[] = new Point($point[0], $point[1]);
         }
     }
     $myLineString = new LineString($ring);
     $myLineString->close();
     $polygon = new CrEOFPolygon($rings = array($myLineString));
     $polygon->setSRID($srid);
     return $polygon;
 }
Example #5
0
 public static function polygon()
 {
     $lineString = new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10)));
     $lineString->close();
     return new Polygon($rings = array($lineString));
 }