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 listAction()
 {
     $pageNum = $this->params()->fromRoute('page');
     $item_count_per_page = $this->params()->fromRoute('count_per_page');
     if (!$pageNum) {
         $pageNum = 0;
     }
     if (!$item_count_per_page) {
         $item_count_per_page = 20;
     }
     $query = $this->m()->userPolygonMapper()->getPaginationQuery();
     $paginator = new \Whathood\View\Paginator\UserPolygonPaginator(new \Whathood\View\Paginator\UserPolygonPaginatorAdapter($query));
     $paginator->setDefaultItemCountPerPage($item_count_per_page);
     $paginator->setCurrentPageNumber($pageNum);
     $userPolygons = $paginator->getCurrentItems();
     $arr = UserPolygon::polygonsToArray($userPolygons, array('strings_only' => true, 'include_neighborhood' => true));
     return new JsonModel(array('user_polygons' => $arr));
 }
 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;
 }
 public function area(UserPolygon $up)
 {
     $sql = "SELECT ST_Area(polygon) AS area FROM user_polygon up WHERE up.id = :up_id";
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('area', 'area');
     $query = $this->em->createNativeQuery($sql, $rsm);
     $result = $query->setParameter('up_id', $up->getId())->getSingleResult();
     return $result['area'];
 }
 public function addAction()
 {
     if (!$this->getRequest()->isPost()) {
         return new ViewModel();
     }
     $neighborhood_name = $this->getRequest()->getPost('neighborhood_name');
     $region_name = $this->getRequest()->getPost('region_name');
     $polygon_array = $this->getRequest()->getPost('polygon_json');
     if (empty($polygon_array)) {
         throw new \InvalidArgumentException("polygon_json may not be empty");
     }
     if (empty($neighborhood_name)) {
         throw new \InvalidArgumentException("neighborhood_name may not be empty");
     }
     $neighborhood = new Neighborhood(array('name' => $neighborhood_name));
     $region = new Region(array('name' => $region_name));
     $polygon = \Whathood\Polygon::buildPolygonFromGeoJsonArray($polygon_array, $srid = 4326);
     $whathoodUser = $this->getWhathoodUser();
     $userPolygon = new UserPolygon(array('neighborhood' => $neighborhood, 'polygon' => $polygon, 'region' => $region, 'whathoodUser' => $whathoodUser));
     $this->logger()->info(sprintf("saving user-polygon id=%s neighborhood=%s region=%s ip-address=%s", $userPolygon->getId(), $neighborhood->getName(), $region->getName(), $whathoodUser->getIpAddress()));
     $this->userPolygonMapper()->save($userPolygon);
     $this->logger()->info("user polygon added id(" . $userPolygon->getId() . ")");
     return new JsonModel(array('status' => 'success', 'user_polygon_id' => $userPolygon->getId()));
 }
Example #6
0
 public static function buildTestUserPolygon(array $data = null)
 {
     if (empty($data)) {
         $data = array();
     }
     $defaults = array('neighborhood' => static::buildTestNeighborhood());
     return UserPolygon::build(array_merge($defaults, $data));
 }
Example #7
0
 public static function neighborhoodAdd(UserPolygon $np)
 {
     return 'A new neighborhood polygon has been added<br/><br/>' . '<a href="http://whathood.in/n/id/' . $np->getId() . '">Go to neighborhood</a>';
 }
Example #8
0
 public function notifyUserNeighborhoodAdd(UserPolygon $userPolygon)
 {
     $this->getEmailer()->send(sprintf("New %s Neigborhood Added", $userPolygon->getNeighborhood()->getName()), sprintf("by user %s", $userPolygon->getWhathoodUser()->__toString()));
 }