Пример #1
0
 /**
  * return geojson representation of test points given either
  *
  *  - neighborhood name and region name
  */
 public function showAction()
 {
     $neighborhood_name = $this->getRequestParameter('neighborhood');
     $region_name = $this->getRequestParameter('region');
     $grid_resolution = $this->getRequestParameter('grid-res');
     if (empty($neighborhood_name) or empty($region_name) or empty($grid_resolution)) {
         die("neighborhood_name,region_name and grid_res must all be defined");
     }
     $neighborhood = $this->m()->neighborhoodMapper()->byName($neighborhood_name, $region_name);
     if (empty($neighborhood)) {
         die("no neighborhood found");
     }
     $user_polygons = $this->m()->userPolygonMapper()->byNeighborhood($neighborhood);
     if (empty($user_polygons)) {
         die("no user polygons found for neighborhood");
     }
     $timer = \Whathood\Timer::start('api');
     $points = $this->m()->testPointMapper()->createByUserPolygons($user_polygons, $grid_resolution);
     $test_point_ms = $timer->elapsed_milliseconds();
     $test_point_count = count($points);
     $this->logger()->info(sprintf("generated %s test points in %sms; %sms per 1000 points", $test_point_count, $test_point_ms, round($test_point_ms / $test_point_count * 1000, 1)));
     if (empty($points)) {
         die("no points returned with grid_resolution {$grid_resolution}");
     }
     $timer = \Whathood\Timer::start('election');
     $consensus_col = $this->m()->electionMapper()->buildElectionPointCollection($points);
     $consensus_seconds = $timer->elapsed_seconds();
     $this->logger()->info(sprintf("got consensus in %s seconds; %sms per point", $consensus_seconds, round($consensus_seconds / count($points) * 1000, 2)));
     $timer = \Whathood\Timer::start('election');
     $consensus_col = $this->m()->electionMapper()->buildElectionPointCollection($points);
     $points = $consensus_col->pointsByNeighborhoodId($neighborhood->getId());
     \Zend\Debug\Debug::dump(get_class($points[0]));
     print Json::encode(\Whathood\Spatial\Util::multiPointToGeoJsonArray(new WhMultiPoint($points)));
 }
 /**
  * @api {get} /neighborhood-border/debug-build/:region/:neighborhood/:grid_resolution
  *
  * @apiName getBorderDebugBuild
  * @apiGroup NeighborhoodBoundary
  *
  * @apiParam {String} regionName the name of the region
  * @apiParam {String} neighborhoodName the name of the neighborhood
  * @apiParam {String} gridResolution the desired grid resolution
  *
  * @apiSuccess {Object} boundary - the boundary geometry
  * @apiSuccess {Array} neighborhood election points
  */
 public function debugBuildAction()
 {
     $neighborhood_name = $this->getRequestParameter('neighborhood');
     $region_name = $this->getRequestParameter('region');
     $grid_resolution = $this->getRequestParameter('grid_res');
     if (empty($neighborhood_name)) {
         throw new \InvalidArgumentException("neighborhood must be defined");
     }
     if (empty($grid_resolution)) {
         throw new \InvalidArgumentException("grid_res must be defined");
     }
     $neighborhood = $this->m()->neighborhoodMapper()->byName($neighborhood_name, $region_name);
     $userPolygons = $this->m()->userPolygonMapper()->byNeighborhood($neighborhood);
     $pointElectionCollection = $this->m()->pointElectionMapper()->getCollection($userPolygons, $neighborhood->getId(), $grid_resolution);
     $neighborhoodWinningPointElections = $pointElectionCollection->byNeighborhood($neighborhood);
     $boundary_polygon = $this->getServiceLocator()->get('Whathood\\Spatial\\Neighborhood\\Boundary\\BoundaryBuilder')->build($pointElectionCollection, $neighborhood);
     $points = $this->m()->testPointMapper()->createByUserPolygons($userPolygons, $grid_resolution);
     $multi_point = new MultiPoint($points);
     return new JsonModel(array('boundary' => $boundary_polygon->toArray(), 'all_point_elections' => PointElection::allToArrays($pointElectionCollection->getPointElections()), 'neighborhood_election_points' => PointElection::allToArrays($neighborhoodWinningPointElections), 'test_points' => \Whathood\Spatial\Util::toGeoJsonArray($multi_point)));
 }
 /**
  * return geojson representation of test points given either
  *
  *  - neighborhood name and region name
  */
 public function getList()
 {
     $neighborhood_name = $this->getRequestParameter('neighborhood_name');
     $region_name = $this->getRequestParameter('region_name');
     $grid_resolution = $this->getRequestParameter('grid_res');
     if (empty($neighborhood_name) or empty($region_name) or empty($grid_resolution)) {
         return $this->badRequestJson("neighborhood_name,region_name and grid_res must all be defined");
     }
     $neighborhood = $this->m()->neighborhoodMapper()->byName($neighborhood_name, $region_name);
     if (empty($neighborhood)) {
         return $this->badRequestJson("no neighborhood found");
     }
     $user_polygons = $this->m()->userPolygonMapper()->byNeighborhood($neighborhood);
     if (empty($user_polygons)) {
         return $this->badRequestJson("no user polygons found for neighborhood");
     }
     $points = $this->m()->testPointMapper()->createByUserPolygons($user_polygons, $grid_resolution);
     if (empty($points)) {
         return $this->badRequestJson("no points returned with grid_resolution {$grid_resolution}");
     }
     $multi_point = new MultiPoint($points);
     return new JsonModel(\Whathood\Spatial\Util::toGeoJsonArray($multi_point));
 }