def test_grid_stack(self): boundary = Boundary(cells=[ CellID('N11'), CellID('N12'), CellID('N13'), CellID('N88'), CellID('O0'), CellID('P123'), CellID('S34567') ]) grid_stack = boundary.get_as_grid_stack() self.assertEqual(grid_stack.grids.__len__(), 4) self.assertEqual(grid_stack.grids[0].refinement_level, 1) self.assertEqual(grid_stack.grids[0].cells, [CellID('O0')]) self.assertEqual(grid_stack.grids[1].refinement_level, 2) self.assertEqual( grid_stack.grids[1].cells, [CellID('N11'), CellID('N12'), CellID('N13'), CellID('N88')]) self.assertEqual(grid_stack.grids[2].refinement_level, 3) self.assertEqual(grid_stack.grids[2].cells, [CellID('P123')]) self.assertEqual(grid_stack.grids[3].refinement_level, 5) self.assertEqual(grid_stack.grids[3].cells, [CellID('S34567')])
def test_delete_boundary_in_boundary_datasets(self): store.dropAll() bds = BoundaryDataSet("id") boundaries = [ 'O23P12P34S56', 'P10P11P2', 'N0', 'N8O2P0', 'O6S0S1S2', 'Q' ] for boundary in boundaries: bds.add(Boundary(boundary_ID=BoundaryID(boundary)), Data("")) store.insert(bds) deleted_boundaries = store.delete_boundary_in_boundary_datasets( "id", (Boundary(boundary_ID=BoundaryID('O23P12P34S56')))) self.assertEqual(deleted_boundaries, 1) stored_bds = store.query_by_boundary_in_boundary_datasets( "id", (Boundary(boundary_ID=BoundaryID('O23P12P34S56')))) num_bds = 0 for bds in stored_bds: assert bds.get_boundaries().__len__() == 0 num_bds = num_bds + 1 assert num_bds == 1 self.assertEqual(num_bds, 1) store.dropAll()
def test_update_cell_in_cell_datasets(self): store.dropAll() bds = BoundaryDataSet("id") boundaries = [ 'O23P12P34S56', 'P10P11P2', 'N0', 'N8O2P0', 'O6S0S1S2', 'Q' ] for boundary in boundaries: bds.add(Boundary(boundary_ID=BoundaryID(boundary)), Data("")) store.insert(bds) store.update_boundary_in_boundary_datasets( "id", (Boundary(boundary_ID=BoundaryID('O23P12P34S56'))), Data("test")) stored_bds = store.query_by_boundary_in_boundary_datasets( "id", (Boundary(boundary_ID=BoundaryID('O23P12P34S56')))) num_bds = 0 num_boundaries = 0 for bds in stored_bds: for boundary, data in bds.get_boundaries_and_data(): assert boundaries.__contains__(boundary.AUID_to_CUIDs()) assert data.content == Data("test").content num_boundaries = num_boundaries + 1 num_bds = num_bds + 1 self.assertEqual(num_bds, 1) self.assertEqual(num_boundaries, 1) store.dropAll()
def test_update_boundary_dataset(self): store.dropAll() bds = BoundaryDataSet("id") boundaries = [ 'O23P12P34S56', 'P10P11P2', 'N0', 'N8O2P0', 'O6S0S1S2', 'Q' ] for boundary in boundaries: bds.add(Boundary(boundary_ID=BoundaryID(boundary)), Data("")) store.insert(bds) bds2 = BoundaryDataSet("id") boundaries2 = ['N0', 'N8O2P0', 'O6S0S1S2', 'Q'] for boundary in boundaries2: bds2.add(Boundary(boundary_ID=BoundaryID(boundary)), Data("")) store.update_boundary_dataset(bds2) stored_bds = store.query_by_boundary_dataset_id("id") num_bds = 0 num_boundaries = 0 for bds in stored_bds: for boundary in bds.get_boundaries(): assert boundaries2.__contains__(boundary.AUID_to_CUIDs()) num_boundaries = num_boundaries + 1 num_bds = num_bds + 1 self.assertEqual(num_bds, 1) self.assertEqual(num_boundaries, len(boundaries2)) store.dropAll()
def test_max_refinement(self): boundary = Boundary(cells=[ CellID('N'), CellID('O0'), CellID('P123'), CellID('S34567') ]) max_refinement = boundary.get_max_refinement() self.assertEqual(max_refinement, 5)
def test_limit_cells(self): boundary = Boundary(cells=[ CellID('N1'), CellID('O0'), CellID('P123'), CellID('S34567') ]) top_cell, bottom_cell, left_cell, right_cell = boundary.get_limit_cells( ) self.assertEqual(top_cell, CellID('N1')) self.assertEqual(bottom_cell, CellID('S34567')) self.assertEqual(left_cell, CellID('O0')) self.assertEqual(right_cell, CellID('P123'))
def get_boundary_from_shp_file(self, file, with_ids, refinement=None, unic_data=False): shapes = fiona.open(file) cells = [] data = {} first = True for polygon in shapes: if with_ids: cells.append(CellID(polygon['properties']['id'])) else: assert refinement is not None cells.append(self.get_cell_ID(polygon, int(refinement))) if not unic_data: if 'data' in polygon['properties']: data[polygon['properties'] ['id']] = polygon['properties']['data'] else: data[polygon['properties']['id']] = polygon['properties'] elif unic_data and first: if 'data' in polygon['properties']: data = polygon['properties']['data'] else: data = polygon['properties'] return Boundary(cells=cells), Data(data)
def test_query_by_boundary(self): store.dropAll() bds = BoundaryDataSet("id") boundaries = [ 'O23P12P34S56', 'P10P11P2', 'N0', 'N8O2P0', 'O6S0S1S2', 'Q' ] for boundary in boundaries: bds.add(Boundary(boundary_ID=BoundaryID(boundary)), Data("")) store.insert(bds) stored_boundaries = store.query_by_boundary( (Boundary(boundary_ID=BoundaryID('O23P12P34S56')))) num_boundaries = 0 for boundary in stored_boundaries: assert boundaries.__contains__(boundary[0].AUID_to_CUIDs()) num_boundaries = num_boundaries + 1 self.assertEqual(num_boundaries, 1) store.dropAll()
def test_delete_boundary(self): store.dropAll() bds = BoundaryDataSet("id") boundaries = [ 'O23P12P34S56', 'P10P11P2', 'N0', 'N8O2P0', 'O6S0S1S2', 'Q' ] for boundary in boundaries: bds.add(Boundary(boundary_ID=BoundaryID(boundary)), Data("")) store.insert(bds) deleted_boundaries = store.delete_boundary( (Boundary(boundary_ID=BoundaryID('O23P12P34S56')))) self.assertEqual(deleted_boundaries, 1) stored_boundaries = store.query_by_boundary( (Boundary(boundary_ID=BoundaryID('O23P12P34S56')))) self.assertEqual(stored_boundaries.__len__(), 0) store.dropAll()
def test_boundary_from_boundary_ID(self): boundary = Boundary(boundary_ID=BoundaryID('N11N12N13N88O0P123S34567')) self.assertEqual(boundary.cells, [ CellID('N11'), CellID('N12'), CellID('N13'), CellID('N88'), CellID('O0'), CellID('P123'), CellID('S34567') ])
def test_boundary_from_cells(self): boundary = Boundary(cells=[ CellID('N11'), CellID('N12'), CellID('N13'), CellID('N88'), CellID('O0'), CellID('P123'), CellID('S34567') ]) self.assertEqual(boundary.boundary_ID.value, 'N11N12N13N88O0P123S34567')
def test_optimize_boundary(self): boundary = Boundary(boundary_ID=BoundaryID('N11N12N2N3')) optimal_boundary = boundary.optimize() self.assertEqual(optimal_boundary.boundary_ID.value, "RN11$))2$)))2$))3$))))") self.assertEqual(optimal_boundary.is_optimal(), True) boundary = Boundary( boundary_ID=BoundaryID('N11N20N21N22N23N24N25N26N27N28')) self.assertEqual(boundary.boundary_ID.value, "N11N20N21N22N23N24N25N26N27N28") self.assertEqual(boundary.is_optimal(), False) optimal_boundary = boundary.optimize() self.assertEqual(optimal_boundary.boundary_ID.value, "RN11$)))2$))))") self.assertEqual(optimal_boundary.is_optimal(), True) boundary = Boundary(boundary_ID=BoundaryID( 'N7N00N01N02N03N04N05N06N07N08N11N21N22N23N24N25N26N27N28N200N201N202N203N204N205N206N207N208N9878' )) optimal_boundary = boundary.optimize() self.assertEqual(optimal_boundary.boundary_ID.value, "RN0$))11$)))2$))7$))9878$)))))))") self.assertEqual(optimal_boundary.is_optimal(), True)
def get_boundary_dataset_from_shp_file(self, dir, id, with_ids, refinement=None, unic_data=False): import os import glob os.chdir(dir) boundaries = [] for file in glob.glob('*.shp'): boundaries.append(fiona.open(file)) bds = BoundaryDataSet(id=id) for boundary in boundaries: data = {} boundary_id = '' first = True for polygon in boundary: if with_ids: boundary_id = boundary_id + polygon['properties']['id'] else: assert refinement is not None cell = self.get_cell_ID(polygon, int(refinement)) boundary_id = boundary_id + cell.value if not unic_data: if 'data' in polygon['properties']: data[polygon['properties'] ['id']] = polygon['properties']['data'] else: data[polygon['properties'] ['id']] = polygon['properties'] elif unic_data and first: if 'data' in polygon['properties']: data = polygon['properties']['data'] else: data = polygon['properties'] bds.add(boundary=Boundary(boundary_ID=BoundaryID(boundary_id)), data=Data(data)) return bds
def test_API(self, n_person): print('TEST START') store = BoundaryStore() store.dropAll() boundary_dataset_test = {} all_bds_test = [] all_boundaries = [] boundary_test = [] test_boundary_id = '' number_person = 0 test_person_number = '' for person in self.bds[0:n_person]: number_person = number_person + 1 bds = [] bds_test = [] for boundaries in person['boundaries']: data = {} boundary_id = '' for polygon in boundaries: boundary_id = boundary_id + polygon['properties']['id'] data[polygon['properties']['id']] = polygon['properties'] bds.append({'boundary': boundary_id, 'data': data}) optB = Boundary(boundary_ID=BoundaryID(boundary_id)).optimize() bds_test.append({'AUID': optB.boundary_ID.value, 'boundary': optB.AUID_to_CUIDs(), 'data': data}) all_boundaries.append({'AUID': optB.boundary_ID.value, 'boundary': optB.AUID_to_CUIDs(), 'data': data}) test_boundary_id = boundary_id boundary_test = [{'AUID': optB.boundary_ID.value, 'boundary': optB.AUID_to_CUIDs(), 'data': data}] boundary_dataset = {"id": "persona" + str(number_person), 'boundary_data_set': bds} test_person_number = "persona" + str(number_person) boundary_dataset_test = {"id": "persona" + str(number_person), 'boundary_data_set': bds_test} all_bds_test.append(boundary_dataset_test) # POST BOUNDARY_DATASETS TEST r = requests.post('http://127.0.0.1:8000/bdatasets/', json=boundary_dataset) assert r.status_code == 201 # GET ALL BOUNDARY_DATASETS TEST r = requests.get('http://127.0.0.1:8000/bdatasets/') assert r.status_code == 200 json_test = json.dumps(all_bds_test) json_data = json.dumps(r.json()) assert json_test == json_data # GET BOUNDARY_DATASET TEST r = requests.get('http://127.0.0.1:8000/bdatasets/' + test_person_number) assert r.status_code == 200 json_test = json.dumps([boundary_dataset_test]) json_data = json.dumps(r.json()) assert json_test == json_data # GET BOUNDARY IN BOUNDARY_DATASET TEST r = requests.get('http://127.0.0.1:8000/bdatasets/' + test_person_number + "/" + test_boundary_id) assert r.status_code == 200 boundary_in_boundary_dataset = {"id": test_person_number, 'boundary_data_set': boundary_test} json_test = json.dumps([boundary_in_boundary_dataset]) json_data = json.dumps(r.json()) assert json_test == json_data # GET ALL BOUNDARIES TEST r = requests.get('http://127.0.0.1:8000/boundaries/') assert r.status_code == 200 json_test = json.dumps(all_boundaries) json_data = json.dumps(r.json()) assert json_test == json_data # GET BOUNDARY TEST r = requests.get('http://127.0.0.1:8000/boundaries/' + test_boundary_id) assert r.status_code == 200 json_test = json.dumps(boundary_test) json_data = json.dumps(r.json()) assert json_test == json_data # DELETE BOUNDARY TEST r = requests.delete('http://127.0.0.1:8000/boundaries/' + test_boundary_id) assert r.status_code == 204 r = requests.get('http://127.0.0.1:8000/boundaries/') assert r.status_code == 200 all_boundaries.pop() json_test = json.dumps(all_boundaries) json_data = json.dumps(r.json()) assert json_test == json_data store.dropAll() print('TEST FINISH')
def shp_file_from_boundary_cli(self, boundary_file, out_shp, bbox): with open(boundary_file) as json_file: boundary = json.load(json_file) self.shp_file_from_boundary(Boundary(boundary_ID=BoundaryID(boundary['boundary'])), out_shp, bbox, data=Data(boundary['data']))
def test_bbox(self): boundary = Boundary(boundary_ID=BoundaryID('O0O1O3O4')) bbox = [[[-179.9999997096064, -12.895312716341486], [-120.00000018880363, -12.895312716341486], [-120.00000018880363, 41.93785365811587], [-179.9999997096064, 41.93785365811587], [-179.9999997096064, -12.895312716341486]]] self.assertEqual(boundary.get_bbox(), bbox) boundary = Boundary(boundary_ID=BoundaryID('O0O1O3')) bbox = [[[-179.9999997096064, -12.895312716341486], [-120.00000018880363, -12.895312716341486], [-120.00000018880363, 41.93785365811587], [-179.9999997096064, 41.93785365811587], [-179.9999997096064, -12.895312716341486]]] self.assertEqual(boundary.get_bbox(), bbox) boundary = Boundary(boundary_ID=BoundaryID('O1O3O4')) bbox = [[[-179.9999997096064, -12.895312716341486], [-120.00000018880363, -12.895312716341486], [-120.00000018880363, 41.93785365811587], [-179.9999997096064, 41.93785365811587], [-179.9999997096064, -12.895312716341486]]] self.assertEqual(boundary.get_bbox(), bbox) boundary = Boundary(boundary_ID=BoundaryID('O0O4')) bbox = [[[-179.9999997096064, -12.895312716341486], [-120.00000018880363, -12.895312716341486], [-120.00000018880363, 41.93785365811587], [-179.9999997096064, 41.93785365811587], [-179.9999997096064, -12.895312716341486]]] self.assertEqual(boundary.get_bbox(), bbox) boundary = Boundary(boundary_ID=BoundaryID('N5P1P2')) bbox = [[[-89.99999763120867, 12.895313217732834], [-5.735989944427416e-07, 12.895313217732834], [-5.735989944427416e-07, 74.42400629900254], [-89.99999763120867, 74.42400629900254], [-89.99999763120867, 12.895313217732834]]] self.assertEqual(boundary.get_bbox(), bbox) boundary = Boundary(boundary_ID=BoundaryID('Q6Q7S7')) bbox = [[[1.9224187603958446e-06, -74.4240062287476], [89.9999976312087, -74.4240062287476], [89.9999976312087, -12.895313217732834], [1.9224187603958446e-06, -12.895313217732834], [1.9224187603958446e-06, -74.4240062287476]]] self.assertEqual(boundary.get_bbox(), bbox)
def test_boundary_geodetic_coordinates(self): boundary = Boundary(cells=[CellID('N')]) a = boundary.get_geodetic_coordinates() b = [[(89.99999978400184, 41.93785398898271), (6.72073022798356e-08, 41.93785398898271), (179.99999993279272, 41.93785423508538), (-89.99999978400186, 41.93785406555696), (21.357842301203913, 90.0)]] self.assertEqual(a, b) boundary = Boundary(cells=[CellID('O')]) a = boundary.get_geodetic_coordinates() b = [[(-179.9999997096064, 41.93785365811587), (-90.00000014160271, 41.93785365811587), (-179.9999997096064, -41.93785365811587), (-90.00000014160271, -41.93785365811587), (-134.99999992560458, 0.0)]] self.assertEqual(a, b) boundary = Boundary(cells=[CellID('P')]) a = boundary.get_geodetic_coordinates() b = [[(-89.99999956800372, 41.93785365811587), (0.0, 41.93785365811587), (-89.99999956800372, -41.93785365811587), (0.0, -41.93785365811587), (-44.99999978400186, 0.0)]] self.assertEqual(a, b) boundary = Boundary(cells=[CellID('Q')]) a = boundary.get_geodetic_coordinates() b = [[(0.0, 41.93785365811587), (89.99999956800372, 41.93785365811587), (0.0, -41.93785365811587), (89.99999956800372, -41.93785365811587), (45.000000357600854, 0.0)]] self.assertEqual(a, b) boundary = Boundary(cells=[CellID('R')]) a = boundary.get_geodetic_coordinates() b = [[(90.00000014160271, 41.93785365811587), (179.9999997096064, 41.93785365811587), (90.00000014160271, -41.93785365811587), (179.9999997096064, -41.93785365811587), (135.00000049920357, 0.0)]] self.assertEqual(a, b) boundary = Boundary(cells=[CellID('S')]) a = boundary.get_geodetic_coordinates() b = [[(179.99999993279272, -41.93785423508538), (-89.99999978400186, -41.93785406555696), (89.99999978400184, -41.93785398898271), (6.72073022798356e-08, -41.93785398898271), (-127.2504110460384, -90.0)]] self.assertEqual(a, b) boundary = Boundary( cells=[CellID('N11'), CellID('N12'), CellID('N13'), CellID('N88')]) a = boundary.get_geodetic_coordinates() b = [[(49.99999984613771, 41.93785398898271), (40.00000000507141, 41.93785398898271), (51.42857120155658, 53.09647119578482), (38.57142860714087, 53.09647119578482), (44.99999991630516, 47.57255097966877)], [(39.99999943147242, 41.93785398898271), (30.000000164005154, 41.93785398898271), (38.57142786965645, 53.09647119578482), (25.714286012725182, 53.09647119578482), (33.74999947215674, 47.57255097966877)], [(64.28571411203704, 53.096471823859616), (51.42857204439592, 53.096471823859616), (71.9999990936704, 63.883501580904124), (54.00000064109378, 63.883501580904124), (59.99999953080601, 58.528017276850065)], [(-90.00000045977251, 53.09647087781202), (-80.00000050159962, 41.93785406555696), (-99.99999968800269, 41.93785431165961), (-89.99999978400186, 41.93785406555696), (-89.99999911170322, 47.57255041493694)]] self.assertEqual(a, b)
def test_API(self): print('TEST START') store = BoundaryStore(MongoClient(port=27017).bds) store.dropAll() i = 0 data = {} bds = [] boundary_id = '' bds_test = [] boundary_test = [] test_boundary_id = '' for polygon in self.shapes: if i % 10 == 0 and i != 0: bds.append({'boundary': boundary_id, 'data': data}) optB = Boundary(boundary_ID=BoundaryID(boundary_id)).optimize() bds_test.append({ 'AUID': optB.boundary_ID.value, 'boundary': optB.AUID_to_CUIDs(), 'data': data }) test_boundary_id = boundary_id boundary_test = [{ 'AUID': optB.boundary_ID.value, 'boundary': optB.AUID_to_CUIDs(), 'data': data }] data = {} boundary_id = '' boundary_id = boundary_id + polygon['properties']['id'] data[polygon['properties']['id']] = polygon['properties'] i = i + 1 boundary_dataset = {'boundary_data_set': bds} boundary_dataset_test = {'boundary_data_set': bds_test} # POST BOUNDARY_DATASETS TEST r = requests.post('http://127.0.0.1:8000/bdatasets/', json=boundary_dataset) assert r.status_code == 201 # GET ALL BOUNDARY_DATASETS TEST r = requests.get('http://127.0.0.1:8000/bdatasets/') json_test = json.dumps([boundary_dataset_test]) json_data = json.dumps(r.json()) assert r.status_code == 200 assert json_test == json_data # GET BOUNDARY IN BOUNDARY_DATASET TEST r = requests.get('http://127.0.0.1:8000/bdatasets/' + test_boundary_id) json_test = json.dumps([boundary_dataset_test]) json_data = json.dumps(r.json()) assert r.status_code == 200 assert json_test == json_data # GET ALL BOUNDARIES TEST r = requests.get('http://127.0.0.1:8000/boundaries/') json_test = json.dumps(bds_test) json_data = json.dumps(r.json()) assert r.status_code == 200 assert json_test == json_data # GET BOUNDARY TEST r = requests.get('http://127.0.0.1:8000/boundaries/' + test_boundary_id) json_test = json.dumps(boundary_test) json_data = json.dumps(r.json()) assert r.status_code == 200 assert json_test == json_data # DELETE BOUNDARY TEST r = requests.delete('http://127.0.0.1:8000/boundaries/' + test_boundary_id) assert r.status_code == 204 r = requests.get('http://127.0.0.1:8000/boundaries/') bds_test.pop() json_test = json.dumps(bds_test) json_data = json.dumps(r.json()) assert r.status_code == 200 assert json_test == json_data store.dropAll() print('TEST FINISH')
def test_boundary_projected_coordinates(self): boundary = Boundary(cells=[CellID('N')]) a = boundary.get_projected_coordinates() b = [((-3.1380808151030846, 2.3535606113273135), (-1.5690404075515423, 2.3535606113273135), (-3.1380808151030846, 0.7845202037757713), (-1.5690404075515423, 0.7845202037757713), (-2.3535606113273135, 1.5690404075515425))] self.assertEqual(a, b) boundary = Boundary(cells=[CellID('O')]) a = boundary.get_projected_coordinates() b = [((-3.1380808151030846, 0.7845202037757711), (-1.5690404075515423, 0.7845202037757711), (-3.1380808151030846, -0.7845202037757711), (-1.5690404075515423, -0.7845202037757711), (-2.3535606113273135, 0.0))] self.assertEqual(a, b) boundary = Boundary(cells=[CellID('P')]) a = boundary.get_projected_coordinates() b = [((-1.5690404075515423, 0.7845202037757711), (0.0, 0.7845202037757711), (-1.5690404075515423, -0.7845202037757711), (0.0, -0.7845202037757711), (-0.7845202037757711, 0.0))] self.assertEqual(a, b) boundary = Boundary(cells=[CellID('Q')]) a = boundary.get_projected_coordinates() b = [((0.0, 0.7845202037757711), (1.5690404075515423, 0.7845202037757711), (0.0, -0.7845202037757711), (1.5690404075515423, -0.7845202037757711), (0.7845202037757711, 0.0))] self.assertEqual(a, b) boundary = Boundary(cells=[CellID('R')]) a = boundary.get_projected_coordinates() b = [((1.5690404075515423, 0.7845202037757711), (3.1380808151030846, 0.7845202037757711), (1.5690404075515423, -0.7845202037757711), (3.1380808151030846, -0.7845202037757711), (2.3535606113273135, 0.0))] self.assertEqual(a, b) boundary = Boundary(cells=[CellID('S')]) a = boundary.get_projected_coordinates() b = [ ((-3.1380808151030846, -0.7845202037757711), (-1.5690404075515423, -0.7845202037757711), (-3.1380808151030846, -2.3535606113273135), (-1.5690404075515423, -2.3535606113273135), (-2.3535606113273135, -1.5690404075515423)) ] self.assertEqual(a, b) boundary = Boundary( cells=[CellID('N11'), CellID('N12'), CellID('N13'), CellID('N88')]) a = boundary.get_projected_coordinates() b = [((-2.440729522857955, 2.3535606113273135), (-2.266391699796672, 2.3535606113273135), (-2.440729522857955, 2.179222788266031), (-2.266391699796672, 2.179222788266031), (-2.3535606113273135, 2.266391699796672)), ((-2.266391699796672, 2.3535606113273135), (-2.0920538767353896, 2.3535606113273135), (-2.266391699796672, 2.179222788266031), (-2.0920538767353896, 2.179222788266031), (-2.179222788266031, 2.266391699796672)), ((-2.615067345919237, 2.179222788266031), (-2.4407295228579544, 2.179222788266031), (-2.615067345919237, 2.0048849652047482), (-2.4407295228579544, 2.0048849652047482), (-2.5278984343885957, 2.0920538767353896)), ((-1.743378230612825, 0.9588580268370539), (-1.5690404075515425, 0.9588580268370539), (-1.743378230612825, 0.7845202037757715), (-1.5690404075515425, 0.7845202037757715), (-1.6562093190821836, 0.8716891153064127))] self.assertEqual(a, b)
def test_API_polygon_11(self): print('TEST START') store = BoundaryStore(MongoClient(port=27017).bds) store.dropAll() i = 0 data = {} bds = [] boundary_id = '' for polygon in self.shapes: if i != 0: bds.append({'boundary': boundary_id, 'data': data}) optB = Boundary(boundary_ID=BoundaryID(boundary_id)).optimize() data = {} boundary_id = '' boundary_id = boundary_id + polygon['properties']['id'] data[polygon['properties']['id']] = polygon['properties'] i = i + 1 boundary_dataset = {'boundary_data_set': bds} # POST BOUNDARY_DATASETS TEST r = requests.post('http://127.0.0.1:8000/bdatasets/', json=boundary_dataset) assert r.status_code == 201 # GET BOUNDARY (POLYGON) TEST params = { 'dlx': '-0.903563', 'dly': '41.644185', 'urx': '-0.902558', 'ury': '41.644762' } cells = [ Boundary(boundary_ID=BoundaryID( 'P22220720640')).optimize().boundary_ID.value, Boundary(boundary_ID=BoundaryID( 'P22220720641')).optimize().boundary_ID.value, Boundary(boundary_ID=BoundaryID( 'P22220720642')).optimize().boundary_ID.value, Boundary(boundary_ID=BoundaryID( 'P22220720643')).optimize().boundary_ID.value, Boundary(boundary_ID=BoundaryID( 'P22220720644')).optimize().boundary_ID.value, Boundary(boundary_ID=BoundaryID( 'P22220720645')).optimize().boundary_ID.value ] r = requests.get('http://127.0.0.1:8000/boundaries/', params=params) assert r.status_code == 200 num_cells = 0 for boundary in r.json(): assert cells.__contains__(boundary['AUID']) num_cells = num_cells + 1 assert num_cells == len(cells) store.dropAll() print('TEST FINISH')