def test_updateBlockContainerData_squareWithinAnother(self): exterior = [[-10, 10], [10, 10], [10, -10], [-10, -10]] shape1 = [[-1, 1], [1, 1], [1, -1], [-1, -1]] shape2 = [[-5, 5], [-4, 5], [-4, 4], [-5, 4]] a = CensusBlock(countyFIPS='01', tractFIPS='01', blockFIPS='01', population=int('1'), isWater=False, geoJSONGeometry={'type': 'Polygon', 'coordinates': [exterior, shape1, shape2]}) b = CensusBlock(countyFIPS='01', tractFIPS='01', blockFIPS='01', population=int('1'), isWater=False, geoJSONGeometry={ "type": "MultiPolygon", "coordinates": [ [shape1], [shape2] ] }) blocks = [a, b] blockContainer = CensusContainer() blockContainer.children = blocks self.assertEqual(blockContainer.population, 2) self.assertEqual(blockContainer.geometry, Polygon(exterior))
def test_updateBlockContainerData_singleCircle(self): a = CensusBlock(countyFIPS='01', tractFIPS='01', blockFIPS='01', population=int('1'), isWater=False, geoJSONGeometry={'type': 'Polygon', 'coordinates': [[[0,0], [-1, 1], [1, 1], [1, 0]]]}) circle = Point(0,0).buffer(1) #replace the geometry a.geometry = circle blocks = [a] blockContainer = CensusContainer() blockContainer.children = blocks self.assertEqual(blockContainer.population, 1) self.assertEqual(blockContainer.geometry, circle)
def test_updateBlockContainerData_touchingSquares(self): a = CensusBlock(countyFIPS='01', tractFIPS='01', blockFIPS='01', population=int('1'), isWater=False, geoJSONGeometry={'type': 'Polygon', 'coordinates': [[[-1, 0], [-1, 1], [1, 1], [1, 0]]]}) b = CensusBlock(countyFIPS='01', tractFIPS='01', blockFIPS='01', population=int('1'), isWater=False, geoJSONGeometry={'type': 'Polygon', 'coordinates': [[[-1, 1], [-1, 2], [1, 2], [1, 1]]]}) blocks = [a,b] blockContainer = CensusContainer() blockContainer.children = blocks self.assertEqual(blockContainer.population, 2) combinedPolygon = Polygon([(-1, 0), (-1, 2), (1, 2), (1, 0)]) self.assertEqual(blockContainer.geometry, combinedPolygon)
def __init__(self, childrenBlocks): CensusContainer.__init__(self) self.children = childrenBlocks GraphObject.__init__(self, self.geometry.centroid) self.isWater = self.getWaterPropertyFromBlocks() AtomicBlock.atomicBlockList.append(self)
def __init__(self): CensusContainer.__init__(self) self.__northernChildBlocks = [] self.__westernChildBlocks = [] self.__easternChildBlocks = [] self.__southernChildBlocks = []