public function testByNeighborhood() { $neighborhood1 = $this->buildTestNeighborhood(); $neighborhood2 = $this->buildTestNeighborhood(); $userPolygons = array(static::buildTestUserPolygon(array('neighborhood' => $neighborhood1)), static::buildTestUserPolygon(array('neighborhood' => $neighborhood1)), static::buildTestUserPolygon(array('neighborhood' => $neighborhood2))); // create 5 PointElections $objects = array($this->buildTestPointElection(array('user_polygons' => $userPolygons)), $this->buildTestPointElection(array('user_polygons' => $userPolygons)), $this->buildTestPointElection(array('user_polygons' => $userPolygons)), $this->buildTestPointElection(array('user_polygons' => $userPolygons)), $this->buildTestPointElection(array('user_polygons' => $userPolygons))); $peCollection = new PointElectionCollection($objects); $this->assertEquals(count($peCollection->byNeighborhood($neighborhood1)), 5); }
/** * given a collection of ElectionPoints, builds the neighborhood border for the given neighborhood id * * @param electionCollect \Whathood\Election\PointElectionCollection - a collection of ElectionPoints * @param neighbood_id int - the neighborhood id to generate the border for * * @return mixed - Polygon object */ public function build(PointElectionCollection $pointElectionCollection, Neighborhood $neighborhood) { if (empty($pointElectionCollection)) { throw new \InvalidArgumentException("pointElectionCollection must be defined"); } if (empty($pointElectionCollection->getPointElections())) { throw new \InvalidArgumentException("electionCollection must have points"); } // these are the neighborhood points we'll use to wrap the border $neighborhood_points = $pointElectionCollection->byNeighborhood($neighborhood); if (empty($neighborhood_points)) { throw new \Exception("neighborhood did not win any points in election"); } $points = $this->getStandardPoints($neighborhood_points); return $this->getMapper('pointsAsPolygon')->toPolygon(new MultiPoint($points)); }
/** * build the neighborhood polygon * **/ public function buildNeighborhoodBoundary(PointElectionCollection $electionCollection, Neighborhood $neighborhood, $ups) { if (empty($electionCollection->getPointElections())) { throw new \InvalidArgumentException("electionCollection may not be empty"); } $this->infoLog(sprintf("working with %s election points", count($electionCollection->getPointElections()))); return $this->getBoundaryBuilder()->build($electionCollection, $neighborhood); }