private function getBoundaryAsGeoJsonFromDb(Region $region)
 {
     $sql = "SELECT whathood.latest_neighborhoods_geojson(:regionId) as geojson";
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('geojson', 'geojson');
     $query = $this->em->createNativeQuery($sql, $rsm);
     $query->setParameter('regionId', $region->getId());
     $result = $query->getSingleResult();
     $geojson = $result['geojson'];
     if (preg_match('/"features":null/', $geojson)) {
         throw new \Exception("no neighborhood polygons returned for region '" . $region->getName() . "'");
     }
     return $geojson;
 }
Пример #2
0
 /**
  * 
  * @param \Whathood\Entity\Neighborhood $testNeighborhood
  * @param \Whathood\Entity\Region $testRegion
  * @param type $sideLength
  * @return null|\Whathood\Entity\HeatMap
  * @throws \InvalidArgumentException
  */
 public function getLatestHeatMap(Neighborhood $testNeighborhood, Region $testRegion, $sideLength)
 {
     if (empty($sideLength)) {
         throw new \InvalidArgumentException('sidLength may not be null');
     }
     $testNeighborhoodName = $testNeighborhood->getName();
     $testRegionName = $testRegion->getName();
     $neighborhoodPolygons = $this->neighborhoodPolygonMapper()->getNeighborhoodByName($testNeighborhoodName, $testRegionName);
     $testPoints = $this->getBoundarySquare($neighborhoodPolygons)->getTestPoints($sideLength);
     $heatMapPoints = $this->getHeatMapPoints($testPoints, $testNeighborhoodName);
     if (count($heatMapPoints) > 0) {
         return new HeatMap(array('neighborhood' => $testNeighborhood, 'region' => $testRegion, 'heatMapPoints' => $heatMapPoints, 'neighborhoodPolygons' => new ArrayCollection($neighborhoodPolygons)));
     } else {
         return null;
     }
 }
 public function getNeighborhoodPolygonsAsGeoJsonByRegion(Region $region)
 {
     if (empty($region->getId())) {
         throw new \InvalidArgumentException("region.id must not be null");
     }
     $sql = "SELECT whathood.latest_neighborhoods_geojson(:regionId) as geojson";
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('geojson', 'geojson');
     $query = $this->em->createNativeQuery($sql, $rsm);
     $query->setParameter('regionId', $region->getId());
     $result = $query->getSingleResult();
     $geojson = $result['geojson'];
     if (preg_match('/"features":null/', $geojson)) {
         throw new \Exception("no neighborhood polygons returned for region '" . $region->getName() . "'");
     } else {
         return $geojson;
     }
 }
Пример #4
0
 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()));
 }
 public function getName()
 {
     $this->__load();
     return parent::getName();
 }