Пример #1
0
    def test_intersectingGeometries_BinAwithHole(self):
        exterior = [[-10, 10], [10, 10], [10, -10], [-10, -10]]
        hole = [[-1, 1], [1, 1], [1, -1], [-1, -1]]

        a = CensusBlock(countyFIPS='01',
                        tractFIPS='01',
                        blockFIPS='01',
                        population=int('1'),
                        isWater=False,
                        geoJSONGeometry={
                            'type': 'Polygon',
                            'coordinates': [exterior, hole]
                        })
        b = CensusBlock(countyFIPS='01',
                        tractFIPS='01',
                        blockFIPS='01',
                        population=int('1'),
                        isWater=False,
                        geoJSONGeometry={
                            'type': 'Polygon',
                            'coordinates': [hole]
                        })
        aIntersectsB = intersectingGeometries(a, b)
        bIntersectsA = intersectingGeometries(b, a)
        self.assertTrue(aIntersectsB and bIntersectsA)
def assignNeighboringRedistrictingGroupsToRedistrictingGroups(changedRedistrictingGroups,
                                                              allNeighborCandidates,
                                                              shouldAttachOrphans=True):
    tqdm.write('\n')
    tqdm.write('*** Removing Outdated Neighbor Connections ***')
    with tqdm(total=len(allNeighborCandidates)) as pbar:
        # remove outdated neighbor connections
        for redistrictingGroup in allNeighborCandidates:
            outdatedNeighborConnections = [neighbor for neighbor in redistrictingGroup.allNeighbors
                                           if neighbor not in allNeighborCandidates]
            if outdatedNeighborConnections:
                redistrictingGroup.removeNeighbors(outdatedNeighborConnections)
            pbar.update(1)

    tqdm.write('\n')
    tqdm.write('*** Assign Neighbors to Changed Redistricting Groups ***')
    with tqdm(total=len(changedRedistrictingGroups)) as pbar:
        # assign neighbors to changed groups and those that they touch
        for changedRedistrictingGroup in changedRedistrictingGroups:
            changedRedistrictingGroup.clearNeighborGraphObjects()
            for redistrictingGroupToCheckAgainst in [aGroup for aGroup in allNeighborCandidates
                                                     if aGroup is not changedRedistrictingGroup]:
                if intersectingGeometries(changedRedistrictingGroup, redistrictingGroupToCheckAgainst):
                    changedRedistrictingGroup.addNeighbors([redistrictingGroupToCheckAgainst])
                    redistrictingGroupToCheckAgainst.addNeighbors([changedRedistrictingGroup])
            pbar.update(1)

        unionOfRedistrictingGroups = list(set(changedRedistrictingGroups) | set(allNeighborCandidates))

    if shouldAttachOrphans:
        attachOrphanRedistrictingGroupsToClosestNeighbor(unionOfRedistrictingGroups)
Пример #3
0
def getRedistrictingGroupsBetweenCandidates(aCandidate, bCandidate):
    groupsBetween = []

    for aGroup in aCandidate:
        for bGroup in bCandidate:
            if intersectingGeometries(aGroup, bGroup):
                if aGroup not in groupsBetween:
                    groupsBetween.append(aGroup)
                if bGroup not in groupsBetween:
                    groupsBetween.append(bGroup)

    return groupsBetween
Пример #4
0
 def test_intersectingGeometries_BsharesSideWithA(self):
     a = CensusBlock(countyFIPS='01',
                     tractFIPS='01',
                     blockFIPS='01',
                     population=int('1'),
                     isWater=False,
                     geoJSONGeometry={
                         'type': 'Polygon',
                         'coordinates': [[[-1, 0], [-1, 1], [0, 1], [0, 0]]]
                     })
     b = CensusBlock(countyFIPS='01',
                     tractFIPS='01',
                     blockFIPS='01',
                     population=int('1'),
                     isWater=False,
                     geoJSONGeometry={
                         'type': 'Polygon',
                         'coordinates': [[[0, 0], [0, 1], [1, 1], [1, 0]]]
                     })
     aIntersectsB = intersectingGeometries(a, b)
     bIntersectsA = intersectingGeometries(b, a)
     self.assertTrue(aIntersectsB and bIntersectsA)
Пример #5
0
 def test_intersectingGeometries_BnotInA(self):
     a = CensusBlock(countyFIPS='01',
                     tractFIPS='01',
                     blockFIPS='01',
                     population=int('1'),
                     isWater=False,
                     geoJSONGeometry={
                         'type': 'Polygon',
                         'coordinates': [[[5, 5], [6, 5], [6, 4], [5, 4]]]
                     })
     b = CensusBlock(countyFIPS='01',
                     tractFIPS='01',
                     blockFIPS='01',
                     population=int('1'),
                     isWater=False,
                     geoJSONGeometry={
                         'type': 'Polygon',
                         'coordinates': [[[-1, 1], [1, 1], [1, -1],
                                          [-1, -1]]]
                     })
     aIntersectsB = intersectingGeometries(a, b)
     bIntersectsA = intersectingGeometries(b, a)
     self.assertFalse(aIntersectsB and bIntersectsA)
Пример #6
0
def assignNeighborBlocksFromCandidateBlocks(block,
                                            candidateBlocks,
                                            progressObject=None):
    block.clearNeighborGraphObjects()
    neighborBlocks = []
    for candidateBlock in candidateBlocks:
        if candidateBlock is not block:
            if intersectingGeometries(block, candidateBlock):
                neighborBlocks.append(candidateBlock)
    block.addNeighbors(neighbors=neighborBlocks)

    for neighborBlock in neighborBlocks:
        if block not in neighborBlock.allNeighbors:
            neighborBlock.addNeighbor(block)

    if progressObject:
        progressObject.update(1)
Пример #7
0
 def removeNonIntersectingNeighbors(self):
     for neighbor in self.allNeighbors:
         if not intersectingGeometries(self, neighbor):
             self.removeNeighbor(neighbor)