/** * given an array of test points, build a collection of election test points * * @param array - an array of test point objects * @return mixed - PointElectionCollection */ public function buildPointElectionCollection(array $test_points) { if (empty($test_points)) { throw new \InvalidArgumentException("test_points may not be empty"); } $c_points = array(); foreach ($test_points as $p) { $user_polygons = $this->m()->userPolygonMapper()->byPoint($p); array_push($c_points, PointElection::build(array('point' => $p, 'userPolygons' => $user_polygons, 'logger' => $this->logger()))); } return new PointElectionCollection($c_points); }
/** * can handle queries of: * - x and y */ public function getListAction() { $x = $this->params()->fromRoute('x'); $y = $this->params()->fromRoute('y'); $this->logger()->info("whathood REST get xy={$x},{$y}"); $point = new Point($x, $y); $userPolygons = $this->m()->userPolygonMapper()->byPoint($point); if (empty($userPolygons)) { $userPolygons = array(); } $electionPoint = PointElection::Build(array('point' => $point, 'user_polygons' => $userPolygons, 'logger' => $this->logger())); return new JsonModel($electionPoint->toArray()); }
/** * @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))); }
/** * will return a random point election * @return PointElection */ public static function buildTestPointElection(array $data = null) { if (empty($data)) { $data = array(); } $user_polygons = array(static::buildTestUserPolygon(), static::buildTestUserPolygon(), static::buildTestUserPolygon()); $x = static::rand_int(); $y = static::rand_int(); $defaults = array('point' => Point::buildFromText("POINT({$x} {$y})"), 'user_polygons' => $user_polygons, 'logger' => new \Whathood\Logger()); return PointElection::build(array_merge($defaults, $data)); }