def query_polygon(self, event, context): hexagons = h3.polyfill(event['geometry'], event['resolution'], geo_json_conformant=True) if event['compact']: hexagons = h3.compact(hexagons) processes = [] parent_connections = [] for item in hexagons: parent_conn, child_conn = Pipe() parent_connections.append(parent_conn) process = Process(target=self.query_cell_wrapper, args=(item, child_conn)) processes.append(process) for process in processes: process.start() for process in processes: process.join() cities = [] for parent_connection in parent_connections: for city in parent_connection.recv()[0]: if city not in cities: cities.append(city) resp = {'statusCode': 200, 'body': json.dumps({'cities': cities})} return resp
def test_compact_and_uncompact(self): hexagons = h3.polyfill( { 'type': 'Polygon', 'coordinates': [ [ [37.813318999983238, -122.4089866999972145], [ 37.7866302000007224, -122.3805436999997056 ], [37.7198061999978478, -122.3544736999993603], [ 37.7076131999975672, -122.5123436999983966 ], [37.7835871999971715, -122.5247187000021967], [37.8151571999998453, -122.4798767000009008] ] ] }, 9 ) compactedHexagons = h3.compact(hexagons) self.assertEqual( len(compactedHexagons), 209, 'got an appropriate number of hexagons back' ) uncompactedHexagons = h3.uncompact(compactedHexagons, 9) self.assertEqual( len(uncompactedHexagons), 1253, 'got an appropriate number of hexagons back' )
def test_compact_malformed_input(self): with pytest.raises(Exception) as e_info: h3.compact([ '89283082813ffff', '89283082813ffff', '89283082813ffff', '89283082813ffff', '89283082813ffff', '89283082813ffff', '89283082813ffff', '89283082813ffff', '89283082813ffff', '89283082813ffff', '89283082813ffff', '89283082813ffff', '89283082813ffff', ]) self.assertTrue(isinstance(e_info.value, Exception))
def test_compact_and_uncompact_nothing(self): compactedNothing = h3.compact([]) self.assertEqual(len(compactedNothing), 0, 'still nothing') uncompactedNothing = h3.uncompact([], 9) self.assertEqual(len(uncompactedNothing), 0, 'still nothing')