Geometry Types#

HeavyDB offers an extensive range of geometry types, encompassing (Multi)Point, (Multi)LineString, and (Multi)Polygon.

Basics#

GeoPoint#

from test_geopoint of rbc/tests/heavydb/test_howtos.py#
1from rbc.heavydb import Point2D
2
3@heavydb('int32(TableFunctionManager, int64 size, OutputColumn<Z>)',
4         Z=['GeoPoint'])
5def generate_geo(mgr, size, out):
6    mgr.set_output_row_size(size)
7    for i in range(size):
8        out[i] = Point2D(i, i)
9    return size
Example SQL Query
from test_geopoint of rbc/tests/heavydb/test_howtos.py#
1query = '''
2    SELECT * FROM TABLE(
3        generate_geo(5)
4    );
5'''
6_, r = heavydb.sql_execute(query)
7r = list(r)
8assert r == [('POINT (0 0)',), ('POINT (1 1)',), ('POINT (2 2)',),
9             ('POINT (3 3)',), ('POINT (4 4)',)]

GeoMultiPoint#

MultiPoint works a bit different than Point. They are created by calling the .from_coords method.

from test_geomultipoint of rbc/tests/heavydb/test_howtos.py#
1@heavydb('int32(TableFunctionManager, int64 size, OutputColumn<Z>)',
2         Z=['GeoMultiPoint'])
3def generate_geo(mgr, size, out):
4    mgr.set_output_item_values_total_number(0, size * 4)
5    mgr.set_output_row_size(size)
6    for i in range(size):
7        coords = [i + 1.0, i + 2.0, i + 3.0, i + 4.0]
8        out[i].from_coords(coords)
9    return size
Example SQL Query
from test_geopoint of rbc/tests/heavydb/test_howtos.py#
1query = '''
2    SELECT * FROM TABLE(
3        generate_geo(3)
4    );
5'''
6_, r = heavydb.sql_execute(query)
7r = list(r)
8assert r == [('MULTIPOINT (1 2,3 4)',), ('MULTIPOINT (2 3,4 5)',),
9             ('MULTIPOINT (3 4,5 6)',)]