From 4dd5ad61020c8c386d82136f6b6b6b8dcdbbd981 Mon Sep 17 00:00:00 2001 From: "xi.ge" Date: Wed, 25 Mar 2020 11:20:34 +0800 Subject: [PATCH 01/24] fix wrong choroplethmap when png size is small --- cpp/src/render/render_builder_impl.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cpp/src/render/render_builder_impl.h b/cpp/src/render/render_builder_impl.h index 72188747a..aa8bd0921 100644 --- a/cpp/src/render/render_builder_impl.h +++ b/cpp/src/render/render_builder_impl.h @@ -67,7 +67,7 @@ std::shared_ptr TransformAndProjection( pointXY_from_wkt(bottom_right, bottom_right_x, bottom_right_y, poCT); auto coordinate_width = bottom_right_x - top_left_x; auto coordinate_height = top_left_y - bottom_right_y; - uint32_t output_x, output_y; + int32_t output_x, output_y; for (int32_t i = 0; i < len; i++) { if (wkt_geometries->IsNull(i)) { @@ -88,9 +88,9 @@ std::shared_ptr TransformAndProjection( // 2. projection auto type = wkbFlatten(geo->getGeometryType()); if (type == wkbPoint) { - output_x = (uint32_t)(((geo->toPoint()->getX() - top_left_x) * width) / + output_x = (int32_t)(((geo->toPoint()->getX() - top_left_x) * width) / coordinate_width); - output_y = (uint32_t)(((geo->toPoint()->getY() - bottom_right_y) * height) / + output_y = (int32_t)(((geo->toPoint()->getY() - bottom_right_y) * height) / coordinate_height); geo->toPoint()->setX(output_x); geo->toPoint()->setY(output_y); @@ -99,9 +99,9 @@ std::shared_ptr TransformAndProjection( auto ring_size = ring->getNumPoints(); for (int j = 0; j < ring_size; j++) { output_x = - (uint32_t)(((ring->getX(j) - top_left_x) * width) / coordinate_width); + (int32_t)(((ring->getX(j) - top_left_x) * width) / coordinate_width); output_y = - (uint32_t)(((ring->getY(j) - bottom_right_y) * height) / coordinate_height); + (int32_t)(((ring->getY(j) - bottom_right_y) * height) / coordinate_height); ring->setPoint(j, output_x, output_y); } } else { From fc27d604c9e999192031c8e609c7cc7eff3bbed4 Mon Sep 17 00:00:00 2001 From: "xi.ge" Date: Wed, 25 Mar 2020 11:27:13 +0800 Subject: [PATCH 02/24] fix wrong choroplethmap when png size is small --- cpp/src/render/render_builder_impl.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cpp/src/render/render_builder_impl.h b/cpp/src/render/render_builder_impl.h index aa8bd0921..b7990f1e4 100644 --- a/cpp/src/render/render_builder_impl.h +++ b/cpp/src/render/render_builder_impl.h @@ -62,11 +62,11 @@ std::shared_ptr TransformAndProjection( auto len = geos->length(); auto wkt_geometries = std::static_pointer_cast(geos); - double top_left_x, top_left_y, bottom_right_x, bottom_right_y; - pointXY_from_wkt(top_left, top_left_x, top_left_y, poCT); - pointXY_from_wkt(bottom_right, bottom_right_x, bottom_right_y, poCT); - auto coordinate_width = bottom_right_x - top_left_x; - auto coordinate_height = top_left_y - bottom_right_y; + double min_x, max_y, max_x, min_y; + pointXY_from_wkt(top_left, min_x, max_y, poCT); + pointXY_from_wkt(bottom_right, max_x, min_y, poCT); + auto coor_width = max_x - min_x; + auto coor_height = max_y - min_y; int32_t output_x, output_y; for (int32_t i = 0; i < len; i++) { @@ -88,20 +88,20 @@ std::shared_ptr TransformAndProjection( // 2. projection auto type = wkbFlatten(geo->getGeometryType()); if (type == wkbPoint) { - output_x = (int32_t)(((geo->toPoint()->getX() - top_left_x) * width) / - coordinate_width); - output_y = (int32_t)(((geo->toPoint()->getY() - bottom_right_y) * height) / - coordinate_height); + auto x = geo->toPoint()->getX(); + auto y = geo->toPoint()->getY(); + output_x = (int32_t)(((x - min_x) * width) / coor_width); + output_y = (int32_t)(((y - min_y) * height) / coor_height); geo->toPoint()->setX(output_x); geo->toPoint()->setY(output_y); } else if (type == wkbPolygon) { auto ring = geo->toPolygon()->getExteriorRing(); auto ring_size = ring->getNumPoints(); for (int j = 0; j < ring_size; j++) { - output_x = - (int32_t)(((ring->getX(j) - top_left_x) * width) / coordinate_width); - output_y = - (int32_t)(((ring->getY(j) - bottom_right_y) * height) / coordinate_height); + auto x = ring->getX(j); + auto y = ring->getY(j); + output_x = (int32_t)(((x - min_x) * width) / coor_width); + output_y = (int32_t)(((y - min_y) * height) / coor_height); ring->setPoint(j, output_x, output_y); } } else { From ae85f5efa2747ffcf022a651b20dbe858cad9bb2 Mon Sep 17 00:00:00 2001 From: "xi.ge" Date: Wed, 25 Mar 2020 14:44:05 +0800 Subject: [PATCH 03/24] add test for transform_projection --- .../render/coordinate_projection_test.cpp | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/cpp/unittest/render/coordinate_projection_test.cpp b/cpp/unittest/render/coordinate_projection_test.cpp index d295da164..953d77fb9 100644 --- a/cpp/unittest/render/coordinate_projection_test.cpp +++ b/cpp/unittest/render/coordinate_projection_test.cpp @@ -46,10 +46,33 @@ TEST(TRANSFORM_PROJECTION_TEST, POINT_TEST) { bottom_right, top_left, 200, 300); auto str_arr = std::static_pointer_cast(arr); - auto res1 = str_arr->GetString(0); - auto res2 = str_arr->GetString(1); - // assert(res1 == "POINT (129 128)"); - // assert(res2 == "POINT (180 61)"); - std::cout << res1 << std::endl; - std::cout << res2 << std::endl; +} + +TEST(TRANSFORM_PROJECTION_TEST, POLYGON_TEST) { + // param1: wkt string -73.984092,40.753893,-73.977588,40.756342 + std::string wkt1 = "POLYGON ((-73.989754263774 40.7677468202825,-73.9899519048903 40.7678302792556,-73.989912476786 40.7678842519974,-73.9899105593281 40.7678834422768,-73.9899028933374 40.7678939333729,-73.9897724980032 40.7678388704833,-73.989737963688 40.7678242873584,-73.9897071707312 40.7678112849412,-73.9897080734511 40.7678100513318,-73.9897150393223 40.7678005156204,-73.989754263774 40.7677468202825))"; + std::string wkt2 = "POLYGON ((-73.9870535105538 40.7601363221624,-73.9871923522742 40.7599470020734,-73.9874629426019 40.7600617372231,-73.9875093817809 40.7600814281999,-73.9874059754083 40.7602224305671,-73.9873933701613 40.7602396189215,-73.9873705406814 40.7602707486673,-73.9873691883338 40.7602701748976,-73.9870535105538 40.7601363221624))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt1); + status = string_builder.Append(wkt2); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: src_rs + std::string src_ts = "EPSG:4326"; + + // param3: dst_rs + std::string dst_rs = "EPSG:3857"; + + // param4: top_left + std::string top_left = "POINT (-73.984092 40.756342)"; + + // param5: bottom_right + std::string bottom_right = "POINT (-73.977588 40.753893)"; + + auto arr = arctern::render::transform_and_projection(string_array, src_ts, dst_rs, + bottom_right, top_left, 200, 300); + + auto str_arr = std::static_pointer_cast(arr); } From ab227a65ed8034e6579444a8c168f25001407f68 Mon Sep 17 00:00:00 2001 From: "xi.ge" Date: Wed, 25 Mar 2020 14:56:11 +0800 Subject: [PATCH 04/24] format projection test --- .../render/coordinate_projection_test.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cpp/unittest/render/coordinate_projection_test.cpp b/cpp/unittest/render/coordinate_projection_test.cpp index 953d77fb9..905c63f53 100644 --- a/cpp/unittest/render/coordinate_projection_test.cpp +++ b/cpp/unittest/render/coordinate_projection_test.cpp @@ -50,8 +50,19 @@ TEST(TRANSFORM_PROJECTION_TEST, POINT_TEST) { TEST(TRANSFORM_PROJECTION_TEST, POLYGON_TEST) { // param1: wkt string -73.984092,40.753893,-73.977588,40.756342 - std::string wkt1 = "POLYGON ((-73.989754263774 40.7677468202825,-73.9899519048903 40.7678302792556,-73.989912476786 40.7678842519974,-73.9899105593281 40.7678834422768,-73.9899028933374 40.7678939333729,-73.9897724980032 40.7678388704833,-73.989737963688 40.7678242873584,-73.9897071707312 40.7678112849412,-73.9897080734511 40.7678100513318,-73.9897150393223 40.7678005156204,-73.989754263774 40.7677468202825))"; - std::string wkt2 = "POLYGON ((-73.9870535105538 40.7601363221624,-73.9871923522742 40.7599470020734,-73.9874629426019 40.7600617372231,-73.9875093817809 40.7600814281999,-73.9874059754083 40.7602224305671,-73.9873933701613 40.7602396189215,-73.9873705406814 40.7602707486673,-73.9873691883338 40.7602701748976,-73.9870535105538 40.7601363221624))"; + std::string wkt1 = "POLYGON ((" + "-73.989754263774 40.7677468202825,-73.9899519048903 40.7678302792556," + "-73.989912476786 40.7678842519974,-73.9899105593281 40.7678834422768," + "-73.9899028933374 40.7678939333729,-73.9897724980032 40.7678388704833," + "-73.989737963688 40.7678242873584,-73.9897071707312 40.7678112849412," + "-73.9897080734511 40.7678100513318,-73.9897150393223 40.7678005156204," + "-73.989754263774 40.7677468202825))"; + std::string wkt2 = "POLYGON ((" + "-73.9870535105538 40.7601363221624,-73.9871923522742 40.7599470020734," + "-73.9874629426019 40.7600617372231,-73.9875093817809 40.7600814281999," + "-73.9874059754083 40.7602224305671,-73.9873933701613 40.7602396189215," + "-73.9873705406814 40.7602707486673,-73.9873691883338 40.7602701748976," + "-73.9870535105538 40.7601363221624))"; arrow::StringBuilder string_builder; auto status = string_builder.Append(wkt1); status = string_builder.Append(wkt2); From 13d4f60c1432e5fe2abd17e8c3190a5e8d193531 Mon Sep 17 00:00:00 2001 From: "xi.ge" Date: Wed, 22 Apr 2020 17:03:32 +0800 Subject: [PATCH 05/24] package python transform and render --- python/arctern/_wrapper_func.py | 137 +++++++++++++++---- python/arctern/cython/arctern_core_.pyx | 4 +- python/tests/geo/render_test.py | 100 +++++++------- spark/pyspark/arctern_pyspark/render_func.py | 37 ++--- 4 files changed, 175 insertions(+), 103 deletions(-) diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index 5fa0a5606..4ca2cc5c9 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1108,22 +1108,56 @@ def ST_CurveToLine(geos): rs = arctern_core_.ST_CurveToLine(arr_geos) return rs.to_pandas() -def point_map(vega, points): +def point_map(vega, points, transform=True): import pyarrow as pa - array_points = pa.array(points, type='binary') + geos = pa.array(points, type='binary') + + if transform: + bounding_box = vega.bounding_box() + top_left = 'POINT (' + str(bounding_box[0]) + ' ' + str(bounding_box[3]) + ')' + bottom_right = 'POINT (' + str(bounding_box[2]) + ' ' + str(bounding_box[1]) + ')' + height = vega.height() + width = vega.width() + coor = vega.coor() + src = bytes(coor, encoding="utf8") + dst = bytes('EPSG:3857', encoding="utf8") + bounding_box_min = bytes(top_left, encoding="utf8") + bounding_box_max = bytes(bottom_right, encoding="utf8") + if coor != 'EPSG:3857': + geos = arctern_core_.transform_and_projection(geos, src, dst, bounding_box_max, bounding_box_min, height, width) + else: + geos = arctern_core_.projection(geos, bounding_box_max, bounding_box_min, height, width) + vega_string = vega.build().encode('utf-8') - rs = arctern_core_.point_map(vega_string, array_points) + rs = arctern_core_.point_map(vega_string, geos) return base64.b64encode(rs.buffers()[1].to_pybytes()) -def weighted_point_map(vega, points, **kwargs): +def weighted_point_map(vega, points, transform=True, **kwargs): import pyarrow as pa color_weights = kwargs.get('color_weights', None) size_weights = kwargs.get('size_weights', None) vega_string = vega.build().encode('utf-8') - array_points = pa.array(points, type='binary') + geos = pa.array(points, type='binary') + + if transform: + bounding_box = vega.bounding_box() + top_left = 'POINT (' + str(bounding_box[0]) + ' ' + str(bounding_box[3]) + ')' + bottom_right = 'POINT (' + str(bounding_box[2]) + ' ' + str(bounding_box[1]) + ')' + height = vega.height() + width = vega.width() + coor = vega.coor() + src = bytes(coor, encoding="utf8") + dst = bytes('EPSG:3857', encoding="utf8") + bounding_box_min = bytes(top_left, encoding="utf8") + bounding_box_max = bytes(bottom_right, encoding="utf8") + if coor != 'EPSG:3857': + geos = arctern_core_.transform_and_projection(geos, src, dst, bounding_box_max, bounding_box_min, height, width) + else: + geos = arctern_core_.projection(geos, bounding_box_max, bounding_box_min, height, width) + if (color_weights is None and size_weights is None): - rs = arctern_core_.weighted_point_map(vega_string, array_points) + rs = arctern_core_.weighted_point_map(vega_string, geos) elif (color_weights is not None and size_weights is not None): if color_weights.dtypes == 'float64': arr_c = pa.array(color_weights, type='double') @@ -1134,25 +1168,42 @@ def weighted_point_map(vega, points, **kwargs): arr_s = pa.array(size_weights, type='double') else: arr_s = pa.array(size_weights, type='int64') - rs = arctern_core_.weighted_color_size_point_map(vega_string, array_points, arr_c, arr_s) + rs = arctern_core_.weighted_color_size_point_map(vega_string, geos, arr_c, arr_s) elif (color_weights is None and size_weights is not None): if size_weights.dtypes == 'float64': arr_s = pa.array(size_weights, type='double') else: arr_s = pa.array(size_weights, type='int64') - rs = arctern_core_.weighted_size_point_map(vega_string, array_points, arr_s) + rs = arctern_core_.weighted_size_point_map(vega_string, geos, arr_s) else: if color_weights.dtypes == 'float64': arr_c = pa.array(color_weights, type='double') else: arr_c = pa.array(color_weights, type='int64') - rs = arctern_core_.weighted_color_point_map(vega_string, array_points, arr_c) + rs = arctern_core_.weighted_color_point_map(vega_string, geos, arr_c) return base64.b64encode(rs.buffers()[1].to_pybytes()) -def heat_map(vega, points, weights): +def heat_map(vega, points, weights, transform=True): import pyarrow as pa - array_points = pa.array(points, type='binary') + geos = pa.array(points, type='binary') + + if transform: + bounding_box = vega.bounding_box() + top_left = 'POINT (' + str(bounding_box[0]) + ' ' + str(bounding_box[3]) + ')' + bottom_right = 'POINT (' + str(bounding_box[2]) + ' ' + str(bounding_box[1]) + ')' + height = vega.height() + width = vega.width() + coor = vega.coor() + src = bytes(coor, encoding="utf8") + dst = bytes('EPSG:3857', encoding="utf8") + bounding_box_min = bytes(top_left, encoding="utf8") + bounding_box_max = bytes(bottom_right, encoding="utf8") + if coor != 'EPSG:3857': + geos = arctern_core_.transform_and_projection(geos, src, dst, bounding_box_max, bounding_box_min, height, width) + else: + geos = arctern_core_.projection(geos, bounding_box_max, bounding_box_min, height, width) + vega_string = vega.build().encode('utf-8') if weights.dtypes == 'float64': @@ -1160,44 +1211,78 @@ def heat_map(vega, points, weights): else: arr_c = pa.array(weights, type='int64') - rs = arctern_core_.heat_map(vega_string, array_points, arr_c) + rs = arctern_core_.heat_map(vega_string, geos, arr_c) return base64.b64encode(rs.buffers()[1].to_pybytes()) -def choropleth_map(vega, region_boundaries, weights): +def choropleth_map(vega, region_boundaries, weights, transform=True): import pyarrow as pa - arr_wkb = pa.array(region_boundaries, type='binary') + geos = pa.array(region_boundaries, type='binary') + + if transform: + bounding_box = vega.bounding_box() + top_left = 'POINT (' + str(bounding_box[0]) + ' ' + str(bounding_box[3]) + ')' + bottom_right = 'POINT (' + str(bounding_box[2]) + ' ' + str(bounding_box[1]) + ')' + height = vega.height() + width = vega.width() + coor = vega.coor() + src = bytes(coor, encoding="utf8") + dst = bytes('EPSG:3857', encoding="utf8") + bounding_box_min = bytes(top_left, encoding="utf8") + bounding_box_max = bytes(bottom_right, encoding="utf8") + if coor != 'EPSG:3857': + geos = arctern_core_.transform_and_projection(geos, src, dst, bounding_box_max, bounding_box_min, height, width) + else: + geos = arctern_core_.projection(geos, bounding_box_max, bounding_box_min, height, width) + vega_string = vega.build().encode('utf-8') if weights.dtypes == 'float64': arr_c = pa.array(weights, type='double') else: arr_c = pa.array(weights, type='int64') - rs = arctern_core_.choropleth_map(vega_string, arr_wkb, arr_c) + rs = arctern_core_.choropleth_map(vega_string, geos, arr_c) return base64.b64encode(rs.buffers()[1].to_pybytes()) -def icon_viz(vega, points): +def icon_viz(vega, points, transform=True): import pyarrow as pa - array_points = pa.array(points, type='binary') + geos = pa.array(points, type='binary') + + if transform: + bounding_box = vega.bounding_box() + top_left = 'POINT (' + str(bounding_box[0]) + ' ' + str(bounding_box[3]) + ')' + bottom_right = 'POINT (' + str(bounding_box[2]) + ' ' + str(bounding_box[1]) + ')' + height = vega.height() + width = vega.width() + coor = vega.coor() + src = bytes(coor, encoding="utf8") + dst = bytes('EPSG:3857', encoding="utf8") + bounding_box_min = bytes(top_left, encoding="utf8") + bounding_box_max = bytes(bottom_right, encoding="utf8") + if coor != 'EPSG:3857': + geos = arctern_core_.transform_and_projection(geos, src, dst, bounding_box_max, bounding_box_min, height, width) + else: + geos = arctern_core_.projection(geos, bounding_box_max, bounding_box_min, height, width) + vega_string = vega.build().encode('utf-8') - rs = arctern_core_.icon_viz(vega_string, array_points) + rs = arctern_core_.icon_viz(vega_string, geos) return base64.b64encode(rs.buffers()[1].to_pybytes()) -def projection(geos, bottom_geo2, top_geo1, height, width): +def projection(geos, bottom_right, top_left, height, width): import pyarrow as pa arr_geos = pa.array(geos, type='binary') - bounding_box_min = bytes(bottom_geo2, encoding="utf8") - bounding_box_max = bytes(top_geo1, encoding="utf8") - rs = arctern_core_.projection(arr_geos, bounding_box_min, bounding_box_max, height, width) + bounding_box_max = bytes(bottom_right, encoding="utf8") + bounding_box_min = bytes(top_left, encoding="utf8") + rs = arctern_core_.projection(arr_geos, bounding_box_max, bounding_box_min, height, width) return rs.to_pandas() -def transform_and_projection(geos, src_rs, dst_rs, bottom_geo2, top_geo1, height, width): +def transform_and_projection(geos, src_rs, dst_rs, bottom_right, top_left, height, width): import pyarrow as pa arr_geos = pa.array(geos, type='binary') src = bytes(src_rs, encoding="utf8") dst = bytes(dst_rs, encoding="utf8") - bounding_box_min = bytes(bottom_geo2, encoding="utf8") - bounding_box_max = bytes(top_geo1, encoding="utf8") - rs = arctern_core_.transform_and_projection(arr_geos, src, dst, bounding_box_min, bounding_box_max, height, width) + bounding_box_max = bytes(bottom_right, encoding="utf8") + bounding_box_min = bytes(top_left, encoding="utf8") + rs = arctern_core_.transform_and_projection(arr_geos, src, dst, bounding_box_max, bounding_box_min, height, width) return rs.to_pandas() def wkt2wkb(arr_wkt): diff --git a/python/arctern/cython/arctern_core_.pyx b/python/arctern/cython/arctern_core_.pyx index a5643d5dd..fb6dd3913 100644 --- a/python/arctern/cython/arctern_core_.pyx +++ b/python/arctern/cython/arctern_core_.pyx @@ -18,10 +18,10 @@ from pyarrow.lib cimport (pyarrow_wrap_array, pyarrow_unwrap_array) cimport arctern_core__ as arctern_core_pxd -def projection(geos, bottom_right, top_left, int height, int width): +def projection(geos, bottom_right, top_left, height, width): return pyarrow_wrap_array(arctern_core_pxd.projection(pyarrow_unwrap_array(geos), bottom_right, top_left, height, width)) -def transform_and_projection(geos, src_rs, dst_rs, bottom_right, top_left, int height, int width): +def transform_and_projection(geos, src_rs, dst_rs, bottom_right, top_left, height, width): return pyarrow_wrap_array(arctern_core_pxd.transform_and_projection(pyarrow_unwrap_array(geos), src_rs, dst_rs, bottom_right, top_left, height, width)) def point_map(vega, points): diff --git a/python/tests/geo/render_test.py b/python/tests/geo/render_test.py index 53ab4bf61..4dd749349 100644 --- a/python/tests/geo/render_test.py +++ b/python/tests/geo/render_test.py @@ -43,26 +43,20 @@ def test_point_map(): x_data = [] y_data = [] - # y = 150 - for i in range(100, 200): - x_data.append(i) - y_data.append(150) - - # y = x - 50 - for i in range(100, 200): - x_data.append(i) - y_data.append(i - 50) - - # y = 50 - for i in range(100, 200): - x_data.append(i) - y_data.append(50) + x_data.append(-73.96524) + x_data.append(-73.96118) + x_data.append(-73.97324) + x_data.append(-73.98456) + y_data.append(40.73747) + y_data.append(40.74507) + y_data.append(40.75890) + y_data.append(40.77654) arr_x = pandas.Series(x_data) arr_y = pandas.Series(y_data) points = arctern.ST_Point(arr_x, arr_y) - vega = vega_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], point_size=3, point_color="#2DEF4A", opacity=0.5, coordinate_system="EPSG:4326") + vega = vega_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], point_size=10, point_color="#0000FF", opacity=1.0, coordinate_system="EPSG:4326") curve_z1 = arctern.point_map(vega, points) save_png(curve_z1, "/tmp/test_curve_z1.png") @@ -73,25 +67,21 @@ def test_weighted_point_map(): c_data = [] s_data = [] - x_data.append(10) - x_data.append(20) - x_data.append(30) - x_data.append(40) - x_data.append(50) + x_data.append(-73.96524) + x_data.append(-73.96118) + x_data.append(-73.97324) + x_data.append(-73.98456) - y_data.append(10) - y_data.append(20) - y_data.append(30) - y_data.append(40) - y_data.append(50) + y_data.append(40.73747) + y_data.append(40.74507) + y_data.append(40.75890) + y_data.append(40.77654) c_data.append(1) c_data.append(2) c_data.append(3) c_data.append(4) - c_data.append(5) - s_data.append(2) s_data.append(4) s_data.append(6) s_data.append(8) @@ -103,61 +93,69 @@ def test_weighted_point_map(): arr_c = pandas.Series(c_data) arr_s = pandas.Series(s_data) - vega1 = vega_weighted_pointmap(300, 200, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#87CEEB"], opacity=1.0, coordinate_system="EPSG:3857") + vega1 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF"], opacity=1.0, coordinate_system="EPSG:4326") res1 = arctern.weighted_point_map(vega1, points) save_png(res1, "/tmp/test_weighted_0_0.png") - vega2 = vega_weighted_pointmap(300, 200, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF", "#FF0000"], color_bound=[1, 5], opacity=1.0, coordinate_system="EPSG:3857") + vega2 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF", "#FF0000"], color_bound=[1, 5], opacity=1.0, coordinate_system="EPSG:4326") res2 = arctern.weighted_point_map(vega2, points, color_weights=arr_c) save_png(res2, "/tmp/test_weighted_1_0.png") - vega3 = vega_weighted_pointmap(300, 200, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#87CEEB"], size_bound=[1, 10], opacity=1.0, coordinate_system="EPSG:3857") + vega3 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF"], size_bound=[1, 10], opacity=1.0, coordinate_system="EPSG:4326") res3 = arctern.weighted_point_map(vega3, points, size_weights=arr_s) save_png(res3, "/tmp/test_weighted_0_1.png") - vega4 = vega_weighted_pointmap(300, 200, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF", "#FF0000"], color_bound=[1, 5], size_bound=[1, 10], opacity=1.0, coordinate_system="EPSG:3857") + vega4 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF", "#FF0000"], color_bound=[1, 5], size_bound=[1, 10], opacity=1.0, coordinate_system="EPSG:4326") res4 = arctern.weighted_point_map(vega4, points, color_weights=arr_c, size_weights=arr_s) save_png(res4, "/tmp/test_weighted_1_1.png") - def test_heat_map(): x_data = [] y_data = [] c_data = [] - for i in range(0, 5): - x_data.append(i + 50) - y_data.append(i + 50) - c_data.append(i + 50) + x_data.append(-73.96524) + x_data.append(-73.96118) + x_data.append(-73.97324) + x_data.append(-73.98456) + + y_data.append(40.73747) + y_data.append(40.74507) + y_data.append(40.75890) + y_data.append(40.77654) + + c_data.append(10) + c_data.append(20) + c_data.append(30) + c_data.append(40) arr_x = pandas.Series(x_data) arr_y = pandas.Series(y_data) points = arctern.ST_Point(arr_x, arr_y) arr_c = pandas.Series(c_data) - vega = vega_heatmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], map_zoom_level=10.0, coordinate_system='EPSG:4326') + vega = vega_heatmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], map_zoom_level=13.0, coordinate_system='EPSG:4326') heat_map1 = arctern.heat_map(vega, points, arr_c) save_png(heat_map1, "/tmp/test_heat_map1.png") - def test_choropleth_map(): wkt_data = [] count_data = [] wkt_data.append("POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))") + "-73.97324 40.73747, " + "-73.96524 40.74507, " + "-73.96118 40.75890, " + "-73.95556 40.77654, " + "-73.97324 40.73747))") count_data.append(5.0) arr_wkt = pandas.Series(wkt_data) arr_wkb = arctern.wkt2wkb(arr_wkt) arr_count = pandas.Series(count_data) - vega = vega_choroplethmap(1900, 1410, bounding_box=[-73.994092, 40.753893, -73.977588, 40.759642], color_gradient=["#0000FF", "#FF0000"], color_bound=[2.5, 5], opacity=1.0, coordinate_system='EPSG:4326') + vega = vega_choroplethmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF", "#FF0000"], color_bound=[2.5, 5], opacity=1.0, coordinate_system='EPSG:4326') choropleth_map1 = arctern.choropleth_map(vega, arr_wkb, arr_count) save_png(choropleth_map1, "/tmp/test_choropleth_map1.png") @@ -165,9 +163,15 @@ def test_icon_viz(): x_data = [] y_data = [] - for i in range(5): - x_data.append(i * 100) - y_data.append(i * 100) + x_data.append(-73.96524) + x_data.append(-73.96118) + x_data.append(-73.97324) + x_data.append(-73.98456) + + y_data.append(40.73747) + y_data.append(40.74507) + y_data.append(40.75890) + y_data.append(40.77654) arr_x = pandas.Series(x_data) arr_y = pandas.Series(y_data) @@ -177,7 +181,7 @@ def test_icon_viz(): dir_path = os.path.dirname(os.path.realpath(__file__)) png_path = dir_path + "/../images/taxi.png" - vega = vega_icon(800, 600, [-73.998427, 40.730309, -73.954348, 40.780816], png_path, "EPSG:43") + vega = vega_icon(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], icon_path=png_path, coordinate_system="EPSG:4326") icon_buf = arctern.icon_viz(vega, points) save_png(icon_buf, "/tmp/test_icon_viz.png") diff --git a/spark/pyspark/arctern_pyspark/render_func.py b/spark/pyspark/arctern_pyspark/render_func.py index 6e12772a3..f3df7cb0d 100644 --- a/spark/pyspark/arctern_pyspark/render_func.py +++ b/spark/pyspark/arctern_pyspark/render_func.py @@ -20,23 +20,6 @@ "icon_viz", ] - -def print_partitions(df): - numPartitions = df.rdd.getNumPartitions() - print("Total partitions: {}".format(numPartitions)) - print("Partitioner: {}".format(df.rdd.partitioner)) - df.explain() - parts = df.rdd.glom().collect() - i = 0 - j = 0 - for p in parts: - print("Partition {}:".format(i)) - for r in p: - print("Row {}:{}".format(j, r)) - j = j + 1 - i = i + 1 - - def pointmap(vega, df): if df.rdd.isEmpty(): return None @@ -65,7 +48,7 @@ def pointmap(vega, df): @pandas_udf("string", PandasUDFType.GROUPED_AGG) def pointmap_wkb(point, conf=vega): from arctern import point_map - return point_map(conf, point) + return point_map(conf, point, False) df = df.rdd.coalesce(1, shuffle=True).toDF() hex_data = df.agg(pointmap_wkb(df[col_point])).collect()[0][0] @@ -124,7 +107,7 @@ def render_agg_UDF_3857_2(batch_iter): @pandas_udf("string", PandasUDFType.GROUPED_AGG) def weighted_pointmap_wkb_3857_2(point, c, s, conf=vega): from arctern import weighted_point_map - return weighted_point_map(conf, point, color_weights=c, size_weights=s) + return weighted_point_map(conf, point, False, color_weights=c, size_weights=s) agg_df = df.mapInPandas(render_agg_UDF_3857_2) agg_df = agg_df.rdd.coalesce(1, shuffle=True).toDF() @@ -145,7 +128,7 @@ def render_agg_UDF_3857_1(batch_iter): @pandas_udf("string", PandasUDFType.GROUPED_AGG) def weighted_pointmap_wkb_3857_1(point, c, conf=vega): from arctern import weighted_point_map - return weighted_point_map(conf, point, color_weights=c) + return weighted_point_map(conf, point, False, color_weights=c) agg_df = df.mapInPandas(render_agg_UDF_3857_1) agg_df = agg_df.rdd.coalesce(1, shuffle=True).toDF() @@ -155,7 +138,7 @@ def weighted_pointmap_wkb_3857_1(point, c, conf=vega): @pandas_udf("string", PandasUDFType.GROUPED_AGG) def weighted_pointmap_wkb(point, conf=vega): from arctern import weighted_point_map - return weighted_point_map(conf, point) + return weighted_point_map(conf, point, False) df = df.rdd.coalesce(1, shuffle=True).toDF() hex_data = df.agg(weighted_pointmap_wkb(df[col_point])).collect()[0][0] @@ -179,7 +162,7 @@ def render_agg_UDF_2(batch_iter): @pandas_udf("string", PandasUDFType.GROUPED_AGG) def weighted_pointmap_wkb_2(point, c, s, conf=vega): from arctern import weighted_point_map - return weighted_point_map(conf, point, color_weights=c, size_weights=s) + return weighted_point_map(conf, point, False, color_weights=c, size_weights=s) agg_df = df.mapInPandas(render_agg_UDF_2) agg_df = agg_df.rdd.coalesce(1, shuffle=True).toDF() @@ -200,7 +183,7 @@ def render_agg_UDF_1(batch_iter): @pandas_udf("string", PandasUDFType.GROUPED_AGG) def weighted_pointmap_wkb_1(point, c, conf=vega): from arctern import weighted_point_map - return weighted_point_map(conf, point, color_weights=c) + return weighted_point_map(conf, point, False, color_weights=c) agg_df = df.mapInPandas(render_agg_UDF_1) agg_df = agg_df.rdd.coalesce(1, shuffle=True).toDF() @@ -210,7 +193,7 @@ def weighted_pointmap_wkb_1(point, c, conf=vega): @pandas_udf("string", PandasUDFType.GROUPED_AGG) def weighted_pointmap_wkb_0(point, conf=vega): from arctern import weighted_point_map - return weighted_point_map(conf, point) + return weighted_point_map(conf, point, False) df = df.rdd.coalesce(1, shuffle=True).toDF() hex_data = df.agg(weighted_pointmap_wkb_0(df[col_point])).collect()[0][0] @@ -259,7 +242,7 @@ def render_agg_UDF(batch_iter): @pandas_udf("string", PandasUDFType.GROUPED_AGG) def heatmap_wkb(point, w, conf=vega): from arctern import heat_map - return heat_map(conf, point, w) + return heat_map(conf, point, w, False) agg_df = df.mapInPandas(render_agg_UDF) agg_df = agg_df.rdd.coalesce(1, shuffle=True).toDF() @@ -309,7 +292,7 @@ def render_agg_UDF(batch_iter): @pandas_udf("string", PandasUDFType.GROUPED_AGG) def choroplethmap_wkb(wkb, w, conf=vega): from arctern import choropleth_map - return choropleth_map(conf, wkb, w) + return choropleth_map(conf, wkb, w, False) agg_df = df.mapInPandas(render_agg_UDF) agg_df = agg_df.rdd.coalesce(1, shuffle=True).toDF() @@ -345,7 +328,7 @@ def icon_viz(vega, df): @pandas_udf("string", PandasUDFType.GROUPED_AGG) def iconviz(point, conf=vega): import arctern - return arctern.icon_viz(conf, point) + return arctern.icon_viz(conf, point, False) df = df.rdd.coalesce(1, shuffle=True).toDF() hex_data = df.agg(iconviz(df[col_point])).collect()[0][0] From 1b31a6ab9d7c97a755567222cbdf60953da04c1c Mon Sep 17 00:00:00 2001 From: "xi.ge" Date: Thu, 23 Apr 2020 12:03:09 +0800 Subject: [PATCH 06/24] pylint && code format --- python/arctern/_wrapper_func.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index 4ca2cc5c9..350d858df 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1132,6 +1132,7 @@ def point_map(vega, points, transform=True): rs = arctern_core_.point_map(vega_string, geos) return base64.b64encode(rs.buffers()[1].to_pybytes()) +# pylint: disable=too-many-branches def weighted_point_map(vega, points, transform=True, **kwargs): import pyarrow as pa color_weights = kwargs.get('color_weights', None) From 4b1de4a454227dbbe5520920be70ad48469b86e7 Mon Sep 17 00:00:00 2001 From: "xi.ge" Date: Mon, 27 Apr 2020 10:37:56 +0800 Subject: [PATCH 07/24] python support chunkarray --- cpp/src/arrow/render_api.cpp | 145 +- cpp/src/arrow/render_api.h | 9 + cpp/src/render/render_builder_impl.h | 9 +- cpp/unittest/render/choropleth_map_test.cpp | 3246 ++++++++++--------- python/arctern/_wrapper_func.py | 33 +- python/arctern/cython/arctern_core_.pyx | 26 +- python/arctern/cython/arctern_core__.pxd | 5 +- python/arctern/cython/render.h | 9 + 8 files changed, 1858 insertions(+), 1624 deletions(-) diff --git a/cpp/src/arrow/render_api.cpp b/cpp/src/arrow/render_api.cpp index fce36dce8..054207558 100644 --- a/cpp/src/arrow/render_api.cpp +++ b/cpp/src/arrow/render_api.cpp @@ -449,6 +449,129 @@ std::pair render_choroplethmap( return choroplethmap(data.first, &input_c[0], num_geo, conf); } +template +void concate_array (const std::vector>& arrs, T1& builder) { + std::cout << "vector size " << arrs.size()<length(); + auto array = std::static_pointer_cast(arrs[i]); + std::cout << "done cast " << i <<"th pointer "<< array <type_id(); + for(size_t j = 0; j < length; j++) { + auto element = array->Value(j); + // std::cout << "element:[ " <length(); + auto array = std::static_pointer_cast(arrs[i]); + std::cout << "done cast " << i <<"th pointer "<< array <type_id(); + for(size_t j = 0; j < length; j++) { + auto element = array->GetString(j); + // std::cout << "element:[ " < result; + switch (type) + { + case arrow::Type::BINARY: { + arrow::BinaryBuilder builder; + concate_array2(arrs, builder); + std::cout << "before finish "<(result))->byte_width()<(arrs, builder); + auto status = builder.Finish(&result); + return result; + } + case arrow::Type::INT8: { + arrow::Int8Builder builder; + concate_array(arrs, builder); + auto status = builder.Finish(&result); + return result; + } + case arrow::Type::INT16: { + arrow::Int16Builder builder; + concate_array(arrs, builder); + auto status = builder.Finish(&result); + return result; + } + case arrow::Type::INT32: { + arrow::Int32Builder builder; + concate_array(arrs, builder); + auto status = builder.Finish(&result); + return result; + } + case arrow::Type::INT64: { + arrow::Int64Builder builder; + concate_array(arrs, builder); + auto status = builder.Finish(&result); + return result; + } + case arrow::Type::UINT8: { + arrow::UInt8Builder builder; + concate_array(arrs, builder); + auto status = builder.Finish(&result); + return result; + } + case arrow::Type::UINT16: { + arrow::UInt16Builder builder; + concate_array(arrs, builder); + auto status = builder.Finish(&result); + return result; + } + case arrow::Type::UINT32: { + arrow::UInt32Builder builder; + concate_array(arrs, builder); + auto status = builder.Finish(&result); + return result; + } + case arrow::Type::UINT64: { + arrow::UInt64Builder builder; + concate_array(arrs, builder); + auto status = builder.Finish(&result); + return result; + } + case arrow::Type::FLOAT: { + arrow::FloatBuilder builder; + concate_array(arrs, builder); + auto status = builder.Finish(&result); + return result; + } + case arrow::Type::DOUBLE: { + arrow::DoubleBuilder builder; + concate_array(arrs, builder); + auto status = builder.Finish(&result); + return result; + } + default: + std::string err_msg = "type error while concate vector arrow, type = " + + std::to_string(type); + throw std::runtime_error(err_msg); + } +} + + + + std::shared_ptr projection(const std::shared_ptr& geos, const std::string& bottom_right, const std::string& top_left, const int& height, @@ -456,6 +579,15 @@ std::shared_ptr projection(const std::shared_ptr& ge return Projection(geos, bottom_right, top_left, height, width); } +std::shared_ptr transform_and_projection( + const std::vector>& geos, const std::string& src_rs, + const std::string& dst_rs, const std::string& bottom_right, + const std::string& top_left, const int& height, const int& width) { + auto geo = data_trans(geos); + return TransformAndProjection(geo, src_rs, dst_rs, bottom_right, top_left, height, + width); +} + std::shared_ptr transform_and_projection( const std::shared_ptr& geos, const std::string& src_rs, const std::string& dst_rs, const std::string& bottom_right, @@ -953,9 +1085,11 @@ std::shared_ptr heat_map(const std::shared_ptr& arr_ } } + std::shared_ptr choropleth_map(const std::shared_ptr& arr_wkb, const std::shared_ptr& arr_c, - const std::string& conf) { + const std::string& conf) { + auto geo_arr = std::static_pointer_cast(arr_wkb); auto geo_size = arr_wkb->length(); auto wkb_type = arr_wkb->type_id(); @@ -1014,6 +1148,15 @@ std::shared_ptr choropleth_map(const std::shared_ptr return out_pic(result); } +std::shared_ptr choropleth_map( + const std::vector>& arrs_wkb, + const std::vector>& arrs_c, + const std::string& conf){ + auto arr_wkb = data_trans(arrs_wkb); + auto arr_c = data_trans(arrs_c); + return choropleth_map(arr_wkb, arr_c, conf); +} + std::shared_ptr icon_viz(const std::shared_ptr& points, const std::string& conf) { auto point_arr = std::static_pointer_cast(points); diff --git a/cpp/src/arrow/render_api.h b/cpp/src/arrow/render_api.h index 089df74fc..bff3e7e03 100644 --- a/cpp/src/arrow/render_api.h +++ b/cpp/src/arrow/render_api.h @@ -36,6 +36,11 @@ std::shared_ptr transform_and_projection( const std::string& dst_rs, const std::string& bottom_right, const std::string& top_left, const int& height, const int& width); +std::shared_ptr transform_and_projection( + const std::vector>& geos, const std::string& src_rs, + const std::string& dst_rs, const std::string& bottom_right, + const std::string& top_left, const int& height, const int& width); + std::shared_ptr point_map(const std::shared_ptr& arr_x, const std::shared_ptr& arr_y, const std::string& conf); @@ -78,6 +83,10 @@ std::shared_ptr choropleth_map( const std::shared_ptr& arr_wkt, const std::shared_ptr& arr_count, const std::string& conf); +std::shared_ptr choropleth_map( + const std::vector>& arr_wkt, + const std::vector>& arr_count, const std::string& conf); + std::shared_ptr icon_viz(const std::shared_ptr& arr_x, const std::shared_ptr& arr_y, const std::string& conf); diff --git a/cpp/src/render/render_builder_impl.h b/cpp/src/render/render_builder_impl.h index f1b04e31e..c48f935e5 100644 --- a/cpp/src/render/render_builder_impl.h +++ b/cpp/src/render/render_builder_impl.h @@ -154,11 +154,11 @@ std::shared_ptr TransformAndProjection( arrow::BinaryBuilder builder; auto len = geos->length(); - auto wkt_geometries = std::static_pointer_cast(geos); - + auto wkt_geometries = std::static_pointer_cast(geos); double min_x, max_y, max_x, min_y; pointXY_from_wkt_with_transform(top_left, min_x, max_y, poCT); pointXY_from_wkt_with_transform(bottom_right, max_x, min_y, poCT); + std::cout << "transform1-3 "< TransformAndProjection( OGRGeometryFactory::destroyGeometry(geo); } } - + std::shared_ptr results; CHECK_ARROW(builder.Finish(&results)); - OCTDestroyCoordinateTransformation(poCT); - + OCTDestroyCoordinateTransformation(poCT); return results; } diff --git a/cpp/unittest/render/choropleth_map_test.cpp b/cpp/unittest/render/choropleth_map_test.cpp index af2c83e1f..121f031fb 100644 --- a/cpp/unittest/render/choropleth_map_test.cpp +++ b/cpp/unittest/render/choropleth_map_test.cpp @@ -17,1444 +17,1624 @@ #include "arrow/render_api.h" -TEST(CHOROPLETHMAP_TEST, BLUE_TO_RED) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, SKYBLUE_TO_WHITE) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#B4E7F5\", \"#FFFFFF\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, GREEN_YELLOW_RED) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#4D904F\", \"#C23728\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, BLUE_WHITE_RED) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#1984C5\", \"#C23728\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, WHITE_BLUE) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#E2E2E2\", \"#115F9A\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, BLUE_GREEN_YELLOW) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#115F9A\", \"#D0F401\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, BLUE_TRANSPARENCY) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#0000FF\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, RED_TRANSPARENCY) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#FF0000\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, PURPLE_TO_YELLOW) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#FF00FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -// TEST(CHOROPLETHMAP_TEST, INVALID_color_gradient_TEST) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); -// -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); -// -// // param2: color -// std::shared_ptr color_array; -// arrow::UInt32Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); -// -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": \"xxxxxx\"},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; -// -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -//} - -// TEST(CHOROPLETHMAP_TEST, INVALID_JSON_TEST) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); -// -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); -// -// // param2: color -// std::shared_ptr color_array; -// arrow::UInt32Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); -// -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": \"blue_to_red\"},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": \"INVALID_NUMBER\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; -// -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -//} - -TEST(CHOROPLETHMAP_TEST, INT8) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::Int8Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, INT16) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::Int16Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, INT32) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::Int32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, INT64) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::Int64Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, UINT8) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt8Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, UINT16) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt16Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, UINT32) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, UINT64) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt64Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, FLOAT) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::FloatBuilder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, DOUBLE) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::DoubleBuilder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -// TEST(CHOROPLETHMAP_TEST, INVALID_DATA_TYPE_TEST) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); -// -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); -// -// // param2: color -// std::shared_ptr color_array; -// arrow::StringBuilder color_builder; -// status = color_builder.Append(""); -// status = color_builder.Finish(&color_array); -// -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": \"blue_to_red\"},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; -// -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -//} - -TEST(CHOROPLETHMAP_TEST, MEAN) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::DoubleBuilder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"mean\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, SUM) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::DoubleBuilder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} +// TEST(CHOROPLETHMAP_TEST, BLUE_TO_RED) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::UInt32Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, SKYBLUE_TO_WHITE) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::UInt32Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#B4E7F5\", \"#FFFFFF\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, GREEN_YELLOW_RED) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::UInt32Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#4D904F\", \"#C23728\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, BLUE_WHITE_RED) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::UInt32Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#1984C5\", \"#C23728\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, WHITE_BLUE) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::UInt32Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#E2E2E2\", \"#115F9A\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, BLUE_GREEN_YELLOW) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::UInt32Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#115F9A\", \"#D0F401\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, BLUE_TRANSPARENCY) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::UInt32Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#0000FF\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, RED_TRANSPARENCY) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::UInt32Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#FF0000\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, PURPLE_TO_YELLOW) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::UInt32Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#FF00FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// // TEST(CHOROPLETHMAP_TEST, INVALID_color_gradient_TEST) { +// // // param1: wkt string +// // std::string wkt_string1 = +// // "POLYGON ((" +// // "200 200, " +// // "200 300, " +// // "300 300, " +// // "300 200, " +// // "200 200))"; +// // arrow::StringBuilder string_builder; +// // auto status = string_builder.Append(wkt_string1); +// // +// // std::shared_ptr string_array; +// // status = string_builder.Finish(&string_array); +// // +// // // param2: color +// // std::shared_ptr color_array; +// // arrow::UInt32Builder color_builder; +// // status = color_builder.Append(5); +// // status = color_builder.Finish(&color_array); +// // +// // // param3: conf +// // const std::string vega = +// // "{\n" +// // " \"width\": 1900,\n" +// // " \"height\": 1410,\n" +// // " \"description\": \"choropleth_map\",\n" +// // " \"data\": [\n" +// // " {\n" +// // " \"name\": \"data\",\n" +// // " \"url\": \"data/data.csv\"\n" +// // " }\n" +// // " ],\n" +// // " \"scales\": [\n" +// // " {\n" +// // " \"name\": \"building\",\n" +// // " \"type\": \"linear\",\n" +// // " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// // " }\n" +// // " ],\n" +// // " \"marks\": [\n" +// // " {\n" +// // " \"encode\": {\n" +// // " \"enter\": {\n" +// // " \"bounding_box\": {\"value\": " +// // "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// // " \"color_gradient\": {\"value\": \"xxxxxx\"},\n" +// // " \"color_bound\": {\"value\": [2.5, 5]},\n" +// // " \"opacity\": {\"value\": 1.0}\n" +// // " }\n" +// // " }\n" +// // " }\n" +// // " ]\n" +// // "}"; +// // +// // auto wkb = arctern::render::WktToWkb(string_array); +// // arctern::render::choropleth_map(wkb, color_array, vega); +// //} + +// // TEST(CHOROPLETHMAP_TEST, INVALID_JSON_TEST) { +// // // param1: wkt string +// // std::string wkt_string1 = +// // "POLYGON ((" +// // "200 200, " +// // "200 300, " +// // "300 300, " +// // "300 200, " +// // "200 200))"; +// // arrow::StringBuilder string_builder; +// // auto status = string_builder.Append(wkt_string1); +// // +// // std::shared_ptr string_array; +// // status = string_builder.Finish(&string_array); +// // +// // // param2: color +// // std::shared_ptr color_array; +// // arrow::UInt32Builder color_builder; +// // status = color_builder.Append(5); +// // status = color_builder.Finish(&color_array); +// // +// // // param3: conf +// // const std::string vega = +// // "{\n" +// // " \"width\": 1900,\n" +// // " \"height\": 1410,\n" +// // " \"description\": \"choropleth_map\",\n" +// // " \"data\": [\n" +// // " {\n" +// // " \"name\": \"data\",\n" +// // " \"url\": \"data/data.csv\"\n" +// // " }\n" +// // " ],\n" +// // " \"scales\": [\n" +// // " {\n" +// // " \"name\": \"building\",\n" +// // " \"type\": \"linear\",\n" +// // " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// // " }\n" +// // " ],\n" +// // " \"marks\": [\n" +// // " {\n" +// // " \"encode\": {\n" +// // " \"enter\": {\n" +// // " \"bounding_box\": {\"value\": " +// // "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// // " \"color_gradient\": {\"value\": \"blue_to_red\"},\n" +// // " \"color_bound\": {\"value\": [2.5, 5]},\n" +// // " \"opacity\": {\"value\": \"INVALID_NUMBER\"}\n" +// // " }\n" +// // " }\n" +// // " }\n" +// // " ]\n" +// // "}"; +// // +// // auto wkb = arctern::render::WktToWkb(string_array); +// // arctern::render::choropleth_map(wkb, color_array, vega); +// //} + +// TEST(CHOROPLETHMAP_TEST, INT8) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::Int8Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, INT16) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::Int16Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, INT32) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::Int32Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, INT64) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::Int64Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, UINT8) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::UInt8Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, UINT16) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::UInt16Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, UINT32) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::UInt32Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, UINT64) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::UInt64Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, FLOAT) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::FloatBuilder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, DOUBLE) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::DoubleBuilder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// // TEST(CHOROPLETHMAP_TEST, INVALID_DATA_TYPE_TEST) { +// // // param1: wkt string +// // std::string wkt_string1 = +// // "POLYGON ((" +// // "200 200, " +// // "200 300, " +// // "300 300, " +// // "300 200, " +// // "200 200))"; +// // arrow::StringBuilder string_builder; +// // auto status = string_builder.Append(wkt_string1); +// // +// // std::shared_ptr string_array; +// // status = string_builder.Finish(&string_array); +// // +// // // param2: color +// // std::shared_ptr color_array; +// // arrow::StringBuilder color_builder; +// // status = color_builder.Append(""); +// // status = color_builder.Finish(&color_array); +// // +// // // param3: conf +// // const std::string vega = +// // "{\n" +// // " \"width\": 1900,\n" +// // " \"height\": 1410,\n" +// // " \"description\": \"choropleth_map\",\n" +// // " \"data\": [\n" +// // " {\n" +// // " \"name\": \"data\",\n" +// // " \"url\": \"data/data.csv\"\n" +// // " }\n" +// // " ],\n" +// // " \"scales\": [\n" +// // " {\n" +// // " \"name\": \"building\",\n" +// // " \"type\": \"linear\",\n" +// // " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// // " }\n" +// // " ],\n" +// // " \"marks\": [\n" +// // " {\n" +// // " \"encode\": {\n" +// // " \"enter\": {\n" +// // " \"bounding_box\": {\"value\": " +// // "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// // " \"color_gradient\": {\"value\": \"blue_to_red\"},\n" +// // " \"color_bound\": {\"value\": [2.5, 5]},\n" +// // " \"opacity\": {\"value\": 1.0}\n" +// // " }\n" +// // " }\n" +// // " }\n" +// // " ]\n" +// // "}"; +// // +// // auto wkb = arctern::render::WktToWkb(string_array); +// // arctern::render::choropleth_map(wkb, color_array, vega); +// //} + +// TEST(CHOROPLETHMAP_TEST, MEAN) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::DoubleBuilder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"mean\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, SUM) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::DoubleBuilder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"sum\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, MAX) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::DoubleBuilder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"max\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, MIN) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::DoubleBuilder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"min\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } + +// TEST(CHOROPLETHMAP_TEST, COUNT) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); + +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); + +// // param2: color +// std::shared_ptr color_array; +// arrow::DoubleBuilder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); + +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"aggregation_type\": {\"value\": \"count\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; + +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +// } -TEST(CHOROPLETHMAP_TEST, MAX) { +TEST(CHOROPLETHMAP_TEST, STD) { // param1: wkt string std::string wkt_string1 = "POLYGON ((" @@ -1464,130 +1644,22 @@ TEST(CHOROPLETHMAP_TEST, MAX) { "300 200, " "200 200))"; arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::DoubleBuilder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"max\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, MIN) { - // param1: wkt string - std::string wkt_string1 = + std::string wkt_string2 = "POLYGON ((" "200 200, " "200 300, " "300 300, " "300 200, " "200 200))"; - arrow::StringBuilder string_builder; + arrow::StringBuilder string_builder2; auto status = string_builder.Append(wkt_string1); + status = string_builder2.Append(wkt_string2); std::shared_ptr string_array; + std::shared_ptr string_array2; status = string_builder.Finish(&string_array); + status = string_builder.Finish(&string_array2); - // param2: color - std::shared_ptr color_array; - arrow::DoubleBuilder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"min\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, COUNT) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); // param2: color std::shared_ptr color_array; @@ -1595,6 +1667,10 @@ TEST(CHOROPLETHMAP_TEST, COUNT) { status = color_builder.Append(5); status = color_builder.Finish(&color_array); + std::shared_ptr color_array2; + arrow::DoubleBuilder color_builder2; + status = color_builder2.Append(5); + status = color_builder2.Finish(&color_array2); // param3: conf const std::string vega = "{\n" @@ -1623,7 +1699,7 @@ TEST(CHOROPLETHMAP_TEST, COUNT) { " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" " \"color_bound\": {\"value\": [2.5, 5]},\n" " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"count\"}\n" + " \"aggregation_type\": {\"value\": \"std\"}\n" " }\n" " }\n" " }\n" @@ -1631,65 +1707,15 @@ TEST(CHOROPLETHMAP_TEST, COUNT) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); -} - -TEST(CHOROPLETHMAP_TEST, STD) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::DoubleBuilder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); + std::vector> voc1; - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"std\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + auto wkb2 = arctern::render::WktToWkb(string_array2); - auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::choropleth_map(wkb, color_array, vega); + voc1.push_back(wkb); + voc1.push_back(wkb2); + std::vector> voc2; + voc2.push_back(color_array); + voc2.push_back(color_array2); + // arctern::render::choropleth_map(wkb, color_array, vega); + arctern::render::choropleth_map(voc1, voc2, vega); } diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index 5078cc44b..7a2268eba 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1230,6 +1230,14 @@ def heat_map_layer(vega, points, weights, transform=True): def choropleth_map_layer(vega, region_boundaries, weights, transform=True): import pyarrow as pa geos = pa.array(region_boundaries, type='binary') + geos_list = [] + # pylint: disable=c-extension-no-member + if isinstance(geos, pa.lib.ChunkedArray): + num_chunks = len(geos.chunks) + for chunk_idx in range(num_chunks): + geos_list.append(geos.chunks[chunk_idx]) + else: + geos_list.append(geos) if transform: bounding_box = vega.bounding_box() @@ -1243,17 +1251,38 @@ def choropleth_map_layer(vega, region_boundaries, weights, transform=True): bounding_box_min = bytes(top_left, encoding="utf8") bounding_box_max = bytes(bottom_right, encoding="utf8") if coor != 'EPSG:3857': - geos = arctern_core_.transform_and_projection(geos, src, dst, bounding_box_max, bounding_box_min, height, width) + geos = arctern_core_.transform_and_projection(geos_list, src, dst, bounding_box_max, bounding_box_min, height, width) else: geos = arctern_core_.projection(geos, bounding_box_max, bounding_box_min, height, width) vega_string = vega.build().encode('utf-8') + geos_list = [] + # pylint: disable=c-extension-no-member + if isinstance(geos, pa.lib.ChunkedArray): + num_chunks = len(geos.chunks) + for chunk_idx in range(num_chunks): + geos_list.append(geos.chunks[chunk_idx]) + else: + geos_list.append(geos) + if weights.dtypes == 'float64': arr_c = pa.array(weights, type='double') else: arr_c = pa.array(weights, type='int64') - rs = arctern_core_.choropleth_map(vega_string, geos, arr_c) + + weights_list = [] + if isinstance(arr_c, pa.lib.ChunkedArray): + num_chunks = len(arr_c.chunks) + for chunk_idx in range(num_chunks): + weights_list.append(arr_c.chunks[chunk_idx]) + else: + weights_list.append(arr_c) + print("**************before map****************") + print(type(geos_list)) + print(type(weights_list)) + + rs = arctern_core_.choropleth_map(vega_string, geos_list, weights_list) return base64.b64encode(rs.buffers()[1].to_pybytes()) def icon_viz_layer(vega, points, transform=True): diff --git a/python/arctern/cython/arctern_core_.pyx b/python/arctern/cython/arctern_core_.pyx index fb6dd3913..6ae14f301 100644 --- a/python/arctern/cython/arctern_core_.pyx +++ b/python/arctern/cython/arctern_core_.pyx @@ -17,12 +17,20 @@ from pyarrow.lib cimport (pyarrow_wrap_array, pyarrow_unwrap_array) cimport arctern_core__ as arctern_core_pxd +from libcpp.vector cimport vector +from pyarrow.lib cimport (shared_ptr, CArray) def projection(geos, bottom_right, top_left, height, width): return pyarrow_wrap_array(arctern_core_pxd.projection(pyarrow_unwrap_array(geos), bottom_right, top_left, height, width)) -def transform_and_projection(geos, src_rs, dst_rs, bottom_right, top_left, height, width): - return pyarrow_wrap_array(arctern_core_pxd.transform_and_projection(pyarrow_unwrap_array(geos), src_rs, dst_rs, bottom_right, top_left, height, width)) +def transform_and_projection(geos_array, src_rs, dst_rs, bottom_right, top_left, height, width): + print(geos_array) + cdef shared_ptr[CArray] arr + cdef vector[shared_ptr[CArray]] geos_vector + for geos in geos_array: + arr = pyarrow_unwrap_array(geos) + geos_vector.push_back(arr) + return pyarrow_wrap_array(arctern_core_pxd.transform_and_projection(geos_vector, src_rs, dst_rs, bottom_right, top_left, height, width)) def point_map(vega, points): return pyarrow_wrap_array(arctern_core_pxd.point_map(pyarrow_unwrap_array(points), vega)) @@ -42,8 +50,18 @@ def weighted_color_size_point_map(vega, points, color_weights, size_weights): def heat_map(vega, points, weights): return pyarrow_wrap_array(arctern_core_pxd.heat_map(pyarrow_unwrap_array(points), pyarrow_unwrap_array(weights), vega)) -def choropleth_map(vega,region_boundaries, weights): - return pyarrow_wrap_array(arctern_core_pxd.choropleth_map(pyarrow_unwrap_array(region_boundaries), pyarrow_unwrap_array(weights), vega)) +def choropleth_map(vega,region_boundaries_arrays, weights_arrays): + cdef shared_ptr[CArray] arr + cdef vector[shared_ptr[CArray]] region_boundaries_vector + cdef vector[shared_ptr[CArray]] weights_vector + for region in region_boundaries_arrays: + arr = pyarrow_unwrap_array(region) + region_boundaries_vector.push_back(arr) + for weights in weights_arrays: + arr = pyarrow_unwrap_array(weights) + weights_vector.push_back(arr) + return pyarrow_wrap_array(arctern_core_pxd.choropleth_map(region_boundaries_vector, weights_vector, vega)) + def icon_viz(vega, points): return pyarrow_wrap_array(arctern_core_pxd.icon_viz(pyarrow_unwrap_array(points), vega)) diff --git a/python/arctern/cython/arctern_core__.pxd b/python/arctern/cython/arctern_core__.pxd index a66002066..9e3927866 100644 --- a/python/arctern/cython/arctern_core__.pxd +++ b/python/arctern/cython/arctern_core__.pxd @@ -14,17 +14,18 @@ from pyarrow.lib cimport (shared_ptr, CArray, int32_t) from libcpp.string cimport (string) +from libcpp.vector cimport vector cdef extern from "render.h" namespace "arctern::render": shared_ptr[CArray] projection(const shared_ptr[CArray] &geos,const string &bottom_right,const string &top_left,const int &height,const int &width) except + - shared_ptr[CArray] transform_and_projection(const shared_ptr[CArray] &geos,const string &src_rs,const string &dst_rs,const string &bottom_right,const string &top_left,const int &height,const int &width) except + + shared_ptr[CArray] transform_and_projection(const vector[shared_ptr[CArray]] &geos,const string &src_rs,const string &dst_rs,const string &bottom_right,const string &top_left,const int &height,const int &width) except + shared_ptr[CArray] point_map(const shared_ptr[CArray] &points,const string &vega) except + shared_ptr[CArray] weighted_point_map(const shared_ptr[CArray] &points,const string &vega) except + shared_ptr[CArray] weighted_point_map(const shared_ptr[CArray] &points,const shared_ptr[CArray] &weights,const string &vega) except + shared_ptr[CArray] weighted_point_map(const shared_ptr[CArray] &points,const shared_ptr[CArray] &color_weights,const shared_ptr[CArray] &size_weights,const string &vega) except + shared_ptr[CArray] heat_map(const shared_ptr[CArray] &points,const shared_ptr[CArray] &weights,const string &vega) except + - shared_ptr[CArray] choropleth_map(const shared_ptr[CArray] ®ion_boundaries,const shared_ptr[CArray] &weights,const string &vega) except + + shared_ptr[CArray] choropleth_map(const vector[shared_ptr[CArray]] ®ion_boundaries,const vector[shared_ptr[CArray]] &weights,const string &vega) except + shared_ptr[CArray] icon_viz(const shared_ptr[CArray] &points,const string &conf) except + shared_ptr[CArray] WktToWkb(const shared_ptr[CArray] && arr_wkt) except + shared_ptr[CArray] WkbToWkt(const shared_ptr[CArray] && arr_wkb) except + diff --git a/python/arctern/cython/render.h b/python/arctern/cython/render.h index b5c4785e1..efa9375d1 100644 --- a/python/arctern/cython/render.h +++ b/python/arctern/cython/render.h @@ -39,6 +39,11 @@ std::shared_ptr transform_and_projection( const std::string& dst_rs, const std::string& bottom_right, const std::string& top_left, const int& height, const int& width); +std::shared_ptr transform_and_projection( + const std::vector>& geos, const std::string& src_rs, + const std::string& dst_rs, const std::string& bottom_right, + const std::string& top_left, const int& height, const int& width); + std::shared_ptr coordinate_projection( const std::shared_ptr& points, const std::string top_left, const std::string bottom_right, const int height, const int width); @@ -65,6 +70,10 @@ std::shared_ptr choropleth_map( const std::shared_ptr& region_boundaries, const std::shared_ptr& weights, const std::string& vega); +std::shared_ptr choropleth_map( + const std::vector>& region_boundaries, + const std::vector>& weights, const std::string& vega); + std::shared_ptr icon_viz(const std::shared_ptr& points, const std::string& conf); From 3e50c97e0d4fa7cd8a578546dafbab0ecdf50952 Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Tue, 28 Apr 2020 18:06:14 +0800 Subject: [PATCH 08/24] choroplethmap without agg, done --- cpp/src/CMakeLists.txt | 1 + cpp/src/arrow/render_api.cpp | 217 +------------ cpp/src/arrow/render_api.h | 11 +- .../2d/choropleth_map/choropleth_map.cpp | 9 +- .../render/2d/choropleth_map/choropleth_map.h | 2 + cpp/src/render/render_builder.h | 8 +- cpp/src/render/render_builder_impl.h | 43 +-- cpp/src/render/utils/render_utils.cpp | 85 ++++++ cpp/src/render/utils/render_utils.h | 56 ++++ cpp/unittest/render/CMakeLists.txt | 10 +- python/arctern/_wrapper_func.py | 161 ++++++---- python/arctern/cython/arctern_core_.pyx | 16 +- python/arctern/cython/arctern_core__.pxd | 2 +- python/arctern/cython/render.h | 2 +- python/tests/geo/render_test.py | 286 +++++++++--------- 15 files changed, 448 insertions(+), 461 deletions(-) create mode 100644 cpp/src/render/utils/render_utils.cpp create mode 100644 cpp/src/render/utils/render_utils.h diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt index cb52edb7d..7986ac153 100644 --- a/cpp/src/CMakeLists.txt +++ b/cpp/src/CMakeLists.txt @@ -25,6 +25,7 @@ set(render_src render/2d/heatmap/heatmap.cpp render/2d/heatmap/set_color.cpp render/2d/icon/icon_viz.cpp + render/utils/render_utils.cpp render/utils/vega/vega_scatter_plot/vega_pointmap.cpp render/utils/vega/vega_scatter_plot/vega_weighted_pointmap.cpp render/utils/vega/vega_choropleth_map/vega_choropleth_map.cpp diff --git a/cpp/src/arrow/render_api.cpp b/cpp/src/arrow/render_api.cpp index 054207558..55a22ec6c 100644 --- a/cpp/src/arrow/render_api.cpp +++ b/cpp/src/arrow/render_api.cpp @@ -24,6 +24,7 @@ #include #include "render/render_builder.h" +#include "render/utils/render_utils.h" #include "arrow/render_api.h" @@ -449,129 +450,6 @@ std::pair render_choroplethmap( return choroplethmap(data.first, &input_c[0], num_geo, conf); } -template -void concate_array (const std::vector>& arrs, T1& builder) { - std::cout << "vector size " << arrs.size()<length(); - auto array = std::static_pointer_cast(arrs[i]); - std::cout << "done cast " << i <<"th pointer "<< array <type_id(); - for(size_t j = 0; j < length; j++) { - auto element = array->Value(j); - // std::cout << "element:[ " <length(); - auto array = std::static_pointer_cast(arrs[i]); - std::cout << "done cast " << i <<"th pointer "<< array <type_id(); - for(size_t j = 0; j < length; j++) { - auto element = array->GetString(j); - // std::cout << "element:[ " < result; - switch (type) - { - case arrow::Type::BINARY: { - arrow::BinaryBuilder builder; - concate_array2(arrs, builder); - std::cout << "before finish "<(result))->byte_width()<(arrs, builder); - auto status = builder.Finish(&result); - return result; - } - case arrow::Type::INT8: { - arrow::Int8Builder builder; - concate_array(arrs, builder); - auto status = builder.Finish(&result); - return result; - } - case arrow::Type::INT16: { - arrow::Int16Builder builder; - concate_array(arrs, builder); - auto status = builder.Finish(&result); - return result; - } - case arrow::Type::INT32: { - arrow::Int32Builder builder; - concate_array(arrs, builder); - auto status = builder.Finish(&result); - return result; - } - case arrow::Type::INT64: { - arrow::Int64Builder builder; - concate_array(arrs, builder); - auto status = builder.Finish(&result); - return result; - } - case arrow::Type::UINT8: { - arrow::UInt8Builder builder; - concate_array(arrs, builder); - auto status = builder.Finish(&result); - return result; - } - case arrow::Type::UINT16: { - arrow::UInt16Builder builder; - concate_array(arrs, builder); - auto status = builder.Finish(&result); - return result; - } - case arrow::Type::UINT32: { - arrow::UInt32Builder builder; - concate_array(arrs, builder); - auto status = builder.Finish(&result); - return result; - } - case arrow::Type::UINT64: { - arrow::UInt64Builder builder; - concate_array(arrs, builder); - auto status = builder.Finish(&result); - return result; - } - case arrow::Type::FLOAT: { - arrow::FloatBuilder builder; - concate_array(arrs, builder); - auto status = builder.Finish(&result); - return result; - } - case arrow::Type::DOUBLE: { - arrow::DoubleBuilder builder; - concate_array(arrs, builder); - auto status = builder.Finish(&result); - return result; - } - default: - std::string err_msg = "type error while concate vector arrow, type = " + - std::to_string(type); - throw std::runtime_error(err_msg); - } -} - - - - std::shared_ptr projection(const std::shared_ptr& geos, const std::string& bottom_right, const std::string& top_left, const int& height, @@ -579,21 +457,17 @@ std::shared_ptr projection(const std::shared_ptr& ge return Projection(geos, bottom_right, top_left, height, width); } -std::shared_ptr transform_and_projection( +const std::vector> transform_and_projection( const std::vector>& geos, const std::string& src_rs, const std::string& dst_rs, const std::string& bottom_right, const std::string& top_left, const int& height, const int& width) { - auto geo = data_trans(geos); - return TransformAndProjection(geo, src_rs, dst_rs, bottom_right, top_left, height, - width); -} - -std::shared_ptr transform_and_projection( - const std::shared_ptr& geos, const std::string& src_rs, - const std::string& dst_rs, const std::string& bottom_right, - const std::string& top_left, const int& height, const int& width) { - return TransformAndProjection(geos, src_rs, dst_rs, bottom_right, top_left, height, - width); + std::cout << "c++ trans enter c++" << std::endl; + const auto& geo = GeometryExtraction(geos); + std::cout << "c++ geo extract ok" << std::endl; + TransformAndProjection(geo, src_rs, dst_rs, bottom_right, top_left, height, width); + std::cout << "c++ transform and proj ok" << std::endl; + const auto& res = GeometryExport(geo, geos.size()); + return res; } std::shared_ptr point_map(const std::shared_ptr& points, @@ -1085,76 +959,13 @@ std::shared_ptr heat_map(const std::shared_ptr& arr_ } } - -std::shared_ptr choropleth_map(const std::shared_ptr& arr_wkb, - const std::shared_ptr& arr_c, - const std::string& conf) { - - auto geo_arr = std::static_pointer_cast(arr_wkb); - auto geo_size = arr_wkb->length(); - auto wkb_type = arr_wkb->type_id(); - assert(wkb_type == arrow::Type::BINARY); - - std::pair result; - auto c_size = arr_c->length(); - auto c_type = arr_c->type_id(); - assert(geo_size == c_size); - switch (c_type) { - case arrow::Type::INT8: { - result = render_choroplethmap(arr_wkb, arr_c, conf); - break; - } - case arrow::Type::INT16: { - result = render_choroplethmap(arr_wkb, arr_c, conf); - break; - } - case arrow::Type::INT32: { - result = render_choroplethmap(arr_wkb, arr_c, conf); - break; - } - case arrow::Type::INT64: { - result = render_choroplethmap(arr_wkb, arr_c, conf); - break; - } - case arrow::Type::UINT8: { - result = render_choroplethmap(arr_wkb, arr_c, conf); - break; - } - case arrow::Type::UINT16: { - result = render_choroplethmap(arr_wkb, arr_c, conf); - break; - } - case arrow::Type::UINT32: { - result = render_choroplethmap(arr_wkb, arr_c, conf); - break; - } - case arrow::Type::UINT64: { - result = render_choroplethmap(arr_wkb, arr_c, conf); - break; - } - case arrow::Type::FLOAT: { - result = render_choroplethmap(arr_wkb, arr_c, conf); - break; - } - case arrow::Type::DOUBLE: { - result = render_choroplethmap(arr_wkb, arr_c, conf); - break; - } - default: - std::string err_msg = "type error of count while running choropleth map, type = " + - std::to_string(c_type); - throw std::runtime_error(err_msg); - } - return out_pic(result); -} - std::shared_ptr choropleth_map( const std::vector>& arrs_wkb, - const std::vector>& arrs_c, - const std::string& conf){ - auto arr_wkb = data_trans(arrs_wkb); - auto arr_c = data_trans(arrs_c); - return choropleth_map(arr_wkb, arr_c, conf); + const std::vector>& arrs_c, const std::string& conf) { + const auto& wkb_vec = GeometryExtraction(arrs_wkb); + auto num_buildings = wkb_vec.size(); + auto arr_c = WeightExtraction(arrs_c); + return out_pic(choroplethmap(wkb_vec, arr_c, num_buildings, conf)); } std::shared_ptr icon_viz(const std::shared_ptr& points, diff --git a/cpp/src/arrow/render_api.h b/cpp/src/arrow/render_api.h index bff3e7e03..df4dfae95 100644 --- a/cpp/src/arrow/render_api.h +++ b/cpp/src/arrow/render_api.h @@ -31,12 +31,7 @@ std::shared_ptr projection(const std::shared_ptr& ge const std::string& top_left, const int& height, const int& width); -std::shared_ptr transform_and_projection( - const std::shared_ptr& geos, const std::string& src_rs, - const std::string& dst_rs, const std::string& bottom_right, - const std::string& top_left, const int& height, const int& width); - -std::shared_ptr transform_and_projection( +const std::vector> transform_and_projection( const std::vector>& geos, const std::string& src_rs, const std::string& dst_rs, const std::string& bottom_right, const std::string& top_left, const int& height, const int& width); @@ -79,10 +74,6 @@ std::shared_ptr heat_map(const std::shared_ptr& poin const std::shared_ptr& arr_c, const std::string& conf); -std::shared_ptr choropleth_map( - const std::shared_ptr& arr_wkt, - const std::shared_ptr& arr_count, const std::string& conf); - std::shared_ptr choropleth_map( const std::vector>& arr_wkt, const std::vector>& arr_count, const std::string& conf); diff --git a/cpp/src/render/2d/choropleth_map/choropleth_map.cpp b/cpp/src/render/2d/choropleth_map/choropleth_map.cpp index e3030f652..e7332ee60 100644 --- a/cpp/src/render/2d/choropleth_map/choropleth_map.cpp +++ b/cpp/src/render/2d/choropleth_map/choropleth_map.cpp @@ -49,6 +49,13 @@ template class ChoroplethMap; template class ChoroplethMap; +template +ChoroplethMap::~ChoroplethMap() { + if (count_ != nullptr) { + free(count_); + } +} + template ChoroplethMap::ChoroplethMap(std::vector choropleth_wkb, T* count, int64_t num_buildings) @@ -70,7 +77,7 @@ void ChoroplethMap::Draw() { for (int i = 0; i < num_buildings_; i++) { glColor4f(colors_[i * 4], colors_[i * 4 + 1], colors_[i * 4 + 2], colors_[i * 4 + 3]); - glBegin(GL_POLYGON); + glBegin(GL_LINES); for (int j = 0; j < buildings_x_[i].size(); j++) { glVertex2d(buildings_x_[i][j], buildings_y_[i][j]); } diff --git a/cpp/src/render/2d/choropleth_map/choropleth_map.h b/cpp/src/render/2d/choropleth_map/choropleth_map.h index dc6c8ccfe..42b78afa1 100644 --- a/cpp/src/render/2d/choropleth_map/choropleth_map.h +++ b/cpp/src/render/2d/choropleth_map/choropleth_map.h @@ -31,6 +31,8 @@ class ChoroplethMap : public General2D { public: ChoroplethMap() = delete; + ~ChoroplethMap(); + ChoroplethMap(std::vector choropleth_wkb, T* count, int64_t num_vertices); uint8_t* Render() final; diff --git a/cpp/src/render/render_builder.h b/cpp/src/render/render_builder.h index b21272de2..77747827d 100644 --- a/cpp/src/render/render_builder.h +++ b/cpp/src/render/render_builder.h @@ -48,10 +48,10 @@ std::shared_ptr Projection(const std::shared_ptr& ge const std::string& top_left, const int& height, const int& width); -std::shared_ptr TransformAndProjection( - const std::shared_ptr& geos, const std::string& src_rs, - const std::string& dst_rs, const std::string& bottom_right, - const std::string& top_left, const int& height, const int& width); +void TransformAndProjection(const std::vector& geos, + const std::string& src_rs, const std::string& dst_rs, + const std::string& bottom_right, const std::string& top_left, + const int& height, const int& width); template std::pair, std::vector>> weight_agg( diff --git a/cpp/src/render/render_builder_impl.h b/cpp/src/render/render_builder_impl.h index c48f935e5..a14136766 100644 --- a/cpp/src/render/render_builder_impl.h +++ b/cpp/src/render/render_builder_impl.h @@ -25,6 +25,7 @@ #include #include +#include "render/utils/render_utils.h" #include "utils/check_status.h" namespace arctern { @@ -133,10 +134,10 @@ std::shared_ptr Projection(const std::shared_ptr& ge return results; } -std::shared_ptr TransformAndProjection( - const std::shared_ptr& geos, const std::string& src_rs, - const std::string& dst_rs, const std::string& bottom_right, - const std::string& top_left, const int& height, const int& width) { +void TransformAndProjection(const std::vector& geos, + const std::string& src_rs, const std::string& dst_rs, + const std::string& bottom_right, const std::string& top_left, + const int& height, const int& width) { OGRSpatialReference oSrcSRS; oSrcSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); if (oSrcSRS.SetFromUserInput(src_rs.c_str()) != OGRERR_NONE) { @@ -153,25 +154,18 @@ std::shared_ptr TransformAndProjection( void* poCT = OCTNewCoordinateTransformation(&oSrcSRS, &oDstS); arrow::BinaryBuilder builder; - auto len = geos->length(); - auto wkt_geometries = std::static_pointer_cast(geos); + auto len = geos.size(); + double min_x, max_y, max_x, min_y; pointXY_from_wkt_with_transform(top_left, min_x, max_y, poCT); pointXY_from_wkt_with_transform(bottom_right, max_x, min_y, poCT); - std::cout << "transform1-3 "<IsNull(i)) { - CHECK_ARROW(builder.Append("")); - continue; - } - OGRGeometry* geo = nullptr; - auto err_code = OGRGeometryFactory::createFromWkb( - wkt_geometries->GetString(i).c_str(), nullptr, &geo); - if (err_code) continue; + auto geo = geos[i]; if (geo == nullptr) { CHECK_ARROW(builder.AppendNull()); } else { @@ -201,25 +195,10 @@ std::shared_ptr TransformAndProjection( std::string err_msg = "unsupported geometry type, type = " + std::to_string(type); throw std::runtime_error(err_msg); } - - auto sz = geo->WkbSize(); - std::vector str(sz); - err_code = geo->exportToWkb(OGRwkbByteOrder::wkbNDR, (uint8_t*)str.data()); - if (err_code != OGRERR_NONE) { - std::string err_msg = - "failed to export to wkt, error code = " + std::to_string(err_code); - throw std::runtime_error(err_msg); - } - - CHECK_ARROW(builder.Append(str.data(), str.size())); - OGRGeometryFactory::destroyGeometry(geo); } } - - std::shared_ptr results; - CHECK_ARROW(builder.Finish(&results)); - OCTDestroyCoordinateTransformation(poCT); - return results; + + OCTDestroyCoordinateTransformation(poCT); } template diff --git a/cpp/src/render/utils/render_utils.cpp b/cpp/src/render/utils/render_utils.cpp new file mode 100644 index 000000000..e428ecfcb --- /dev/null +++ b/cpp/src/render/utils/render_utils.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2019-2020 Zilliz. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include + +#include "arrow/render_api.h" +#include "render/utils/render_utils.h" +#include "utils/check_status.h" + +namespace arctern { +namespace render { + +std::vector GeometryExtraction( + const std::vector>& arrs) { + int total_size = 0; + for (const auto& arr : arrs) { + total_size += arr->length(); + } + std::vector geos_res(total_size); + + int index = 0; + for (const auto& arr : arrs) { + auto wkb_geometries = std::static_pointer_cast(arr); + for (int i = 0; i < wkb_geometries->length(); i++) { + OGRGeometry* geo = nullptr; + auto err_code = OGRGeometryFactory::createFromWkb( + wkb_geometries->GetString(i).c_str(), nullptr, &geo); + if (err_code || geo == nullptr) { + geos_res[index] = nullptr; + } else { + geos_res[index] = geo; + } + index++; + } + } + + return geos_res; +} + +std::vector> GeometryExport( + const std::vector& geos, int arrays_size) { + std::vector> arrays(arrays_size); + int size_per_array = geos.size() / arrays_size; + + for (int i = 0; i < arrays_size; i++) { + arrow::BinaryBuilder builder; + + for (int j = i * size_per_array; j < (i + 1) * size_per_array; j++) { + auto sz = geos[j]->WkbSize(); + std::vector str(sz); + auto err_code = geos[j]->exportToWkb(OGRwkbByteOrder::wkbNDR, (uint8_t*)str.data()); + if (err_code != OGRERR_NONE) { + std::string err_msg = + "failed to export to wkt, error code = " + std::to_string(err_code); + throw std::runtime_error(err_msg); + } + CHECK_ARROW(builder.Append(str.data(), str.size())); + OGRGeometryFactory::destroyGeometry(geos[j]); + } + + std::shared_ptr array; + CHECK_ARROW(builder.Finish(&array)); + arrays[i] = array; + } + + return arrays; +} + +} // namespace render +} // namespace arctern diff --git a/cpp/src/render/utils/render_utils.h b/cpp/src/render/utils/render_utils.h new file mode 100644 index 000000000..1e3755076 --- /dev/null +++ b/cpp/src/render/utils/render_utils.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2019-2020 Zilliz. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include +#include + +#include "arrow/render_api.h" + +namespace arctern { +namespace render { + +std::vector GeometryExtraction( + const std::vector>& arrs); + +std::vector> GeometryExport( + const std::vector& geos, int arrays_size); + +template +T* WeightExtraction(const std::vector>& arrs) { + int total_size = 0; + + for (const auto& arr : arrs) { + total_size += arr->length(); + } + + auto res = (T*)malloc(total_size * sizeof(T)); + + int offset = 0; + for (const auto& arr : arrs) { + // TODO: if to use numeric array + // auto numeric_arr = std::static_pointer_cast>(arr); + // (T*)numeric_arr->data()->GetValues(1); + auto ptr = (T*)arr->data()->GetValues(1); + std::memcpy(res + offset, ptr, arr->length() * sizeof(T)); + offset += arr->length(); + } + + return res; +} + +} // namespace render +} // namespace arctern diff --git a/cpp/unittest/render/CMakeLists.txt b/cpp/unittest/render/CMakeLists.txt index 8d5eed6fb..9133ea7e3 100644 --- a/cpp/unittest/render/CMakeLists.txt +++ b/cpp/unittest/render/CMakeLists.txt @@ -14,12 +14,12 @@ set(render_tests_src ${unittest_srcs} - pointmap_test.cpp - heatmap_test.cpp +# pointmap_test.cpp +# heatmap_test.cpp choropleth_map_test.cpp - coordinate_projection_test.cpp - weighted_pointmap_test.cpp - iconviz_test.cpp +# coordinate_projection_test.cpp +# weighted_pointmap_test.cpp +# iconviz_test.cpp ) add_executable(render_tests ${render_tests_src}) diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index 7a2268eba..54cf62e8e 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1120,6 +1120,81 @@ def ST_CurveToLine(geos): arr_geos = pa.array(geos, type='binary') return arctern_caller(arctern_core_.ST_CurveToLine, arr_geos) + +# def render_caller(func, geos, *func_args): +# import pyarrow +# num_chunks = 1 +# # pylint: disable=c-extension-no-member +# if isinstance(geos, pyarrow.lib.ChunkedArray): +# num_chunks = len(geos.chunks) +# +# if num_chunks <= 1: +# result = func(*func_args) +# return result.to_pandas() +# +# result_total = None +# for chunk_idx in range(num_chunks): +# args = [] +# # pylint: disable=c-extension-no-member +# if isinstance(geos, pyarrow.lib.ChunkedArray): +# args.append(geos.chunks[chunk_idx]) +# else: +# args.append(geos) +# result = func(*args) +# if result_total is None: +# result_total = result.to_pandas() +# else: +# result_total = result_total.append(result.to_pandas(), ignore_index=True) +# return result_total + + +def projection(geos, bottom_right, top_left, height, width): + import pyarrow as pa + arr_geos = pa.array(geos, type='binary') + bounding_box_max = bytes(bottom_right, encoding="utf8") + bounding_box_min = bytes(top_left, encoding="utf8") + rs = arctern_core_.projection(arr_geos, bounding_box_max, bounding_box_min, height, width) + return rs.to_pandas() + + +def transform_and_projection(geos, src_rs, dst_rs, bottom_right, top_left, height, width): + import pyarrow as pa + import pandas as pd + arr_geos = pa.array(geos, type='binary') + src = bytes(src_rs, encoding="utf8") + dst = bytes(dst_rs, encoding="utf8") + + bounding_box_max = bytes(bottom_right, encoding="utf8") + bounding_box_min = bytes(top_left, encoding="utf8") + + pd_rs = pd.Series() + + # pylint: disable=c-extension-no-member + if isinstance(arr_geos, pa.lib.ChunkedArray): + for chunk_idx in range(arr_geos.num_chunks): + rs = arctern_core_.transform_and_projection(arr_geos.chunk(chunk_idx), src, dst, bounding_box_max, bounding_box_min, height, width) + pd_rs.append(rs.to_pandas) + else: + rs = arctern_core_.transform_and_projection(arr_geos, src, dst, bounding_box_max, bounding_box_min, height, width) + pd_rs.append(rs.to_pandas) + + return pd_rs.to_pandas() + + +def wkt2wkb(arr_wkt): + import pyarrow as pa + wkts = pa.array(arr_wkt, type='string') + rs = arctern_core_.wkt2wkb(wkts) + return rs.to_pandas() + + +def wkb2wkt(arr_wkb): + import pyarrow as pa + wkbs = pa.array(arr_wkb, type='binary') + rs = arctern_core_.wkb2wkt(wkbs) + return rs.to_pandas() + + def point_map_layer(vega, points, transform=True): import pyarrow as pa geos = pa.array(points, type='binary') @@ -1144,6 +1219,7 @@ def point_map_layer(vega, points, transform=True): rs = arctern_core_.point_map(vega_string, geos) return base64.b64encode(rs.buffers()[1].to_pybytes()) + # pylint: disable=too-many-branches def weighted_point_map_layer(vega, points, transform=True, **kwargs): import pyarrow as pa @@ -1197,6 +1273,7 @@ def weighted_point_map_layer(vega, points, transform=True, **kwargs): return base64.b64encode(rs.buffers()[1].to_pybytes()) + def heat_map_layer(vega, points, weights, transform=True): import pyarrow as pa geos = pa.array(points, type='binary') @@ -1227,64 +1304,62 @@ def heat_map_layer(vega, points, weights, transform=True): rs = arctern_core_.heat_map(vega_string, geos, arr_c) return base64.b64encode(rs.buffers()[1].to_pybytes()) + def choropleth_map_layer(vega, region_boundaries, weights, transform=True): import pyarrow as pa geos = pa.array(region_boundaries, type='binary') - geos_list = [] - # pylint: disable=c-extension-no-member - if isinstance(geos, pa.lib.ChunkedArray): - num_chunks = len(geos.chunks) - for chunk_idx in range(num_chunks): - geos_list.append(geos.chunks[chunk_idx]) - else: - geos_list.append(geos) if transform: bounding_box = vega.bounding_box() top_left = 'POINT (' + str(bounding_box[0]) + ' ' + str(bounding_box[3]) + ')' bottom_right = 'POINT (' + str(bounding_box[2]) + ' ' + str(bounding_box[1]) + ')' + height = vega.height() width = vega.width() coor = vega.coor() + src = bytes(coor, encoding="utf8") dst = bytes('EPSG:3857', encoding="utf8") bounding_box_min = bytes(top_left, encoding="utf8") bounding_box_max = bytes(bottom_right, encoding="utf8") + + print("data prepare ok") + # transform and projection handler + geos_rs = [] + if isinstance(geos, pa.lib.ChunkedArray): + for chunk_idx in range(geos.num_chunks): + geos_rs.append(geos.chunk(chunk_idx)) + else: + geos_rs.append(geos) if coor != 'EPSG:3857': - geos = arctern_core_.transform_and_projection(geos_list, src, dst, bounding_box_max, bounding_box_min, height, width) + geos = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) + print(type(geos)) else: - geos = arctern_core_.projection(geos, bounding_box_max, bounding_box_min, height, width) + geos = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) vega_string = vega.build().encode('utf-8') - geos_list = [] - # pylint: disable=c-extension-no-member - if isinstance(geos, pa.lib.ChunkedArray): - num_chunks = len(geos.chunks) - for chunk_idx in range(num_chunks): - geos_list.append(geos.chunks[chunk_idx]) - else: - geos_list.append(geos) - + print("transform done") + # weights handler if weights.dtypes == 'float64': arr_c = pa.array(weights, type='double') else: arr_c = pa.array(weights, type='int64') - weights_list = [] + weights_rs = [] if isinstance(arr_c, pa.lib.ChunkedArray): - num_chunks = len(arr_c.chunks) - for chunk_idx in range(num_chunks): - weights_list.append(arr_c.chunks[chunk_idx]) + for chunk_idx in range(arr_c.num_chunks): + weights_rs.append(arr_c.chunk(chunk_idx)) else: - weights_list.append(arr_c) - print("**************before map****************") - print(type(geos_list)) - print(type(weights_list)) + weights_rs.append(arr_c) + + print("weights handle done") - rs = arctern_core_.choropleth_map(vega_string, geos_list, weights_list) + rs = arctern_core_.choropleth_map(vega_string, geos, weights_rs) + print("draw map, Done!!!") return base64.b64encode(rs.buffers()[1].to_pybytes()) + def icon_viz_layer(vega, points, transform=True): import pyarrow as pa geos = pa.array(points, type='binary') @@ -1308,33 +1383,3 @@ def icon_viz_layer(vega, points, transform=True): vega_string = vega.build().encode('utf-8') rs = arctern_core_.icon_viz(vega_string, geos) return base64.b64encode(rs.buffers()[1].to_pybytes()) - -def projection(geos, bottom_right, top_left, height, width): - import pyarrow as pa - arr_geos = pa.array(geos, type='binary') - bounding_box_max = bytes(bottom_right, encoding="utf8") - bounding_box_min = bytes(top_left, encoding="utf8") - rs = arctern_core_.projection(arr_geos, bounding_box_max, bounding_box_min, height, width) - return rs.to_pandas() - -def transform_and_projection(geos, src_rs, dst_rs, bottom_right, top_left, height, width): - import pyarrow as pa - arr_geos = pa.array(geos, type='binary') - src = bytes(src_rs, encoding="utf8") - dst = bytes(dst_rs, encoding="utf8") - bounding_box_max = bytes(bottom_right, encoding="utf8") - bounding_box_min = bytes(top_left, encoding="utf8") - rs = arctern_core_.transform_and_projection(arr_geos, src, dst, bounding_box_max, bounding_box_min, height, width) - return rs.to_pandas() - -def wkt2wkb(arr_wkt): - import pyarrow as pa - wkts = pa.array(arr_wkt, type='string') - rs = arctern_core_.wkt2wkb(wkts) - return rs.to_pandas() - -def wkb2wkt(arr_wkb): - import pyarrow as pa - wkbs = pa.array(arr_wkb, type='binary') - rs = arctern_core_.wkb2wkt(wkbs) - return rs.to_pandas() diff --git a/python/arctern/cython/arctern_core_.pyx b/python/arctern/cython/arctern_core_.pyx index 6ae14f301..3cab02b18 100644 --- a/python/arctern/cython/arctern_core_.pyx +++ b/python/arctern/cython/arctern_core_.pyx @@ -24,13 +24,21 @@ def projection(geos, bottom_right, top_left, height, width): return pyarrow_wrap_array(arctern_core_pxd.projection(pyarrow_unwrap_array(geos), bottom_right, top_left, height, width)) def transform_and_projection(geos_array, src_rs, dst_rs, bottom_right, top_left, height, width): - print(geos_array) - cdef shared_ptr[CArray] arr + # input + # cdef shared_ptr[CArray] arr cdef vector[shared_ptr[CArray]] geos_vector for geos in geos_array: arr = pyarrow_unwrap_array(geos) geos_vector.push_back(arr) - return pyarrow_wrap_array(arctern_core_pxd.transform_and_projection(geos_vector, src_rs, dst_rs, bottom_right, top_left, height, width)) + # output + cdef vector[shared_ptr[CArray]] output_geos + output_geos = arctern_core_pxd.transform_and_projection(geos_vector, src_rs, dst_rs, bottom_right, top_left, height, width) + res = [] + print("output_geos size:") + print(output_geos.size()) + for i in range(output_geos.size()): + res.append(pyarrow_wrap_array(output_geos[i])) + return res def point_map(vega, points): return pyarrow_wrap_array(arctern_core_pxd.point_map(pyarrow_unwrap_array(points), vega)) @@ -51,6 +59,7 @@ def heat_map(vega, points, weights): return pyarrow_wrap_array(arctern_core_pxd.heat_map(pyarrow_unwrap_array(points), pyarrow_unwrap_array(weights), vega)) def choropleth_map(vega,region_boundaries_arrays, weights_arrays): + # wrapper input cdef shared_ptr[CArray] arr cdef vector[shared_ptr[CArray]] region_boundaries_vector cdef vector[shared_ptr[CArray]] weights_vector @@ -60,6 +69,7 @@ def choropleth_map(vega,region_boundaries_arrays, weights_arrays): for weights in weights_arrays: arr = pyarrow_unwrap_array(weights) weights_vector.push_back(arr) + return pyarrow_wrap_array(arctern_core_pxd.choropleth_map(region_boundaries_vector, weights_vector, vega)) diff --git a/python/arctern/cython/arctern_core__.pxd b/python/arctern/cython/arctern_core__.pxd index 9e3927866..758c84cbc 100644 --- a/python/arctern/cython/arctern_core__.pxd +++ b/python/arctern/cython/arctern_core__.pxd @@ -19,7 +19,7 @@ from libcpp.vector cimport vector cdef extern from "render.h" namespace "arctern::render": shared_ptr[CArray] projection(const shared_ptr[CArray] &geos,const string &bottom_right,const string &top_left,const int &height,const int &width) except + - shared_ptr[CArray] transform_and_projection(const vector[shared_ptr[CArray]] &geos,const string &src_rs,const string &dst_rs,const string &bottom_right,const string &top_left,const int &height,const int &width) except + + const vector[shared_ptr[CArray]] transform_and_projection(const vector[shared_ptr[CArray]] &geos,const string &src_rs,const string &dst_rs,const string &bottom_right,const string &top_left,const int &height,const int &width) except + shared_ptr[CArray] point_map(const shared_ptr[CArray] &points,const string &vega) except + shared_ptr[CArray] weighted_point_map(const shared_ptr[CArray] &points,const string &vega) except + shared_ptr[CArray] weighted_point_map(const shared_ptr[CArray] &points,const shared_ptr[CArray] &weights,const string &vega) except + diff --git a/python/arctern/cython/render.h b/python/arctern/cython/render.h index efa9375d1..18954cc3c 100644 --- a/python/arctern/cython/render.h +++ b/python/arctern/cython/render.h @@ -39,7 +39,7 @@ std::shared_ptr transform_and_projection( const std::string& dst_rs, const std::string& bottom_right, const std::string& top_left, const int& height, const int& width); -std::shared_ptr transform_and_projection( +const std::vector> transform_and_projection( const std::vector>& geos, const std::string& src_rs, const std::string& dst_rs, const std::string& bottom_right, const std::string& top_left, const int& height, const int& width); diff --git a/python/tests/geo/render_test.py b/python/tests/geo/render_test.py index 7d634ec04..10c6fa7f1 100644 --- a/python/tests/geo/render_test.py +++ b/python/tests/geo/render_test.py @@ -19,125 +19,125 @@ from arctern.util.vega import vega_pointmap, vega_weighted_pointmap, vega_heatmap, vega_choroplethmap, vega_icon -def test_projection(): - wkt = ["POINT (-8235193.62386326 4976211.44428777)"] - top_left = "POINT (-8235871.4482427 4976468.32320551)" - bottom_right = "POINT (-8235147.42627458 4976108.43009739)" - - arr_wkb = pandas.Series(arctern.wkt2wkb(wkt)) - arctern.projection(arr_wkb, bottom_right, top_left, 200, 300) - - -def test_transfrom_and_projection(): - wkt = ["POINT (-73.978003 40.754594)"] - top_left = "POINT (-73.984092 40.756342)" - bottom_right = "POINT (-73.977588 40.753893)" - src_ts = "EPSG:4326" - dst_rs = "EPSG:3857" - - arr_wkb = pandas.Series(arctern.wkt2wkb(wkt)) - arctern.transform_and_projection(arr_wkb, src_ts, dst_rs, bottom_right, top_left, 200, 300) - - -def test_point_map(): - x_data = [] - y_data = [] - - x_data.append(-73.96524) - x_data.append(-73.96118) - x_data.append(-73.97324) - x_data.append(-73.98456) - y_data.append(40.73747) - y_data.append(40.74507) - y_data.append(40.75890) - y_data.append(40.77654) - - arr_x = pandas.Series(x_data) - arr_y = pandas.Series(y_data) - points = arctern.ST_Point(arr_x, arr_y) - - vega = vega_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], point_size=10, point_color="#0000FF", opacity=1.0, coordinate_system="EPSG:4326") - curve_z1 = arctern.point_map_layer(vega, points) - save_png(curve_z1, "/tmp/test_curve_z1.png") - - -def test_weighted_point_map(): - x_data = [] - y_data = [] - c_data = [] - s_data = [] - - x_data.append(-73.96524) - x_data.append(-73.96118) - x_data.append(-73.97324) - x_data.append(-73.98456) - - y_data.append(40.73747) - y_data.append(40.74507) - y_data.append(40.75890) - y_data.append(40.77654) - - c_data.append(1) - c_data.append(2) - c_data.append(3) - c_data.append(4) - - s_data.append(4) - s_data.append(6) - s_data.append(8) - s_data.append(10) - - arr_x = pandas.Series(x_data) - arr_y = pandas.Series(y_data) - points = arctern.ST_Point(arr_x, arr_y) - arr_c = pandas.Series(c_data) - arr_s = pandas.Series(s_data) - - vega1 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF"], opacity=1.0, coordinate_system="EPSG:4326") - res1 = arctern.weighted_point_map_layer(vega1, points) - save_png(res1, "/tmp/test_weighted_0_0.png") - - vega2 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF", "#FF0000"], color_bound=[1, 5], opacity=1.0, coordinate_system="EPSG:4326") - res2 = arctern.weighted_point_map_layer(vega2, points, color_weights=arr_c) - save_png(res2, "/tmp/test_weighted_1_0.png") - - vega3 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF"], size_bound=[1, 10], opacity=1.0, coordinate_system="EPSG:4326") - res3 = arctern.weighted_point_map_layer(vega3, points, size_weights=arr_s) - save_png(res3, "/tmp/test_weighted_0_1.png") - - vega4 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF", "#FF0000"], color_bound=[1, 5], size_bound=[1, 10], opacity=1.0, coordinate_system="EPSG:4326") - res4 = arctern.weighted_point_map_layer(vega4, points, color_weights=arr_c, size_weights=arr_s) - save_png(res4, "/tmp/test_weighted_1_1.png") - -def test_heat_map(): - x_data = [] - y_data = [] - c_data = [] - - x_data.append(-73.96524) - x_data.append(-73.96118) - x_data.append(-73.97324) - x_data.append(-73.98456) - - y_data.append(40.73747) - y_data.append(40.74507) - y_data.append(40.75890) - y_data.append(40.77654) - - c_data.append(10) - c_data.append(20) - c_data.append(30) - c_data.append(40) - - arr_x = pandas.Series(x_data) - arr_y = pandas.Series(y_data) - points = arctern.ST_Point(arr_x, arr_y) - arr_c = pandas.Series(c_data) +# def test_projection(): +# wkt = ["POINT (-8235193.62386326 4976211.44428777)"] +# top_left = "POINT (-8235871.4482427 4976468.32320551)" +# bottom_right = "POINT (-8235147.42627458 4976108.43009739)" +# +# arr_wkb = pandas.Series(arctern.wkt2wkb(wkt)) +# arctern.projection(arr_wkb, bottom_right, top_left, 200, 300) +# +# +# def test_transfrom_and_projection(): +# wkt = ["POINT (-73.978003 40.754594)"] +# top_left = "POINT (-73.984092 40.756342)" +# bottom_right = "POINT (-73.977588 40.753893)" +# src_ts = "EPSG:4326" +# dst_rs = "EPSG:3857" +# +# arr_wkb = pandas.Series(arctern.wkt2wkb(wkt)) +# arctern.transform_and_projection(arr_wkb, src_ts, dst_rs, bottom_right, top_left, 200, 300) +# +# +# def test_point_map(): +# x_data = [] +# y_data = [] +# +# x_data.append(-73.96524) +# x_data.append(-73.96118) +# x_data.append(-73.97324) +# x_data.append(-73.98456) +# y_data.append(40.73747) +# y_data.append(40.74507) +# y_data.append(40.75890) +# y_data.append(40.77654) +# +# arr_x = pandas.Series(x_data) +# arr_y = pandas.Series(y_data) +# points = arctern.ST_Point(arr_x, arr_y) +# +# vega = vega_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], point_size=10, point_color="#0000FF", opacity=1.0, coordinate_system="EPSG:4326") +# curve_z1 = arctern.point_map_layer(vega, points) +# save_png(curve_z1, "/tmp/test_curve_z1.png") - vega = vega_heatmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], map_zoom_level=13.0, coordinate_system='EPSG:4326') - heat_map1 = arctern.heat_map_layer(vega, points, arr_c) - save_png(heat_map1, "/tmp/test_heat_map1.png") +# def test_weighted_point_map(): +# x_data = [] +# y_data = [] +# c_data = [] +# s_data = [] +# +# x_data.append(-73.96524) +# x_data.append(-73.96118) +# x_data.append(-73.97324) +# x_data.append(-73.98456) +# +# y_data.append(40.73747) +# y_data.append(40.74507) +# y_data.append(40.75890) +# y_data.append(40.77654) +# +# c_data.append(1) +# c_data.append(2) +# c_data.append(3) +# c_data.append(4) +# +# s_data.append(4) +# s_data.append(6) +# s_data.append(8) +# s_data.append(10) +# +# arr_x = pandas.Series(x_data) +# arr_y = pandas.Series(y_data) +# points = arctern.ST_Point(arr_x, arr_y) +# arr_c = pandas.Series(c_data) +# arr_s = pandas.Series(s_data) +# +# vega1 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF"], opacity=1.0, coordinate_system="EPSG:4326") +# res1 = arctern.weighted_point_map_layer(vega1, points) +# save_png(res1, "/tmp/test_weighted_0_0.png") +# +# vega2 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF", "#FF0000"], color_bound=[1, 5], opacity=1.0, coordinate_system="EPSG:4326") +# res2 = arctern.weighted_point_map_layer(vega2, points, color_weights=arr_c) +# save_png(res2, "/tmp/test_weighted_1_0.png") +# +# vega3 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF"], size_bound=[1, 10], opacity=1.0, coordinate_system="EPSG:4326") +# res3 = arctern.weighted_point_map_layer(vega3, points, size_weights=arr_s) +# save_png(res3, "/tmp/test_weighted_0_1.png") +# +# vega4 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF", "#FF0000"], color_bound=[1, 5], size_bound=[1, 10], opacity=1.0, coordinate_system="EPSG:4326") +# res4 = arctern.weighted_point_map_layer(vega4, points, color_weights=arr_c, size_weights=arr_s) +# save_png(res4, "/tmp/test_weighted_1_1.png") +# +# def test_heat_map(): +# x_data = [] +# y_data = [] +# c_data = [] +# +# x_data.append(-73.96524) +# x_data.append(-73.96118) +# x_data.append(-73.97324) +# x_data.append(-73.98456) +# +# y_data.append(40.73747) +# y_data.append(40.74507) +# y_data.append(40.75890) +# y_data.append(40.77654) +# +# c_data.append(10) +# c_data.append(20) +# c_data.append(30) +# c_data.append(40) +# +# arr_x = pandas.Series(x_data) +# arr_y = pandas.Series(y_data) +# points = arctern.ST_Point(arr_x, arr_y) +# arr_c = pandas.Series(c_data) +# +# vega = vega_heatmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], map_zoom_level=13.0, coordinate_system='EPSG:4326') +# heat_map1 = arctern.heat_map_layer(vega, points, arr_c) +# +# save_png(heat_map1, "/tmp/test_heat_map1.png") def test_choropleth_map(): wkt_data = [] @@ -159,29 +159,29 @@ def test_choropleth_map(): choropleth_map1 = arctern.choropleth_map_layer(vega, arr_wkb, arr_count) save_png(choropleth_map1, "/tmp/test_choropleth_map1.png") -def test_icon_viz(): - x_data = [] - y_data = [] - - x_data.append(-73.96524) - x_data.append(-73.96118) - x_data.append(-73.97324) - x_data.append(-73.98456) - - y_data.append(40.73747) - y_data.append(40.74507) - y_data.append(40.75890) - y_data.append(40.77654) - - arr_x = pandas.Series(x_data) - arr_y = pandas.Series(y_data) - points = arctern.ST_Point(arr_x, arr_y) - - import os - dir_path = os.path.dirname(os.path.realpath(__file__)) - png_path = dir_path + "/../images/taxi.png" - - vega = vega_icon(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], icon_path=png_path, coordinate_system="EPSG:4326") - - icon_buf = arctern.icon_viz_layer(vega, points) - save_png(icon_buf, "/tmp/test_icon_viz.png") +# def test_icon_viz(): +# x_data = [] +# y_data = [] +# +# x_data.append(-73.96524) +# x_data.append(-73.96118) +# x_data.append(-73.97324) +# x_data.append(-73.98456) +# +# y_data.append(40.73747) +# y_data.append(40.74507) +# y_data.append(40.75890) +# y_data.append(40.77654) +# +# arr_x = pandas.Series(x_data) +# arr_y = pandas.Series(y_data) +# points = arctern.ST_Point(arr_x, arr_y) +# +# import os +# dir_path = os.path.dirname(os.path.realpath(__file__)) +# png_path = dir_path + "/../images/taxi.png" +# +# vega = vega_icon(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], icon_path=png_path, coordinate_system="EPSG:4326") +# +# icon_buf = arctern.icon_viz_layer(vega, points) +# save_png(icon_buf, "/tmp/test_icon_viz.png") From b6dcc0a9989969f37d8f727817501c2d5e95035f Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Tue, 28 Apr 2020 20:15:16 +0800 Subject: [PATCH 09/24] chroplethmap with agg, done --- cpp/src/arrow/render_api.cpp | 13 ++++---- .../2d/choropleth_map/choropleth_map.cpp | 9 +----- .../render/2d/choropleth_map/choropleth_map.h | 2 -- cpp/src/render/render_builder.h | 4 +++ cpp/src/render/render_builder_impl.h | 32 +++++++++++++++++++ cpp/src/render/utils/render_utils.cpp | 22 +++++++++++++ cpp/src/render/utils/render_utils.h | 9 ++++-- 7 files changed, 71 insertions(+), 20 deletions(-) diff --git a/cpp/src/arrow/render_api.cpp b/cpp/src/arrow/render_api.cpp index 55a22ec6c..4464f2491 100644 --- a/cpp/src/arrow/render_api.cpp +++ b/cpp/src/arrow/render_api.cpp @@ -384,9 +384,9 @@ std::pair render_heatmap(const std::shared_ptr& } template -std::pair render_choroplethmap( - const std::shared_ptr& arr_wkb, - const std::shared_ptr& arr_c, const std::string& conf) { +std::pair render_choroplethmap(const std::vector& arr_wkb, + const std::vector& arr_c, + const std::string& conf) { auto data = weight_agg(arr_wkb, arr_c); auto num_geo = data.second.size(); @@ -962,10 +962,9 @@ std::shared_ptr heat_map(const std::shared_ptr& arr_ std::shared_ptr choropleth_map( const std::vector>& arrs_wkb, const std::vector>& arrs_c, const std::string& conf) { - const auto& wkb_vec = GeometryExtraction(arrs_wkb); - auto num_buildings = wkb_vec.size(); - auto arr_c = WeightExtraction(arrs_c); - return out_pic(choroplethmap(wkb_vec, arr_c, num_buildings, conf)); + const auto& wkb_vec = WkbExtraction(arrs_wkb); + const auto& arr_c = WeightExtraction(arrs_c); + return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); } std::shared_ptr icon_viz(const std::shared_ptr& points, diff --git a/cpp/src/render/2d/choropleth_map/choropleth_map.cpp b/cpp/src/render/2d/choropleth_map/choropleth_map.cpp index e7332ee60..e3030f652 100644 --- a/cpp/src/render/2d/choropleth_map/choropleth_map.cpp +++ b/cpp/src/render/2d/choropleth_map/choropleth_map.cpp @@ -49,13 +49,6 @@ template class ChoroplethMap; template class ChoroplethMap; -template -ChoroplethMap::~ChoroplethMap() { - if (count_ != nullptr) { - free(count_); - } -} - template ChoroplethMap::ChoroplethMap(std::vector choropleth_wkb, T* count, int64_t num_buildings) @@ -77,7 +70,7 @@ void ChoroplethMap::Draw() { for (int i = 0; i < num_buildings_; i++) { glColor4f(colors_[i * 4], colors_[i * 4 + 1], colors_[i * 4 + 2], colors_[i * 4 + 3]); - glBegin(GL_LINES); + glBegin(GL_POLYGON); for (int j = 0; j < buildings_x_[i].size(); j++) { glVertex2d(buildings_x_[i][j], buildings_y_[i][j]); } diff --git a/cpp/src/render/2d/choropleth_map/choropleth_map.h b/cpp/src/render/2d/choropleth_map/choropleth_map.h index 42b78afa1..dc6c8ccfe 100644 --- a/cpp/src/render/2d/choropleth_map/choropleth_map.h +++ b/cpp/src/render/2d/choropleth_map/choropleth_map.h @@ -31,8 +31,6 @@ class ChoroplethMap : public General2D { public: ChoroplethMap() = delete; - ~ChoroplethMap(); - ChoroplethMap(std::vector choropleth_wkb, T* count, int64_t num_vertices); uint8_t* Render() final; diff --git a/cpp/src/render/render_builder.h b/cpp/src/render/render_builder.h index 77747827d..6cc3d45d4 100644 --- a/cpp/src/render/render_builder.h +++ b/cpp/src/render/render_builder.h @@ -58,6 +58,10 @@ std::pair, std::vector>> weight_agg( const std::shared_ptr& geos, const std::shared_ptr& arr_c); +template +std::pair, std::vector>> weight_agg( + const std::vector& wkb_arr, const std::vector& arr_c); + template std::tuple, std::vector>, std::vector>> diff --git a/cpp/src/render/render_builder_impl.h b/cpp/src/render/render_builder_impl.h index a14136766..f050e6c36 100644 --- a/cpp/src/render/render_builder_impl.h +++ b/cpp/src/render/render_builder_impl.h @@ -240,6 +240,38 @@ std::pair, std::vector>> weight_agg( return std::make_pair(results_wkb, results_weight); } +template +std::pair, std::vector>> weight_agg( + const std::vector& wkb_arr, const std::vector& arr_c) { + assert(wkb_arr.size() == arr_c.size()); + + std::unordered_map> wkb_map; + for (size_t i = 0; i < wkb_arr.size(); i++) { + std::string wkb = wkb_arr[i]; + if (wkb_map.find(wkb) == wkb_map.end()) { + std::vector weight; + weight.emplace_back(arr_c[i]); + wkb_map[wkb] = weight; + } else { + auto& weight = wkb_map[wkb]; + weight.emplace_back(arr_c[i]); + } + } + + std::vector results_wkb(wkb_map.size()); + std::vector> results_weight(wkb_map.size()); + int i = 0; + for (auto iter = wkb_map.begin(); iter != wkb_map.end(); iter++) { + OGRGeometry* res_geo; + CHECK_GDAL(OGRGeometryFactory::createFromWkb(iter->first.c_str(), nullptr, &res_geo)); + results_wkb[i] = res_geo; + results_weight[i] = iter->second; + i++; + } + + return std::make_pair(results_wkb, results_weight); +} + template std::tuple, std::vector>, std::vector>> diff --git a/cpp/src/render/utils/render_utils.cpp b/cpp/src/render/utils/render_utils.cpp index e428ecfcb..4fb190943 100644 --- a/cpp/src/render/utils/render_utils.cpp +++ b/cpp/src/render/utils/render_utils.cpp @@ -35,6 +35,7 @@ std::vector GeometryExtraction( int index = 0; for (const auto& arr : arrs) { + assert(arr->type_id() == arrow::Type::BINARY); auto wkb_geometries = std::static_pointer_cast(arr); for (int i = 0; i < wkb_geometries->length(); i++) { OGRGeometry* geo = nullptr; @@ -52,6 +53,27 @@ std::vector GeometryExtraction( return geos_res; } +std::vector WkbExtraction( + const std::vector>& arrs) { + int total_size = 0; + for (const auto& arr : arrs) { + total_size += arr->length(); + } + std::vector wkb_res(total_size); + + int index = 0; + for (const auto& arr : arrs) { + assert(arr->type_id() == arrow::Type::BINARY); + auto wkb_geometries = std::static_pointer_cast(arr); + for (int i = 0; i < wkb_geometries->length(); i++) { + wkb_res[index] = wkb_geometries->GetString(i); + index++; + } + } + + return wkb_res; +} + std::vector> GeometryExport( const std::vector& geos, int arrays_size) { std::vector> arrays(arrays_size); diff --git a/cpp/src/render/utils/render_utils.h b/cpp/src/render/utils/render_utils.h index 1e3755076..ecb539fea 100644 --- a/cpp/src/render/utils/render_utils.h +++ b/cpp/src/render/utils/render_utils.h @@ -26,18 +26,21 @@ namespace render { std::vector GeometryExtraction( const std::vector>& arrs); +std::vector WkbExtraction( + const std::vector>& arrs); + std::vector> GeometryExport( const std::vector& geos, int arrays_size); template -T* WeightExtraction(const std::vector>& arrs) { +std::vector WeightExtraction(const std::vector>& arrs) { int total_size = 0; for (const auto& arr : arrs) { total_size += arr->length(); } - auto res = (T*)malloc(total_size * sizeof(T)); + std::vector res(total_size); int offset = 0; for (const auto& arr : arrs) { @@ -45,7 +48,7 @@ T* WeightExtraction(const std::vector>& arrs) { // auto numeric_arr = std::static_pointer_cast>(arr); // (T*)numeric_arr->data()->GetValues(1); auto ptr = (T*)arr->data()->GetValues(1); - std::memcpy(res + offset, ptr, arr->length() * sizeof(T)); + std::memcpy(res.data() + offset, ptr, arr->length() * sizeof(T)); offset += arr->length(); } From c23e2acade2810c7bf4835b6bf36ab08086e9b4c Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Wed, 29 Apr 2020 11:03:51 +0800 Subject: [PATCH 10/24] icion map, done --- cpp/src/arrow/render_api.cpp | 20 ++++----- cpp/src/arrow/render_api.h | 2 +- cpp/src/render/2d/icon/icon_viz.cpp | 1 + python/arctern/_wrapper_func.py | 25 ++++++++++- python/arctern/cython/arctern_core_.pyx | 9 +++- python/arctern/cython/arctern_core__.pxd | 2 +- python/arctern/cython/render.h | 2 +- python/tests/geo/render_test.py | 53 ++++++++++++------------ 8 files changed, 71 insertions(+), 43 deletions(-) diff --git a/cpp/src/arrow/render_api.cpp b/cpp/src/arrow/render_api.cpp index 4464f2491..fa5db5b7e 100644 --- a/cpp/src/arrow/render_api.cpp +++ b/cpp/src/arrow/render_api.cpp @@ -967,26 +967,26 @@ std::shared_ptr choropleth_map( return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); } -std::shared_ptr icon_viz(const std::shared_ptr& points, +std::shared_ptr icon_viz(const std::vector>& points, const std::string& conf) { - auto point_arr = std::static_pointer_cast(points); - auto num_icons = points->length(); - auto wkb_type = points->type_id(); - assert(wkb_type == arrow::Type::BINARY); + const auto& wkb_vec = WkbExtraction(points); + std::cout << "wkb extraction, done" << std::endl; + auto num_of_point = wkb_vec.size(); - std::vector input_x(num_icons); - std::vector input_y(num_icons); + std::vector input_x(num_of_point); + std::vector input_y(num_of_point); OGRGeometry* res_geo = nullptr; - for (size_t i = 0; i < num_icons; i++) { - std::string geo_wkb = point_arr->GetString(i); + for (size_t i = 0; i < num_of_point; i++) { + std::string geo_wkb = wkb_vec[i]; CHECK_GDAL(OGRGeometryFactory::createFromWkb(geo_wkb.c_str(), nullptr, &res_geo)); auto rs_pointer = reinterpret_cast(res_geo); input_x[i] = rs_pointer->getX(); input_y[i] = rs_pointer->getY(); } - auto result = iconviz(&input_x[0], &input_y[0], num_icons, conf); + std::cout << "c++ enter draw map" << std::endl; + auto result = iconviz(&input_x[0], &input_y[0], num_of_point, conf); return out_pic(result); } diff --git a/cpp/src/arrow/render_api.h b/cpp/src/arrow/render_api.h index df4dfae95..67d0a4d23 100644 --- a/cpp/src/arrow/render_api.h +++ b/cpp/src/arrow/render_api.h @@ -82,7 +82,7 @@ std::shared_ptr icon_viz(const std::shared_ptr& arr_ const std::shared_ptr& arr_y, const std::string& conf); -std::shared_ptr icon_viz(const std::shared_ptr& points, +std::shared_ptr icon_viz(const std::vector>& points, const std::string& conf); } // namespace render diff --git a/cpp/src/render/2d/icon/icon_viz.cpp b/cpp/src/render/2d/icon/icon_viz.cpp index d73539ddd..f546b91b8 100644 --- a/cpp/src/render/2d/icon/icon_viz.cpp +++ b/cpp/src/render/2d/icon/icon_viz.cpp @@ -52,6 +52,7 @@ void IconViz::Draw() { } for (int i = 0; i < num_icons_; i++) { + printf("%d", i); glRasterPos2f(vertices_x_[i], vertices_y_[i]); glDrawPixels(image_buffer.image_params.width, image_buffer.image_params.height, GL_RGBA, GL_UNSIGNED_BYTE, image_buffer.buffer); diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index 54cf62e8e..79b2d8658 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1323,6 +1323,7 @@ def choropleth_map_layer(vega, region_boundaries, weights, transform=True): bounding_box_min = bytes(top_left, encoding="utf8") bounding_box_max = bytes(bottom_right, encoding="utf8") + # TODO: delete print("data prepare ok") # transform and projection handler geos_rs = [] @@ -1331,6 +1332,8 @@ def choropleth_map_layer(vega, region_boundaries, weights, transform=True): geos_rs.append(geos.chunk(chunk_idx)) else: geos_rs.append(geos) + + # transform and projection if coor != 'EPSG:3857': geos = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) print(type(geos)) @@ -1368,18 +1371,36 @@ def icon_viz_layer(vega, points, transform=True): bounding_box = vega.bounding_box() top_left = 'POINT (' + str(bounding_box[0]) + ' ' + str(bounding_box[3]) + ')' bottom_right = 'POINT (' + str(bounding_box[2]) + ' ' + str(bounding_box[1]) + ')' + height = vega.height() width = vega.width() coor = vega.coor() + src = bytes(coor, encoding="utf8") dst = bytes('EPSG:3857', encoding="utf8") bounding_box_min = bytes(top_left, encoding="utf8") bounding_box_max = bytes(bottom_right, encoding="utf8") + + # TODO: delete + print("data prepare ok") + # transform and projection handler + geos_rs = [] + if isinstance(geos, pa.lib.ChunkedArray): + print("chunk num:") + print(geos.num_chunks) + for chunk_idx in range(geos.num_chunks): + geos_rs.append(geos.chunk(chunk_idx)) + else: + geos_rs.append(geos) + + # transform and projection if coor != 'EPSG:3857': - geos = arctern_core_.transform_and_projection(geos, src, dst, bounding_box_max, bounding_box_min, height, width) + geos = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) else: - geos = arctern_core_.projection(geos, bounding_box_max, bounding_box_min, height, width) + geos = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) vega_string = vega.build().encode('utf-8') + rs = arctern_core_.icon_viz(vega_string, geos) + print("draw map, Done!!!") return base64.b64encode(rs.buffers()[1].to_pybytes()) diff --git a/python/arctern/cython/arctern_core_.pyx b/python/arctern/cython/arctern_core_.pyx index 3cab02b18..2a203eed3 100644 --- a/python/arctern/cython/arctern_core_.pyx +++ b/python/arctern/cython/arctern_core_.pyx @@ -73,8 +73,13 @@ def choropleth_map(vega,region_boundaries_arrays, weights_arrays): return pyarrow_wrap_array(arctern_core_pxd.choropleth_map(region_boundaries_vector, weights_vector, vega)) -def icon_viz(vega, points): - return pyarrow_wrap_array(arctern_core_pxd.icon_viz(pyarrow_unwrap_array(points), vega)) +def icon_viz(vega, points_list): + cdef vector[shared_ptr[CArray]] points_vector + for points in points_list: + arr = pyarrow_unwrap_array(points) + points_vector.push_back(arr) + + return pyarrow_wrap_array(arctern_core_pxd.icon_viz(points_vector, vega)) def wkt2wkb(arr_wkt): return pyarrow_wrap_array(arctern_core_pxd.WktToWkb(pyarrow_unwrap_array(arr_wkt))) diff --git a/python/arctern/cython/arctern_core__.pxd b/python/arctern/cython/arctern_core__.pxd index 758c84cbc..f5688ec84 100644 --- a/python/arctern/cython/arctern_core__.pxd +++ b/python/arctern/cython/arctern_core__.pxd @@ -26,7 +26,7 @@ cdef extern from "render.h" namespace "arctern::render": shared_ptr[CArray] weighted_point_map(const shared_ptr[CArray] &points,const shared_ptr[CArray] &color_weights,const shared_ptr[CArray] &size_weights,const string &vega) except + shared_ptr[CArray] heat_map(const shared_ptr[CArray] &points,const shared_ptr[CArray] &weights,const string &vega) except + shared_ptr[CArray] choropleth_map(const vector[shared_ptr[CArray]] ®ion_boundaries,const vector[shared_ptr[CArray]] &weights,const string &vega) except + - shared_ptr[CArray] icon_viz(const shared_ptr[CArray] &points,const string &conf) except + + shared_ptr[CArray] icon_viz(const vector[shared_ptr[CArray]] &points_list,const string &conf) except + shared_ptr[CArray] WktToWkb(const shared_ptr[CArray] && arr_wkt) except + shared_ptr[CArray] WkbToWkt(const shared_ptr[CArray] && arr_wkb) except + diff --git a/python/arctern/cython/render.h b/python/arctern/cython/render.h index 18954cc3c..db283758c 100644 --- a/python/arctern/cython/render.h +++ b/python/arctern/cython/render.h @@ -74,7 +74,7 @@ std::shared_ptr choropleth_map( const std::vector>& region_boundaries, const std::vector>& weights, const std::string& vega); -std::shared_ptr icon_viz(const std::shared_ptr& points, +std::shared_ptr icon_viz(const std::vector>& points, const std::string& conf); } // namespace render diff --git a/python/tests/geo/render_test.py b/python/tests/geo/render_test.py index 10c6fa7f1..c643c57c0 100644 --- a/python/tests/geo/render_test.py +++ b/python/tests/geo/render_test.py @@ -159,29 +159,30 @@ def test_choropleth_map(): choropleth_map1 = arctern.choropleth_map_layer(vega, arr_wkb, arr_count) save_png(choropleth_map1, "/tmp/test_choropleth_map1.png") -# def test_icon_viz(): -# x_data = [] -# y_data = [] -# -# x_data.append(-73.96524) -# x_data.append(-73.96118) -# x_data.append(-73.97324) -# x_data.append(-73.98456) -# -# y_data.append(40.73747) -# y_data.append(40.74507) -# y_data.append(40.75890) -# y_data.append(40.77654) -# -# arr_x = pandas.Series(x_data) -# arr_y = pandas.Series(y_data) -# points = arctern.ST_Point(arr_x, arr_y) -# -# import os -# dir_path = os.path.dirname(os.path.realpath(__file__)) -# png_path = dir_path + "/../images/taxi.png" -# -# vega = vega_icon(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], icon_path=png_path, coordinate_system="EPSG:4326") -# -# icon_buf = arctern.icon_viz_layer(vega, points) -# save_png(icon_buf, "/tmp/test_icon_viz.png") + +def test_icon_viz(): + x_data = [] + y_data = [] + + x_data.append(-73.96524) + x_data.append(-73.96118) + x_data.append(-73.97324) + x_data.append(-73.98456) + + y_data.append(40.73747) + y_data.append(40.74507) + y_data.append(40.75890) + y_data.append(40.77654) + + arr_x = pandas.Series(x_data) + arr_y = pandas.Series(y_data) + points = arctern.ST_Point(arr_x, arr_y) + + import os + dir_path = os.path.dirname(os.path.realpath(__file__)) + png_path = dir_path + "/../images/taxi.png" + + vega = vega_icon(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], icon_path=png_path, coordinate_system="EPSG:4326") + + icon_buf = arctern.icon_viz_layer(vega, points) + save_png(icon_buf, "/tmp/test_icon_viz.png") From 815f9de0730643c29e18a4d817508c1ed2bdfa30 Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Wed, 29 Apr 2020 14:29:43 +0800 Subject: [PATCH 11/24] heat map, done --- cpp/src/arrow/render_api.cpp | 73 ++++-------------------- cpp/src/arrow/render_api.h | 8 +-- cpp/src/render/2d/icon/icon_viz.cpp | 1 - python/arctern/_wrapper_func.py | 39 ++++++++++--- python/arctern/cython/arctern_core_.pyx | 19 ++++-- python/arctern/cython/arctern_core__.pxd | 10 ++-- python/arctern/cython/render.h | 6 +- 7 files changed, 69 insertions(+), 87 deletions(-) diff --git a/cpp/src/arrow/render_api.cpp b/cpp/src/arrow/render_api.cpp index fa5db5b7e..3e909ac21 100644 --- a/cpp/src/arrow/render_api.cpp +++ b/cpp/src/arrow/render_api.cpp @@ -297,8 +297,8 @@ std::pair render_weighted_pointmap( } template -std::pair render_heatmap(const std::shared_ptr& points, - const std::shared_ptr& arr_c, +std::pair render_heatmap(const std::vector& points, + const std::vector& arr_c, const std::string& conf) { auto data = weight_agg(points, arr_c); auto num_point = data.first.size(); @@ -834,63 +834,12 @@ std::shared_ptr weighted_point_map( } } -std::shared_ptr heat_map(const std::shared_ptr& points, - const std::shared_ptr& arr_c, +std::shared_ptr heat_map(const std::vector>& points_vector, + const std::vector>& weights_vector, const std::string& conf) { - auto points_arr = std::static_pointer_cast(points); - auto wkb_type = points->type_id(); - assert(wkb_type == arrow::Type::BINARY); - - std::pair result; - auto c_type = arr_c->type_id(); - switch (c_type) { - case arrow::Type::INT8: { - result = render_heatmap(points, arr_c, conf); - break; - } - case arrow::Type::INT16: { - result = render_heatmap(points, arr_c, conf); - break; - } - case arrow::Type::INT32: { - result = render_heatmap(points, arr_c, conf); - break; - } - case arrow::Type::INT64: { - result = render_heatmap(points, arr_c, conf); - break; - } - case arrow::Type::UINT8: { - result = render_heatmap(points, arr_c, conf); - break; - } - case arrow::Type::UINT16: { - result = render_heatmap(points, arr_c, conf); - break; - } - case arrow::Type::UINT32: { - result = render_heatmap(points, arr_c, conf); - break; - } - case arrow::Type::UINT64: { - result = render_heatmap(points, arr_c, conf); - break; - } - case arrow::Type::FLOAT: { - result = render_heatmap(points, arr_c, conf); - break; - } - case arrow::Type::DOUBLE: { - result = render_heatmap(points, arr_c, conf); - break; - } - default: - std::string err_msg = - "type error of count while running heat map, type = " + std::to_string(c_type); - throw std::runtime_error(err_msg); - } - - return out_pic(result); + const auto& wkb_vec = WkbExtraction(points_vector); + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_heatmap(wkb_vec, arr_c, conf)); } std::shared_ptr heat_map(const std::shared_ptr& arr_x, @@ -960,10 +909,10 @@ std::shared_ptr heat_map(const std::shared_ptr& arr_ } std::shared_ptr choropleth_map( - const std::vector>& arrs_wkb, - const std::vector>& arrs_c, const std::string& conf) { - const auto& wkb_vec = WkbExtraction(arrs_wkb); - const auto& arr_c = WeightExtraction(arrs_c); + const std::vector>& polygons_vector, + const std::vector>& weights_vector, const std::string& conf) { + const auto& wkb_vec = WkbExtraction(polygons_vector); + const auto& arr_c = WeightExtraction(weights_vector); return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); } diff --git a/cpp/src/arrow/render_api.h b/cpp/src/arrow/render_api.h index 67d0a4d23..25be5748c 100644 --- a/cpp/src/arrow/render_api.h +++ b/cpp/src/arrow/render_api.h @@ -70,13 +70,13 @@ std::shared_ptr heat_map(const std::shared_ptr& arr_ const std::shared_ptr& arr_c, const std::string& conf); -std::shared_ptr heat_map(const std::shared_ptr& points, - const std::shared_ptr& arr_c, +std::shared_ptr heat_map(const std::vector>& points_vector, + const std::vector>& weights_vector, const std::string& conf); std::shared_ptr choropleth_map( - const std::vector>& arr_wkt, - const std::vector>& arr_count, const std::string& conf); + const std::vector>& polygons_vector, + const std::vector>& weights_vector, const std::string& conf); std::shared_ptr icon_viz(const std::shared_ptr& arr_x, const std::shared_ptr& arr_y, diff --git a/cpp/src/render/2d/icon/icon_viz.cpp b/cpp/src/render/2d/icon/icon_viz.cpp index f546b91b8..d73539ddd 100644 --- a/cpp/src/render/2d/icon/icon_viz.cpp +++ b/cpp/src/render/2d/icon/icon_viz.cpp @@ -52,7 +52,6 @@ void IconViz::Draw() { } for (int i = 0; i < num_icons_; i++) { - printf("%d", i); glRasterPos2f(vertices_x_[i], vertices_y_[i]); glDrawPixels(image_buffer.image_params.width, image_buffer.image_params.height, GL_RGBA, GL_UNSIGNED_BYTE, image_buffer.buffer); diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index 79b2d8658..c6c5d6b30 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1282,26 +1282,49 @@ def heat_map_layer(vega, points, weights, transform=True): bounding_box = vega.bounding_box() top_left = 'POINT (' + str(bounding_box[0]) + ' ' + str(bounding_box[3]) + ')' bottom_right = 'POINT (' + str(bounding_box[2]) + ' ' + str(bounding_box[1]) + ')' + height = vega.height() width = vega.width() coor = vega.coor() + src = bytes(coor, encoding="utf8") dst = bytes('EPSG:3857', encoding="utf8") bounding_box_min = bytes(top_left, encoding="utf8") bounding_box_max = bytes(bottom_right, encoding="utf8") - if coor != 'EPSG:3857': - geos = arctern_core_.transform_and_projection(geos, src, dst, bounding_box_max, bounding_box_min, height, width) + + # TODO: delete + print("data prepare ok") + # transform and projection handler + geos_rs = [] + if isinstance(geos, pa.lib.ChunkedArray): + for chunk_idx in range(geos.num_chunks): + geos_rs.append(geos.chunk(chunk_idx)) else: - geos = arctern_core_.projection(geos, bounding_box_max, bounding_box_min, height, width) + geos_rs.append(geos) - vega_string = vega.build().encode('utf-8') + # transform and projection + if coor != 'EPSG:3857': + geos = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) + else: + geos = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) + print("transform done") + # weights handler if weights.dtypes == 'float64': - arr_c = pa.array(weights, type='double') + arr = pa.array(weights, type='double') else: - arr_c = pa.array(weights, type='int64') + arr = pa.array(weights, type='int64') - rs = arctern_core_.heat_map(vega_string, geos, arr_c) + weights_rs = [] + if isinstance(arr, pa.lib.ChunkedArray): + for chunk_idx in range(arr.num_chunks): + weights_rs.append(arr.chunk(chunk_idx)) + else: + weights_rs.append(arr) + print("weights handle done") + + vega_string = vega.build().encode('utf-8') + rs = arctern_core_.heat_map(vega_string, geos, weights_rs) return base64.b64encode(rs.buffers()[1].to_pybytes()) @@ -1391,6 +1414,7 @@ def icon_viz_layer(vega, points, transform=True): for chunk_idx in range(geos.num_chunks): geos_rs.append(geos.chunk(chunk_idx)) else: + print("only one chunk") geos_rs.append(geos) # transform and projection @@ -1399,6 +1423,7 @@ def icon_viz_layer(vega, points, transform=True): else: geos = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) + print("transform done") vega_string = vega.build().encode('utf-8') rs = arctern_core_.icon_viz(vega_string, geos) diff --git a/python/arctern/cython/arctern_core_.pyx b/python/arctern/cython/arctern_core_.pyx index 2a203eed3..37ff35a76 100644 --- a/python/arctern/cython/arctern_core_.pyx +++ b/python/arctern/cython/arctern_core_.pyx @@ -55,18 +55,27 @@ def weighted_size_point_map(vega, points, size_weights): def weighted_color_size_point_map(vega, points, color_weights, size_weights): return pyarrow_wrap_array(arctern_core_pxd.weighted_point_map(pyarrow_unwrap_array(points), pyarrow_unwrap_array(color_weights), pyarrow_unwrap_array(size_weights), vega)) -def heat_map(vega, points, weights): - return pyarrow_wrap_array(arctern_core_pxd.heat_map(pyarrow_unwrap_array(points), pyarrow_unwrap_array(weights), vega)) +def heat_map(vega, points_list, weights_list): + cdef vector[shared_ptr[CArray]] points_vector + cdef vector[shared_ptr[CArray]] weights_vector + for points in points_list: + arr = pyarrow_unwrap_array(points) + points_vector.push_back(arr) + for weights in weights_list: + arr = pyarrow_unwrap_array(weights) + weights_vector.push_back(arr) + + return pyarrow_wrap_array(arctern_core_pxd.heat_map(points_vector, weights_vector, vega)) -def choropleth_map(vega,region_boundaries_arrays, weights_arrays): +def choropleth_map(vega,region_boundaries_list, weights_list): # wrapper input cdef shared_ptr[CArray] arr cdef vector[shared_ptr[CArray]] region_boundaries_vector cdef vector[shared_ptr[CArray]] weights_vector - for region in region_boundaries_arrays: + for region in region_boundaries_list: arr = pyarrow_unwrap_array(region) region_boundaries_vector.push_back(arr) - for weights in weights_arrays: + for weights in weights_list: arr = pyarrow_unwrap_array(weights) weights_vector.push_back(arr) diff --git a/python/arctern/cython/arctern_core__.pxd b/python/arctern/cython/arctern_core__.pxd index f5688ec84..6106713a9 100644 --- a/python/arctern/cython/arctern_core__.pxd +++ b/python/arctern/cython/arctern_core__.pxd @@ -24,11 +24,11 @@ cdef extern from "render.h" namespace "arctern::render": shared_ptr[CArray] weighted_point_map(const shared_ptr[CArray] &points,const string &vega) except + shared_ptr[CArray] weighted_point_map(const shared_ptr[CArray] &points,const shared_ptr[CArray] &weights,const string &vega) except + shared_ptr[CArray] weighted_point_map(const shared_ptr[CArray] &points,const shared_ptr[CArray] &color_weights,const shared_ptr[CArray] &size_weights,const string &vega) except + - shared_ptr[CArray] heat_map(const shared_ptr[CArray] &points,const shared_ptr[CArray] &weights,const string &vega) except + - shared_ptr[CArray] choropleth_map(const vector[shared_ptr[CArray]] ®ion_boundaries,const vector[shared_ptr[CArray]] &weights,const string &vega) except + - shared_ptr[CArray] icon_viz(const vector[shared_ptr[CArray]] &points_list,const string &conf) except + - shared_ptr[CArray] WktToWkb(const shared_ptr[CArray] && arr_wkt) except + - shared_ptr[CArray] WkbToWkt(const shared_ptr[CArray] && arr_wkb) except + + shared_ptr[CArray] heat_map(const vector[shared_ptr[CArray]] &points_vector, const vector[shared_ptr[CArray]] &weights_vector, const string &vega) except + + shared_ptr[CArray] choropleth_map(const vector[shared_ptr[CArray]] ®ion_boundaries_vector, const vector[shared_ptr[CArray]] &weights_vector, const string &vega) except + + shared_ptr[CArray] icon_viz(const vector[shared_ptr[CArray]] &points_vector, const string &conf) except + + shared_ptr[CArray] WktToWkb(const shared_ptr[CArray] && arr_wkt) except + + shared_ptr[CArray] WkbToWkt(const shared_ptr[CArray] && arr_wkb) except + cdef extern from "gis.h" namespace "arctern::gis": shared_ptr[CArray] ST_Point(const shared_ptr[CArray] &ptr_x,const shared_ptr[CArray] &ptr_y) except + diff --git a/python/arctern/cython/render.h b/python/arctern/cython/render.h index db283758c..a046d99fe 100644 --- a/python/arctern/cython/render.h +++ b/python/arctern/cython/render.h @@ -51,9 +51,9 @@ std::shared_ptr coordinate_projection( std::shared_ptr point_map(const std::shared_ptr& points, const std::string& vega); -std::shared_ptr heat_map(const std::shared_ptr& points, - const std::shared_ptr& weights, - const std::string& vega); +std::shared_ptr heat_map(const std::vector>& points_vector, + const std::vector>& weights_vector, + const std::string& conf); std::shared_ptr weighted_point_map( const std::shared_ptr& points, const std::string& vega); From cc45d6bf4ee4c6a4f1889b53ca67c3d5ae1d1840 Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Wed, 29 Apr 2020 14:42:54 +0800 Subject: [PATCH 12/24] point map, done --- cpp/src/arrow/render_api.cpp | 24 ++++++++++++------------ cpp/src/arrow/render_api.h | 4 ++-- python/arctern/_wrapper_func.py | 23 +++++++++++++++++++++-- python/arctern/cython/arctern_core_.pyx | 12 ++++++------ python/arctern/cython/arctern_core__.pxd | 2 +- python/arctern/cython/render.h | 4 ++-- 6 files changed, 44 insertions(+), 25 deletions(-) diff --git a/cpp/src/arrow/render_api.cpp b/cpp/src/arrow/render_api.cpp index 3e909ac21..acf1fcfcd 100644 --- a/cpp/src/arrow/render_api.cpp +++ b/cpp/src/arrow/render_api.cpp @@ -470,24 +470,24 @@ const std::vector> transform_and_projection( return res; } -std::shared_ptr point_map(const std::shared_ptr& points, +std::shared_ptr point_map(const std::vector>& points_vector, const std::string& conf) { - auto point_arr = std::static_pointer_cast(points); - auto num_point = points->length(); - auto wkb_type = points->type_id(); - assert(wkb_type == arrow::Type::BINARY); + const auto& wkb_vec = WkbExtraction(points_vector); + std::cout << "wkb extraction, done" << std::endl; + auto num_of_point = wkb_vec.size(); + + std::vector input_x(num_of_point); + std::vector input_y(num_of_point); - std::vector input_x(num_point); - std::vector input_y(num_point); OGRGeometry* res_geo = nullptr; - for (size_t i = 0; i < num_point; i++) { - std::string geo_wkb = point_arr->GetString(i); + for (size_t i = 0; i < num_of_point; i++) { + std::string geo_wkb = wkb_vec[i]; CHECK_GDAL(OGRGeometryFactory::createFromWkb(geo_wkb.c_str(), nullptr, &res_geo)); auto rs_pointer = reinterpret_cast(res_geo); input_x[i] = rs_pointer->getX(); input_y[i] = rs_pointer->getY(); } - auto result = pointmap(&input_x[0], &input_y[0], num_point, conf); + auto result = pointmap(&input_x[0], &input_y[0], num_of_point, conf); return out_pic(result); } @@ -916,9 +916,9 @@ std::shared_ptr choropleth_map( return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); } -std::shared_ptr icon_viz(const std::vector>& points, +std::shared_ptr icon_viz(const std::vector>& points_vector, const std::string& conf) { - const auto& wkb_vec = WkbExtraction(points); + const auto& wkb_vec = WkbExtraction(points_vector); std::cout << "wkb extraction, done" << std::endl; auto num_of_point = wkb_vec.size(); diff --git a/cpp/src/arrow/render_api.h b/cpp/src/arrow/render_api.h index 25be5748c..a9246305f 100644 --- a/cpp/src/arrow/render_api.h +++ b/cpp/src/arrow/render_api.h @@ -40,7 +40,7 @@ std::shared_ptr point_map(const std::shared_ptr& arr const std::shared_ptr& arr_y, const std::string& conf); -std::shared_ptr point_map(const std::shared_ptr& points, +std::shared_ptr point_map(const std::vector>& points_vector, const std::string& conf); // two args api: point_map(wkt, conf) @@ -82,7 +82,7 @@ std::shared_ptr icon_viz(const std::shared_ptr& arr_ const std::shared_ptr& arr_y, const std::string& conf); -std::shared_ptr icon_viz(const std::vector>& points, +std::shared_ptr icon_viz(const std::vector>& points_vector, const std::string& conf); } // namespace render diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index c6c5d6b30..6ed58d8c3 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1203,20 +1203,39 @@ def point_map_layer(vega, points, transform=True): bounding_box = vega.bounding_box() top_left = 'POINT (' + str(bounding_box[0]) + ' ' + str(bounding_box[3]) + ')' bottom_right = 'POINT (' + str(bounding_box[2]) + ' ' + str(bounding_box[1]) + ')' + height = vega.height() width = vega.width() coor = vega.coor() + src = bytes(coor, encoding="utf8") dst = bytes('EPSG:3857', encoding="utf8") bounding_box_min = bytes(top_left, encoding="utf8") bounding_box_max = bytes(bottom_right, encoding="utf8") + + # TODO: delete + print("data prepare ok") + # transform and projection handler + geos_rs = [] + if isinstance(geos, pa.lib.ChunkedArray): + print("chunk num:") + print(geos.num_chunks) + for chunk_idx in range(geos.num_chunks): + geos_rs.append(geos.chunk(chunk_idx)) + else: + print("only one chunk") + geos_rs.append(geos) + + # transform and projection if coor != 'EPSG:3857': - geos = arctern_core_.transform_and_projection(geos, src, dst, bounding_box_max, bounding_box_min, height, width) + geos = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) else: - geos = arctern_core_.projection(geos, bounding_box_max, bounding_box_min, height, width) + geos = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) + print("transform done") vega_string = vega.build().encode('utf-8') rs = arctern_core_.point_map(vega_string, geos) + print("draw map, Done!!!") return base64.b64encode(rs.buffers()[1].to_pybytes()) diff --git a/python/arctern/cython/arctern_core_.pyx b/python/arctern/cython/arctern_core_.pyx index 37ff35a76..24118b05d 100644 --- a/python/arctern/cython/arctern_core_.pyx +++ b/python/arctern/cython/arctern_core_.pyx @@ -40,8 +40,12 @@ def transform_and_projection(geos_array, src_rs, dst_rs, bottom_right, top_left, res.append(pyarrow_wrap_array(output_geos[i])) return res -def point_map(vega, points): - return pyarrow_wrap_array(arctern_core_pxd.point_map(pyarrow_unwrap_array(points), vega)) +def point_map(vega, points_list): + cdef vector[shared_ptr[CArray]] points_vector + for points in points_list: + arr = pyarrow_unwrap_array(points) + points_vector.push_back(arr) + return pyarrow_wrap_array(arctern_core_pxd.point_map(points_vector, vega)) def weighted_point_map(vega, points): return pyarrow_wrap_array(arctern_core_pxd.weighted_point_map(pyarrow_unwrap_array(points), vega)) @@ -64,12 +68,9 @@ def heat_map(vega, points_list, weights_list): for weights in weights_list: arr = pyarrow_unwrap_array(weights) weights_vector.push_back(arr) - return pyarrow_wrap_array(arctern_core_pxd.heat_map(points_vector, weights_vector, vega)) def choropleth_map(vega,region_boundaries_list, weights_list): - # wrapper input - cdef shared_ptr[CArray] arr cdef vector[shared_ptr[CArray]] region_boundaries_vector cdef vector[shared_ptr[CArray]] weights_vector for region in region_boundaries_list: @@ -78,7 +79,6 @@ def choropleth_map(vega,region_boundaries_list, weights_list): for weights in weights_list: arr = pyarrow_unwrap_array(weights) weights_vector.push_back(arr) - return pyarrow_wrap_array(arctern_core_pxd.choropleth_map(region_boundaries_vector, weights_vector, vega)) diff --git a/python/arctern/cython/arctern_core__.pxd b/python/arctern/cython/arctern_core__.pxd index 6106713a9..bf0c3a286 100644 --- a/python/arctern/cython/arctern_core__.pxd +++ b/python/arctern/cython/arctern_core__.pxd @@ -20,7 +20,7 @@ from libcpp.vector cimport vector cdef extern from "render.h" namespace "arctern::render": shared_ptr[CArray] projection(const shared_ptr[CArray] &geos,const string &bottom_right,const string &top_left,const int &height,const int &width) except + const vector[shared_ptr[CArray]] transform_and_projection(const vector[shared_ptr[CArray]] &geos,const string &src_rs,const string &dst_rs,const string &bottom_right,const string &top_left,const int &height,const int &width) except + - shared_ptr[CArray] point_map(const shared_ptr[CArray] &points,const string &vega) except + + shared_ptr[CArray] point_map(const vector[shared_ptr[CArray]] &points_vector, const string &vega) except + shared_ptr[CArray] weighted_point_map(const shared_ptr[CArray] &points,const string &vega) except + shared_ptr[CArray] weighted_point_map(const shared_ptr[CArray] &points,const shared_ptr[CArray] &weights,const string &vega) except + shared_ptr[CArray] weighted_point_map(const shared_ptr[CArray] &points,const shared_ptr[CArray] &color_weights,const shared_ptr[CArray] &size_weights,const string &vega) except + diff --git a/python/arctern/cython/render.h b/python/arctern/cython/render.h index a046d99fe..41d9d979b 100644 --- a/python/arctern/cython/render.h +++ b/python/arctern/cython/render.h @@ -48,8 +48,8 @@ std::shared_ptr coordinate_projection( const std::shared_ptr& points, const std::string top_left, const std::string bottom_right, const int height, const int width); -std::shared_ptr point_map(const std::shared_ptr& points, - const std::string& vega); +std::shared_ptr point_map(const std::vector>& points_vector, + const std::string& conf); std::shared_ptr heat_map(const std::vector>& points_vector, const std::vector>& weights_vector, From 8c612abe0c8397f32025d5ecdc04610d69d6f097 Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Wed, 29 Apr 2020 15:02:25 +0800 Subject: [PATCH 13/24] modify weighted pointmap in c++ --- cpp/src/arrow/render_api.cpp | 242 +++------------------------ cpp/src/arrow/render_api.h | 8 +- cpp/src/render/render_builder.h | 6 +- cpp/src/render/render_builder_impl.h | 34 ++-- 4 files changed, 44 insertions(+), 246 deletions(-) diff --git a/cpp/src/arrow/render_api.cpp b/cpp/src/arrow/render_api.cpp index acf1fcfcd..8b956bdea 100644 --- a/cpp/src/arrow/render_api.cpp +++ b/cpp/src/arrow/render_api.cpp @@ -105,9 +105,9 @@ std::shared_ptr WkbToWkt(const std::shared_ptr& arr_ template std::pair render_weighted_pointmap( - const std::shared_ptr& points, const std::shared_ptr& arr, + const std::vector& points, const std::vector& weights, const std::string& conf) { - auto data = weight_agg(points, arr); + auto data = weight_agg(points, weights); auto num_point = data.first.size(); std::vector input_x(num_point); @@ -192,9 +192,9 @@ std::pair render_weighted_pointmap( template std::pair render_weighted_pointmap( - const std::shared_ptr& points, - const std::shared_ptr& arr_c, - const std::shared_ptr& arr_s, const std::string& conf) { + const std::vector& points, + const std::vector& arr_c, + const std::vector& arr_s, const std::string& conf) { auto agg_res = weight_agg_multiple_column(points, arr_c, arr_s); auto num_point = std::get<0>(agg_res).size(); @@ -510,234 +510,44 @@ std::shared_ptr point_map(const std::shared_ptr& arr } std::shared_ptr weighted_point_map( - const std::shared_ptr& arr1, const std::string& conf) { - auto wkt_type = arr1->type_id(); - assert(wkt_type == arrow::Type::BINARY); - - auto point_arr = std::static_pointer_cast(arr1); - auto num_point = arr1->length(); + const std::vector>& points_vector, const std::string& conf) { + const auto& wkb_vec = WkbExtraction(points_vector); + std::cout << "wkb extraction, done" << std::endl; + auto num_of_point = wkb_vec.size(); - std::vector input_x(num_point); - std::vector input_y(num_point); + std::vector input_x(num_of_point); + std::vector input_y(num_of_point); OGRGeometry* res_geo = nullptr; - for (size_t i = 0; i < num_point; i++) { - std::string geo_wkb = point_arr->GetString(i); + for (size_t i = 0; i < num_of_point; i++) { + std::string geo_wkb = wkb_vec[i]; CHECK_GDAL(OGRGeometryFactory::createFromWkb(geo_wkb.c_str(), nullptr, &res_geo)); auto rst_pointer = reinterpret_cast(res_geo); input_x[i] = (uint32_t)rst_pointer->getX(); input_y[i] = (uint32_t)rst_pointer->getY(); } - auto result = weighted_pointmap(&input_x[0], &input_y[0], num_point, conf); - + auto result = weighted_pointmap(&input_x[0], &input_y[0], num_of_point, conf); return out_pic(result); } std::shared_ptr weighted_point_map( - const std::shared_ptr& arr1, const std::shared_ptr& arr2, + const std::vector>& points_vector, const std::vector>& weights_vector, const std::string& conf) { - auto type1 = arr1->type_id(); - auto type2 = arr2->type_id(); - auto length1 = arr1->length(); - auto length2 = arr2->length(); - - assert(length1 == length2); - - if (type1 == arrow::Type::UINT32 && type2 == arrow::Type::UINT32) { - auto input_x = (uint32_t*)arr1->data()->GetValues(1); - auto input_y = (uint32_t*)arr2->data()->GetValues(1); - - return out_pic(weighted_pointmap(input_x, input_y, length1, conf)); - } else if (type1 == arrow::Type::BINARY) { - std::pair result; - switch (type2) { - case arrow::Type::INT8: { - result = render_weighted_pointmap(arr1, arr2, conf); - break; - } - case arrow::Type::INT16: { - result = render_weighted_pointmap(arr1, arr2, conf); - break; - } - case arrow::Type::INT32: { - result = render_weighted_pointmap(arr1, arr2, conf); - break; - } - case arrow::Type::INT64: { - result = render_weighted_pointmap(arr1, arr2, conf); - break; - } - case arrow::Type::UINT8: { - result = render_weighted_pointmap(arr1, arr2, conf); - break; - } - case arrow::Type::UINT16: { - result = render_weighted_pointmap(arr1, arr2, conf); - break; - } - case arrow::Type::UINT32: { - result = render_weighted_pointmap(arr1, arr2, conf); - break; - } - case arrow::Type::UINT64: { - result = render_weighted_pointmap(arr1, arr2, conf); - break; - } - case arrow::Type::FLOAT: { - result = render_weighted_pointmap(arr1, arr2, conf); - break; - } - case arrow::Type::DOUBLE: { - result = render_weighted_pointmap(arr1, arr2, conf); - break; - } - default: - std::string err_msg = - "type error of count while running weighted_point map, type = " + - std::to_string(type2); - throw std::runtime_error(err_msg); - } - - return out_pic(result); - - } else { - std::string err_msg = - "type error of arrow::Array while running weighted_point map, type = " + - std::to_string(type1); - throw std::runtime_error(err_msg); - } + const auto& wkb_vec = WkbExtraction(points_vector); + const auto& arr_c = WeightExtraction(weights_vector); + const auto& render_result = render_weighted_pointmap(wkb_vec, arr_c, conf); + return out_pic(render_result); } std::shared_ptr weighted_point_map( - const std::shared_ptr& arr1, const std::shared_ptr& arr2, - const std::shared_ptr& arr3, const std::string& conf) { - auto length1 = arr1->length(); - auto length2 = arr2->length(); - auto length3 = arr3->length(); - - auto type1 = arr1->type_id(); - auto type2 = arr2->type_id(); - auto type3 = arr3->type_id(); - - assert(length1 == length2); - assert(length2 == length3); - - if (type1 == arrow::Type::UINT32 && type2 == arrow::Type::UINT32) { - auto input_x = (uint32_t*)arr1->data()->GetValues(1); - auto input_y = (uint32_t*)arr2->data()->GetValues(1); - - switch (type3) { - case arrow::Type::INT8: { - auto input = (int8_t*)arr3->data()->GetValues(1); - return out_pic(weighted_pointmap(input_x, input_y, input, length1, conf)); - } - case arrow::Type::INT16: { - auto input = (int16_t*)arr3->data()->GetValues(1); - return out_pic( - weighted_pointmap(input_x, input_y, input, length1, conf)); - } - case arrow::Type::INT32: { - auto input = (int32_t*)arr3->data()->GetValues(1); - return out_pic( - weighted_pointmap(input_x, input_y, input, length1, conf)); - } - case arrow::Type::INT64: { - auto input = (int64_t*)arr3->data()->GetValues(1); - return out_pic( - weighted_pointmap(input_x, input_y, input, length1, conf)); - } - case arrow::Type::UINT8: { - auto input = (uint8_t*)arr3->data()->GetValues(1); - return out_pic( - weighted_pointmap(input_x, input_y, input, length1, conf)); - } - case arrow::Type::UINT16: { - auto input = (uint16_t*)arr3->data()->GetValues(1); - return out_pic( - weighted_pointmap(input_x, input_y, input, length1, conf)); - } - case arrow::Type::UINT32: { - auto input = (uint32_t*)arr3->data()->GetValues(1); - return out_pic( - weighted_pointmap(input_x, input_y, input, length1, conf)); - } - case arrow::Type::UINT64: { - auto input = (uint64_t*)arr3->data()->GetValues(1); - return out_pic( - weighted_pointmap(input_x, input_y, input, length1, conf)); - } - case arrow::Type::FLOAT: { - auto input = (float*)arr3->data()->GetValues(1); - return out_pic(weighted_pointmap(input_x, input_y, input, length1, conf)); - } - case arrow::Type::DOUBLE: { - auto input = (double*)arr3->data()->GetValues(1); - return out_pic(weighted_pointmap(input_x, input_y, input, length1, conf)); - } - default: - std::string err_msg = - "type error of count while running weighted_point map, type = " + - std::to_string(type3); - throw std::runtime_error(err_msg); - } - } else if (type1 == arrow::Type::BINARY && type2 == type3) { - std::pair result; - - switch (type3) { - case arrow::Type::INT8: { - result = render_weighted_pointmap(arr1, arr2, arr3, conf); - break; - } - case arrow::Type::INT16: { - result = render_weighted_pointmap(arr1, arr2, arr3, conf); - break; - } - case arrow::Type::INT32: { - result = render_weighted_pointmap(arr1, arr2, arr3, conf); - break; - } - case arrow::Type::INT64: { - result = render_weighted_pointmap(arr1, arr2, arr3, conf); - break; - } - case arrow::Type::UINT8: { - result = render_weighted_pointmap(arr1, arr2, arr3, conf); - break; - } - case arrow::Type::UINT16: { - result = render_weighted_pointmap(arr1, arr2, arr3, conf); - break; - } - case arrow::Type::UINT32: { - result = render_weighted_pointmap(arr1, arr2, arr3, conf); - break; - } - case arrow::Type::UINT64: { - result = render_weighted_pointmap(arr1, arr2, arr3, conf); - break; - } - case arrow::Type::FLOAT: { - result = render_weighted_pointmap(arr1, arr2, arr3, conf); - break; - } - case arrow::Type::DOUBLE: { - result = render_weighted_pointmap(arr1, arr2, arr3, conf); - break; - } - default: - std::string err_msg = - "type error of count while running weighted_point map, type = " + - std::to_string(type3); - throw std::runtime_error(err_msg); - } - return out_pic(result); - } else { - std::string err_msg = - "type error of arrow::Array while running weighted_point map, type = " + - std::to_string(type1); - throw std::runtime_error(err_msg); - } + const std::vector>& points_vector, const std::vector>& color_weights_vector, + const std::vector>& point_size_weights_vector, const std::string& conf) { + const auto& wkb_vec = WkbExtraction(points_vector); + const auto& arr_c = WeightExtraction(color_weights_vector); + const auto& arr_s = WeightExtraction(point_size_weights_vector); + const auto& render_result = render_weighted_pointmap(wkb_vec, arr_c, arr_s, conf); + return out_pic(render_result); } std::shared_ptr weighted_point_map( diff --git a/cpp/src/arrow/render_api.h b/cpp/src/arrow/render_api.h index a9246305f..720fe2496 100644 --- a/cpp/src/arrow/render_api.h +++ b/cpp/src/arrow/render_api.h @@ -45,18 +45,18 @@ std::shared_ptr point_map(const std::vector weighted_point_map( - const std::shared_ptr& arr1, const std::string& conf); + const std::vector>& points_vector, const std::string& conf); // three args api: point_map(x, y, conf), point_map(wkt, c, conf), point_map(wkt, s, conf) std::shared_ptr weighted_point_map( - const std::shared_ptr& arr1, const std::shared_ptr& arr2, + const std::vector>& points_vector, const std::vector>& weights_vector, const std::string& conf); // four args api: point_map(x, y, c, conf), point_map(x, y, s, conf), point_map(wkt, c, s, // conf) std::shared_ptr weighted_point_map( - const std::shared_ptr& arr1, const std::shared_ptr& arr2, - const std::shared_ptr& arr3, const std::string& conf); + const std::vector>& points_vector, const std::vector>& color_weights_vector, + const std::vector>& point_size_weights_vector, const std::string& conf); // five args api: point_map(x, y, c, s, conf) std::shared_ptr weighted_point_map( diff --git a/cpp/src/render/render_builder.h b/cpp/src/render/render_builder.h index 6cc3d45d4..85bb9dd46 100644 --- a/cpp/src/render/render_builder.h +++ b/cpp/src/render/render_builder.h @@ -65,9 +65,9 @@ std::pair, std::vector>> weight_agg( template std::tuple, std::vector>, std::vector>> -weight_agg_multiple_column(const std::shared_ptr& geos, - const std::shared_ptr& arr_c, - const std::shared_ptr& arr_s); +weight_agg_multiple_column(const std::vector& geos, + const std::vector& arr_c, + const std::vector& arr_s); std::pair pointmap(uint32_t* arr_x, uint32_t* arr_y, int64_t num_vertices, const std::string& conf); diff --git a/cpp/src/render/render_builder_impl.h b/cpp/src/render/render_builder_impl.h index f050e6c36..9cd43c6ca 100644 --- a/cpp/src/render/render_builder_impl.h +++ b/cpp/src/render/render_builder_impl.h @@ -275,40 +275,28 @@ std::pair, std::vector>> weight_agg( template std::tuple, std::vector>, std::vector>> -weight_agg_multiple_column(const std::shared_ptr& geos, - const std::shared_ptr& arr_c, - const std::shared_ptr& arr_s) { - auto geo_arr = std::static_pointer_cast(geos); - - auto c_arr = (T*)arr_c->data()->GetValues(1); - auto s_arr = (T*)arr_s->data()->GetValues(1); - - auto geo_type = geos->type_id(); - assert(geo_type == arrow::Type::BINARY); - - auto geos_size = geos->length(); - auto c_size = arr_c->length(); - auto s_size = arr_s->length(); - - assert(geos_size == c_size); - assert(c_size == s_size); +weight_agg_multiple_column(const std::vector& geos, + const std::vector& arr_c, + const std::vector& arr_s) { + assert(geos.size() == arr_c.size()); + assert(arr_c.size() == arr_s.size()); using vector_pair = std::pair, std::vector>; std::unordered_map wkb_map; - for (size_t i = 0; i < geos_size; i++) { - std::string geo_wkb = geo_arr->GetString(i); + for (size_t i = 0; i < geos.size(); i++) { + std::string geo_wkb = geos[i]; if (wkb_map.find(geo_wkb) == wkb_map.end()) { std::vector weight_c; std::vector weight_s; - weight_c.emplace_back(c_arr[i]); - weight_s.emplace_back(s_arr[i]); + weight_c.emplace_back(arr_c[i]); + weight_s.emplace_back(arr_s[i]); wkb_map[geo_wkb] = std::make_pair(weight_c, weight_s); } else { auto& weight_c = wkb_map[geo_wkb].first; auto& weight_s = wkb_map[geo_wkb].second; - weight_c.emplace_back(c_arr[i]); - weight_s.emplace_back(s_arr[i]); + weight_c.emplace_back(arr_c[i]); + weight_s.emplace_back(arr_s[i]); } } From 6fe05f01a6f7e8d3dceca6e8cbe2734d0b67a1e1 Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Wed, 29 Apr 2020 15:26:57 +0800 Subject: [PATCH 14/24] wrap weighted pointmap in cython --- cpp/src/arrow/render_api.cpp | 37 +++++----- cpp/src/arrow/render_api.h | 32 +++++---- cpp/src/render/render_builder.h | 3 +- cpp/src/render/render_builder_impl.h | 4 +- python/arctern/cython/arctern_core_.pyx | 67 +++++++++++++++---- python/arctern/cython/arctern_core__.pxd | 14 ++-- .../arctern/cython/arctern_core_symbol_.pyx | 41 +++++------- python/arctern/cython/gis.h | 5 +- python/arctern/cython/render.h | 43 ++++++------ 9 files changed, 149 insertions(+), 97 deletions(-) diff --git a/cpp/src/arrow/render_api.cpp b/cpp/src/arrow/render_api.cpp index 8b956bdea..4028160de 100644 --- a/cpp/src/arrow/render_api.cpp +++ b/cpp/src/arrow/render_api.cpp @@ -192,8 +192,7 @@ std::pair render_weighted_pointmap( template std::pair render_weighted_pointmap( - const std::vector& points, - const std::vector& arr_c, + const std::vector& points, const std::vector& arr_c, const std::vector& arr_s, const std::string& conf) { auto agg_res = weight_agg_multiple_column(points, arr_c, arr_s); auto num_point = std::get<0>(agg_res).size(); @@ -470,8 +469,9 @@ const std::vector> transform_and_projection( return res; } -std::shared_ptr point_map(const std::vector>& points_vector, - const std::string& conf) { +std::shared_ptr point_map( + const std::vector>& points_vector, + const std::string& conf) { const auto& wkb_vec = WkbExtraction(points_vector); std::cout << "wkb extraction, done" << std::endl; auto num_of_point = wkb_vec.size(); @@ -510,7 +510,8 @@ std::shared_ptr point_map(const std::shared_ptr& arr } std::shared_ptr weighted_point_map( - const std::vector>& points_vector, const std::string& conf) { + const std::vector>& points_vector, + const std::string& conf) { const auto& wkb_vec = WkbExtraction(points_vector); std::cout << "wkb extraction, done" << std::endl; auto num_of_point = wkb_vec.size(); @@ -532,7 +533,8 @@ std::shared_ptr weighted_point_map( } std::shared_ptr weighted_point_map( - const std::vector>& points_vector, const std::vector>& weights_vector, + const std::vector>& points_vector, + const std::vector>& weights_vector, const std::string& conf) { const auto& wkb_vec = WkbExtraction(points_vector); const auto& arr_c = WeightExtraction(weights_vector); @@ -541,11 +543,13 @@ std::shared_ptr weighted_point_map( } std::shared_ptr weighted_point_map( - const std::vector>& points_vector, const std::vector>& color_weights_vector, - const std::vector>& point_size_weights_vector, const std::string& conf) { + const std::vector>& points_vector, + const std::vector>& color_weights_vector, + const std::vector>& size_weights_vector, + const std::string& conf) { const auto& wkb_vec = WkbExtraction(points_vector); const auto& arr_c = WeightExtraction(color_weights_vector); - const auto& arr_s = WeightExtraction(point_size_weights_vector); + const auto& arr_s = WeightExtraction(size_weights_vector); const auto& render_result = render_weighted_pointmap(wkb_vec, arr_c, arr_s, conf); return out_pic(render_result); } @@ -644,9 +648,10 @@ std::shared_ptr weighted_point_map( } } -std::shared_ptr heat_map(const std::vector>& points_vector, - const std::vector>& weights_vector, - const std::string& conf) { +std::shared_ptr heat_map( + const std::vector>& points_vector, + const std::vector>& weights_vector, + const std::string& conf) { const auto& wkb_vec = WkbExtraction(points_vector); const auto& arr_c = WeightExtraction(weights_vector); return out_pic(render_heatmap(wkb_vec, arr_c, conf)); @@ -720,14 +725,16 @@ std::shared_ptr heat_map(const std::shared_ptr& arr_ std::shared_ptr choropleth_map( const std::vector>& polygons_vector, - const std::vector>& weights_vector, const std::string& conf) { + const std::vector>& weights_vector, + const std::string& conf) { const auto& wkb_vec = WkbExtraction(polygons_vector); const auto& arr_c = WeightExtraction(weights_vector); return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); } -std::shared_ptr icon_viz(const std::vector>& points_vector, - const std::string& conf) { +std::shared_ptr icon_viz( + const std::vector>& points_vector, + const std::string& conf) { const auto& wkb_vec = WkbExtraction(points_vector); std::cout << "wkb extraction, done" << std::endl; auto num_of_point = wkb_vec.size(); diff --git a/cpp/src/arrow/render_api.h b/cpp/src/arrow/render_api.h index 720fe2496..9ed8f188d 100644 --- a/cpp/src/arrow/render_api.h +++ b/cpp/src/arrow/render_api.h @@ -40,23 +40,28 @@ std::shared_ptr point_map(const std::shared_ptr& arr const std::shared_ptr& arr_y, const std::string& conf); -std::shared_ptr point_map(const std::vector>& points_vector, - const std::string& conf); +std::shared_ptr point_map( + const std::vector>& points_vector, + const std::string& conf); // two args api: point_map(wkt, conf) std::shared_ptr weighted_point_map( - const std::vector>& points_vector, const std::string& conf); + const std::vector>& points_vector, + const std::string& conf); // three args api: point_map(x, y, conf), point_map(wkt, c, conf), point_map(wkt, s, conf) std::shared_ptr weighted_point_map( - const std::vector>& points_vector, const std::vector>& weights_vector, + const std::vector>& points_vector, + const std::vector>& weights_vector, const std::string& conf); // four args api: point_map(x, y, c, conf), point_map(x, y, s, conf), point_map(wkt, c, s, // conf) std::shared_ptr weighted_point_map( - const std::vector>& points_vector, const std::vector>& color_weights_vector, - const std::vector>& point_size_weights_vector, const std::string& conf); + const std::vector>& points_vector, + const std::vector>& color_weights_vector, + const std::vector>& size_weights_vector, + const std::string& conf); // five args api: point_map(x, y, c, s, conf) std::shared_ptr weighted_point_map( @@ -70,20 +75,23 @@ std::shared_ptr heat_map(const std::shared_ptr& arr_ const std::shared_ptr& arr_c, const std::string& conf); -std::shared_ptr heat_map(const std::vector>& points_vector, - const std::vector>& weights_vector, - const std::string& conf); +std::shared_ptr heat_map( + const std::vector>& points_vector, + const std::vector>& weights_vector, + const std::string& conf); std::shared_ptr choropleth_map( const std::vector>& polygons_vector, - const std::vector>& weights_vector, const std::string& conf); + const std::vector>& weights_vector, + const std::string& conf); std::shared_ptr icon_viz(const std::shared_ptr& arr_x, const std::shared_ptr& arr_y, const std::string& conf); -std::shared_ptr icon_viz(const std::vector>& points_vector, - const std::string& conf); +std::shared_ptr icon_viz( + const std::vector>& points_vector, + const std::string& conf); } // namespace render } // namespace arctern diff --git a/cpp/src/render/render_builder.h b/cpp/src/render/render_builder.h index 85bb9dd46..3999767ef 100644 --- a/cpp/src/render/render_builder.h +++ b/cpp/src/render/render_builder.h @@ -66,8 +66,7 @@ template std::tuple, std::vector>, std::vector>> weight_agg_multiple_column(const std::vector& geos, - const std::vector& arr_c, - const std::vector& arr_s); + const std::vector& arr_c, const std::vector& arr_s); std::pair pointmap(uint32_t* arr_x, uint32_t* arr_y, int64_t num_vertices, const std::string& conf); diff --git a/cpp/src/render/render_builder_impl.h b/cpp/src/render/render_builder_impl.h index 9cd43c6ca..de962688a 100644 --- a/cpp/src/render/render_builder_impl.h +++ b/cpp/src/render/render_builder_impl.h @@ -243,6 +243,7 @@ std::pair, std::vector>> weight_agg( template std::pair, std::vector>> weight_agg( const std::vector& wkb_arr, const std::vector& arr_c) { + std::cout << "wkb size = " << wkb_arr.size() << ", arr_c.size = " << arr_c.size() << std::endl; assert(wkb_arr.size() == arr_c.size()); std::unordered_map> wkb_map; @@ -276,8 +277,7 @@ template std::tuple, std::vector>, std::vector>> weight_agg_multiple_column(const std::vector& geos, - const std::vector& arr_c, - const std::vector& arr_s) { + const std::vector& arr_c, const std::vector& arr_s) { assert(geos.size() == arr_c.size()); assert(arr_c.size() == arr_s.size()); diff --git a/python/arctern/cython/arctern_core_.pyx b/python/arctern/cython/arctern_core_.pyx index 24118b05d..97c5333e5 100644 --- a/python/arctern/cython/arctern_core_.pyx +++ b/python/arctern/cython/arctern_core_.pyx @@ -16,10 +16,13 @@ # distutils: language = c++ from pyarrow.lib cimport (pyarrow_wrap_array, pyarrow_unwrap_array) -cimport arctern_core__ as arctern_core_pxd from libcpp.vector cimport vector from pyarrow.lib cimport (shared_ptr, CArray) +cimport arctern_core__ as arctern_core_pxd + + +# render func api: def projection(geos, bottom_right, top_left, height, width): return pyarrow_wrap_array(arctern_core_pxd.projection(pyarrow_unwrap_array(geos), bottom_right, top_left, height, width)) @@ -40,6 +43,14 @@ def transform_and_projection(geos_array, src_rs, dst_rs, bottom_right, top_left, res.append(pyarrow_wrap_array(output_geos[i])) return res +def wkt2wkb(arr_wkt): + return pyarrow_wrap_array(arctern_core_pxd.WktToWkb(pyarrow_unwrap_array(arr_wkt))) + +def wkb2wkt(arr_wkb): + return pyarrow_wrap_array(arctern_core_pxd.WkbToWkt(pyarrow_unwrap_array(arr_wkb))) + + +# render drawing api: def point_map(vega, points_list): cdef vector[shared_ptr[CArray]] points_vector for points in points_list: @@ -47,17 +58,49 @@ def point_map(vega, points_list): points_vector.push_back(arr) return pyarrow_wrap_array(arctern_core_pxd.point_map(points_vector, vega)) -def weighted_point_map(vega, points): - return pyarrow_wrap_array(arctern_core_pxd.weighted_point_map(pyarrow_unwrap_array(points), vega)) +def weighted_point_map(vega, points_list): + cdef vector[shared_ptr[CArray]] points_vector + for points in points_list: + arr = pyarrow_unwrap_array(points) + points_vector.push_back(arr) + return pyarrow_wrap_array(arctern_core_pxd.weighted_point_map(points_vector, vega)) -def weighted_color_point_map(vega, points, color_weights): - return pyarrow_wrap_array(arctern_core_pxd.weighted_point_map(pyarrow_unwrap_array(points), pyarrow_unwrap_array(color_weights), vega)) +def weighted_color_point_map(vega, points_list, color_list): + cdef vector[shared_ptr[CArray]] points_vector + cdef vector[shared_ptr[CArray]] color_vector + for points in points_list: + arr = pyarrow_unwrap_array(points) + points_vector.push_back(arr) + for color in color_list: + arr = pyarrow_unwrap_array(color) + color_vector.push_back(arr) + return pyarrow_wrap_array(arctern_core_pxd.weighted_point_map(points_vector, color_vector, vega)) -def weighted_size_point_map(vega, points, size_weights): - return pyarrow_wrap_array(arctern_core_pxd.weighted_point_map(pyarrow_unwrap_array(points), pyarrow_unwrap_array(size_weights), vega)) +def weighted_size_point_map(vega, points_list, size_list): + cdef vector[shared_ptr[CArray]] points_vector + cdef vector[shared_ptr[CArray]] size_vector + for points in points_list: + arr = pyarrow_unwrap_array(points) + points_vector.push_back(arr) + for size in size_list: + arr = pyarrow_unwrap_array(size) + size_vector.push_back(arr) + return pyarrow_wrap_array(arctern_core_pxd.weighted_point_map(points_vector, size_vector, vega)) -def weighted_color_size_point_map(vega, points, color_weights, size_weights): - return pyarrow_wrap_array(arctern_core_pxd.weighted_point_map(pyarrow_unwrap_array(points), pyarrow_unwrap_array(color_weights), pyarrow_unwrap_array(size_weights), vega)) +def weighted_color_size_point_map(vega, points_list, color_list, size_list): + cdef vector[shared_ptr[CArray]] points_vector + cdef vector[shared_ptr[CArray]] color_vector + cdef vector[shared_ptr[CArray]] size_vector + for points in points_list: + arr = pyarrow_unwrap_array(points) + points_vector.push_back(arr) + for color in color_list: + arr = pyarrow_unwrap_array(color) + color_vector.push_back(arr) + for size in size_list: + arr = pyarrow_unwrap_array(size) + size_vector.push_back(arr) + return pyarrow_wrap_array(arctern_core_pxd.weighted_point_map(points_vector, color_vector, size_vector, vega)) def heat_map(vega, points_list, weights_list): cdef vector[shared_ptr[CArray]] points_vector @@ -81,7 +124,6 @@ def choropleth_map(vega,region_boundaries_list, weights_list): weights_vector.push_back(arr) return pyarrow_wrap_array(arctern_core_pxd.choropleth_map(region_boundaries_vector, weights_vector, vega)) - def icon_viz(vega, points_list): cdef vector[shared_ptr[CArray]] points_vector for points in points_list: @@ -90,12 +132,9 @@ def icon_viz(vega, points_list): return pyarrow_wrap_array(arctern_core_pxd.icon_viz(points_vector, vega)) -def wkt2wkb(arr_wkt): - return pyarrow_wrap_array(arctern_core_pxd.WktToWkb(pyarrow_unwrap_array(arr_wkt))) -def wkb2wkt(arr_wkb): - return pyarrow_wrap_array(arctern_core_pxd.WkbToWkt(pyarrow_unwrap_array(arr_wkb))) +# gis api: def ST_Point(object arr_x,object arr_y): return pyarrow_wrap_array(arctern_core_pxd.ST_Point(pyarrow_unwrap_array(arr_x),pyarrow_unwrap_array(arr_y))) diff --git a/python/arctern/cython/arctern_core__.pxd b/python/arctern/cython/arctern_core__.pxd index bf0c3a286..0309ecdb3 100644 --- a/python/arctern/cython/arctern_core__.pxd +++ b/python/arctern/cython/arctern_core__.pxd @@ -18,17 +18,21 @@ from libcpp.vector cimport vector cdef extern from "render.h" namespace "arctern::render": + # func api: shared_ptr[CArray] projection(const shared_ptr[CArray] &geos,const string &bottom_right,const string &top_left,const int &height,const int &width) except + const vector[shared_ptr[CArray]] transform_and_projection(const vector[shared_ptr[CArray]] &geos,const string &src_rs,const string &dst_rs,const string &bottom_right,const string &top_left,const int &height,const int &width) except + + shared_ptr[CArray] WktToWkb(const shared_ptr[CArray] && arr_wkt) except + + shared_ptr[CArray] WkbToWkt(const shared_ptr[CArray] && arr_wkb) except + + + # drawing api: shared_ptr[CArray] point_map(const vector[shared_ptr[CArray]] &points_vector, const string &vega) except + - shared_ptr[CArray] weighted_point_map(const shared_ptr[CArray] &points,const string &vega) except + - shared_ptr[CArray] weighted_point_map(const shared_ptr[CArray] &points,const shared_ptr[CArray] &weights,const string &vega) except + - shared_ptr[CArray] weighted_point_map(const shared_ptr[CArray] &points,const shared_ptr[CArray] &color_weights,const shared_ptr[CArray] &size_weights,const string &vega) except + + shared_ptr[CArray] weighted_point_map(const vector[shared_ptr[CArray]] &points_vector, const string &vega) except + + shared_ptr[CArray] weighted_point_map(const vector[shared_ptr[CArray]] &points_vector, const vector[shared_ptr[CArray]] &weights_vector, const string &vega) except + + shared_ptr[CArray] weighted_point_map(const vector[shared_ptr[CArray]] &points_vector, const vector[shared_ptr[CArray]] &color_weights_vector, const vector[shared_ptr[CArray]] &size_weights_vector, const string &vega) except + shared_ptr[CArray] heat_map(const vector[shared_ptr[CArray]] &points_vector, const vector[shared_ptr[CArray]] &weights_vector, const string &vega) except + shared_ptr[CArray] choropleth_map(const vector[shared_ptr[CArray]] ®ion_boundaries_vector, const vector[shared_ptr[CArray]] &weights_vector, const string &vega) except + shared_ptr[CArray] icon_viz(const vector[shared_ptr[CArray]] &points_vector, const string &conf) except + - shared_ptr[CArray] WktToWkb(const shared_ptr[CArray] && arr_wkt) except + - shared_ptr[CArray] WkbToWkt(const shared_ptr[CArray] && arr_wkb) except + + cdef extern from "gis.h" namespace "arctern::gis": shared_ptr[CArray] ST_Point(const shared_ptr[CArray] &ptr_x,const shared_ptr[CArray] &ptr_y) except + diff --git a/python/arctern/cython/arctern_core_symbol_.pyx b/python/arctern/cython/arctern_core_symbol_.pyx index 081f9a706..38f3be569 100644 --- a/python/arctern/cython/arctern_core_symbol_.pyx +++ b/python/arctern/cython/arctern_core_symbol_.pyx @@ -15,60 +15,49 @@ # cython: language_level=3 # distutils: language = c++ -def projection(geos, bottom_right, top_left, int height, int width): - pass - -def transform_and_projection(geos, src_rs, dst_rs, bottom_right, top_left, int height, int width): - pass -def point_map_wkb(points, conf): +# render func api: +def projection(geos, bottom_right, top_left, height, width): pass -def weighted_point_map_wkb_0_0(points, conf): +def transform_and_projection(geos_array, src_rs, dst_rs, bottom_right, top_left, height, width): pass -def weighted_point_map_wkb_1_0(points, conf, cs): - pass - -def weighted_point_map_wkb_0_1(points, conf, ss): +def wkt2wkb(arr_wkt): pass -def weighted_point_map_wkb_1_1(points, conf, cs, ss): +def wkb2wkt(arr_wkb): pass -def weighted_point_map_0_0(arr_x, arr_y, conf): - pass -def weighted_point_map_0_1(arr_x, arr_y, conf, ss): +# render drawing api: +def point_map(vega, points_list): pass -def weighted_point_map_1_0(arr_x, arr_y, conf, cs): +def weighted_point_map(vega, points_list): pass -def weighted_point_map_1_1(arr_x, arr_y, conf, cs, ss): +def weighted_color_point_map(vega, points_list, color_list): pass -def heat_map_wkb(points, arr_c, conf): +def weighted_size_point_map(vega, points, size_list): pass -def point_map(arr_x, arr_y, conf): +def weighted_color_size_point_map(vega, points, color_list, size_list): pass -def heat_map(arr_x, arr_y, arr_c, conf): +def heat_map(vega, points_list, weights_list): pass -def choropleth_map(arr_wkt, arr_count, conf): +def choropleth_map(vega,region_boundaries_list, weights_list): pass -def icon_viz(points, conf): +def icon_viz(vega, points_list): pass -def wkt2wkb(arr_wkt): - pass -def wkb2wkt(arr_wkb): - pass +# gis api def ST_Point(object arr_x,object arr_y): pass diff --git a/python/arctern/cython/gis.h b/python/arctern/cython/gis.h index 8b88dfd20..b9fefe133 100644 --- a/python/arctern/cython/gis.h +++ b/python/arctern/cython/gis.h @@ -92,8 +92,9 @@ std::shared_ptr ST_Within(const std::shared_ptr& geo std::shared_ptr ST_Distance(const std::shared_ptr& geo_arr1, const std::shared_ptr& geo_arr2); -std::shared_ptr ST_DistanceSphere(const std::shared_ptr& point_left, - const std::shared_ptr& point_right); +std::shared_ptr ST_DistanceSphere( + const std::shared_ptr& point_left, + const std::shared_ptr& point_right); std::shared_ptr ST_Area(const std::shared_ptr& geo_arr); diff --git a/python/arctern/cython/render.h b/python/arctern/cython/render.h index 41d9d979b..51c2179f5 100644 --- a/python/arctern/cython/render.h +++ b/python/arctern/cython/render.h @@ -24,15 +24,14 @@ namespace arctern { namespace render { -std::shared_ptr -WktToWkb(const std::shared_ptr& arr_wkt); +std::shared_ptr WktToWkb(const std::shared_ptr& arr_wkt); -std::shared_ptr -WkbToWkt(const std::shared_ptr& arr_wkb); +std::shared_ptr WkbToWkt(const std::shared_ptr& arr_wkb); -std::shared_ptr projection( - const std::shared_ptr& geos, const std::string& bottom_right, - const std::string& top_left, const int& height, const int& width); +std::shared_ptr projection(const std::shared_ptr& geos, + const std::string& bottom_right, + const std::string& top_left, const int& height, + const int& width); std::shared_ptr transform_and_projection( const std::shared_ptr& geos, const std::string& src_rs, @@ -48,23 +47,29 @@ std::shared_ptr coordinate_projection( const std::shared_ptr& points, const std::string top_left, const std::string bottom_right, const int height, const int width); -std::shared_ptr point_map(const std::vector>& points_vector, - const std::string& conf); +std::shared_ptr point_map( + const std::vector>& points_vector, + const std::string& conf); -std::shared_ptr heat_map(const std::vector>& points_vector, - const std::vector>& weights_vector, - const std::string& conf); +std::shared_ptr heat_map( + const std::vector>& points_vector, + const std::vector>& weights_vector, + const std::string& conf); std::shared_ptr weighted_point_map( - const std::shared_ptr& points, const std::string& vega); + const std::vector>& points_vector, + const std::string& conf); std::shared_ptr weighted_point_map( - const std::shared_ptr& points, const std::shared_ptr& weights, - const std::string& vega); + const std::vector>& points_vector, + const std::vector>& weights_vector, + const std::string& conf); std::shared_ptr weighted_point_map( - const std::shared_ptr& points, const std::shared_ptr& color_weights, - const std::shared_ptr& size_weights, const std::string& vega); + const std::vector>& points_vector, + const std::vector>& color_weights_vector, + const std::vector>& size_weights_vector, + const std::string& conf); std::shared_ptr choropleth_map( const std::shared_ptr& region_boundaries, @@ -74,8 +79,8 @@ std::shared_ptr choropleth_map( const std::vector>& region_boundaries, const std::vector>& weights, const std::string& vega); -std::shared_ptr icon_viz(const std::vector>& points, - const std::string& conf); +std::shared_ptr icon_viz( + const std::vector>& points, const std::string& conf); } // namespace render } // namespace arctern From 35fa2341ed04b3784e8b25186cd3ab5da969dfdd Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Wed, 29 Apr 2020 15:44:44 +0800 Subject: [PATCH 15/24] wrap weighted pointmap in pandas api, done --- python/arctern/_wrapper_func.py | 88 +++++++++++++++---------- python/arctern/cython/arctern_core_.pyx | 5 -- 2 files changed, 52 insertions(+), 41 deletions(-) diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index 6ed58d8c3..4873f059c 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1121,33 +1121,6 @@ def ST_CurveToLine(geos): return arctern_caller(arctern_core_.ST_CurveToLine, arr_geos) -# def render_caller(func, geos, *func_args): -# import pyarrow -# num_chunks = 1 -# # pylint: disable=c-extension-no-member -# if isinstance(geos, pyarrow.lib.ChunkedArray): -# num_chunks = len(geos.chunks) -# -# if num_chunks <= 1: -# result = func(*func_args) -# return result.to_pandas() -# -# result_total = None -# for chunk_idx in range(num_chunks): -# args = [] -# # pylint: disable=c-extension-no-member -# if isinstance(geos, pyarrow.lib.ChunkedArray): -# args.append(geos.chunks[chunk_idx]) -# else: -# args.append(geos) -# result = func(*args) -# if result_total is None: -# result_total = result.to_pandas() -# else: -# result_total = result_total.append(result.to_pandas(), ignore_index=True) -# return result_total - - def projection(geos, bottom_right, top_left, height, width): import pyarrow as pa arr_geos = pa.array(geos, type='binary') @@ -1252,43 +1225,86 @@ def weighted_point_map_layer(vega, points, transform=True, **kwargs): bounding_box = vega.bounding_box() top_left = 'POINT (' + str(bounding_box[0]) + ' ' + str(bounding_box[3]) + ')' bottom_right = 'POINT (' + str(bounding_box[2]) + ' ' + str(bounding_box[1]) + ')' + height = vega.height() width = vega.width() coor = vega.coor() + src = bytes(coor, encoding="utf8") dst = bytes('EPSG:3857', encoding="utf8") bounding_box_min = bytes(top_left, encoding="utf8") bounding_box_max = bytes(bottom_right, encoding="utf8") + + # TODO: delete + print("data prepare ok") + # transform and projection handler + geos_rs = [] + if isinstance(geos, pa.lib.ChunkedArray): + print("chunk num:") + print(geos.num_chunks) + for chunk_idx in range(geos.num_chunks): + geos_rs.append(geos.chunk(chunk_idx)) + else: + print("only one chunk") + geos_rs.append(geos) + + # transform and projection if coor != 'EPSG:3857': - geos = arctern_core_.transform_and_projection(geos, src, dst, bounding_box_max, bounding_box_min, height, width) + geos = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) else: - geos = arctern_core_.projection(geos, bounding_box_max, bounding_box_min, height, width) + geos = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) - if (color_weights is None and size_weights is None): + if color_weights is None and size_weights is None: rs = arctern_core_.weighted_point_map(vega_string, geos) - elif (color_weights is not None and size_weights is not None): + elif color_weights is not None and size_weights is not None: if color_weights.dtypes == 'float64': arr_c = pa.array(color_weights, type='double') else: arr_c = pa.array(color_weights, type='int64') - if size_weights.dtypes == 'float64': arr_s = pa.array(size_weights, type='double') else: arr_s = pa.array(size_weights, type='int64') - rs = arctern_core_.weighted_color_size_point_map(vega_string, geos, arr_c, arr_s) - elif (color_weights is None and size_weights is not None): + color_weights_rs = [] + size_weights_rs = [] + if isinstance(arr_c, pa.lib.ChunkedArray): + for chunk_idx in range(arr_c.num_chunks): + color_weights_rs.append(arr_c.chunk(chunk_idx)) + else: + color_weights_rs.append(arr_c) + if isinstance(arr_s, pa.lib.ChunkedArray): + for chunk_idx in range(arr_s.num_chunks): + size_weights_rs.append(arr_s.chunk(chunk_idx)) + else: + size_weights_rs.append(arr_s) + print("weights handle done") + rs = arctern_core_.weighted_color_size_point_map(vega_string, geos, color_weights_rs, size_weights_rs) + elif color_weights is None and size_weights is not None: if size_weights.dtypes == 'float64': arr_s = pa.array(size_weights, type='double') else: arr_s = pa.array(size_weights, type='int64') - rs = arctern_core_.weighted_size_point_map(vega_string, geos, arr_s) + size_weights_rs = [] + if isinstance(arr_s, pa.lib.ChunkedArray): + for chunk_idx in range(arr_s.num_chunks): + size_weights_rs.append(arr_s.chunk(chunk_idx)) + else: + size_weights_rs.append(arr_s) + print("weights handle done") + rs = arctern_core_.weighted_size_point_map(vega_string, geos, size_weights_rs) else: if color_weights.dtypes == 'float64': arr_c = pa.array(color_weights, type='double') else: arr_c = pa.array(color_weights, type='int64') - rs = arctern_core_.weighted_color_point_map(vega_string, geos, arr_c) + color_weights_rs = [] + if isinstance(arr_c, pa.lib.ChunkedArray): + for chunk_idx in range(arr_c.num_chunks): + color_weights_rs.append(arr_c.chunk(chunk_idx)) + else: + color_weights_rs.append(arr_c) + print("weights handle done") + rs = arctern_core_.weighted_color_point_map(vega_string, geos, color_weights_rs) return base64.b64encode(rs.buffers()[1].to_pybytes()) diff --git a/python/arctern/cython/arctern_core_.pyx b/python/arctern/cython/arctern_core_.pyx index 97c5333e5..d87ec8675 100644 --- a/python/arctern/cython/arctern_core_.pyx +++ b/python/arctern/cython/arctern_core_.pyx @@ -27,18 +27,13 @@ def projection(geos, bottom_right, top_left, height, width): return pyarrow_wrap_array(arctern_core_pxd.projection(pyarrow_unwrap_array(geos), bottom_right, top_left, height, width)) def transform_and_projection(geos_array, src_rs, dst_rs, bottom_right, top_left, height, width): - # input - # cdef shared_ptr[CArray] arr cdef vector[shared_ptr[CArray]] geos_vector for geos in geos_array: arr = pyarrow_unwrap_array(geos) geos_vector.push_back(arr) - # output cdef vector[shared_ptr[CArray]] output_geos output_geos = arctern_core_pxd.transform_and_projection(geos_vector, src_rs, dst_rs, bottom_right, top_left, height, width) res = [] - print("output_geos size:") - print(output_geos.size()) for i in range(output_geos.size()): res.append(pyarrow_wrap_array(output_geos[i])) return res From c829d1592ec603521c087d4bc29c397b2fb048b3 Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Wed, 29 Apr 2020 16:20:48 +0800 Subject: [PATCH 16/24] projection api, done --- cpp/src/arrow/render_api.cpp | 22 ++++--- cpp/src/arrow/render_api.h | 8 +-- cpp/src/render/render_builder.h | 6 +- cpp/src/render/render_builder_impl.h | 57 ++++--------------- python/arctern/_wrapper_func.py | 31 +++++++--- python/arctern/cython/arctern_core_.pyx | 17 ++++-- python/arctern/cython/arctern_core__.pxd | 2 +- .../arctern/cython/arctern_core_symbol_.pyx | 4 +- python/arctern/cython/render.h | 22 ++----- 9 files changed, 75 insertions(+), 94 deletions(-) diff --git a/cpp/src/arrow/render_api.cpp b/cpp/src/arrow/render_api.cpp index 4028160de..44abd7af7 100644 --- a/cpp/src/arrow/render_api.cpp +++ b/cpp/src/arrow/render_api.cpp @@ -449,11 +449,17 @@ std::pair render_choroplethmap(const std::vector return choroplethmap(data.first, &input_c[0], num_geo, conf); } -std::shared_ptr projection(const std::shared_ptr& geos, - const std::string& bottom_right, - const std::string& top_left, const int& height, - const int& width) { - return Projection(geos, bottom_right, top_left, height, width); +const std::vector> projection( + const std::vector>& geos, + const std::string& bottom_right, const std::string& top_left, const int& height, + const int& width) { + std::cout << "c++ proj enter c++" << std::endl; + const auto& geo_vec = GeometryExtraction(geos); + std::cout << "c++ geo extract ok" << std::endl; + Projection(geo_vec, bottom_right, top_left, height, width); + std::cout << "c++ proj ok" << std::endl; + const auto& res = GeometryExport(geo_vec, geos.size()); + return res; } const std::vector> transform_and_projection( @@ -461,11 +467,11 @@ const std::vector> transform_and_projection( const std::string& dst_rs, const std::string& bottom_right, const std::string& top_left, const int& height, const int& width) { std::cout << "c++ trans enter c++" << std::endl; - const auto& geo = GeometryExtraction(geos); + const auto& geo_vec = GeometryExtraction(geos); std::cout << "c++ geo extract ok" << std::endl; - TransformAndProjection(geo, src_rs, dst_rs, bottom_right, top_left, height, width); + TransformAndProjection(geo_vec, src_rs, dst_rs, bottom_right, top_left, height, width); std::cout << "c++ transform and proj ok" << std::endl; - const auto& res = GeometryExport(geo, geos.size()); + const auto& res = GeometryExport(geo_vec, geos.size()); return res; } diff --git a/cpp/src/arrow/render_api.h b/cpp/src/arrow/render_api.h index 9ed8f188d..ddb65537d 100644 --- a/cpp/src/arrow/render_api.h +++ b/cpp/src/arrow/render_api.h @@ -26,10 +26,10 @@ namespace render { std::shared_ptr WktToWkb(const std::shared_ptr& arr_wkt); std::shared_ptr WkbToWkt(const std::shared_ptr& arr_wkt); -std::shared_ptr projection(const std::shared_ptr& geos, - const std::string& bottom_right, - const std::string& top_left, const int& height, - const int& width); +const std::vector> projection( + const std::vector>& geos, + const std::string& bottom_right, const std::string& top_left, const int& height, + const int& width); const std::vector> transform_and_projection( const std::vector>& geos, const std::string& src_rs, diff --git a/cpp/src/render/render_builder.h b/cpp/src/render/render_builder.h index 3999767ef..cee621f75 100644 --- a/cpp/src/render/render_builder.h +++ b/cpp/src/render/render_builder.h @@ -43,10 +43,8 @@ enum AggType { AVG, }; -std::shared_ptr Projection(const std::shared_ptr& geos, - const std::string& bottom_right, - const std::string& top_left, const int& height, - const int& width); +void Projection(const std::vector& geos, const std::string& bottom_right, + const std::string& top_left, const int& height, const int& width); void TransformAndProjection(const std::vector& geos, const std::string& src_rs, const std::string& dst_rs, diff --git a/cpp/src/render/render_builder_impl.h b/cpp/src/render/render_builder_impl.h index de962688a..ccee30996 100644 --- a/cpp/src/render/render_builder_impl.h +++ b/cpp/src/render/render_builder_impl.h @@ -62,33 +62,19 @@ void pointXY_from_wkt(const std::string& wkt, double& x, double& y) { OGRGeometryFactory::destroyGeometry(res_geo); } -std::shared_ptr Projection(const std::shared_ptr& geos, - const std::string& bottom_right, - const std::string& top_left, const int& height, - const int& width) { - arrow::BinaryBuilder builder; - - auto len = geos->length(); - auto wkt_geometries = std::static_pointer_cast(geos); - +void Projection(const std::vector& geos, const std::string& bottom_right, + const std::string& top_left, const int& height, const int& width) { double top_left_x, top_left_y, bottom_right_x, bottom_right_y; pointXY_from_wkt(top_left, top_left_x, top_left_y); pointXY_from_wkt(bottom_right, bottom_right_x, bottom_right_y); + auto coordinate_width = bottom_right_x - top_left_x; auto coordinate_height = top_left_y - bottom_right_y; - uint32_t output_x, output_y; - for (int32_t i = 0; i < len; i++) { - if (wkt_geometries->IsNull(i)) { - CHECK_ARROW(builder.Append("")); - continue; - } - OGRGeometry* geo = nullptr; - auto err_code = OGRGeometryFactory::createFromWkb( - wkt_geometries->GetString(i).c_str(), nullptr, &geo); - if (err_code) continue; + uint32_t output_x, output_y; + for (auto geo : geos) { if (geo == nullptr) { - CHECK_ARROW(builder.AppendNull()); + continue; } else { // projection auto type = wkbFlatten(geo->getGeometryType()); @@ -113,25 +99,8 @@ std::shared_ptr Projection(const std::shared_ptr& ge std::string err_msg = "unsupported geometry type, type = " + std::to_string(type); throw std::runtime_error(err_msg); } - - auto sz = geo->WkbSize(); - std::vector str(sz); - err_code = geo->exportToWkb(OGRwkbByteOrder::wkbNDR, (uint8_t*)str.data()); - if (err_code != OGRERR_NONE) { - std::string err_msg = - "failed to export to wkt, error code = " + std::to_string(err_code); - throw std::runtime_error(err_msg); - } - - CHECK_ARROW(builder.Append(str.data(), str.size())); - OGRGeometryFactory::destroyGeometry(geo); } } - - std::shared_ptr results; - CHECK_ARROW(builder.Finish(&results)); - - return results; } void TransformAndProjection(const std::vector& geos, @@ -151,10 +120,8 @@ void TransformAndProjection(const std::vector& geos, std::string err_msg = "faild to tranform with targetCRS = " + dst_rs; throw std::runtime_error(err_msg); } - void* poCT = OCTNewCoordinateTransformation(&oSrcSRS, &oDstS); - arrow::BinaryBuilder builder; - auto len = geos.size(); + void* poCT = OCTNewCoordinateTransformation(&oSrcSRS, &oDstS); double min_x, max_y, max_x, min_y; pointXY_from_wkt_with_transform(top_left, min_x, max_y, poCT); @@ -162,12 +129,11 @@ void TransformAndProjection(const std::vector& geos, auto coor_width = max_x - min_x; auto coor_height = max_y - min_y; - int32_t output_x, output_y; - for (int32_t i = 0; i < len; i++) { - auto geo = geos[i]; + int32_t output_x, output_y; + for (auto geo : geos) { if (geo == nullptr) { - CHECK_ARROW(builder.AppendNull()); + continue; } else { // 1. transform CHECK_GDAL(OGR_G_Transform(geo, (OGRCoordinateTransformation*)poCT)); @@ -243,7 +209,8 @@ std::pair, std::vector>> weight_agg( template std::pair, std::vector>> weight_agg( const std::vector& wkb_arr, const std::vector& arr_c) { - std::cout << "wkb size = " << wkb_arr.size() << ", arr_c.size = " << arr_c.size() << std::endl; + std::cout << "wkb size = " << wkb_arr.size() << ", arr_c.size = " << arr_c.size() + << std::endl; assert(wkb_arr.size() == arr_c.size()); std::unordered_map> wkb_map; diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index 4873f059c..bbc470f13 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1123,17 +1123,30 @@ def ST_CurveToLine(geos): def projection(geos, bottom_right, top_left, height, width): import pyarrow as pa - arr_geos = pa.array(geos, type='binary') + import pandas as pd + geos = pa.array(geos, type='binary') + bounding_box_max = bytes(bottom_right, encoding="utf8") bounding_box_min = bytes(top_left, encoding="utf8") - rs = arctern_core_.projection(arr_geos, bounding_box_max, bounding_box_min, height, width) - return rs.to_pandas() + + pd_rs = pd.Series() + + if isinstance(geos, pa.lib.ChunkedArray): + for chunk_idx in range(geos.num_chunks): + rs = arctern_core_.projection(geos.chunk(chunk_idx), bounding_box_max, bounding_box_min, height, width) + pd_rs.append(rs.to_pandas) + else: + rs = arctern_core_.projection(geos, bounding_box_max, bounding_box_min, height, width) + pd_rs.append(rs.to_pandas) + + return pd_rs def transform_and_projection(geos, src_rs, dst_rs, bottom_right, top_left, height, width): import pyarrow as pa import pandas as pd - arr_geos = pa.array(geos, type='binary') + geos = pa.array(geos, type='binary') + src = bytes(src_rs, encoding="utf8") dst = bytes(dst_rs, encoding="utf8") @@ -1143,15 +1156,15 @@ def transform_and_projection(geos, src_rs, dst_rs, bottom_right, top_left, heigh pd_rs = pd.Series() # pylint: disable=c-extension-no-member - if isinstance(arr_geos, pa.lib.ChunkedArray): - for chunk_idx in range(arr_geos.num_chunks): - rs = arctern_core_.transform_and_projection(arr_geos.chunk(chunk_idx), src, dst, bounding_box_max, bounding_box_min, height, width) + if isinstance(geos, pa.lib.ChunkedArray): + for chunk_idx in range(geos.num_chunks): + rs = arctern_core_.transform_and_projection(geos.chunk(chunk_idx), src, dst, bounding_box_max, bounding_box_min, height, width) pd_rs.append(rs.to_pandas) else: - rs = arctern_core_.transform_and_projection(arr_geos, src, dst, bounding_box_max, bounding_box_min, height, width) + rs = arctern_core_.transform_and_projection(geos, src, dst, bounding_box_max, bounding_box_min, height, width) pd_rs.append(rs.to_pandas) - return pd_rs.to_pandas() + return pd_rs def wkt2wkb(arr_wkt): diff --git a/python/arctern/cython/arctern_core_.pyx b/python/arctern/cython/arctern_core_.pyx index d87ec8675..8728b6544 100644 --- a/python/arctern/cython/arctern_core_.pyx +++ b/python/arctern/cython/arctern_core_.pyx @@ -23,12 +23,21 @@ cimport arctern_core__ as arctern_core_pxd # render func api: -def projection(geos, bottom_right, top_left, height, width): - return pyarrow_wrap_array(arctern_core_pxd.projection(pyarrow_unwrap_array(geos), bottom_right, top_left, height, width)) +def projection(geos_list, bottom_right, top_left, height, width): + cdef vector[shared_ptr[CArray]] geos_vector + for geos in geos_list: + arr = pyarrow_unwrap_array(geos) + geos_vector.push_back(arr) + cdef vector[shared_ptr[CArray]] output_geos + output_geos = arctern_core_pxd.projection(geos_vector, bottom_right, top_left, height, width) + res = [] + for i in range(output_geos.size()): + res.append(pyarrow_wrap_array(output_geos[i])) + return res -def transform_and_projection(geos_array, src_rs, dst_rs, bottom_right, top_left, height, width): +def transform_and_projection(geos_list, src_rs, dst_rs, bottom_right, top_left, height, width): cdef vector[shared_ptr[CArray]] geos_vector - for geos in geos_array: + for geos in geos_list: arr = pyarrow_unwrap_array(geos) geos_vector.push_back(arr) cdef vector[shared_ptr[CArray]] output_geos diff --git a/python/arctern/cython/arctern_core__.pxd b/python/arctern/cython/arctern_core__.pxd index 0309ecdb3..51b565348 100644 --- a/python/arctern/cython/arctern_core__.pxd +++ b/python/arctern/cython/arctern_core__.pxd @@ -19,7 +19,7 @@ from libcpp.vector cimport vector cdef extern from "render.h" namespace "arctern::render": # func api: - shared_ptr[CArray] projection(const shared_ptr[CArray] &geos,const string &bottom_right,const string &top_left,const int &height,const int &width) except + + const vector[shared_ptr[CArray]] projection(const vector[shared_ptr[CArray]] &geos,const string &bottom_right,const string &top_left,const int &height,const int &width) except + const vector[shared_ptr[CArray]] transform_and_projection(const vector[shared_ptr[CArray]] &geos,const string &src_rs,const string &dst_rs,const string &bottom_right,const string &top_left,const int &height,const int &width) except + shared_ptr[CArray] WktToWkb(const shared_ptr[CArray] && arr_wkt) except + shared_ptr[CArray] WkbToWkt(const shared_ptr[CArray] && arr_wkb) except + diff --git a/python/arctern/cython/arctern_core_symbol_.pyx b/python/arctern/cython/arctern_core_symbol_.pyx index 38f3be569..475fba927 100644 --- a/python/arctern/cython/arctern_core_symbol_.pyx +++ b/python/arctern/cython/arctern_core_symbol_.pyx @@ -17,10 +17,10 @@ # render func api: -def projection(geos, bottom_right, top_left, height, width): +def projection(geos_list, bottom_right, top_left, height, width): pass -def transform_and_projection(geos_array, src_rs, dst_rs, bottom_right, top_left, height, width): +def transform_and_projection(geos_list, src_rs, dst_rs, bottom_right, top_left, height, width): pass def wkt2wkb(arr_wkt): diff --git a/python/arctern/cython/render.h b/python/arctern/cython/render.h index 51c2179f5..7fabcaada 100644 --- a/python/arctern/cython/render.h +++ b/python/arctern/cython/render.h @@ -19,6 +19,7 @@ #include #include + #include "arrow/api.h" namespace arctern { @@ -28,25 +29,16 @@ std::shared_ptr WktToWkb(const std::shared_ptr& arr_ std::shared_ptr WkbToWkt(const std::shared_ptr& arr_wkb); -std::shared_ptr projection(const std::shared_ptr& geos, - const std::string& bottom_right, - const std::string& top_left, const int& height, - const int& width); - -std::shared_ptr transform_and_projection( - const std::shared_ptr& geos, const std::string& src_rs, - const std::string& dst_rs, const std::string& bottom_right, - const std::string& top_left, const int& height, const int& width); +const std::vector> projection( + const std::vector>& geos, + const std::string& bottom_right, const std::string& top_left, const int& height, + const int& width); const std::vector> transform_and_projection( const std::vector>& geos, const std::string& src_rs, const std::string& dst_rs, const std::string& bottom_right, const std::string& top_left, const int& height, const int& width); -std::shared_ptr coordinate_projection( - const std::shared_ptr& points, const std::string top_left, - const std::string bottom_right, const int height, const int width); - std::shared_ptr point_map( const std::vector>& points_vector, const std::string& conf); @@ -71,10 +63,6 @@ std::shared_ptr weighted_point_map( const std::vector>& size_weights_vector, const std::string& conf); -std::shared_ptr choropleth_map( - const std::shared_ptr& region_boundaries, - const std::shared_ptr& weights, const std::string& vega); - std::shared_ptr choropleth_map( const std::vector>& region_boundaries, const std::vector>& weights, const std::string& vega); From 865f11abe9764269e76785777ca27e995e1a434a Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Wed, 29 Apr 2020 17:03:48 +0800 Subject: [PATCH 17/24] fix transform api --- cpp/src/render/utils/render_utils.cpp | 4 +- python/arctern/_wrapper_func.py | 32 ++-- python/tests/geo/render_test.py | 234 +++++++++++++------------- 3 files changed, 138 insertions(+), 132 deletions(-) diff --git a/cpp/src/render/utils/render_utils.cpp b/cpp/src/render/utils/render_utils.cpp index 4fb190943..ac2117984 100644 --- a/cpp/src/render/utils/render_utils.cpp +++ b/cpp/src/render/utils/render_utils.cpp @@ -28,11 +28,13 @@ namespace render { std::vector GeometryExtraction( const std::vector>& arrs) { int total_size = 0; + std::cout << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << std::endl; for (const auto& arr : arrs) { total_size += arr->length(); } + std::cout << "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" << std::endl; std::vector geos_res(total_size); - + std::cout << "total_size = " << total_size << std::endl; int index = 0; for (const auto& arr : arrs) { assert(arr->type_id() == arrow::Type::BINARY); diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index bbc470f13..de61dfea1 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1123,28 +1123,29 @@ def ST_CurveToLine(geos): def projection(geos, bottom_right, top_left, height, width): import pyarrow as pa - import pandas as pd geos = pa.array(geos, type='binary') bounding_box_max = bytes(bottom_right, encoding="utf8") bounding_box_min = bytes(top_left, encoding="utf8") - pd_rs = pd.Series() - + geos_rs = [] if isinstance(geos, pa.lib.ChunkedArray): for chunk_idx in range(geos.num_chunks): - rs = arctern_core_.projection(geos.chunk(chunk_idx), bounding_box_max, bounding_box_min, height, width) - pd_rs.append(rs.to_pandas) + geos_rs.append(geos.chunk(chunk_idx)) else: - rs = arctern_core_.projection(geos, bounding_box_max, bounding_box_min, height, width) - pd_rs.append(rs.to_pandas) + geos_rs.append(geos) + + geos = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) + pd_rs = geos[0] + if len(geos) >= 2: + for i in range(1, len(geos)): + pd_rs.append(geos[i]) return pd_rs def transform_and_projection(geos, src_rs, dst_rs, bottom_right, top_left, height, width): import pyarrow as pa - import pandas as pd geos = pa.array(geos, type='binary') src = bytes(src_rs, encoding="utf8") @@ -1153,16 +1154,19 @@ def transform_and_projection(geos, src_rs, dst_rs, bottom_right, top_left, heigh bounding_box_max = bytes(bottom_right, encoding="utf8") bounding_box_min = bytes(top_left, encoding="utf8") - pd_rs = pd.Series() - + geos_rs = [] # pylint: disable=c-extension-no-member if isinstance(geos, pa.lib.ChunkedArray): for chunk_idx in range(geos.num_chunks): - rs = arctern_core_.transform_and_projection(geos.chunk(chunk_idx), src, dst, bounding_box_max, bounding_box_min, height, width) - pd_rs.append(rs.to_pandas) + geos_rs.append(geos.chunk(chunk_idx)) else: - rs = arctern_core_.transform_and_projection(geos, src, dst, bounding_box_max, bounding_box_min, height, width) - pd_rs.append(rs.to_pandas) + geos_rs.append(geos) + + geos = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) + pd_rs = geos[0] + if len(geos) >= 2: + for i in range(1, len(geos)): + pd_rs.append(geos[i]) return pd_rs diff --git a/python/tests/geo/render_test.py b/python/tests/geo/render_test.py index c643c57c0..3b97ba450 100644 --- a/python/tests/geo/render_test.py +++ b/python/tests/geo/render_test.py @@ -19,125 +19,125 @@ from arctern.util.vega import vega_pointmap, vega_weighted_pointmap, vega_heatmap, vega_choroplethmap, vega_icon -# def test_projection(): -# wkt = ["POINT (-8235193.62386326 4976211.44428777)"] -# top_left = "POINT (-8235871.4482427 4976468.32320551)" -# bottom_right = "POINT (-8235147.42627458 4976108.43009739)" -# -# arr_wkb = pandas.Series(arctern.wkt2wkb(wkt)) -# arctern.projection(arr_wkb, bottom_right, top_left, 200, 300) -# -# -# def test_transfrom_and_projection(): -# wkt = ["POINT (-73.978003 40.754594)"] -# top_left = "POINT (-73.984092 40.756342)" -# bottom_right = "POINT (-73.977588 40.753893)" -# src_ts = "EPSG:4326" -# dst_rs = "EPSG:3857" -# -# arr_wkb = pandas.Series(arctern.wkt2wkb(wkt)) -# arctern.transform_and_projection(arr_wkb, src_ts, dst_rs, bottom_right, top_left, 200, 300) -# -# -# def test_point_map(): -# x_data = [] -# y_data = [] -# -# x_data.append(-73.96524) -# x_data.append(-73.96118) -# x_data.append(-73.97324) -# x_data.append(-73.98456) -# y_data.append(40.73747) -# y_data.append(40.74507) -# y_data.append(40.75890) -# y_data.append(40.77654) -# -# arr_x = pandas.Series(x_data) -# arr_y = pandas.Series(y_data) -# points = arctern.ST_Point(arr_x, arr_y) -# -# vega = vega_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], point_size=10, point_color="#0000FF", opacity=1.0, coordinate_system="EPSG:4326") -# curve_z1 = arctern.point_map_layer(vega, points) -# save_png(curve_z1, "/tmp/test_curve_z1.png") +def test_projection(): + point = arctern.ST_GeomFromText("POINT (-8235193.62386326 4976211.44428777)")[0] + top_left = "POINT (-8235871.4482427 4976468.32320551)" + bottom_right = "POINT (-8235147.42627458 4976108.43009739)" + arr_wkb = pandas.Series([point]) + arctern.projection(arr_wkb, bottom_right, top_left, 200, 300) -# def test_weighted_point_map(): -# x_data = [] -# y_data = [] -# c_data = [] -# s_data = [] -# -# x_data.append(-73.96524) -# x_data.append(-73.96118) -# x_data.append(-73.97324) -# x_data.append(-73.98456) -# -# y_data.append(40.73747) -# y_data.append(40.74507) -# y_data.append(40.75890) -# y_data.append(40.77654) -# -# c_data.append(1) -# c_data.append(2) -# c_data.append(3) -# c_data.append(4) -# -# s_data.append(4) -# s_data.append(6) -# s_data.append(8) -# s_data.append(10) -# -# arr_x = pandas.Series(x_data) -# arr_y = pandas.Series(y_data) -# points = arctern.ST_Point(arr_x, arr_y) -# arr_c = pandas.Series(c_data) -# arr_s = pandas.Series(s_data) -# -# vega1 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF"], opacity=1.0, coordinate_system="EPSG:4326") -# res1 = arctern.weighted_point_map_layer(vega1, points) -# save_png(res1, "/tmp/test_weighted_0_0.png") -# -# vega2 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF", "#FF0000"], color_bound=[1, 5], opacity=1.0, coordinate_system="EPSG:4326") -# res2 = arctern.weighted_point_map_layer(vega2, points, color_weights=arr_c) -# save_png(res2, "/tmp/test_weighted_1_0.png") -# -# vega3 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF"], size_bound=[1, 10], opacity=1.0, coordinate_system="EPSG:4326") -# res3 = arctern.weighted_point_map_layer(vega3, points, size_weights=arr_s) -# save_png(res3, "/tmp/test_weighted_0_1.png") -# -# vega4 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF", "#FF0000"], color_bound=[1, 5], size_bound=[1, 10], opacity=1.0, coordinate_system="EPSG:4326") -# res4 = arctern.weighted_point_map_layer(vega4, points, color_weights=arr_c, size_weights=arr_s) -# save_png(res4, "/tmp/test_weighted_1_1.png") -# -# def test_heat_map(): -# x_data = [] -# y_data = [] -# c_data = [] -# -# x_data.append(-73.96524) -# x_data.append(-73.96118) -# x_data.append(-73.97324) -# x_data.append(-73.98456) -# -# y_data.append(40.73747) -# y_data.append(40.74507) -# y_data.append(40.75890) -# y_data.append(40.77654) -# -# c_data.append(10) -# c_data.append(20) -# c_data.append(30) -# c_data.append(40) -# -# arr_x = pandas.Series(x_data) -# arr_y = pandas.Series(y_data) -# points = arctern.ST_Point(arr_x, arr_y) -# arr_c = pandas.Series(c_data) -# -# vega = vega_heatmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], map_zoom_level=13.0, coordinate_system='EPSG:4326') -# heat_map1 = arctern.heat_map_layer(vega, points, arr_c) -# -# save_png(heat_map1, "/tmp/test_heat_map1.png") + +def test_transfrom_and_projection(): + point = arctern.ST_GeomFromText("POINT (-73.978003 40.754594)")[0] + top_left = "POINT (-73.984092 40.756342)" + bottom_right = "POINT (-73.977588 40.753893)" + src_ts = "EPSG:4326" + dst_rs = "EPSG:3857" + + arr_wkb = pandas.Series([point]) + arctern.transform_and_projection(arr_wkb, src_ts, dst_rs, bottom_right, top_left, 200, 300) + + +def test_point_map(): + x_data = [] + y_data = [] + + x_data.append(-73.96524) + x_data.append(-73.96118) + x_data.append(-73.97324) + x_data.append(-73.98456) + y_data.append(40.73747) + y_data.append(40.74507) + y_data.append(40.75890) + y_data.append(40.77654) + + arr_x = pandas.Series(x_data) + arr_y = pandas.Series(y_data) + points = arctern.ST_Point(arr_x, arr_y) + + vega = vega_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], point_size=10, point_color="#0000FF", opacity=1.0, coordinate_system="EPSG:4326") + curve_z1 = arctern.point_map_layer(vega, points) + save_png(curve_z1, "/tmp/test_curve_z1.png") + + +def test_weighted_point_map(): + x_data = [] + y_data = [] + c_data = [] + s_data = [] + + x_data.append(-73.96524) + x_data.append(-73.96118) + x_data.append(-73.97324) + x_data.append(-73.98456) + + y_data.append(40.73747) + y_data.append(40.74507) + y_data.append(40.75890) + y_data.append(40.77654) + + c_data.append(1) + c_data.append(2) + c_data.append(3) + c_data.append(4) + + s_data.append(4) + s_data.append(6) + s_data.append(8) + s_data.append(10) + + arr_x = pandas.Series(x_data) + arr_y = pandas.Series(y_data) + points = arctern.ST_Point(arr_x, arr_y) + arr_c = pandas.Series(c_data) + arr_s = pandas.Series(s_data) + + vega1 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF"], opacity=1.0, coordinate_system="EPSG:4326") + res1 = arctern.weighted_point_map_layer(vega1, points) + save_png(res1, "/tmp/test_weighted_0_0.png") + + vega2 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF", "#FF0000"], color_bound=[1, 5], opacity=1.0, coordinate_system="EPSG:4326") + res2 = arctern.weighted_point_map_layer(vega2, points, color_weights=arr_c) + save_png(res2, "/tmp/test_weighted_1_0.png") + + vega3 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF"], size_bound=[1, 10], opacity=1.0, coordinate_system="EPSG:4326") + res3 = arctern.weighted_point_map_layer(vega3, points, size_weights=arr_s) + save_png(res3, "/tmp/test_weighted_0_1.png") + + vega4 = vega_weighted_pointmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], color_gradient=["#0000FF", "#FF0000"], color_bound=[1, 5], size_bound=[1, 10], opacity=1.0, coordinate_system="EPSG:4326") + res4 = arctern.weighted_point_map_layer(vega4, points, color_weights=arr_c, size_weights=arr_s) + save_png(res4, "/tmp/test_weighted_1_1.png") + +def test_heat_map(): + x_data = [] + y_data = [] + c_data = [] + + x_data.append(-73.96524) + x_data.append(-73.96118) + x_data.append(-73.97324) + x_data.append(-73.98456) + + y_data.append(40.73747) + y_data.append(40.74507) + y_data.append(40.75890) + y_data.append(40.77654) + + c_data.append(10) + c_data.append(20) + c_data.append(30) + c_data.append(40) + + arr_x = pandas.Series(x_data) + arr_y = pandas.Series(y_data) + points = arctern.ST_Point(arr_x, arr_y) + arr_c = pandas.Series(c_data) + + vega = vega_heatmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], map_zoom_level=13.0, coordinate_system='EPSG:4326') + heat_map1 = arctern.heat_map_layer(vega, points, arr_c) + + save_png(heat_map1, "/tmp/test_heat_map1.png") def test_choropleth_map(): wkt_data = [] From 5f9cacec40ae737cec940b97e9eb9589eb0bf075 Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Wed, 29 Apr 2020 17:51:17 +0800 Subject: [PATCH 18/24] use flexible data type --- cpp/src/arrow/render_api.cpp | 220 +- cpp/src/render/utils/render_utils.cpp | 2 - cpp/unittest/render/choropleth_map_test.cpp | 3333 ++++++++++--------- python/arctern/_wrapper_func.py | 2 + python/tests/geo/render_test.py | 2 +- 5 files changed, 1901 insertions(+), 1658 deletions(-) diff --git a/cpp/src/arrow/render_api.cpp b/cpp/src/arrow/render_api.cpp index 44abd7af7..fe0718cc9 100644 --- a/cpp/src/arrow/render_api.cpp +++ b/cpp/src/arrow/render_api.cpp @@ -543,9 +543,55 @@ std::shared_ptr weighted_point_map( const std::vector>& weights_vector, const std::string& conf) { const auto& wkb_vec = WkbExtraction(points_vector); - const auto& arr_c = WeightExtraction(weights_vector); - const auto& render_result = render_weighted_pointmap(wkb_vec, arr_c, conf); - return out_pic(render_result); + + auto weight_data_type = weights_vector[0]->type_id(); + + switch (weight_data_type) { + case arrow::Type::INT8: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::INT16: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::INT32: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::INT64: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::UINT8: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::UINT16: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::UINT32: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::UINT64: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::FLOAT: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::DOUBLE: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, conf)); + } + default: + std::string err_msg = "type error of count while running weighted_pointmap, type = " + + std::to_string(weight_data_type); + throw std::runtime_error(err_msg); + } } std::shared_ptr weighted_point_map( @@ -554,10 +600,65 @@ std::shared_ptr weighted_point_map( const std::vector>& size_weights_vector, const std::string& conf) { const auto& wkb_vec = WkbExtraction(points_vector); - const auto& arr_c = WeightExtraction(color_weights_vector); - const auto& arr_s = WeightExtraction(size_weights_vector); - const auto& render_result = render_weighted_pointmap(wkb_vec, arr_c, arr_s, conf); - return out_pic(render_result); + + auto weight_data_type = color_weights_vector[0]->type_id(); + + switch (weight_data_type) { + case arrow::Type::INT8: { + const auto& arr_c = WeightExtraction(color_weights_vector); + const auto& arr_s = WeightExtraction(size_weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, arr_s, conf)); + } + case arrow::Type::INT16: { + const auto& arr_c = WeightExtraction(color_weights_vector); + const auto& arr_s = WeightExtraction(size_weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, arr_s, conf)); + } + case arrow::Type::INT32: { + const auto& arr_c = WeightExtraction(color_weights_vector); + const auto& arr_s = WeightExtraction(size_weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, arr_s, conf)); + } + case arrow::Type::INT64: { + const auto& arr_c = WeightExtraction(color_weights_vector); + const auto& arr_s = WeightExtraction(size_weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, arr_s, conf)); + } + case arrow::Type::UINT8: { + const auto& arr_c = WeightExtraction(color_weights_vector); + const auto& arr_s = WeightExtraction(size_weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, arr_s, conf)); + } + case arrow::Type::UINT16: { + const auto& arr_c = WeightExtraction(color_weights_vector); + const auto& arr_s = WeightExtraction(size_weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, arr_s, conf)); + } + case arrow::Type::UINT32: { + const auto& arr_c = WeightExtraction(color_weights_vector); + const auto& arr_s = WeightExtraction(size_weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, arr_s, conf)); + } + case arrow::Type::UINT64: { + const auto& arr_c = WeightExtraction(color_weights_vector); + const auto& arr_s = WeightExtraction(size_weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, arr_s, conf)); + } + case arrow::Type::FLOAT: { + const auto& arr_c = WeightExtraction(color_weights_vector); + const auto& arr_s = WeightExtraction(size_weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, arr_s, conf)); + } + case arrow::Type::DOUBLE: { + const auto& arr_c = WeightExtraction(color_weights_vector); + const auto& arr_s = WeightExtraction(size_weights_vector); + return out_pic(render_weighted_pointmap(wkb_vec, arr_c, arr_s, conf)); + } + default: + std::string err_msg = "type error of count while running weighted_pointmap, type = " + + std::to_string(weight_data_type); + throw std::runtime_error(err_msg); + } } std::shared_ptr weighted_point_map( @@ -648,7 +749,7 @@ std::shared_ptr weighted_point_map( } default: std::string err_msg = - "type error of count while running weighted_point map, type = " + + "type error of count while running weighted_pointmap, type = " + std::to_string(c_type); throw std::runtime_error(err_msg); } @@ -659,8 +760,55 @@ std::shared_ptr heat_map( const std::vector>& weights_vector, const std::string& conf) { const auto& wkb_vec = WkbExtraction(points_vector); - const auto& arr_c = WeightExtraction(weights_vector); - return out_pic(render_heatmap(wkb_vec, arr_c, conf)); + + auto weight_data_type = weights_vector[0]->type_id(); + + switch (weight_data_type) { + case arrow::Type::INT8: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_heatmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::INT16: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_heatmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::INT32: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_heatmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::INT64: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_heatmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::UINT8: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_heatmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::UINT16: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_heatmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::UINT32: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_heatmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::UINT64: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_heatmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::FLOAT: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_heatmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::DOUBLE: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_heatmap(wkb_vec, arr_c, conf)); + } + default: + std::string err_msg = "type error of count while running heatmap, type = " + + std::to_string(weight_data_type); + throw std::runtime_error(err_msg); + } } std::shared_ptr heat_map(const std::shared_ptr& arr_x, @@ -724,7 +872,7 @@ std::shared_ptr heat_map(const std::shared_ptr& arr_ } default: std::string err_msg = - "type error of count while running heat map, type = " + std::to_string(c_type); + "type error of count while running heatmap, type = " + std::to_string(c_type); throw std::runtime_error(err_msg); } } @@ -734,8 +882,54 @@ std::shared_ptr choropleth_map( const std::vector>& weights_vector, const std::string& conf) { const auto& wkb_vec = WkbExtraction(polygons_vector); - const auto& arr_c = WeightExtraction(weights_vector); - return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); + auto weight_data_type = weights_vector[0]->type_id(); + + switch (weight_data_type) { + case arrow::Type::INT8: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::INT16: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::INT32: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::INT64: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::UINT8: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::UINT16: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::UINT32: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::UINT64: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::FLOAT: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); + } + case arrow::Type::DOUBLE: { + const auto& arr_c = WeightExtraction(weights_vector); + return out_pic(render_choroplethmap(wkb_vec, arr_c, conf)); + } + default: + std::string err_msg = "type error of count while running choroplethmap, type = " + + std::to_string(weight_data_type); + throw std::runtime_error(err_msg); + } } std::shared_ptr icon_viz( diff --git a/cpp/src/render/utils/render_utils.cpp b/cpp/src/render/utils/render_utils.cpp index ac2117984..a9457a01f 100644 --- a/cpp/src/render/utils/render_utils.cpp +++ b/cpp/src/render/utils/render_utils.cpp @@ -28,11 +28,9 @@ namespace render { std::vector GeometryExtraction( const std::vector>& arrs) { int total_size = 0; - std::cout << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << std::endl; for (const auto& arr : arrs) { total_size += arr->length(); } - std::cout << "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" << std::endl; std::vector geos_res(total_size); std::cout << "total_size = " << total_size << std::endl; int index = 0; diff --git a/cpp/unittest/render/choropleth_map_test.cpp b/cpp/unittest/render/choropleth_map_test.cpp index 121f031fb..6ed545a68 100644 --- a/cpp/unittest/render/choropleth_map_test.cpp +++ b/cpp/unittest/render/choropleth_map_test.cpp @@ -17,1622 +17,1694 @@ #include "arrow/render_api.h" -// TEST(CHOROPLETHMAP_TEST, BLUE_TO_RED) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::UInt32Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, SKYBLUE_TO_WHITE) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::UInt32Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#B4E7F5\", \"#FFFFFF\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, GREEN_YELLOW_RED) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::UInt32Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#4D904F\", \"#C23728\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, BLUE_WHITE_RED) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::UInt32Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#1984C5\", \"#C23728\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, WHITE_BLUE) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::UInt32Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#E2E2E2\", \"#115F9A\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, BLUE_GREEN_YELLOW) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::UInt32Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#115F9A\", \"#D0F401\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, BLUE_TRANSPARENCY) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::UInt32Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#0000FF\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, RED_TRANSPARENCY) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::UInt32Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#FF0000\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, PURPLE_TO_YELLOW) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::UInt32Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#FF00FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// // TEST(CHOROPLETHMAP_TEST, INVALID_color_gradient_TEST) { -// // // param1: wkt string -// // std::string wkt_string1 = -// // "POLYGON ((" -// // "200 200, " -// // "200 300, " -// // "300 300, " -// // "300 200, " -// // "200 200))"; -// // arrow::StringBuilder string_builder; -// // auto status = string_builder.Append(wkt_string1); -// // -// // std::shared_ptr string_array; -// // status = string_builder.Finish(&string_array); -// // -// // // param2: color -// // std::shared_ptr color_array; -// // arrow::UInt32Builder color_builder; -// // status = color_builder.Append(5); -// // status = color_builder.Finish(&color_array); -// // -// // // param3: conf -// // const std::string vega = -// // "{\n" -// // " \"width\": 1900,\n" -// // " \"height\": 1410,\n" -// // " \"description\": \"choropleth_map\",\n" -// // " \"data\": [\n" -// // " {\n" -// // " \"name\": \"data\",\n" -// // " \"url\": \"data/data.csv\"\n" -// // " }\n" -// // " ],\n" -// // " \"scales\": [\n" -// // " {\n" -// // " \"name\": \"building\",\n" -// // " \"type\": \"linear\",\n" -// // " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// // " }\n" -// // " ],\n" -// // " \"marks\": [\n" -// // " {\n" -// // " \"encode\": {\n" -// // " \"enter\": {\n" -// // " \"bounding_box\": {\"value\": " -// // "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// // " \"color_gradient\": {\"value\": \"xxxxxx\"},\n" -// // " \"color_bound\": {\"value\": [2.5, 5]},\n" -// // " \"opacity\": {\"value\": 1.0}\n" -// // " }\n" -// // " }\n" -// // " }\n" -// // " ]\n" -// // "}"; -// // -// // auto wkb = arctern::render::WktToWkb(string_array); -// // arctern::render::choropleth_map(wkb, color_array, vega); -// //} - -// // TEST(CHOROPLETHMAP_TEST, INVALID_JSON_TEST) { -// // // param1: wkt string -// // std::string wkt_string1 = -// // "POLYGON ((" -// // "200 200, " -// // "200 300, " -// // "300 300, " -// // "300 200, " -// // "200 200))"; -// // arrow::StringBuilder string_builder; -// // auto status = string_builder.Append(wkt_string1); -// // -// // std::shared_ptr string_array; -// // status = string_builder.Finish(&string_array); -// // -// // // param2: color -// // std::shared_ptr color_array; -// // arrow::UInt32Builder color_builder; -// // status = color_builder.Append(5); -// // status = color_builder.Finish(&color_array); -// // -// // // param3: conf -// // const std::string vega = -// // "{\n" -// // " \"width\": 1900,\n" -// // " \"height\": 1410,\n" -// // " \"description\": \"choropleth_map\",\n" -// // " \"data\": [\n" -// // " {\n" -// // " \"name\": \"data\",\n" -// // " \"url\": \"data/data.csv\"\n" -// // " }\n" -// // " ],\n" -// // " \"scales\": [\n" -// // " {\n" -// // " \"name\": \"building\",\n" -// // " \"type\": \"linear\",\n" -// // " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// // " }\n" -// // " ],\n" -// // " \"marks\": [\n" -// // " {\n" -// // " \"encode\": {\n" -// // " \"enter\": {\n" -// // " \"bounding_box\": {\"value\": " -// // "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// // " \"color_gradient\": {\"value\": \"blue_to_red\"},\n" -// // " \"color_bound\": {\"value\": [2.5, 5]},\n" -// // " \"opacity\": {\"value\": \"INVALID_NUMBER\"}\n" -// // " }\n" -// // " }\n" -// // " }\n" -// // " ]\n" -// // "}"; -// // -// // auto wkb = arctern::render::WktToWkb(string_array); -// // arctern::render::choropleth_map(wkb, color_array, vega); -// //} - -// TEST(CHOROPLETHMAP_TEST, INT8) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::Int8Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, INT16) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::Int16Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, INT32) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::Int32Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, INT64) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::Int64Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, UINT8) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::UInt8Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, UINT16) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::UInt16Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, UINT32) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::UInt32Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, UINT64) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::UInt64Builder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, FLOAT) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::FloatBuilder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, DOUBLE) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::DoubleBuilder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// // TEST(CHOROPLETHMAP_TEST, INVALID_DATA_TYPE_TEST) { -// // // param1: wkt string -// // std::string wkt_string1 = -// // "POLYGON ((" -// // "200 200, " -// // "200 300, " -// // "300 300, " -// // "300 200, " -// // "200 200))"; -// // arrow::StringBuilder string_builder; -// // auto status = string_builder.Append(wkt_string1); -// // -// // std::shared_ptr string_array; -// // status = string_builder.Finish(&string_array); -// // -// // // param2: color -// // std::shared_ptr color_array; -// // arrow::StringBuilder color_builder; -// // status = color_builder.Append(""); -// // status = color_builder.Finish(&color_array); -// // -// // // param3: conf -// // const std::string vega = -// // "{\n" -// // " \"width\": 1900,\n" -// // " \"height\": 1410,\n" -// // " \"description\": \"choropleth_map\",\n" -// // " \"data\": [\n" -// // " {\n" -// // " \"name\": \"data\",\n" -// // " \"url\": \"data/data.csv\"\n" -// // " }\n" -// // " ],\n" -// // " \"scales\": [\n" -// // " {\n" -// // " \"name\": \"building\",\n" -// // " \"type\": \"linear\",\n" -// // " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// // " }\n" -// // " ],\n" -// // " \"marks\": [\n" -// // " {\n" -// // " \"encode\": {\n" -// // " \"enter\": {\n" -// // " \"bounding_box\": {\"value\": " -// // "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// // " \"color_gradient\": {\"value\": \"blue_to_red\"},\n" -// // " \"color_bound\": {\"value\": [2.5, 5]},\n" -// // " \"opacity\": {\"value\": 1.0}\n" -// // " }\n" -// // " }\n" -// // " }\n" -// // " ]\n" -// // "}"; -// // -// // auto wkb = arctern::render::WktToWkb(string_array); -// // arctern::render::choropleth_map(wkb, color_array, vega); -// //} - -// TEST(CHOROPLETHMAP_TEST, MEAN) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::DoubleBuilder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"mean\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, SUM) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::DoubleBuilder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"sum\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, MAX) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::DoubleBuilder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"max\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, MIN) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::DoubleBuilder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"min\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } - -// TEST(CHOROPLETHMAP_TEST, COUNT) { -// // param1: wkt string -// std::string wkt_string1 = -// "POLYGON ((" -// "200 200, " -// "200 300, " -// "300 300, " -// "300 200, " -// "200 200))"; -// arrow::StringBuilder string_builder; -// auto status = string_builder.Append(wkt_string1); - -// std::shared_ptr string_array; -// status = string_builder.Finish(&string_array); - -// // param2: color -// std::shared_ptr color_array; -// arrow::DoubleBuilder color_builder; -// status = color_builder.Append(5); -// status = color_builder.Finish(&color_array); - -// // param3: conf -// const std::string vega = -// "{\n" -// " \"width\": 1900,\n" -// " \"height\": 1410,\n" -// " \"description\": \"choropleth_map\",\n" -// " \"data\": [\n" -// " {\n" -// " \"name\": \"data\",\n" -// " \"url\": \"data/data.csv\"\n" -// " }\n" -// " ],\n" -// " \"scales\": [\n" -// " {\n" -// " \"name\": \"building\",\n" -// " \"type\": \"linear\",\n" -// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" -// " }\n" -// " ],\n" -// " \"marks\": [\n" -// " {\n" -// " \"encode\": {\n" -// " \"enter\": {\n" -// " \"bounding_box\": {\"value\": " -// "[-73.984092,40.753893,-73.977588,40.756342]},\n" -// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" -// " \"color_bound\": {\"value\": [2.5, 5]},\n" -// " \"opacity\": {\"value\": 1.0},\n" -// " \"aggregation_type\": {\"value\": \"count\"}\n" -// " }\n" -// " }\n" -// " }\n" -// " ]\n" -// "}"; - -// auto wkb = arctern::render::WktToWkb(string_array); -// arctern::render::choropleth_map(wkb, color_array, vega); -// } + TEST(CHOROPLETHMAP_TEST, BLUE_TO_RED) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, SKYBLUE_TO_WHITE) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#B4E7F5\", \"#FFFFFF\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, GREEN_YELLOW_RED) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#4D904F\", \"#C23728\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, BLUE_WHITE_RED) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#1984C5\", \"#C23728\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, WHITE_BLUE) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#E2E2E2\", \"#115F9A\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, BLUE_GREEN_YELLOW) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#115F9A\", \"#D0F401\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, BLUE_TRANSPARENCY) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#0000FF\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, RED_TRANSPARENCY) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#FF0000\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, PURPLE_TO_YELLOW) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#FF00FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + // TEST(CHOROPLETHMAP_TEST, INVALID_color_gradient_TEST) { + // // param1: wkt string + // std::string wkt_string1 = + // "POLYGON ((" + // "200 200, " + // "200 300, " + // "300 300, " + // "300 200, " + // "200 200))"; + // arrow::StringBuilder string_builder; + // auto status = string_builder.Append(wkt_string1); + // + // std::shared_ptr string_array; + // status = string_builder.Finish(&string_array); + // + // // param2: color + // std::shared_ptr color_array; + // arrow::UInt32Builder color_builder; + // status = color_builder.Append(5); + // status = color_builder.Finish(&color_array); + // + // // param3: conf + // const std::string vega = + // "{\n" + // " \"width\": 1900,\n" + // " \"height\": 1410,\n" + // " \"description\": \"choropleth_map\",\n" + // " \"data\": [\n" + // " {\n" + // " \"name\": \"data\",\n" + // " \"url\": \"data/data.csv\"\n" + // " }\n" + // " ],\n" + // " \"scales\": [\n" + // " {\n" + // " \"name\": \"building\",\n" + // " \"type\": \"linear\",\n" + // " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + // " }\n" + // " ],\n" + // " \"marks\": [\n" + // " {\n" + // " \"encode\": {\n" + // " \"enter\": {\n" + // " \"bounding_box\": {\"value\": " + // "[-73.984092,40.753893,-73.977588,40.756342]},\n" + // " \"color_gradient\": {\"value\": \"xxxxxx\"},\n" + // " \"color_bound\": {\"value\": [2.5, 5]},\n" + // " \"opacity\": {\"value\": 1.0}\n" + // " }\n" + // " }\n" + // " }\n" + // " ]\n" + // "}"; + // + // auto wkb = arctern::render::WktToWkb(string_array); + // arctern::render::choropleth_map(wkb, color_array, vega); + //} + + // TEST(CHOROPLETHMAP_TEST, INVALID_JSON_TEST) { + // // param1: wkt string + // std::string wkt_string1 = + // "POLYGON ((" + // "200 200, " + // "200 300, " + // "300 300, " + // "300 200, " + // "200 200))"; + // arrow::StringBuilder string_builder; + // auto status = string_builder.Append(wkt_string1); + // + // std::shared_ptr string_array; + // status = string_builder.Finish(&string_array); + // + // // param2: color + // std::shared_ptr color_array; + // arrow::UInt32Builder color_builder; + // status = color_builder.Append(5); + // status = color_builder.Finish(&color_array); + // + // // param3: conf + // const std::string vega = + // "{\n" + // " \"width\": 1900,\n" + // " \"height\": 1410,\n" + // " \"description\": \"choropleth_map\",\n" + // " \"data\": [\n" + // " {\n" + // " \"name\": \"data\",\n" + // " \"url\": \"data/data.csv\"\n" + // " }\n" + // " ],\n" + // " \"scales\": [\n" + // " {\n" + // " \"name\": \"building\",\n" + // " \"type\": \"linear\",\n" + // " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + // " }\n" + // " ],\n" + // " \"marks\": [\n" + // " {\n" + // " \"encode\": {\n" + // " \"enter\": {\n" + // " \"bounding_box\": {\"value\": " + // "[-73.984092,40.753893,-73.977588,40.756342]},\n" + // " \"color_gradient\": {\"value\": \"blue_to_red\"},\n" + // " \"color_bound\": {\"value\": [2.5, 5]},\n" + // " \"opacity\": {\"value\": \"INVALID_NUMBER\"}\n" + // " }\n" + // " }\n" + // " }\n" + // " ]\n" + // "}"; + // + // auto wkb = arctern::render::WktToWkb(string_array); + // arctern::render::choropleth_map(wkb, color_array, vega); + //} + + TEST(CHOROPLETHMAP_TEST, INT8) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::Int8Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, INT16) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::Int16Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, INT32) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::Int32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, INT64) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::Int64Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, UINT8) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt8Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, UINT16) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt16Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, UINT32) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, UINT64) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt64Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, FLOAT) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::FloatBuilder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, DOUBLE) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::DoubleBuilder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + // TEST(CHOROPLETHMAP_TEST, INVALID_DATA_TYPE_TEST) { + // // param1: wkt string + // std::string wkt_string1 = + // "POLYGON ((" + // "200 200, " + // "200 300, " + // "300 300, " + // "300 200, " + // "200 200))"; + // arrow::StringBuilder string_builder; + // auto status = string_builder.Append(wkt_string1); + // + // std::shared_ptr string_array; + // status = string_builder.Finish(&string_array); + // + // // param2: color + // std::shared_ptr color_array; + // arrow::StringBuilder color_builder; + // status = color_builder.Append(""); + // status = color_builder.Finish(&color_array); + // + // // param3: conf + // const std::string vega = + // "{\n" + // " \"width\": 1900,\n" + // " \"height\": 1410,\n" + // " \"description\": \"choropleth_map\",\n" + // " \"data\": [\n" + // " {\n" + // " \"name\": \"data\",\n" + // " \"url\": \"data/data.csv\"\n" + // " }\n" + // " ],\n" + // " \"scales\": [\n" + // " {\n" + // " \"name\": \"building\",\n" + // " \"type\": \"linear\",\n" + // " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + // " }\n" + // " ],\n" + // " \"marks\": [\n" + // " {\n" + // " \"encode\": {\n" + // " \"enter\": {\n" + // " \"bounding_box\": {\"value\": " + // "[-73.984092,40.753893,-73.977588,40.756342]},\n" + // " \"color_gradient\": {\"value\": \"blue_to_red\"},\n" + // " \"color_bound\": {\"value\": [2.5, 5]},\n" + // " \"opacity\": {\"value\": 1.0}\n" + // " }\n" + // " }\n" + // " }\n" + // " ]\n" + // "}"; + // + // auto wkb = arctern::render::WktToWkb(string_array); + // arctern::render::choropleth_map(wkb, color_array, vega); + //} + + TEST(CHOROPLETHMAP_TEST, MEAN) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::DoubleBuilder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"mean\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, SUM) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::DoubleBuilder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, MAX) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::DoubleBuilder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"max\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, MIN) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::DoubleBuilder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"min\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } + + TEST(CHOROPLETHMAP_TEST, COUNT) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::DoubleBuilder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"count\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); + } TEST(CHOROPLETHMAP_TEST, STD) { // param1: wkt string @@ -1644,22 +1716,10 @@ TEST(CHOROPLETHMAP_TEST, STD) { "300 200, " "200 200))"; arrow::StringBuilder string_builder; - std::string wkt_string2 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder2; auto status = string_builder.Append(wkt_string1); - status = string_builder2.Append(wkt_string2); std::shared_ptr string_array; - std::shared_ptr string_array2; status = string_builder.Finish(&string_array); - status = string_builder.Finish(&string_array2); - // param2: color std::shared_ptr color_array; @@ -1667,10 +1727,6 @@ TEST(CHOROPLETHMAP_TEST, STD) { status = color_builder.Append(5); status = color_builder.Finish(&color_array); - std::shared_ptr color_array2; - arrow::DoubleBuilder color_builder2; - status = color_builder2.Append(5); - status = color_builder2.Finish(&color_array2); // param3: conf const std::string vega = "{\n" @@ -1707,15 +1763,8 @@ TEST(CHOROPLETHMAP_TEST, STD) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - std::vector> voc1; - - auto wkb2 = arctern::render::WktToWkb(string_array2); + std::vector> polygon_vec{wkb}; - voc1.push_back(wkb); - voc1.push_back(wkb2); - std::vector> voc2; - voc2.push_back(color_array); - voc2.push_back(color_array2); - // arctern::render::choropleth_map(wkb, color_array, vega); - arctern::render::choropleth_map(voc1, voc2, vega); + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); } diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index de61dfea1..f0cf76736 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1369,6 +1369,8 @@ def heat_map_layer(vega, points, weights, transform=True): weights_rs = [] if isinstance(arr, pa.lib.ChunkedArray): + print("num_chunks:") + print(arr.num_chunks) for chunk_idx in range(arr.num_chunks): weights_rs.append(arr.chunk(chunk_idx)) else: diff --git a/python/tests/geo/render_test.py b/python/tests/geo/render_test.py index 3b97ba450..fe76cabae 100644 --- a/python/tests/geo/render_test.py +++ b/python/tests/geo/render_test.py @@ -131,8 +131,8 @@ def test_heat_map(): arr_x = pandas.Series(x_data) arr_y = pandas.Series(y_data) - points = arctern.ST_Point(arr_x, arr_y) arr_c = pandas.Series(c_data) + points = arctern.ST_Point(arr_x, arr_y) vega = vega_heatmap(1024, 896, bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816], map_zoom_level=13.0, coordinate_system='EPSG:4326') heat_map1 = arctern.heat_map_layer(vega, points, arr_c) From dce6f14c67c0563877ba5dc2f9941d27da40eca3 Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Wed, 29 Apr 2020 19:59:21 +0800 Subject: [PATCH 19/24] render code refactor, done --- cpp/src/arrow/render_api.cpp | 11 +- cpp/unittest/render/CMakeLists.txt | 10 +- .../render/coordinate_projection_test.cpp | 21 +- cpp/unittest/render/heatmap_test.cpp | 96 +- cpp/unittest/render/iconviz_test.cpp | 5 +- cpp/unittest/render/pointmap_test.cpp | 5 +- .../render/weighted_pointmap_test.cpp | 2583 +++++++++-------- python/arctern/_wrapper_func.py | 158 +- 8 files changed, 1583 insertions(+), 1306 deletions(-) diff --git a/cpp/src/arrow/render_api.cpp b/cpp/src/arrow/render_api.cpp index fe0718cc9..e375abda9 100644 --- a/cpp/src/arrow/render_api.cpp +++ b/cpp/src/arrow/render_api.cpp @@ -472,6 +472,7 @@ const std::vector> transform_and_projection( TransformAndProjection(geo_vec, src_rs, dst_rs, bottom_right, top_left, height, width); std::cout << "c++ transform and proj ok" << std::endl; const auto& res = GeometryExport(geo_vec, geos.size()); + std::cout << "c++ GeometryExport ok" << std::endl; return res; } @@ -588,8 +589,9 @@ std::shared_ptr weighted_point_map( return out_pic(render_weighted_pointmap(wkb_vec, arr_c, conf)); } default: - std::string err_msg = "type error of count while running weighted_pointmap, type = " + - std::to_string(weight_data_type); + std::string err_msg = + "type error of count while running weighted_pointmap, type = " + + std::to_string(weight_data_type); throw std::runtime_error(err_msg); } } @@ -655,8 +657,9 @@ std::shared_ptr weighted_point_map( return out_pic(render_weighted_pointmap(wkb_vec, arr_c, arr_s, conf)); } default: - std::string err_msg = "type error of count while running weighted_pointmap, type = " + - std::to_string(weight_data_type); + std::string err_msg = + "type error of count while running weighted_pointmap, type = " + + std::to_string(weight_data_type); throw std::runtime_error(err_msg); } } diff --git a/cpp/unittest/render/CMakeLists.txt b/cpp/unittest/render/CMakeLists.txt index 9133ea7e3..8d5eed6fb 100644 --- a/cpp/unittest/render/CMakeLists.txt +++ b/cpp/unittest/render/CMakeLists.txt @@ -14,12 +14,12 @@ set(render_tests_src ${unittest_srcs} -# pointmap_test.cpp -# heatmap_test.cpp + pointmap_test.cpp + heatmap_test.cpp choropleth_map_test.cpp -# coordinate_projection_test.cpp -# weighted_pointmap_test.cpp -# iconviz_test.cpp + coordinate_projection_test.cpp + weighted_pointmap_test.cpp + iconviz_test.cpp ) add_executable(render_tests ${render_tests_src}) diff --git a/cpp/unittest/render/coordinate_projection_test.cpp b/cpp/unittest/render/coordinate_projection_test.cpp index b0ac77d12..e257b7329 100644 --- a/cpp/unittest/render/coordinate_projection_test.cpp +++ b/cpp/unittest/render/coordinate_projection_test.cpp @@ -45,10 +45,11 @@ TEST(TRANSFORM_PROJECTION_TEST, POINT_TEST) { // param5: bottom_right std::string bottom_right = "POINT (-73.977588 40.753893)"; - auto arr = arctern::render::transform_and_projection(wkb, src_ts, dst_rs, bottom_right, + std::vector> vec{wkb}; + auto arr = arctern::render::transform_and_projection(vec, src_ts, dst_rs, bottom_right, top_left, 200, 300); - auto str_arr = std::static_pointer_cast(arr); + auto str_arr = std::static_pointer_cast(arr[0]); auto res1 = str_arr->GetString(0); auto res2 = str_arr->GetString(1); @@ -103,10 +104,12 @@ TEST(TRANSFORM_PROJECTION_TEST, POLYGON_TEST) { // param5: bottom_right std::string bottom_right = "POINT (-73.977588 40.753893)"; - auto arr = arctern::render::transform_and_projection(wkb, src_ts, dst_rs, bottom_right, + std::vector> vec{wkb}; + + auto arr = arctern::render::transform_and_projection(vec, src_ts, dst_rs, bottom_right, top_left, 200, 300); - auto str_arr = std::static_pointer_cast(arr); + auto str_arr = std::static_pointer_cast(arr[0]); } TEST(PROJECTION_TEST, POINT_TEST) { @@ -129,9 +132,10 @@ TEST(PROJECTION_TEST, POINT_TEST) { auto wkb = arctern::render::WktToWkb(string_array); - auto arr = arctern::render::projection(wkb, bottom_right, top_left, 200, 300); + std::vector> vec{wkb}; + auto arr = arctern::render::projection(vec, bottom_right, top_left, 200, 300); - auto str_arr = std::static_pointer_cast(arr); + auto str_arr = std::static_pointer_cast(arr[0]); auto res1 = str_arr->GetString(0); auto res2 = str_arr->GetString(1); @@ -172,9 +176,10 @@ TEST(PROJECTION_TEST, POLYGON_TEST) { auto wkb = arctern::render::WktToWkb(string_array); - auto arr = arctern::render::projection(wkb, bottom_right, top_left, 200, 300); + std::vector> vec{wkb}; + auto arr = arctern::render::projection(vec, bottom_right, top_left, 200, 300); - auto str_arr = std::static_pointer_cast(arr); + auto str_arr = std::static_pointer_cast(arr[0]); auto res = str_arr->GetString(0); diff --git a/cpp/unittest/render/heatmap_test.cpp b/cpp/unittest/render/heatmap_test.cpp index c3f5525ef..1f1a80104 100644 --- a/cpp/unittest/render/heatmap_test.cpp +++ b/cpp/unittest/render/heatmap_test.cpp @@ -1002,7 +1002,11 @@ TEST(HEATMAP_TEST, WKT_POINT_INT8_TEST) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } TEST(HEATMAP_TEST, WKT_POINT_INT16_TEST) { @@ -1069,7 +1073,11 @@ TEST(HEATMAP_TEST, WKT_POINT_INT16_TEST) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } TEST(HEATMAP_TEST, WKT_POINT_INT32_TEST) { @@ -1136,7 +1144,11 @@ TEST(HEATMAP_TEST, WKT_POINT_INT32_TEST) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } TEST(HEATMAP_TEST, WKT_POINT_INT64_TEST) { @@ -1203,7 +1215,11 @@ TEST(HEATMAP_TEST, WKT_POINT_INT64_TEST) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } TEST(HEATMAP_TEST, WKT_POINT_UINT8_TEST) { @@ -1270,7 +1286,11 @@ TEST(HEATMAP_TEST, WKT_POINT_UINT8_TEST) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } TEST(HEATMAP_TEST, WKT_POINT_UINT16_TEST) { @@ -1337,7 +1357,11 @@ TEST(HEATMAP_TEST, WKT_POINT_UINT16_TEST) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } TEST(HEATMAP_TEST, WKT_POINT_UINT32_TEST) { @@ -1404,7 +1428,11 @@ TEST(HEATMAP_TEST, WKT_POINT_UINT32_TEST) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } TEST(HEATMAP_TEST, WKT_POINT_UINT64_TEST) { @@ -1471,7 +1499,11 @@ TEST(HEATMAP_TEST, WKT_POINT_UINT64_TEST) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } TEST(HEATMAP_TEST, WKT_POINT_FLOAT_TEST) { @@ -1538,7 +1570,11 @@ TEST(HEATMAP_TEST, WKT_POINT_FLOAT_TEST) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } TEST(HEATMAP_TEST, WKT_POINT_DOUBLE_TEST) { @@ -1605,7 +1641,11 @@ TEST(HEATMAP_TEST, WKT_POINT_DOUBLE_TEST) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } // TEST(HEATMAP_TEST, WKT_POINT_INVALID_DATA_TYPE_TEST) { @@ -1806,7 +1846,11 @@ TEST(HEATMAP_TEST, MEAN) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } TEST(HEATMAP_TEST, SUM) { @@ -1873,7 +1917,11 @@ TEST(HEATMAP_TEST, SUM) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } TEST(HEATMAP_TEST, MAX) { @@ -1940,7 +1988,11 @@ TEST(HEATMAP_TEST, MAX) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } TEST(HEATMAP_TEST, MIN) { @@ -2007,7 +2059,11 @@ TEST(HEATMAP_TEST, MIN) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } TEST(HEATMAP_TEST, COUNT) { @@ -2074,7 +2130,11 @@ TEST(HEATMAP_TEST, COUNT) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } TEST(HEATMAP_TEST, STD) { @@ -2141,5 +2201,9 @@ TEST(HEATMAP_TEST, STD) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::heat_map(wkb, color_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{color_array}; + + arctern::render::heat_map(point_vec, color_vec, vega); } diff --git a/cpp/unittest/render/iconviz_test.cpp b/cpp/unittest/render/iconviz_test.cpp index 45b1a5778..f367a1c08 100644 --- a/cpp/unittest/render/iconviz_test.cpp +++ b/cpp/unittest/render/iconviz_test.cpp @@ -138,5 +138,8 @@ TEST(ICON_VIZ_TEST, WKT_TEST) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::icon_viz(wkb, vega); + + std::vector> point_vec{wkb}; + + arctern::render::icon_viz(point_vec, vega); } diff --git a/cpp/unittest/render/pointmap_test.cpp b/cpp/unittest/render/pointmap_test.cpp index 6c472a823..18258cdf5 100644 --- a/cpp/unittest/render/pointmap_test.cpp +++ b/cpp/unittest/render/pointmap_test.cpp @@ -292,7 +292,10 @@ TEST(POINTMAP_TEST, WKT_POINT_TEST) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::point_map(wkb, vega); + + std::vector> point_vec{wkb}; + + arctern::render::point_map(point_vec, vega); } // TEST(POINTMAP_TEST, WKT_POINT_INVALID_JSON_TEST) { diff --git a/cpp/unittest/render/weighted_pointmap_test.cpp b/cpp/unittest/render/weighted_pointmap_test.cpp index db11f4415..f8a244901 100644 --- a/cpp/unittest/render/weighted_pointmap_test.cpp +++ b/cpp/unittest/render/weighted_pointmap_test.cpp @@ -19,1107 +19,227 @@ #include "arrow/render_api.h" -TEST(POINTMAP_RAW_POINT_TEST, SINGLE_COLOR_SINGLE_POINTSIZE) { - // param1: x, y - arrow::UInt32Builder x_builder; - auto status = x_builder.Append(10); - status = x_builder.Append(40); - status = x_builder.Append(70); - status = x_builder.Append(100); - status = x_builder.Append(130); - - std::shared_ptr x_array; - status = x_builder.Finish(&x_array); - - arrow::UInt32Builder y_builder; - status = y_builder.Append(10); - status = y_builder.Append(40); - status = y_builder.Append(70); - status = y_builder.Append(100); - status = y_builder.Append(130); - - std::shared_ptr y_array; - status = y_builder.Finish(&y_array); - - // param2: conf - const std::string vega = - "{\n" - " \"width\": 300,\n" - " \"height\": 200,\n" - " \"description\": \"pointmap\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"nyc_taxi\",\n" - " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"x\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" - " },\n" - " {\n" - " \"name\": \"y\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" - " \"shape\": {\"value\": \"circle\"},\n" - " \"color_gradient\": {\"value\": [\"#FFD700\"]},\n" - " \"color_bound\": {\"value\": [-1, -1]},\n" - " \"size_bound\": {\"value\": [5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - arctern::render::weighted_point_map(x_array, y_array, vega); -} - -TEST(POINTMAP_RAW_POINT_TEST, MULTIPLE_COLOR_SINGLE_POINTSIZE) { - // param1: x, y - arrow::UInt32Builder x_builder; - auto status = x_builder.Append(10); - status = x_builder.Append(40); - status = x_builder.Append(70); - status = x_builder.Append(100); - status = x_builder.Append(130); - - std::shared_ptr x_array; - status = x_builder.Finish(&x_array); - - arrow::UInt32Builder y_builder; - status = y_builder.Append(10); - status = y_builder.Append(40); - status = y_builder.Append(70); - status = y_builder.Append(100); - status = y_builder.Append(130); - - std::shared_ptr y_array; - status = y_builder.Finish(&y_array); - - // param2: count - arrow::UInt32Builder color_builder; - status = color_builder.Append(1); - status = color_builder.Append(2); - status = color_builder.Append(3); - status = color_builder.Append(4); - status = color_builder.Append(5); - - std::shared_ptr c_array; - status = color_builder.Finish(&c_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 300,\n" - " \"height\": 200,\n" - " \"description\": \"pointmap\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"nyc_taxi\",\n" - " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"x\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" - " },\n" - " {\n" - " \"name\": \"y\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" - " \"shape\": {\"value\": \"circle\"},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2, 5]},\n" - " \"size_bound\": {\"value\": [8]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - arctern::render::weighted_point_map(x_array, y_array, c_array, vega); -} - -TEST(POINTMAP_RAW_POINT_TEST, SINGLE_COLOR_MULTIPLE_POINTSIZE) { - // param1: x, y - arrow::UInt32Builder x_builder; - auto status = x_builder.Append(10); - status = x_builder.Append(40); - status = x_builder.Append(70); - status = x_builder.Append(100); - status = x_builder.Append(130); - - std::shared_ptr x_array; - status = x_builder.Finish(&x_array); - - arrow::UInt32Builder y_builder; - status = y_builder.Append(10); - status = y_builder.Append(40); - status = y_builder.Append(70); - status = y_builder.Append(100); - status = y_builder.Append(130); - - std::shared_ptr y_array; - status = y_builder.Finish(&y_array); - - // param2: point_size - arrow::UInt32Builder ps_builder; - status = ps_builder.Append(2); - status = ps_builder.Append(4); - status = ps_builder.Append(6); - status = ps_builder.Append(8); - status = ps_builder.Append(10); - - std::shared_ptr s_array; - status = ps_builder.Finish(&s_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 300,\n" - " \"height\": 200,\n" - " \"description\": \"pointmap\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"nyc_taxi\",\n" - " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"x\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" - " },\n" - " {\n" - " \"name\": \"y\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" - " \"shape\": {\"value\": \"circle\"},\n" - " \"color_gradient\": {\"value\": [\"#FFD700\"]},\n" - " \"color_bound\": {\"value\": [-1, -1]},\n" - " \"size_bound\": {\"value\": [0, 10]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - arctern::render::weighted_point_map(x_array, y_array, s_array, vega); -} - -TEST(POINTMAP_RAW_POINT_TEST, MULTIPLE_COLOR_MULTIPLE_POINTSIZE) { - // param1: x, y - arrow::UInt32Builder x_builder; - auto status = x_builder.Append(10); - status = x_builder.Append(40); - status = x_builder.Append(70); - status = x_builder.Append(100); - status = x_builder.Append(130); - - std::shared_ptr x_array; - status = x_builder.Finish(&x_array); - - arrow::UInt32Builder y_builder; - status = y_builder.Append(10); - status = y_builder.Append(40); - status = y_builder.Append(70); - status = y_builder.Append(100); - status = y_builder.Append(130); - - std::shared_ptr y_array; - status = y_builder.Finish(&y_array); - - // param2: color - arrow::UInt32Builder color_builder; - status = color_builder.Append(1); - status = color_builder.Append(2); - status = color_builder.Append(3); - status = color_builder.Append(4); - status = color_builder.Append(5); - - std::shared_ptr c_array; - status = color_builder.Finish(&c_array); - - // param3: point size - arrow::UInt32Builder point_size_builder; - status = point_size_builder.Append(2); - status = point_size_builder.Append(4); - status = point_size_builder.Append(6); - status = point_size_builder.Append(8); - status = point_size_builder.Append(10); - - std::shared_ptr s_array; - status = point_size_builder.Finish(&s_array); - - // param4: conf - const std::string vega = - "{\n" - " \"width\": 300,\n" - " \"height\": 200,\n" - " \"description\": \"weighted_pointmap\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"nyc_taxi\",\n" - " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"x\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" - " },\n" - " {\n" - " \"name\": \"y\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" - " \"shape\": {\"value\": \"circle\"},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); -} - -TEST(POINTMAP_RAW_POINT_TEST, INT8) { - // param1: x, y - arrow::UInt32Builder x_builder; - auto status = x_builder.Append(10); - status = x_builder.Append(40); - status = x_builder.Append(70); - status = x_builder.Append(100); - status = x_builder.Append(130); - - std::shared_ptr x_array; - status = x_builder.Finish(&x_array); - - arrow::UInt32Builder y_builder; - status = y_builder.Append(10); - status = y_builder.Append(40); - status = y_builder.Append(70); - status = y_builder.Append(100); - status = y_builder.Append(130); - - std::shared_ptr y_array; - status = y_builder.Finish(&y_array); - - // param2: color - arrow::Int8Builder color_builder; - status = color_builder.Append(1); - status = color_builder.Append(2); - status = color_builder.Append(3); - status = color_builder.Append(4); - status = color_builder.Append(5); - - std::shared_ptr c_array; - status = color_builder.Finish(&c_array); - - // param3: point size - arrow::Int8Builder point_size_builder; - status = point_size_builder.Append(2); - status = point_size_builder.Append(4); - status = point_size_builder.Append(6); - status = point_size_builder.Append(8); - status = point_size_builder.Append(10); - - std::shared_ptr s_array; - status = point_size_builder.Finish(&s_array); - - // param4: conf - const std::string vega = - "{\n" - " \"width\": 300,\n" - " \"height\": 200,\n" - " \"description\": \"weighted_pointmap\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"nyc_taxi\",\n" - " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"x\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" - " },\n" - " {\n" - " \"name\": \"y\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" - " \"shape\": {\"value\": \"circle\"},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); -} - -TEST(POINTMAP_RAW_POINT_TEST, INT16) { - // param1: x, y - arrow::UInt32Builder x_builder; - auto status = x_builder.Append(10); - status = x_builder.Append(40); - status = x_builder.Append(70); - status = x_builder.Append(100); - status = x_builder.Append(130); - - std::shared_ptr x_array; - status = x_builder.Finish(&x_array); - - arrow::UInt32Builder y_builder; - status = y_builder.Append(10); - status = y_builder.Append(40); - status = y_builder.Append(70); - status = y_builder.Append(100); - status = y_builder.Append(130); - - std::shared_ptr y_array; - status = y_builder.Finish(&y_array); - - // param2: color - arrow::Int16Builder color_builder; - status = color_builder.Append(1); - status = color_builder.Append(2); - status = color_builder.Append(3); - status = color_builder.Append(4); - status = color_builder.Append(5); - - std::shared_ptr c_array; - status = color_builder.Finish(&c_array); - - // param3: point size - arrow::Int16Builder point_size_builder; - status = point_size_builder.Append(2); - status = point_size_builder.Append(4); - status = point_size_builder.Append(6); - status = point_size_builder.Append(8); - status = point_size_builder.Append(10); - - std::shared_ptr s_array; - status = point_size_builder.Finish(&s_array); - - // param4: conf - const std::string vega = - "{\n" - " \"width\": 300,\n" - " \"height\": 200,\n" - " \"description\": \"weighted_pointmap\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"nyc_taxi\",\n" - " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"x\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" - " },\n" - " {\n" - " \"name\": \"y\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" - " \"shape\": {\"value\": \"circle\"},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); -} - -TEST(POINTMAP_RAW_POINT_TEST, INT32) { - // param1: x, y - arrow::UInt32Builder x_builder; - auto status = x_builder.Append(10); - status = x_builder.Append(40); - status = x_builder.Append(70); - status = x_builder.Append(100); - status = x_builder.Append(130); - - std::shared_ptr x_array; - status = x_builder.Finish(&x_array); - - arrow::UInt32Builder y_builder; - status = y_builder.Append(10); - status = y_builder.Append(40); - status = y_builder.Append(70); - status = y_builder.Append(100); - status = y_builder.Append(130); - - std::shared_ptr y_array; - status = y_builder.Finish(&y_array); - - // param2: color - arrow::Int32Builder color_builder; - status = color_builder.Append(1); - status = color_builder.Append(2); - status = color_builder.Append(3); - status = color_builder.Append(4); - status = color_builder.Append(5); - - std::shared_ptr c_array; - status = color_builder.Finish(&c_array); - - // param3: point size - arrow::Int32Builder point_size_builder; - status = point_size_builder.Append(2); - status = point_size_builder.Append(4); - status = point_size_builder.Append(6); - status = point_size_builder.Append(8); - status = point_size_builder.Append(10); - - std::shared_ptr s_array; - status = point_size_builder.Finish(&s_array); - - // param4: conf - const std::string vega = - "{\n" - " \"width\": 300,\n" - " \"height\": 200,\n" - " \"description\": \"weighted_pointmap\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"nyc_taxi\",\n" - " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"x\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" - " },\n" - " {\n" - " \"name\": \"y\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" - " \"shape\": {\"value\": \"circle\"},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); -} - -TEST(POINTMAP_RAW_POINT_TEST, INT64) { - // param1: x, y - arrow::UInt32Builder x_builder; - auto status = x_builder.Append(10); - status = x_builder.Append(40); - status = x_builder.Append(70); - status = x_builder.Append(100); - status = x_builder.Append(130); - - std::shared_ptr x_array; - status = x_builder.Finish(&x_array); - - arrow::UInt32Builder y_builder; - status = y_builder.Append(10); - status = y_builder.Append(40); - status = y_builder.Append(70); - status = y_builder.Append(100); - status = y_builder.Append(130); - - std::shared_ptr y_array; - status = y_builder.Finish(&y_array); - - // param2: color - arrow::Int64Builder color_builder; - status = color_builder.Append(1); - status = color_builder.Append(2); - status = color_builder.Append(3); - status = color_builder.Append(4); - status = color_builder.Append(5); - - std::shared_ptr c_array; - status = color_builder.Finish(&c_array); - - // param3: point size - arrow::Int64Builder point_size_builder; - status = point_size_builder.Append(2); - status = point_size_builder.Append(4); - status = point_size_builder.Append(6); - status = point_size_builder.Append(8); - status = point_size_builder.Append(10); - - std::shared_ptr s_array; - status = point_size_builder.Finish(&s_array); - - // param4: conf - const std::string vega = - "{\n" - " \"width\": 300,\n" - " \"height\": 200,\n" - " \"description\": \"weighted_pointmap\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"nyc_taxi\",\n" - " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"x\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" - " },\n" - " {\n" - " \"name\": \"y\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" - " \"shape\": {\"value\": \"circle\"},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); -} - -TEST(POINTMAP_RAW_POINT_TEST, UINT8) { - // param1: x, y - arrow::UInt32Builder x_builder; - auto status = x_builder.Append(10); - status = x_builder.Append(40); - status = x_builder.Append(70); - status = x_builder.Append(100); - status = x_builder.Append(130); - - std::shared_ptr x_array; - status = x_builder.Finish(&x_array); - - arrow::UInt32Builder y_builder; - status = y_builder.Append(10); - status = y_builder.Append(40); - status = y_builder.Append(70); - status = y_builder.Append(100); - status = y_builder.Append(130); - - std::shared_ptr y_array; - status = y_builder.Finish(&y_array); - - // param2: color - arrow::UInt8Builder color_builder; - status = color_builder.Append(1); - status = color_builder.Append(2); - status = color_builder.Append(3); - status = color_builder.Append(4); - status = color_builder.Append(5); - - std::shared_ptr c_array; - status = color_builder.Finish(&c_array); - - // param3: point size - arrow::UInt8Builder point_size_builder; - status = point_size_builder.Append(2); - status = point_size_builder.Append(4); - status = point_size_builder.Append(6); - status = point_size_builder.Append(8); - status = point_size_builder.Append(10); - - std::shared_ptr s_array; - status = point_size_builder.Finish(&s_array); - - // param4: conf - const std::string vega = - "{\n" - " \"width\": 300,\n" - " \"height\": 200,\n" - " \"description\": \"weighted_pointmap\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"nyc_taxi\",\n" - " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"x\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" - " },\n" - " {\n" - " \"name\": \"y\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" - " \"shape\": {\"value\": \"circle\"},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); -} - -TEST(POINTMAP_RAW_POINT_TEST, UINT16) { - // param1: x, y - arrow::UInt32Builder x_builder; - auto status = x_builder.Append(10); - status = x_builder.Append(40); - status = x_builder.Append(70); - status = x_builder.Append(100); - status = x_builder.Append(130); - - std::shared_ptr x_array; - status = x_builder.Finish(&x_array); - - arrow::UInt32Builder y_builder; - status = y_builder.Append(10); - status = y_builder.Append(40); - status = y_builder.Append(70); - status = y_builder.Append(100); - status = y_builder.Append(130); - - std::shared_ptr y_array; - status = y_builder.Finish(&y_array); - - // param2: color - arrow::UInt16Builder color_builder; - status = color_builder.Append(1); - status = color_builder.Append(2); - status = color_builder.Append(3); - status = color_builder.Append(4); - status = color_builder.Append(5); - - std::shared_ptr c_array; - status = color_builder.Finish(&c_array); - - // param3: point size - arrow::UInt16Builder point_size_builder; - status = point_size_builder.Append(2); - status = point_size_builder.Append(4); - status = point_size_builder.Append(6); - status = point_size_builder.Append(8); - status = point_size_builder.Append(10); - - std::shared_ptr s_array; - status = point_size_builder.Finish(&s_array); - - // param4: conf - const std::string vega = - "{\n" - " \"width\": 300,\n" - " \"height\": 200,\n" - " \"description\": \"weighted_pointmap\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"nyc_taxi\",\n" - " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"x\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" - " },\n" - " {\n" - " \"name\": \"y\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" - " \"shape\": {\"value\": \"circle\"},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); -} - -TEST(POINTMAP_RAW_POINT_TEST, UINT32) { - // param1: x, y - arrow::UInt32Builder x_builder; - auto status = x_builder.Append(10); - status = x_builder.Append(40); - status = x_builder.Append(70); - status = x_builder.Append(100); - status = x_builder.Append(130); - - std::shared_ptr x_array; - status = x_builder.Finish(&x_array); - - arrow::UInt32Builder y_builder; - status = y_builder.Append(10); - status = y_builder.Append(40); - status = y_builder.Append(70); - status = y_builder.Append(100); - status = y_builder.Append(130); - - std::shared_ptr y_array; - status = y_builder.Finish(&y_array); - - // param2: color - arrow::UInt32Builder color_builder; - status = color_builder.Append(1); - status = color_builder.Append(2); - status = color_builder.Append(3); - status = color_builder.Append(4); - status = color_builder.Append(5); - - std::shared_ptr c_array; - status = color_builder.Finish(&c_array); - - // param3: point size - arrow::UInt32Builder point_size_builder; - status = point_size_builder.Append(2); - status = point_size_builder.Append(4); - status = point_size_builder.Append(6); - status = point_size_builder.Append(8); - status = point_size_builder.Append(10); - - std::shared_ptr s_array; - status = point_size_builder.Finish(&s_array); - - // param4: conf - const std::string vega = - "{\n" - " \"width\": 300,\n" - " \"height\": 200,\n" - " \"description\": \"weighted_pointmap\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"nyc_taxi\",\n" - " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"x\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" - " },\n" - " {\n" - " \"name\": \"y\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" - " \"shape\": {\"value\": \"circle\"},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); -} - -TEST(POINTMAP_RAW_POINT_TEST, UINT64) { - // param1: x, y - arrow::UInt32Builder x_builder; - auto status = x_builder.Append(10); - status = x_builder.Append(40); - status = x_builder.Append(70); - status = x_builder.Append(100); - status = x_builder.Append(130); - - std::shared_ptr x_array; - status = x_builder.Finish(&x_array); - - arrow::UInt32Builder y_builder; - status = y_builder.Append(10); - status = y_builder.Append(40); - status = y_builder.Append(70); - status = y_builder.Append(100); - status = y_builder.Append(130); - - std::shared_ptr y_array; - status = y_builder.Finish(&y_array); - - // param2: color - arrow::UInt64Builder color_builder; - status = color_builder.Append(1); - status = color_builder.Append(2); - status = color_builder.Append(3); - status = color_builder.Append(4); - status = color_builder.Append(5); - - std::shared_ptr c_array; - status = color_builder.Finish(&c_array); - - // param3: point size - arrow::UInt64Builder point_size_builder; - status = point_size_builder.Append(2); - status = point_size_builder.Append(4); - status = point_size_builder.Append(6); - status = point_size_builder.Append(8); - status = point_size_builder.Append(10); - - std::shared_ptr s_array; - status = point_size_builder.Finish(&s_array); - - // param4: conf - const std::string vega = - "{\n" - " \"width\": 300,\n" - " \"height\": 200,\n" - " \"description\": \"weighted_pointmap\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"nyc_taxi\",\n" - " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"x\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" - " },\n" - " {\n" - " \"name\": \"y\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" - " \"shape\": {\"value\": \"circle\"},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; - - arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); -} - -TEST(POINTMAP_RAW_POINT_TEST, FLOAT) { - // param1: x, y - arrow::UInt32Builder x_builder; - auto status = x_builder.Append(10); - status = x_builder.Append(40); - status = x_builder.Append(70); - status = x_builder.Append(100); - status = x_builder.Append(130); - - std::shared_ptr x_array; - status = x_builder.Finish(&x_array); - - arrow::UInt32Builder y_builder; - status = y_builder.Append(10); - status = y_builder.Append(40); - status = y_builder.Append(70); - status = y_builder.Append(100); - status = y_builder.Append(130); - - std::shared_ptr y_array; - status = y_builder.Finish(&y_array); - - // param2: color - arrow::FloatBuilder color_builder; - status = color_builder.Append(1); - status = color_builder.Append(2); - status = color_builder.Append(3); - status = color_builder.Append(4); - status = color_builder.Append(5); - - std::shared_ptr c_array; - status = color_builder.Finish(&c_array); - - // param3: point size - arrow::FloatBuilder point_size_builder; - status = point_size_builder.Append(2); - status = point_size_builder.Append(4); - status = point_size_builder.Append(6); - status = point_size_builder.Append(8); - status = point_size_builder.Append(10); - - std::shared_ptr s_array; - status = point_size_builder.Finish(&s_array); - - // param4: conf - const std::string vega = - "{\n" - " \"width\": 300,\n" - " \"height\": 200,\n" - " \"description\": \"weighted_pointmap\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"nyc_taxi\",\n" - " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"x\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" - " },\n" - " {\n" - " \"name\": \"y\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" - " \"shape\": {\"value\": \"circle\"},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; +//TEST(POINTMAP_RAW_POINT_TEST, SINGLE_COLOR_SINGLE_POINTSIZE) { +// // param1: x, y +// arrow::UInt32Builder x_builder; +// auto status = x_builder.Append(10); +// status = x_builder.Append(40); +// status = x_builder.Append(70); +// status = x_builder.Append(100); +// status = x_builder.Append(130); +// +// std::shared_ptr x_array; +// status = x_builder.Finish(&x_array); +// +// arrow::UInt32Builder y_builder; +// status = y_builder.Append(10); +// status = y_builder.Append(40); +// status = y_builder.Append(70); +// status = y_builder.Append(100); +// status = y_builder.Append(130); +// +// std::shared_ptr y_array; +// status = y_builder.Finish(&y_array); +// +// // param2: conf +// const std::string vega = +// "{\n" +// " \"width\": 300,\n" +// " \"height\": 200,\n" +// " \"description\": \"pointmap\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"nyc_taxi\",\n" +// " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"x\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" +// " },\n" +// " {\n" +// " \"name\": \"y\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" +// " \"shape\": {\"value\": \"circle\"},\n" +// " \"color_gradient\": {\"value\": [\"#FFD700\"]},\n" +// " \"color_bound\": {\"value\": [-1, -1]},\n" +// " \"size_bound\": {\"value\": [5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// arctern::render::weighted_point_map(x_array, y_array, vega); +//} +// +//TEST(POINTMAP_RAW_POINT_TEST, MULTIPLE_COLOR_SINGLE_POINTSIZE) { +// // param1: x, y +// arrow::UInt32Builder x_builder; +// auto status = x_builder.Append(10); +// status = x_builder.Append(40); +// status = x_builder.Append(70); +// status = x_builder.Append(100); +// status = x_builder.Append(130); +// +// std::shared_ptr x_array; +// status = x_builder.Finish(&x_array); +// +// arrow::UInt32Builder y_builder; +// status = y_builder.Append(10); +// status = y_builder.Append(40); +// status = y_builder.Append(70); +// status = y_builder.Append(100); +// status = y_builder.Append(130); +// +// std::shared_ptr y_array; +// status = y_builder.Finish(&y_array); +// +// // param2: count +// arrow::UInt32Builder color_builder; +// status = color_builder.Append(1); +// status = color_builder.Append(2); +// status = color_builder.Append(3); +// status = color_builder.Append(4); +// status = color_builder.Append(5); +// +// std::shared_ptr c_array; +// status = color_builder.Finish(&c_array); +// +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 300,\n" +// " \"height\": 200,\n" +// " \"description\": \"pointmap\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"nyc_taxi\",\n" +// " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"x\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" +// " },\n" +// " {\n" +// " \"name\": \"y\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" +// " \"shape\": {\"value\": \"circle\"},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2, 5]},\n" +// " \"size_bound\": {\"value\": [8]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// arctern::render::weighted_point_map(x_array, y_array, c_array, vega); +//} +// +//TEST(POINTMAP_RAW_POINT_TEST, SINGLE_COLOR_MULTIPLE_POINTSIZE) { +// // param1: x, y +// arrow::UInt32Builder x_builder; +// auto status = x_builder.Append(10); +// status = x_builder.Append(40); +// status = x_builder.Append(70); +// status = x_builder.Append(100); +// status = x_builder.Append(130); +// +// std::shared_ptr x_array; +// status = x_builder.Finish(&x_array); +// +// arrow::UInt32Builder y_builder; +// status = y_builder.Append(10); +// status = y_builder.Append(40); +// status = y_builder.Append(70); +// status = y_builder.Append(100); +// status = y_builder.Append(130); +// +// std::shared_ptr y_array; +// status = y_builder.Finish(&y_array); +// +// // param2: point_size +// arrow::UInt32Builder ps_builder; +// status = ps_builder.Append(2); +// status = ps_builder.Append(4); +// status = ps_builder.Append(6); +// status = ps_builder.Append(8); +// status = ps_builder.Append(10); +// +// std::shared_ptr s_array; +// status = ps_builder.Finish(&s_array); +// +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 300,\n" +// " \"height\": 200,\n" +// " \"description\": \"pointmap\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"nyc_taxi\",\n" +// " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"x\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" +// " },\n" +// " {\n" +// " \"name\": \"y\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" +// " \"shape\": {\"value\": \"circle\"},\n" +// " \"color_gradient\": {\"value\": [\"#FFD700\"]},\n" +// " \"color_bound\": {\"value\": [-1, -1]},\n" +// " \"size_bound\": {\"value\": [0, 10]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// arctern::render::weighted_point_map(x_array, y_array, s_array, vega); +//} - arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); -} - -TEST(POINTMAP_RAW_POINT_TEST, DOUBLE) { +TEST(POINTMAP_RAW_POINT_TEST, MULTIPLE_COLOR_MULTIPLE_POINTSIZE) { // param1: x, y arrow::UInt32Builder x_builder; auto status = x_builder.Append(10); @@ -1142,25 +262,25 @@ TEST(POINTMAP_RAW_POINT_TEST, DOUBLE) { status = y_builder.Finish(&y_array); // param2: color - arrow::DoubleBuilder color_builder; + arrow::UInt32Builder color_builder; status = color_builder.Append(1); status = color_builder.Append(2); status = color_builder.Append(3); status = color_builder.Append(4); status = color_builder.Append(5); - std::shared_ptr c_array; + std::shared_ptr c_array; status = color_builder.Finish(&c_array); // param3: point size - arrow::DoubleBuilder point_size_builder; + arrow::UInt32Builder point_size_builder; status = point_size_builder.Append(2); status = point_size_builder.Append(4); status = point_size_builder.Append(6); status = point_size_builder.Append(8); status = point_size_builder.Append(10); - std::shared_ptr s_array; + std::shared_ptr s_array; status = point_size_builder.Finish(&s_array); // param4: conf @@ -1207,7 +327,7 @@ TEST(POINTMAP_RAW_POINT_TEST, DOUBLE) { arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); } -TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT8) { +TEST(POINTMAP_RAW_POINT_TEST, INT8) { // param1: x, y arrow::UInt32Builder x_builder; auto status = x_builder.Append(10); @@ -1240,7 +360,18 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT8) { std::shared_ptr c_array; status = color_builder.Finish(&c_array); - // param3: conf + // param3: point size + arrow::Int8Builder point_size_builder; + status = point_size_builder.Append(2); + status = point_size_builder.Append(4); + status = point_size_builder.Append(6); + status = point_size_builder.Append(8); + status = point_size_builder.Append(10); + + std::shared_ptr s_array; + status = point_size_builder.Finish(&s_array); + + // param4: conf const std::string vega = "{\n" " \"width\": 300,\n" @@ -1272,7 +403,7 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT8) { " \"shape\": {\"value\": \"circle\"},\n" " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5]},\n" + " \"size_bound\": {\"value\": [2.5, 5]},\n" " \"opacity\": {\"value\": 1.0},\n" " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" " }\n" @@ -1281,10 +412,10 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT8) { " ]\n" "}"; - arctern::render::weighted_point_map(x_array, y_array, c_array, vega); + arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); } -TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT16) { +TEST(POINTMAP_RAW_POINT_TEST, INT16) { // param1: x, y arrow::UInt32Builder x_builder; auto status = x_builder.Append(10); @@ -1317,7 +448,18 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT16) { std::shared_ptr c_array; status = color_builder.Finish(&c_array); - // param3: conf + // param3: point size + arrow::Int16Builder point_size_builder; + status = point_size_builder.Append(2); + status = point_size_builder.Append(4); + status = point_size_builder.Append(6); + status = point_size_builder.Append(8); + status = point_size_builder.Append(10); + + std::shared_ptr s_array; + status = point_size_builder.Finish(&s_array); + + // param4: conf const std::string vega = "{\n" " \"width\": 300,\n" @@ -1349,7 +491,7 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT16) { " \"shape\": {\"value\": \"circle\"},\n" " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5]},\n" + " \"size_bound\": {\"value\": [2.5, 5]},\n" " \"opacity\": {\"value\": 1.0},\n" " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" " }\n" @@ -1358,10 +500,10 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT16) { " ]\n" "}"; - arctern::render::weighted_point_map(x_array, y_array, c_array, vega); + arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); } -TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT32) { +TEST(POINTMAP_RAW_POINT_TEST, INT32) { // param1: x, y arrow::UInt32Builder x_builder; auto status = x_builder.Append(10); @@ -1394,7 +536,18 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT32) { std::shared_ptr c_array; status = color_builder.Finish(&c_array); - // param3: conf + // param3: point size + arrow::Int32Builder point_size_builder; + status = point_size_builder.Append(2); + status = point_size_builder.Append(4); + status = point_size_builder.Append(6); + status = point_size_builder.Append(8); + status = point_size_builder.Append(10); + + std::shared_ptr s_array; + status = point_size_builder.Finish(&s_array); + + // param4: conf const std::string vega = "{\n" " \"width\": 300,\n" @@ -1426,7 +579,7 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT32) { " \"shape\": {\"value\": \"circle\"},\n" " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5]},\n" + " \"size_bound\": {\"value\": [2.5, 5]},\n" " \"opacity\": {\"value\": 1.0},\n" " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" " }\n" @@ -1435,10 +588,10 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT32) { " ]\n" "}"; - arctern::render::weighted_point_map(x_array, y_array, c_array, vega); + arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); } -TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT64) { +TEST(POINTMAP_RAW_POINT_TEST, INT64) { // param1: x, y arrow::UInt32Builder x_builder; auto status = x_builder.Append(10); @@ -1471,7 +624,18 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT64) { std::shared_ptr c_array; status = color_builder.Finish(&c_array); - // param3: conf + // param3: point size + arrow::Int64Builder point_size_builder; + status = point_size_builder.Append(2); + status = point_size_builder.Append(4); + status = point_size_builder.Append(6); + status = point_size_builder.Append(8); + status = point_size_builder.Append(10); + + std::shared_ptr s_array; + status = point_size_builder.Finish(&s_array); + + // param4: conf const std::string vega = "{\n" " \"width\": 300,\n" @@ -1503,7 +667,7 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT64) { " \"shape\": {\"value\": \"circle\"},\n" " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5]},\n" + " \"size_bound\": {\"value\": [2.5, 5]},\n" " \"opacity\": {\"value\": 1.0},\n" " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" " }\n" @@ -1512,10 +676,10 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT64) { " ]\n" "}"; - arctern::render::weighted_point_map(x_array, y_array, c_array, vega); + arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); } -TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT8) { +TEST(POINTMAP_RAW_POINT_TEST, UINT8) { // param1: x, y arrow::UInt32Builder x_builder; auto status = x_builder.Append(10); @@ -1548,7 +712,18 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT8) { std::shared_ptr c_array; status = color_builder.Finish(&c_array); - // param3: conf + // param3: point size + arrow::UInt8Builder point_size_builder; + status = point_size_builder.Append(2); + status = point_size_builder.Append(4); + status = point_size_builder.Append(6); + status = point_size_builder.Append(8); + status = point_size_builder.Append(10); + + std::shared_ptr s_array; + status = point_size_builder.Finish(&s_array); + + // param4: conf const std::string vega = "{\n" " \"width\": 300,\n" @@ -1580,7 +755,7 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT8) { " \"shape\": {\"value\": \"circle\"},\n" " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5]},\n" + " \"size_bound\": {\"value\": [2.5, 5]},\n" " \"opacity\": {\"value\": 1.0},\n" " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" " }\n" @@ -1589,10 +764,10 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT8) { " ]\n" "}"; - arctern::render::weighted_point_map(x_array, y_array, c_array, vega); + arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); } -TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT16) { +TEST(POINTMAP_RAW_POINT_TEST, UINT16) { // param1: x, y arrow::UInt32Builder x_builder; auto status = x_builder.Append(10); @@ -1625,7 +800,18 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT16) { std::shared_ptr c_array; status = color_builder.Finish(&c_array); - // param3: conf + // param3: point size + arrow::UInt16Builder point_size_builder; + status = point_size_builder.Append(2); + status = point_size_builder.Append(4); + status = point_size_builder.Append(6); + status = point_size_builder.Append(8); + status = point_size_builder.Append(10); + + std::shared_ptr s_array; + status = point_size_builder.Finish(&s_array); + + // param4: conf const std::string vega = "{\n" " \"width\": 300,\n" @@ -1657,7 +843,7 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT16) { " \"shape\": {\"value\": \"circle\"},\n" " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5]},\n" + " \"size_bound\": {\"value\": [2.5, 5]},\n" " \"opacity\": {\"value\": 1.0},\n" " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" " }\n" @@ -1666,10 +852,10 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT16) { " ]\n" "}"; - arctern::render::weighted_point_map(x_array, y_array, c_array, vega); + arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); } -TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT32) { +TEST(POINTMAP_RAW_POINT_TEST, UINT32) { // param1: x, y arrow::UInt32Builder x_builder; auto status = x_builder.Append(10); @@ -1702,7 +888,18 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT32) { std::shared_ptr c_array; status = color_builder.Finish(&c_array); - // param3: conf + // param3: point size + arrow::UInt32Builder point_size_builder; + status = point_size_builder.Append(2); + status = point_size_builder.Append(4); + status = point_size_builder.Append(6); + status = point_size_builder.Append(8); + status = point_size_builder.Append(10); + + std::shared_ptr s_array; + status = point_size_builder.Finish(&s_array); + + // param4: conf const std::string vega = "{\n" " \"width\": 300,\n" @@ -1734,7 +931,7 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT32) { " \"shape\": {\"value\": \"circle\"},\n" " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5]},\n" + " \"size_bound\": {\"value\": [2.5, 5]},\n" " \"opacity\": {\"value\": 1.0},\n" " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" " }\n" @@ -1743,10 +940,10 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT32) { " ]\n" "}"; - arctern::render::weighted_point_map(x_array, y_array, c_array, vega); + arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); } -TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT64) { +TEST(POINTMAP_RAW_POINT_TEST, UINT64) { // param1: x, y arrow::UInt32Builder x_builder; auto status = x_builder.Append(10); @@ -1779,7 +976,18 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT64) { std::shared_ptr c_array; status = color_builder.Finish(&c_array); - // param3: conf + // param3: point size + arrow::UInt64Builder point_size_builder; + status = point_size_builder.Append(2); + status = point_size_builder.Append(4); + status = point_size_builder.Append(6); + status = point_size_builder.Append(8); + status = point_size_builder.Append(10); + + std::shared_ptr s_array; + status = point_size_builder.Finish(&s_array); + + // param4: conf const std::string vega = "{\n" " \"width\": 300,\n" @@ -1811,7 +1019,7 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT64) { " \"shape\": {\"value\": \"circle\"},\n" " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5]},\n" + " \"size_bound\": {\"value\": [2.5, 5]},\n" " \"opacity\": {\"value\": 1.0},\n" " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" " }\n" @@ -1820,10 +1028,10 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT64) { " ]\n" "}"; - arctern::render::weighted_point_map(x_array, y_array, c_array, vega); + arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); } -TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, FLOAT) { +TEST(POINTMAP_RAW_POINT_TEST, FLOAT) { // param1: x, y arrow::UInt32Builder x_builder; auto status = x_builder.Append(10); @@ -1856,7 +1064,18 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, FLOAT) { std::shared_ptr c_array; status = color_builder.Finish(&c_array); - // param3: conf + // param3: point size + arrow::FloatBuilder point_size_builder; + status = point_size_builder.Append(2); + status = point_size_builder.Append(4); + status = point_size_builder.Append(6); + status = point_size_builder.Append(8); + status = point_size_builder.Append(10); + + std::shared_ptr s_array; + status = point_size_builder.Finish(&s_array); + + // param4: conf const std::string vega = "{\n" " \"width\": 300,\n" @@ -1888,7 +1107,7 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, FLOAT) { " \"shape\": {\"value\": \"circle\"},\n" " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5]},\n" + " \"size_bound\": {\"value\": [2.5, 5]},\n" " \"opacity\": {\"value\": 1.0},\n" " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" " }\n" @@ -1897,10 +1116,10 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, FLOAT) { " ]\n" "}"; - arctern::render::weighted_point_map(x_array, y_array, c_array, vega); + arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); } -TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, DOUBLE) { +TEST(POINTMAP_RAW_POINT_TEST, DOUBLE) { // param1: x, y arrow::UInt32Builder x_builder; auto status = x_builder.Append(10); @@ -1933,7 +1152,18 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, DOUBLE) { std::shared_ptr c_array; status = color_builder.Finish(&c_array); - // param3: conf + // param3: point size + arrow::DoubleBuilder point_size_builder; + status = point_size_builder.Append(2); + status = point_size_builder.Append(4); + status = point_size_builder.Append(6); + status = point_size_builder.Append(8); + status = point_size_builder.Append(10); + + std::shared_ptr s_array; + status = point_size_builder.Finish(&s_array); + + // param4: conf const std::string vega = "{\n" " \"width\": 300,\n" @@ -1965,7 +1195,7 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, DOUBLE) { " \"shape\": {\"value\": \"circle\"},\n" " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"size_bound\": {\"value\": [2.5]},\n" + " \"size_bound\": {\"value\": [2.5, 5]},\n" " \"opacity\": {\"value\": 1.0},\n" " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" " }\n" @@ -1974,9 +1204,779 @@ TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, DOUBLE) { " ]\n" "}"; - arctern::render::weighted_point_map(x_array, y_array, c_array, vega); + arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); } +//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT8) { +// // param1: x, y +// arrow::UInt32Builder x_builder; +// auto status = x_builder.Append(10); +// status = x_builder.Append(40); +// status = x_builder.Append(70); +// status = x_builder.Append(100); +// status = x_builder.Append(130); +// +// std::shared_ptr x_array; +// status = x_builder.Finish(&x_array); +// +// arrow::UInt32Builder y_builder; +// status = y_builder.Append(10); +// status = y_builder.Append(40); +// status = y_builder.Append(70); +// status = y_builder.Append(100); +// status = y_builder.Append(130); +// +// std::shared_ptr y_array; +// status = y_builder.Finish(&y_array); +// +// // param2: color +// arrow::Int8Builder color_builder; +// status = color_builder.Append(1); +// status = color_builder.Append(2); +// status = color_builder.Append(3); +// status = color_builder.Append(4); +// status = color_builder.Append(5); +// +// std::shared_ptr c_array; +// status = color_builder.Finish(&c_array); +// +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 300,\n" +// " \"height\": 200,\n" +// " \"description\": \"weighted_pointmap\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"nyc_taxi\",\n" +// " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"x\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" +// " },\n" +// " {\n" +// " \"name\": \"y\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" +// " \"shape\": {\"value\": \"circle\"},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"size_bound\": {\"value\": [2.5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// arctern::render::weighted_point_map(x_array, y_array, c_array, vega); +//} +// +//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT16) { +// // param1: x, y +// arrow::UInt32Builder x_builder; +// auto status = x_builder.Append(10); +// status = x_builder.Append(40); +// status = x_builder.Append(70); +// status = x_builder.Append(100); +// status = x_builder.Append(130); +// +// std::shared_ptr x_array; +// status = x_builder.Finish(&x_array); +// +// arrow::UInt32Builder y_builder; +// status = y_builder.Append(10); +// status = y_builder.Append(40); +// status = y_builder.Append(70); +// status = y_builder.Append(100); +// status = y_builder.Append(130); +// +// std::shared_ptr y_array; +// status = y_builder.Finish(&y_array); +// +// // param2: color +// arrow::Int16Builder color_builder; +// status = color_builder.Append(1); +// status = color_builder.Append(2); +// status = color_builder.Append(3); +// status = color_builder.Append(4); +// status = color_builder.Append(5); +// +// std::shared_ptr c_array; +// status = color_builder.Finish(&c_array); +// +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 300,\n" +// " \"height\": 200,\n" +// " \"description\": \"weighted_pointmap\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"nyc_taxi\",\n" +// " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"x\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" +// " },\n" +// " {\n" +// " \"name\": \"y\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" +// " \"shape\": {\"value\": \"circle\"},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"size_bound\": {\"value\": [2.5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// arctern::render::weighted_point_map(x_array, y_array, c_array, vega); +//} +// +//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT32) { +// // param1: x, y +// arrow::UInt32Builder x_builder; +// auto status = x_builder.Append(10); +// status = x_builder.Append(40); +// status = x_builder.Append(70); +// status = x_builder.Append(100); +// status = x_builder.Append(130); +// +// std::shared_ptr x_array; +// status = x_builder.Finish(&x_array); +// +// arrow::UInt32Builder y_builder; +// status = y_builder.Append(10); +// status = y_builder.Append(40); +// status = y_builder.Append(70); +// status = y_builder.Append(100); +// status = y_builder.Append(130); +// +// std::shared_ptr y_array; +// status = y_builder.Finish(&y_array); +// +// // param2: color +// arrow::Int32Builder color_builder; +// status = color_builder.Append(1); +// status = color_builder.Append(2); +// status = color_builder.Append(3); +// status = color_builder.Append(4); +// status = color_builder.Append(5); +// +// std::shared_ptr c_array; +// status = color_builder.Finish(&c_array); +// +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 300,\n" +// " \"height\": 200,\n" +// " \"description\": \"weighted_pointmap\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"nyc_taxi\",\n" +// " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"x\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" +// " },\n" +// " {\n" +// " \"name\": \"y\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" +// " \"shape\": {\"value\": \"circle\"},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"size_bound\": {\"value\": [2.5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// arctern::render::weighted_point_map(x_array, y_array, c_array, vega); +//} +// +//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT64) { +// // param1: x, y +// arrow::UInt32Builder x_builder; +// auto status = x_builder.Append(10); +// status = x_builder.Append(40); +// status = x_builder.Append(70); +// status = x_builder.Append(100); +// status = x_builder.Append(130); +// +// std::shared_ptr x_array; +// status = x_builder.Finish(&x_array); +// +// arrow::UInt32Builder y_builder; +// status = y_builder.Append(10); +// status = y_builder.Append(40); +// status = y_builder.Append(70); +// status = y_builder.Append(100); +// status = y_builder.Append(130); +// +// std::shared_ptr y_array; +// status = y_builder.Finish(&y_array); +// +// // param2: color +// arrow::Int64Builder color_builder; +// status = color_builder.Append(1); +// status = color_builder.Append(2); +// status = color_builder.Append(3); +// status = color_builder.Append(4); +// status = color_builder.Append(5); +// +// std::shared_ptr c_array; +// status = color_builder.Finish(&c_array); +// +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 300,\n" +// " \"height\": 200,\n" +// " \"description\": \"weighted_pointmap\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"nyc_taxi\",\n" +// " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"x\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" +// " },\n" +// " {\n" +// " \"name\": \"y\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" +// " \"shape\": {\"value\": \"circle\"},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"size_bound\": {\"value\": [2.5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// arctern::render::weighted_point_map(x_array, y_array, c_array, vega); +//} +// +//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT8) { +// // param1: x, y +// arrow::UInt32Builder x_builder; +// auto status = x_builder.Append(10); +// status = x_builder.Append(40); +// status = x_builder.Append(70); +// status = x_builder.Append(100); +// status = x_builder.Append(130); +// +// std::shared_ptr x_array; +// status = x_builder.Finish(&x_array); +// +// arrow::UInt32Builder y_builder; +// status = y_builder.Append(10); +// status = y_builder.Append(40); +// status = y_builder.Append(70); +// status = y_builder.Append(100); +// status = y_builder.Append(130); +// +// std::shared_ptr y_array; +// status = y_builder.Finish(&y_array); +// +// // param2: color +// arrow::UInt8Builder color_builder; +// status = color_builder.Append(1); +// status = color_builder.Append(2); +// status = color_builder.Append(3); +// status = color_builder.Append(4); +// status = color_builder.Append(5); +// +// std::shared_ptr c_array; +// status = color_builder.Finish(&c_array); +// +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 300,\n" +// " \"height\": 200,\n" +// " \"description\": \"weighted_pointmap\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"nyc_taxi\",\n" +// " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"x\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" +// " },\n" +// " {\n" +// " \"name\": \"y\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" +// " \"shape\": {\"value\": \"circle\"},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"size_bound\": {\"value\": [2.5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// arctern::render::weighted_point_map(x_array, y_array, c_array, vega); +//} +// +//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT16) { +// // param1: x, y +// arrow::UInt32Builder x_builder; +// auto status = x_builder.Append(10); +// status = x_builder.Append(40); +// status = x_builder.Append(70); +// status = x_builder.Append(100); +// status = x_builder.Append(130); +// +// std::shared_ptr x_array; +// status = x_builder.Finish(&x_array); +// +// arrow::UInt32Builder y_builder; +// status = y_builder.Append(10); +// status = y_builder.Append(40); +// status = y_builder.Append(70); +// status = y_builder.Append(100); +// status = y_builder.Append(130); +// +// std::shared_ptr y_array; +// status = y_builder.Finish(&y_array); +// +// // param2: color +// arrow::UInt16Builder color_builder; +// status = color_builder.Append(1); +// status = color_builder.Append(2); +// status = color_builder.Append(3); +// status = color_builder.Append(4); +// status = color_builder.Append(5); +// +// std::shared_ptr c_array; +// status = color_builder.Finish(&c_array); +// +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 300,\n" +// " \"height\": 200,\n" +// " \"description\": \"weighted_pointmap\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"nyc_taxi\",\n" +// " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"x\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" +// " },\n" +// " {\n" +// " \"name\": \"y\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" +// " \"shape\": {\"value\": \"circle\"},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"size_bound\": {\"value\": [2.5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// arctern::render::weighted_point_map(x_array, y_array, c_array, vega); +//} +// +//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT32) { +// // param1: x, y +// arrow::UInt32Builder x_builder; +// auto status = x_builder.Append(10); +// status = x_builder.Append(40); +// status = x_builder.Append(70); +// status = x_builder.Append(100); +// status = x_builder.Append(130); +// +// std::shared_ptr x_array; +// status = x_builder.Finish(&x_array); +// +// arrow::UInt32Builder y_builder; +// status = y_builder.Append(10); +// status = y_builder.Append(40); +// status = y_builder.Append(70); +// status = y_builder.Append(100); +// status = y_builder.Append(130); +// +// std::shared_ptr y_array; +// status = y_builder.Finish(&y_array); +// +// // param2: color +// arrow::UInt32Builder color_builder; +// status = color_builder.Append(1); +// status = color_builder.Append(2); +// status = color_builder.Append(3); +// status = color_builder.Append(4); +// status = color_builder.Append(5); +// +// std::shared_ptr c_array; +// status = color_builder.Finish(&c_array); +// +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 300,\n" +// " \"height\": 200,\n" +// " \"description\": \"weighted_pointmap\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"nyc_taxi\",\n" +// " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"x\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" +// " },\n" +// " {\n" +// " \"name\": \"y\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" +// " \"shape\": {\"value\": \"circle\"},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"size_bound\": {\"value\": [2.5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// arctern::render::weighted_point_map(x_array, y_array, c_array, vega); +//} +// +//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT64) { +// // param1: x, y +// arrow::UInt32Builder x_builder; +// auto status = x_builder.Append(10); +// status = x_builder.Append(40); +// status = x_builder.Append(70); +// status = x_builder.Append(100); +// status = x_builder.Append(130); +// +// std::shared_ptr x_array; +// status = x_builder.Finish(&x_array); +// +// arrow::UInt32Builder y_builder; +// status = y_builder.Append(10); +// status = y_builder.Append(40); +// status = y_builder.Append(70); +// status = y_builder.Append(100); +// status = y_builder.Append(130); +// +// std::shared_ptr y_array; +// status = y_builder.Finish(&y_array); +// +// // param2: color +// arrow::UInt64Builder color_builder; +// status = color_builder.Append(1); +// status = color_builder.Append(2); +// status = color_builder.Append(3); +// status = color_builder.Append(4); +// status = color_builder.Append(5); +// +// std::shared_ptr c_array; +// status = color_builder.Finish(&c_array); +// +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 300,\n" +// " \"height\": 200,\n" +// " \"description\": \"weighted_pointmap\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"nyc_taxi\",\n" +// " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"x\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" +// " },\n" +// " {\n" +// " \"name\": \"y\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" +// " \"shape\": {\"value\": \"circle\"},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"size_bound\": {\"value\": [2.5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// arctern::render::weighted_point_map(x_array, y_array, c_array, vega); +//} +// +//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, FLOAT) { +// // param1: x, y +// arrow::UInt32Builder x_builder; +// auto status = x_builder.Append(10); +// status = x_builder.Append(40); +// status = x_builder.Append(70); +// status = x_builder.Append(100); +// status = x_builder.Append(130); +// +// std::shared_ptr x_array; +// status = x_builder.Finish(&x_array); +// +// arrow::UInt32Builder y_builder; +// status = y_builder.Append(10); +// status = y_builder.Append(40); +// status = y_builder.Append(70); +// status = y_builder.Append(100); +// status = y_builder.Append(130); +// +// std::shared_ptr y_array; +// status = y_builder.Finish(&y_array); +// +// // param2: color +// arrow::FloatBuilder color_builder; +// status = color_builder.Append(1); +// status = color_builder.Append(2); +// status = color_builder.Append(3); +// status = color_builder.Append(4); +// status = color_builder.Append(5); +// +// std::shared_ptr c_array; +// status = color_builder.Finish(&c_array); +// +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 300,\n" +// " \"height\": 200,\n" +// " \"description\": \"weighted_pointmap\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"nyc_taxi\",\n" +// " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"x\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" +// " },\n" +// " {\n" +// " \"name\": \"y\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" +// " \"shape\": {\"value\": \"circle\"},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"size_bound\": {\"value\": [2.5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// arctern::render::weighted_point_map(x_array, y_array, c_array, vega); +//} +// +//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, DOUBLE) { +// // param1: x, y +// arrow::UInt32Builder x_builder; +// auto status = x_builder.Append(10); +// status = x_builder.Append(40); +// status = x_builder.Append(70); +// status = x_builder.Append(100); +// status = x_builder.Append(130); +// +// std::shared_ptr x_array; +// status = x_builder.Finish(&x_array); +// +// arrow::UInt32Builder y_builder; +// status = y_builder.Append(10); +// status = y_builder.Append(40); +// status = y_builder.Append(70); +// status = y_builder.Append(100); +// status = y_builder.Append(130); +// +// std::shared_ptr y_array; +// status = y_builder.Finish(&y_array); +// +// // param2: color +// arrow::DoubleBuilder color_builder; +// status = color_builder.Append(1); +// status = color_builder.Append(2); +// status = color_builder.Append(3); +// status = color_builder.Append(4); +// status = color_builder.Append(5); +// +// std::shared_ptr c_array; +// status = color_builder.Finish(&c_array); +// +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 300,\n" +// " \"height\": 200,\n" +// " \"description\": \"weighted_pointmap\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"nyc_taxi\",\n" +// " \"url\": \"data/nyc_taxi_0_5m.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"x\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"longitude_pickup\"}\n" +// " },\n" +// " {\n" +// " \"name\": \"y\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"nyc_taxi\", \"field\": \"latitude_pickup\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": [-73.998427, 40.730309, -73.954348, 40.780816],\n" +// " \"shape\": {\"value\": \"circle\"},\n" +// " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"size_bound\": {\"value\": [2.5]},\n" +// " \"opacity\": {\"value\": 1.0},\n" +// " \"coordinate_system\": {\"value\": \"EPSG:3857\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// arctern::render::weighted_point_map(x_array, y_array, c_array, vega); +//} + TEST(POINTMAP_RAW_POINT_TEST, BLUE_TO_RED) { // param1: x, y arrow::UInt32Builder x_builder; @@ -2829,7 +2829,10 @@ TEST(POINTMAP_WKT_TEST, SINGLE_COLOR_SINGLE_POINTSIZE) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, vega); + + std::vector> point_vec{wkb}; + + arctern::render::weighted_point_map(point_vec, vega); } TEST(POINTMAP_WKT_TEST, MULTIPLE_COLOR_SINGLE_POINTSIZE) { @@ -2903,7 +2906,11 @@ TEST(POINTMAP_WKT_TEST, MULTIPLE_COLOR_SINGLE_POINTSIZE) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST, SINGLE_COLOR_MULTIPLE_POINTSIZE) { @@ -2977,7 +2984,11 @@ TEST(POINTMAP_WKT_TEST, SINGLE_COLOR_MULTIPLE_POINTSIZE) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, MULTIPLE_COLOR_MULTIPLE_POINTSIZE) { @@ -3062,7 +3073,12 @@ TEST(POINTMAP_WKT_TEST, MULTIPLE_COLOR_MULTIPLE_POINTSIZE) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, INT8) { @@ -3147,7 +3163,12 @@ TEST(POINTMAP_WKT_TEST, INT8) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, INT16) { @@ -3232,7 +3253,12 @@ TEST(POINTMAP_WKT_TEST, INT16) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, INT32) { @@ -3317,7 +3343,12 @@ TEST(POINTMAP_WKT_TEST, INT32) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, INT64) { @@ -3402,7 +3433,12 @@ TEST(POINTMAP_WKT_TEST, INT64) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, UINT8) { @@ -3487,7 +3523,12 @@ TEST(POINTMAP_WKT_TEST, UINT8) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, UINT16) { @@ -3572,7 +3613,12 @@ TEST(POINTMAP_WKT_TEST, UINT16) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, UINT32) { @@ -3657,7 +3703,12 @@ TEST(POINTMAP_WKT_TEST, UINT32) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, UINT64) { @@ -3742,7 +3793,12 @@ TEST(POINTMAP_WKT_TEST, UINT64) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, FLOAT) { @@ -3827,7 +3883,12 @@ TEST(POINTMAP_WKT_TEST, FLOAT) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, DOUBLE) { @@ -3912,7 +3973,12 @@ TEST(POINTMAP_WKT_TEST, DOUBLE) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, MEAN) { @@ -3997,7 +4063,12 @@ TEST(POINTMAP_WKT_TEST, MEAN) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, SUM) { @@ -4082,7 +4153,12 @@ TEST(POINTMAP_WKT_TEST, SUM) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, MAX) { @@ -4167,7 +4243,12 @@ TEST(POINTMAP_WKT_TEST, MAX) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, MIN) { @@ -4252,7 +4333,12 @@ TEST(POINTMAP_WKT_TEST, MIN) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, COUNT) { @@ -4337,7 +4423,12 @@ TEST(POINTMAP_WKT_TEST, COUNT) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, STD) { @@ -4422,7 +4513,12 @@ TEST(POINTMAP_WKT_TEST, STD) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, INT8) { @@ -4496,7 +4592,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, INT8) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, INT16) { @@ -4570,7 +4670,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, INT16) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, INT32) { @@ -4644,7 +4748,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, INT32) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, INT64) { @@ -4718,7 +4826,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, INT64) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, UINT8) { @@ -4792,7 +4904,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, UINT8) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, UINT16) { @@ -4866,7 +4982,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, UINT16) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, UINT32) { @@ -4940,7 +5060,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, UINT32) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, UINT64) { @@ -5014,7 +5138,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, UINT64) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, FLOAT) { @@ -5088,7 +5216,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, FLOAT) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, DOUBLE) { @@ -5162,7 +5294,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, DOUBLE) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, MEAN) { @@ -5236,7 +5372,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, MEAN) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, SUM) { @@ -5310,7 +5450,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, SUM) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, MAX) { @@ -5384,7 +5528,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, MAX) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, MIN) { @@ -5458,7 +5606,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, MIN) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, COUNT) { @@ -5532,7 +5684,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, COUNT) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, STD) { @@ -5606,7 +5762,11 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, STD) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, vega); } TEST(POINTMAP_WKT_TEST, BLUE_TO_RED) { @@ -5691,7 +5851,12 @@ TEST(POINTMAP_WKT_TEST, BLUE_TO_RED) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, SKYBLUE_TO_RED) { @@ -5776,7 +5941,12 @@ TEST(POINTMAP_WKT_TEST, SKYBLUE_TO_RED) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, PURPLE_TO_YELLOW) { @@ -5861,7 +6031,12 @@ TEST(POINTMAP_WKT_TEST, PURPLE_TO_YELLOW) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, RED_TRANSPARENCY) { @@ -5946,7 +6121,12 @@ TEST(POINTMAP_WKT_TEST, RED_TRANSPARENCY) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, BLUE_TRANSPARENCY) { @@ -6031,7 +6211,12 @@ TEST(POINTMAP_WKT_TEST, BLUE_TRANSPARENCY) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, BLUE_GREEN_YELLOW) { @@ -6116,7 +6301,12 @@ TEST(POINTMAP_WKT_TEST, BLUE_GREEN_YELLOW) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, WHITE_BLUE) { @@ -6201,7 +6391,12 @@ TEST(POINTMAP_WKT_TEST, WHITE_BLUE) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, BLUE_WHITE_RED) { @@ -6286,7 +6481,12 @@ TEST(POINTMAP_WKT_TEST, BLUE_WHITE_RED) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } TEST(POINTMAP_WKT_TEST, GREEN_YELLOW_RED) { @@ -6371,5 +6571,10 @@ TEST(POINTMAP_WKT_TEST, GREEN_YELLOW_RED) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - arctern::render::weighted_point_map(wkb, c_array, s_array, vega); + + std::vector> point_vec{wkb}; + std::vector> color_vec{c_array}; + std::vector> size_vec{s_array}; + + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index f0cf76736..f8f50604c 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1136,10 +1136,10 @@ def projection(geos, bottom_right, top_left, height, width): geos_rs.append(geos) geos = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) - pd_rs = geos[0] + pd_rs = geos[0].to_pandas() if len(geos) >= 2: for i in range(1, len(geos)): - pd_rs.append(geos[i]) + pd_rs.append(geos[i].to_pandas()) return pd_rs @@ -1162,12 +1162,15 @@ def transform_and_projection(geos, src_rs, dst_rs, bottom_right, top_left, heigh else: geos_rs.append(geos) + print("python enter transform") geos = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) - pd_rs = geos[0] + pd_rs = geos[0].to_pandas() if len(geos) >= 2: for i in range(1, len(geos)): - pd_rs.append(geos[i]) + pd_rs.append(geos[i].to_pandas()) + print("python transform done") + print(type(pd_rs)) return pd_rs @@ -1189,6 +1192,17 @@ def point_map_layer(vega, points, transform=True): import pyarrow as pa geos = pa.array(points, type='binary') + # TODO: delete + print("data prepare ok") + # transform and projection handler + geos_rs = [] + if isinstance(geos, pa.lib.ChunkedArray): + for chunk_idx in range(geos.num_chunks): + geos_rs.append(geos.chunk(chunk_idx)) + else: + print("only one chunk") + geos_rs.append(geos) + if transform: bounding_box = vega.bounding_box() top_left = 'POINT (' + str(bounding_box[0]) + ' ' + str(bounding_box[3]) + ')' @@ -1203,28 +1217,15 @@ def point_map_layer(vega, points, transform=True): bounding_box_min = bytes(top_left, encoding="utf8") bounding_box_max = bytes(bottom_right, encoding="utf8") - # TODO: delete - print("data prepare ok") - # transform and projection handler - geos_rs = [] - if isinstance(geos, pa.lib.ChunkedArray): - print("chunk num:") - print(geos.num_chunks) - for chunk_idx in range(geos.num_chunks): - geos_rs.append(geos.chunk(chunk_idx)) - else: - print("only one chunk") - geos_rs.append(geos) - # transform and projection if coor != 'EPSG:3857': - geos = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) + geos_rs = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) else: - geos = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) + geos_rs = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) print("transform done") vega_string = vega.build().encode('utf-8') - rs = arctern_core_.point_map(vega_string, geos) + rs = arctern_core_.point_map(vega_string, geos_rs) print("draw map, Done!!!") return base64.b64encode(rs.buffers()[1].to_pybytes()) @@ -1238,6 +1239,16 @@ def weighted_point_map_layer(vega, points, transform=True, **kwargs): geos = pa.array(points, type='binary') + # TODO: delete + print("data prepare ok") + # transform and projection handler + geos_rs = [] + if isinstance(geos, pa.lib.ChunkedArray): + for chunk_idx in range(geos.num_chunks): + geos_rs.append(geos.chunk(chunk_idx)) + else: + geos_rs.append(geos) + if transform: bounding_box = vega.bounding_box() top_left = 'POINT (' + str(bounding_box[0]) + ' ' + str(bounding_box[3]) + ')' @@ -1252,27 +1263,14 @@ def weighted_point_map_layer(vega, points, transform=True, **kwargs): bounding_box_min = bytes(top_left, encoding="utf8") bounding_box_max = bytes(bottom_right, encoding="utf8") - # TODO: delete - print("data prepare ok") - # transform and projection handler - geos_rs = [] - if isinstance(geos, pa.lib.ChunkedArray): - print("chunk num:") - print(geos.num_chunks) - for chunk_idx in range(geos.num_chunks): - geos_rs.append(geos.chunk(chunk_idx)) - else: - print("only one chunk") - geos_rs.append(geos) - # transform and projection if coor != 'EPSG:3857': - geos = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) + geos_rs = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) else: - geos = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) + geos_rs = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) if color_weights is None and size_weights is None: - rs = arctern_core_.weighted_point_map(vega_string, geos) + rs = arctern_core_.weighted_point_map(vega_string, geos_rs) elif color_weights is not None and size_weights is not None: if color_weights.dtypes == 'float64': arr_c = pa.array(color_weights, type='double') @@ -1295,7 +1293,7 @@ def weighted_point_map_layer(vega, points, transform=True, **kwargs): else: size_weights_rs.append(arr_s) print("weights handle done") - rs = arctern_core_.weighted_color_size_point_map(vega_string, geos, color_weights_rs, size_weights_rs) + rs = arctern_core_.weighted_color_size_point_map(vega_string, geos_rs, color_weights_rs, size_weights_rs) elif color_weights is None and size_weights is not None: if size_weights.dtypes == 'float64': arr_s = pa.array(size_weights, type='double') @@ -1308,7 +1306,7 @@ def weighted_point_map_layer(vega, points, transform=True, **kwargs): else: size_weights_rs.append(arr_s) print("weights handle done") - rs = arctern_core_.weighted_size_point_map(vega_string, geos, size_weights_rs) + rs = arctern_core_.weighted_size_point_map(vega_string, geos_rs, size_weights_rs) else: if color_weights.dtypes == 'float64': arr_c = pa.array(color_weights, type='double') @@ -1321,7 +1319,7 @@ def weighted_point_map_layer(vega, points, transform=True, **kwargs): else: color_weights_rs.append(arr_c) print("weights handle done") - rs = arctern_core_.weighted_color_point_map(vega_string, geos, color_weights_rs) + rs = arctern_core_.weighted_color_point_map(vega_string, geos_rs, color_weights_rs) return base64.b64encode(rs.buffers()[1].to_pybytes()) @@ -1330,6 +1328,16 @@ def heat_map_layer(vega, points, weights, transform=True): import pyarrow as pa geos = pa.array(points, type='binary') + # TODO: delete + print("data prepare ok") + # transform and projection handler + geos_rs = [] + if isinstance(geos, pa.lib.ChunkedArray): + for chunk_idx in range(geos.num_chunks): + geos_rs.append(geos.chunk(chunk_idx)) + else: + geos_rs.append(geos) + if transform: bounding_box = vega.bounding_box() top_left = 'POINT (' + str(bounding_box[0]) + ' ' + str(bounding_box[3]) + ')' @@ -1344,21 +1352,11 @@ def heat_map_layer(vega, points, weights, transform=True): bounding_box_min = bytes(top_left, encoding="utf8") bounding_box_max = bytes(bottom_right, encoding="utf8") - # TODO: delete - print("data prepare ok") - # transform and projection handler - geos_rs = [] - if isinstance(geos, pa.lib.ChunkedArray): - for chunk_idx in range(geos.num_chunks): - geos_rs.append(geos.chunk(chunk_idx)) - else: - geos_rs.append(geos) - # transform and projection if coor != 'EPSG:3857': - geos = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) + geos_rs = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) else: - geos = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) + geos_rs = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) print("transform done") # weights handler @@ -1378,7 +1376,7 @@ def heat_map_layer(vega, points, weights, transform=True): print("weights handle done") vega_string = vega.build().encode('utf-8') - rs = arctern_core_.heat_map(vega_string, geos, weights_rs) + rs = arctern_core_.heat_map(vega_string, geos_rs, weights_rs) return base64.b64encode(rs.buffers()[1].to_pybytes()) @@ -1386,6 +1384,16 @@ def choropleth_map_layer(vega, region_boundaries, weights, transform=True): import pyarrow as pa geos = pa.array(region_boundaries, type='binary') + # TODO: delete + print("data prepare ok") + # transform and projection handler + geos_rs = [] + if isinstance(geos, pa.lib.ChunkedArray): + for chunk_idx in range(geos.num_chunks): + geos_rs.append(geos.chunk(chunk_idx)) + else: + geos_rs.append(geos) + if transform: bounding_box = vega.bounding_box() top_left = 'POINT (' + str(bounding_box[0]) + ' ' + str(bounding_box[3]) + ')' @@ -1400,22 +1408,11 @@ def choropleth_map_layer(vega, region_boundaries, weights, transform=True): bounding_box_min = bytes(top_left, encoding="utf8") bounding_box_max = bytes(bottom_right, encoding="utf8") - # TODO: delete - print("data prepare ok") - # transform and projection handler - geos_rs = [] - if isinstance(geos, pa.lib.ChunkedArray): - for chunk_idx in range(geos.num_chunks): - geos_rs.append(geos.chunk(chunk_idx)) - else: - geos_rs.append(geos) - # transform and projection if coor != 'EPSG:3857': - geos = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) - print(type(geos)) + geos_rs = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) else: - geos = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) + geos_rs = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) vega_string = vega.build().encode('utf-8') @@ -1435,7 +1432,7 @@ def choropleth_map_layer(vega, region_boundaries, weights, transform=True): print("weights handle done") - rs = arctern_core_.choropleth_map(vega_string, geos, weights_rs) + rs = arctern_core_.choropleth_map(vega_string, geos_rs, weights_rs) print("draw map, Done!!!") return base64.b64encode(rs.buffers()[1].to_pybytes()) @@ -1444,6 +1441,16 @@ def icon_viz_layer(vega, points, transform=True): import pyarrow as pa geos = pa.array(points, type='binary') + # TODO: delete + print("data prepare ok") + # transform and projection handler + geos_rs = [] + if isinstance(geos, pa.lib.ChunkedArray): + for chunk_idx in range(geos.num_chunks): + geos_rs.append(geos.chunk(chunk_idx)) + else: + geos_rs.append(geos) + if transform: bounding_box = vega.bounding_box() top_left = 'POINT (' + str(bounding_box[0]) + ' ' + str(bounding_box[3]) + ')' @@ -1458,28 +1465,15 @@ def icon_viz_layer(vega, points, transform=True): bounding_box_min = bytes(top_left, encoding="utf8") bounding_box_max = bytes(bottom_right, encoding="utf8") - # TODO: delete - print("data prepare ok") - # transform and projection handler - geos_rs = [] - if isinstance(geos, pa.lib.ChunkedArray): - print("chunk num:") - print(geos.num_chunks) - for chunk_idx in range(geos.num_chunks): - geos_rs.append(geos.chunk(chunk_idx)) - else: - print("only one chunk") - geos_rs.append(geos) - # transform and projection if coor != 'EPSG:3857': - geos = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) + geos_rs = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) else: - geos = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) + geos_rs = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) print("transform done") vega_string = vega.build().encode('utf-8') - rs = arctern_core_.icon_viz(vega_string, geos) + rs = arctern_core_.icon_viz(vega_string, geos_rs) print("draw map, Done!!!") return base64.b64encode(rs.buffers()[1].to_pybytes()) From 82995233d5ac2bc884b6ab82d77efc95b377446d Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Wed, 29 Apr 2020 20:04:32 +0800 Subject: [PATCH 20/24] remove redundant print msg --- cpp/src/arrow/render_api.cpp | 11 ---------- cpp/src/render/render_builder_impl.h | 2 -- cpp/src/render/utils/render_utils.cpp | 2 +- python/arctern/_wrapper_func.py | 29 --------------------------- 4 files changed, 1 insertion(+), 43 deletions(-) diff --git a/cpp/src/arrow/render_api.cpp b/cpp/src/arrow/render_api.cpp index e375abda9..79ad4e204 100644 --- a/cpp/src/arrow/render_api.cpp +++ b/cpp/src/arrow/render_api.cpp @@ -453,11 +453,8 @@ const std::vector> projection( const std::vector>& geos, const std::string& bottom_right, const std::string& top_left, const int& height, const int& width) { - std::cout << "c++ proj enter c++" << std::endl; const auto& geo_vec = GeometryExtraction(geos); - std::cout << "c++ geo extract ok" << std::endl; Projection(geo_vec, bottom_right, top_left, height, width); - std::cout << "c++ proj ok" << std::endl; const auto& res = GeometryExport(geo_vec, geos.size()); return res; } @@ -466,13 +463,9 @@ const std::vector> transform_and_projection( const std::vector>& geos, const std::string& src_rs, const std::string& dst_rs, const std::string& bottom_right, const std::string& top_left, const int& height, const int& width) { - std::cout << "c++ trans enter c++" << std::endl; const auto& geo_vec = GeometryExtraction(geos); - std::cout << "c++ geo extract ok" << std::endl; TransformAndProjection(geo_vec, src_rs, dst_rs, bottom_right, top_left, height, width); - std::cout << "c++ transform and proj ok" << std::endl; const auto& res = GeometryExport(geo_vec, geos.size()); - std::cout << "c++ GeometryExport ok" << std::endl; return res; } @@ -480,7 +473,6 @@ std::shared_ptr point_map( const std::vector>& points_vector, const std::string& conf) { const auto& wkb_vec = WkbExtraction(points_vector); - std::cout << "wkb extraction, done" << std::endl; auto num_of_point = wkb_vec.size(); std::vector input_x(num_of_point); @@ -520,7 +512,6 @@ std::shared_ptr weighted_point_map( const std::vector>& points_vector, const std::string& conf) { const auto& wkb_vec = WkbExtraction(points_vector); - std::cout << "wkb extraction, done" << std::endl; auto num_of_point = wkb_vec.size(); std::vector input_x(num_of_point); @@ -939,7 +930,6 @@ std::shared_ptr icon_viz( const std::vector>& points_vector, const std::string& conf) { const auto& wkb_vec = WkbExtraction(points_vector); - std::cout << "wkb extraction, done" << std::endl; auto num_of_point = wkb_vec.size(); std::vector input_x(num_of_point); @@ -954,7 +944,6 @@ std::shared_ptr icon_viz( input_y[i] = rs_pointer->getY(); } - std::cout << "c++ enter draw map" << std::endl; auto result = iconviz(&input_x[0], &input_y[0], num_of_point, conf); return out_pic(result); diff --git a/cpp/src/render/render_builder_impl.h b/cpp/src/render/render_builder_impl.h index ccee30996..2ae691054 100644 --- a/cpp/src/render/render_builder_impl.h +++ b/cpp/src/render/render_builder_impl.h @@ -209,8 +209,6 @@ std::pair, std::vector>> weight_agg( template std::pair, std::vector>> weight_agg( const std::vector& wkb_arr, const std::vector& arr_c) { - std::cout << "wkb size = " << wkb_arr.size() << ", arr_c.size = " << arr_c.size() - << std::endl; assert(wkb_arr.size() == arr_c.size()); std::unordered_map> wkb_map; diff --git a/cpp/src/render/utils/render_utils.cpp b/cpp/src/render/utils/render_utils.cpp index a9457a01f..4fb190943 100644 --- a/cpp/src/render/utils/render_utils.cpp +++ b/cpp/src/render/utils/render_utils.cpp @@ -32,7 +32,7 @@ std::vector GeometryExtraction( total_size += arr->length(); } std::vector geos_res(total_size); - std::cout << "total_size = " << total_size << std::endl; + int index = 0; for (const auto& arr : arrs) { assert(arr->type_id() == arrow::Type::BINARY); diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index f8f50604c..9afdce1e1 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1162,15 +1162,12 @@ def transform_and_projection(geos, src_rs, dst_rs, bottom_right, top_left, heigh else: geos_rs.append(geos) - print("python enter transform") geos = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) pd_rs = geos[0].to_pandas() if len(geos) >= 2: for i in range(1, len(geos)): pd_rs.append(geos[i].to_pandas()) - print("python transform done") - print(type(pd_rs)) return pd_rs @@ -1192,15 +1189,12 @@ def point_map_layer(vega, points, transform=True): import pyarrow as pa geos = pa.array(points, type='binary') - # TODO: delete - print("data prepare ok") # transform and projection handler geos_rs = [] if isinstance(geos, pa.lib.ChunkedArray): for chunk_idx in range(geos.num_chunks): geos_rs.append(geos.chunk(chunk_idx)) else: - print("only one chunk") geos_rs.append(geos) if transform: @@ -1222,11 +1216,9 @@ def point_map_layer(vega, points, transform=True): geos_rs = arctern_core_.transform_and_projection(geos_rs, src, dst, bounding_box_max, bounding_box_min, height, width) else: geos_rs = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) - print("transform done") vega_string = vega.build().encode('utf-8') rs = arctern_core_.point_map(vega_string, geos_rs) - print("draw map, Done!!!") return base64.b64encode(rs.buffers()[1].to_pybytes()) @@ -1239,8 +1231,6 @@ def weighted_point_map_layer(vega, points, transform=True, **kwargs): geos = pa.array(points, type='binary') - # TODO: delete - print("data prepare ok") # transform and projection handler geos_rs = [] if isinstance(geos, pa.lib.ChunkedArray): @@ -1292,7 +1282,6 @@ def weighted_point_map_layer(vega, points, transform=True, **kwargs): size_weights_rs.append(arr_s.chunk(chunk_idx)) else: size_weights_rs.append(arr_s) - print("weights handle done") rs = arctern_core_.weighted_color_size_point_map(vega_string, geos_rs, color_weights_rs, size_weights_rs) elif color_weights is None and size_weights is not None: if size_weights.dtypes == 'float64': @@ -1305,7 +1294,6 @@ def weighted_point_map_layer(vega, points, transform=True, **kwargs): size_weights_rs.append(arr_s.chunk(chunk_idx)) else: size_weights_rs.append(arr_s) - print("weights handle done") rs = arctern_core_.weighted_size_point_map(vega_string, geos_rs, size_weights_rs) else: if color_weights.dtypes == 'float64': @@ -1318,7 +1306,6 @@ def weighted_point_map_layer(vega, points, transform=True, **kwargs): color_weights_rs.append(arr_c.chunk(chunk_idx)) else: color_weights_rs.append(arr_c) - print("weights handle done") rs = arctern_core_.weighted_color_point_map(vega_string, geos_rs, color_weights_rs) return base64.b64encode(rs.buffers()[1].to_pybytes()) @@ -1328,8 +1315,6 @@ def heat_map_layer(vega, points, weights, transform=True): import pyarrow as pa geos = pa.array(points, type='binary') - # TODO: delete - print("data prepare ok") # transform and projection handler geos_rs = [] if isinstance(geos, pa.lib.ChunkedArray): @@ -1358,7 +1343,6 @@ def heat_map_layer(vega, points, weights, transform=True): else: geos_rs = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) - print("transform done") # weights handler if weights.dtypes == 'float64': arr = pa.array(weights, type='double') @@ -1367,13 +1351,10 @@ def heat_map_layer(vega, points, weights, transform=True): weights_rs = [] if isinstance(arr, pa.lib.ChunkedArray): - print("num_chunks:") - print(arr.num_chunks) for chunk_idx in range(arr.num_chunks): weights_rs.append(arr.chunk(chunk_idx)) else: weights_rs.append(arr) - print("weights handle done") vega_string = vega.build().encode('utf-8') rs = arctern_core_.heat_map(vega_string, geos_rs, weights_rs) @@ -1384,8 +1365,6 @@ def choropleth_map_layer(vega, region_boundaries, weights, transform=True): import pyarrow as pa geos = pa.array(region_boundaries, type='binary') - # TODO: delete - print("data prepare ok") # transform and projection handler geos_rs = [] if isinstance(geos, pa.lib.ChunkedArray): @@ -1416,7 +1395,6 @@ def choropleth_map_layer(vega, region_boundaries, weights, transform=True): vega_string = vega.build().encode('utf-8') - print("transform done") # weights handler if weights.dtypes == 'float64': arr_c = pa.array(weights, type='double') @@ -1430,10 +1408,7 @@ def choropleth_map_layer(vega, region_boundaries, weights, transform=True): else: weights_rs.append(arr_c) - print("weights handle done") - rs = arctern_core_.choropleth_map(vega_string, geos_rs, weights_rs) - print("draw map, Done!!!") return base64.b64encode(rs.buffers()[1].to_pybytes()) @@ -1441,8 +1416,6 @@ def icon_viz_layer(vega, points, transform=True): import pyarrow as pa geos = pa.array(points, type='binary') - # TODO: delete - print("data prepare ok") # transform and projection handler geos_rs = [] if isinstance(geos, pa.lib.ChunkedArray): @@ -1471,9 +1444,7 @@ def icon_viz_layer(vega, points, transform=True): else: geos_rs = arctern_core_.projection(geos_rs, bounding_box_max, bounding_box_min, height, width) - print("transform done") vega_string = vega.build().encode('utf-8') rs = arctern_core_.icon_viz(vega_string, geos_rs) - print("draw map, Done!!!") return base64.b64encode(rs.buffers()[1].to_pybytes()) From 8cb7109121d6f204782580285e7ddd4385647c07 Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Wed, 29 Apr 2020 20:33:58 +0800 Subject: [PATCH 21/24] code format, cpp and python --- cpp/src/arrow/render_api.h | 1 + cpp/src/render/utils/render_utils.cpp | 3 +- cpp/src/render/utils/render_utils.h | 3 + cpp/unittest/render/choropleth_map_test.cpp | 3208 ++++++++--------- .../render/weighted_pointmap_test.cpp | 110 +- python/arctern/_wrapper_func.py | 6 + 6 files changed, 1671 insertions(+), 1660 deletions(-) diff --git a/cpp/src/arrow/render_api.h b/cpp/src/arrow/render_api.h index ddb65537d..ec513fb7c 100644 --- a/cpp/src/arrow/render_api.h +++ b/cpp/src/arrow/render_api.h @@ -17,6 +17,7 @@ #include #include +#include #include "arrow/api.h" diff --git a/cpp/src/render/utils/render_utils.cpp b/cpp/src/render/utils/render_utils.cpp index 4fb190943..c91fa3b6e 100644 --- a/cpp/src/render/utils/render_utils.cpp +++ b/cpp/src/render/utils/render_utils.cpp @@ -15,7 +15,8 @@ */ #include #include -#include +#include +#include #include #include "arrow/render_api.h" diff --git a/cpp/src/render/utils/render_utils.h b/cpp/src/render/utils/render_utils.h index ecb539fea..e19118121 100644 --- a/cpp/src/render/utils/render_utils.h +++ b/cpp/src/render/utils/render_utils.h @@ -17,6 +17,9 @@ #include #include +#include +#include +#include #include "arrow/render_api.h" diff --git a/cpp/unittest/render/choropleth_map_test.cpp b/cpp/unittest/render/choropleth_map_test.cpp index 6ed545a68..c5e09bfae 100644 --- a/cpp/unittest/render/choropleth_map_test.cpp +++ b/cpp/unittest/render/choropleth_map_test.cpp @@ -17,1694 +17,1694 @@ #include "arrow/render_api.h" - TEST(CHOROPLETHMAP_TEST, BLUE_TO_RED) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; +TEST(CHOROPLETHMAP_TEST, BLUE_TO_RED) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); +} + +TEST(CHOROPLETHMAP_TEST, SKYBLUE_TO_WHITE) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#B4E7F5\", \"#FFFFFF\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); +} + +TEST(CHOROPLETHMAP_TEST, GREEN_YELLOW_RED) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#4D904F\", \"#C23728\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); +} + +TEST(CHOROPLETHMAP_TEST, BLUE_WHITE_RED) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#1984C5\", \"#C23728\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); +} + +TEST(CHOROPLETHMAP_TEST, WHITE_BLUE) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#E2E2E2\", \"#115F9A\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); +} + +TEST(CHOROPLETHMAP_TEST, BLUE_GREEN_YELLOW) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#115F9A\", \"#D0F401\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); +} + +TEST(CHOROPLETHMAP_TEST, BLUE_TRANSPARENCY) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#0000FF\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); +} + +TEST(CHOROPLETHMAP_TEST, RED_TRANSPARENCY) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#FF0000\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); +} + +TEST(CHOROPLETHMAP_TEST, PURPLE_TO_YELLOW) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#FF00FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); +} + +// TEST(CHOROPLETHMAP_TEST, INVALID_color_gradient_TEST) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); +// +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); +// +// // param2: color +// std::shared_ptr color_array; +// arrow::UInt32Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); +// +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": \"xxxxxx\"},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +//} + +// TEST(CHOROPLETHMAP_TEST, INVALID_JSON_TEST) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); +// +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); +// +// // param2: color +// std::shared_ptr color_array; +// arrow::UInt32Builder color_builder; +// status = color_builder.Append(5); +// status = color_builder.Finish(&color_array); +// +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": \"blue_to_red\"},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": \"INVALID_NUMBER\"}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +//} + +TEST(CHOROPLETHMAP_TEST, INT8) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::Int8Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); +} + +TEST(CHOROPLETHMAP_TEST, INT16) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::Int16Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); +} + +TEST(CHOROPLETHMAP_TEST, INT32) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::Int32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); +} + +TEST(CHOROPLETHMAP_TEST, INT64) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::Int64Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); +} + +TEST(CHOROPLETHMAP_TEST, UINT8) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt8Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); +} + +TEST(CHOROPLETHMAP_TEST, UINT16) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::UInt16Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; + + auto wkb = arctern::render::WktToWkb(string_array); + std::vector> polygon_vec{wkb}; + + std::vector> color_vec{color_array}; + arctern::render::choropleth_map(polygon_vec, color_vec, vega); +} + +TEST(CHOROPLETHMAP_TEST, UINT32) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); - auto wkb = arctern::render::WktToWkb(string_array); - std::vector> polygon_vec{wkb}; + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); - std::vector> color_vec{color_array}; - arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, SKYBLUE_TO_WHITE) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#B4E7F5\", \"#FFFFFF\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + // param2: color + std::shared_ptr color_array; + arrow::UInt32Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; auto wkb = arctern::render::WktToWkb(string_array); std::vector> polygon_vec{wkb}; std::vector> color_vec{color_array}; arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, GREEN_YELLOW_RED) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#4D904F\", \"#C23728\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; +} - auto wkb = arctern::render::WktToWkb(string_array); - std::vector> polygon_vec{wkb}; +TEST(CHOROPLETHMAP_TEST, UINT64) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); - std::vector> color_vec{color_array}; - arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, BLUE_WHITE_RED) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#1984C5\", \"#C23728\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); - auto wkb = arctern::render::WktToWkb(string_array); - std::vector> polygon_vec{wkb}; + // param2: color + std::shared_ptr color_array; + arrow::UInt64Builder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); - std::vector> color_vec{color_array}; - arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, WHITE_BLUE) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#E2E2E2\", \"#115F9A\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; auto wkb = arctern::render::WktToWkb(string_array); std::vector> polygon_vec{wkb}; std::vector> color_vec{color_array}; arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, BLUE_GREEN_YELLOW) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#115F9A\", \"#D0F401\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; +} - auto wkb = arctern::render::WktToWkb(string_array); - std::vector> polygon_vec{wkb}; +TEST(CHOROPLETHMAP_TEST, FLOAT) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); - std::vector> color_vec{color_array}; - arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, BLUE_TRANSPARENCY) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#0000FF\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); - auto wkb = arctern::render::WktToWkb(string_array); - std::vector> polygon_vec{wkb}; + // param2: color + std::shared_ptr color_array; + arrow::FloatBuilder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); - std::vector> color_vec{color_array}; - arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, RED_TRANSPARENCY) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#FF0000\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; auto wkb = arctern::render::WktToWkb(string_array); std::vector> polygon_vec{wkb}; std::vector> color_vec{color_array}; arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, PURPLE_TO_YELLOW) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#FF00FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; +} - auto wkb = arctern::render::WktToWkb(string_array); - std::vector> polygon_vec{wkb}; +TEST(CHOROPLETHMAP_TEST, DOUBLE) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); - std::vector> color_vec{color_array}; - arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - // TEST(CHOROPLETHMAP_TEST, INVALID_color_gradient_TEST) { - // // param1: wkt string - // std::string wkt_string1 = - // "POLYGON ((" - // "200 200, " - // "200 300, " - // "300 300, " - // "300 200, " - // "200 200))"; - // arrow::StringBuilder string_builder; - // auto status = string_builder.Append(wkt_string1); - // - // std::shared_ptr string_array; - // status = string_builder.Finish(&string_array); - // - // // param2: color - // std::shared_ptr color_array; - // arrow::UInt32Builder color_builder; - // status = color_builder.Append(5); - // status = color_builder.Finish(&color_array); - // - // // param3: conf - // const std::string vega = - // "{\n" - // " \"width\": 1900,\n" - // " \"height\": 1410,\n" - // " \"description\": \"choropleth_map\",\n" - // " \"data\": [\n" - // " {\n" - // " \"name\": \"data\",\n" - // " \"url\": \"data/data.csv\"\n" - // " }\n" - // " ],\n" - // " \"scales\": [\n" - // " {\n" - // " \"name\": \"building\",\n" - // " \"type\": \"linear\",\n" - // " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - // " }\n" - // " ],\n" - // " \"marks\": [\n" - // " {\n" - // " \"encode\": {\n" - // " \"enter\": {\n" - // " \"bounding_box\": {\"value\": " - // "[-73.984092,40.753893,-73.977588,40.756342]},\n" - // " \"color_gradient\": {\"value\": \"xxxxxx\"},\n" - // " \"color_bound\": {\"value\": [2.5, 5]},\n" - // " \"opacity\": {\"value\": 1.0}\n" - // " }\n" - // " }\n" - // " }\n" - // " ]\n" - // "}"; - // - // auto wkb = arctern::render::WktToWkb(string_array); - // arctern::render::choropleth_map(wkb, color_array, vega); - //} - - // TEST(CHOROPLETHMAP_TEST, INVALID_JSON_TEST) { - // // param1: wkt string - // std::string wkt_string1 = - // "POLYGON ((" - // "200 200, " - // "200 300, " - // "300 300, " - // "300 200, " - // "200 200))"; - // arrow::StringBuilder string_builder; - // auto status = string_builder.Append(wkt_string1); - // - // std::shared_ptr string_array; - // status = string_builder.Finish(&string_array); - // - // // param2: color - // std::shared_ptr color_array; - // arrow::UInt32Builder color_builder; - // status = color_builder.Append(5); - // status = color_builder.Finish(&color_array); - // - // // param3: conf - // const std::string vega = - // "{\n" - // " \"width\": 1900,\n" - // " \"height\": 1410,\n" - // " \"description\": \"choropleth_map\",\n" - // " \"data\": [\n" - // " {\n" - // " \"name\": \"data\",\n" - // " \"url\": \"data/data.csv\"\n" - // " }\n" - // " ],\n" - // " \"scales\": [\n" - // " {\n" - // " \"name\": \"building\",\n" - // " \"type\": \"linear\",\n" - // " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - // " }\n" - // " ],\n" - // " \"marks\": [\n" - // " {\n" - // " \"encode\": {\n" - // " \"enter\": {\n" - // " \"bounding_box\": {\"value\": " - // "[-73.984092,40.753893,-73.977588,40.756342]},\n" - // " \"color_gradient\": {\"value\": \"blue_to_red\"},\n" - // " \"color_bound\": {\"value\": [2.5, 5]},\n" - // " \"opacity\": {\"value\": \"INVALID_NUMBER\"}\n" - // " }\n" - // " }\n" - // " }\n" - // " ]\n" - // "}"; - // - // auto wkb = arctern::render::WktToWkb(string_array); - // arctern::render::choropleth_map(wkb, color_array, vega); - //} - - TEST(CHOROPLETHMAP_TEST, INT8) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::Int8Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); - auto wkb = arctern::render::WktToWkb(string_array); - std::vector> polygon_vec{wkb}; + // param2: color + std::shared_ptr color_array; + arrow::DoubleBuilder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); - std::vector> color_vec{color_array}; - arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, INT16) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::Int16Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; auto wkb = arctern::render::WktToWkb(string_array); std::vector> polygon_vec{wkb}; std::vector> color_vec{color_array}; arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, INT32) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::Int32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; +} + +// TEST(CHOROPLETHMAP_TEST, INVALID_DATA_TYPE_TEST) { +// // param1: wkt string +// std::string wkt_string1 = +// "POLYGON ((" +// "200 200, " +// "200 300, " +// "300 300, " +// "300 200, " +// "200 200))"; +// arrow::StringBuilder string_builder; +// auto status = string_builder.Append(wkt_string1); +// +// std::shared_ptr string_array; +// status = string_builder.Finish(&string_array); +// +// // param2: color +// std::shared_ptr color_array; +// arrow::StringBuilder color_builder; +// status = color_builder.Append(""); +// status = color_builder.Finish(&color_array); +// +// // param3: conf +// const std::string vega = +// "{\n" +// " \"width\": 1900,\n" +// " \"height\": 1410,\n" +// " \"description\": \"choropleth_map\",\n" +// " \"data\": [\n" +// " {\n" +// " \"name\": \"data\",\n" +// " \"url\": \"data/data.csv\"\n" +// " }\n" +// " ],\n" +// " \"scales\": [\n" +// " {\n" +// " \"name\": \"building\",\n" +// " \"type\": \"linear\",\n" +// " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" +// " }\n" +// " ],\n" +// " \"marks\": [\n" +// " {\n" +// " \"encode\": {\n" +// " \"enter\": {\n" +// " \"bounding_box\": {\"value\": " +// "[-73.984092,40.753893,-73.977588,40.756342]},\n" +// " \"color_gradient\": {\"value\": \"blue_to_red\"},\n" +// " \"color_bound\": {\"value\": [2.5, 5]},\n" +// " \"opacity\": {\"value\": 1.0}\n" +// " }\n" +// " }\n" +// " }\n" +// " ]\n" +// "}"; +// +// auto wkb = arctern::render::WktToWkb(string_array); +// arctern::render::choropleth_map(wkb, color_array, vega); +//} + +TEST(CHOROPLETHMAP_TEST, MEAN) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); + + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); + + // param2: color + std::shared_ptr color_array; + arrow::DoubleBuilder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); + + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"mean\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; auto wkb = arctern::render::WktToWkb(string_array); std::vector> polygon_vec{wkb}; std::vector> color_vec{color_array}; arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, INT64) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::Int64Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; +} - auto wkb = arctern::render::WktToWkb(string_array); - std::vector> polygon_vec{wkb}; +TEST(CHOROPLETHMAP_TEST, SUM) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); - std::vector> color_vec{color_array}; - arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, UINT8) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt8Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); - auto wkb = arctern::render::WktToWkb(string_array); - std::vector> polygon_vec{wkb}; + // param2: color + std::shared_ptr color_array; + arrow::DoubleBuilder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); - std::vector> color_vec{color_array}; - arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, UINT16) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt16Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"sum\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; auto wkb = arctern::render::WktToWkb(string_array); std::vector> polygon_vec{wkb}; std::vector> color_vec{color_array}; arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, UINT32) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt32Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; +} - auto wkb = arctern::render::WktToWkb(string_array); - std::vector> polygon_vec{wkb}; +TEST(CHOROPLETHMAP_TEST, MAX) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); - std::vector> color_vec{color_array}; - arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, UINT64) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::UInt64Builder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); - auto wkb = arctern::render::WktToWkb(string_array); - std::vector> polygon_vec{wkb}; + // param2: color + std::shared_ptr color_array; + arrow::DoubleBuilder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); - std::vector> color_vec{color_array}; - arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, FLOAT) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::FloatBuilder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"max\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; auto wkb = arctern::render::WktToWkb(string_array); std::vector> polygon_vec{wkb}; std::vector> color_vec{color_array}; arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, DOUBLE) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::DoubleBuilder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; +} - auto wkb = arctern::render::WktToWkb(string_array); - std::vector> polygon_vec{wkb}; +TEST(CHOROPLETHMAP_TEST, MIN) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); - std::vector> color_vec{color_array}; - arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - // TEST(CHOROPLETHMAP_TEST, INVALID_DATA_TYPE_TEST) { - // // param1: wkt string - // std::string wkt_string1 = - // "POLYGON ((" - // "200 200, " - // "200 300, " - // "300 300, " - // "300 200, " - // "200 200))"; - // arrow::StringBuilder string_builder; - // auto status = string_builder.Append(wkt_string1); - // - // std::shared_ptr string_array; - // status = string_builder.Finish(&string_array); - // - // // param2: color - // std::shared_ptr color_array; - // arrow::StringBuilder color_builder; - // status = color_builder.Append(""); - // status = color_builder.Finish(&color_array); - // - // // param3: conf - // const std::string vega = - // "{\n" - // " \"width\": 1900,\n" - // " \"height\": 1410,\n" - // " \"description\": \"choropleth_map\",\n" - // " \"data\": [\n" - // " {\n" - // " \"name\": \"data\",\n" - // " \"url\": \"data/data.csv\"\n" - // " }\n" - // " ],\n" - // " \"scales\": [\n" - // " {\n" - // " \"name\": \"building\",\n" - // " \"type\": \"linear\",\n" - // " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - // " }\n" - // " ],\n" - // " \"marks\": [\n" - // " {\n" - // " \"encode\": {\n" - // " \"enter\": {\n" - // " \"bounding_box\": {\"value\": " - // "[-73.984092,40.753893,-73.977588,40.756342]},\n" - // " \"color_gradient\": {\"value\": \"blue_to_red\"},\n" - // " \"color_bound\": {\"value\": [2.5, 5]},\n" - // " \"opacity\": {\"value\": 1.0}\n" - // " }\n" - // " }\n" - // " }\n" - // " ]\n" - // "}"; - // - // auto wkb = arctern::render::WktToWkb(string_array); - // arctern::render::choropleth_map(wkb, color_array, vega); - //} - - TEST(CHOROPLETHMAP_TEST, MEAN) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::DoubleBuilder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"mean\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); - auto wkb = arctern::render::WktToWkb(string_array); - std::vector> polygon_vec{wkb}; + // param2: color + std::shared_ptr color_array; + arrow::DoubleBuilder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); - std::vector> color_vec{color_array}; - arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, SUM) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::DoubleBuilder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"sum\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"min\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; auto wkb = arctern::render::WktToWkb(string_array); std::vector> polygon_vec{wkb}; std::vector> color_vec{color_array}; arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, MAX) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::DoubleBuilder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"max\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; +} - auto wkb = arctern::render::WktToWkb(string_array); - std::vector> polygon_vec{wkb}; +TEST(CHOROPLETHMAP_TEST, COUNT) { + // param1: wkt string + std::string wkt_string1 = + "POLYGON ((" + "200 200, " + "200 300, " + "300 300, " + "300 200, " + "200 200))"; + arrow::StringBuilder string_builder; + auto status = string_builder.Append(wkt_string1); - std::vector> color_vec{color_array}; - arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, MIN) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::DoubleBuilder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"min\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + std::shared_ptr string_array; + status = string_builder.Finish(&string_array); - auto wkb = arctern::render::WktToWkb(string_array); - std::vector> polygon_vec{wkb}; + // param2: color + std::shared_ptr color_array; + arrow::DoubleBuilder color_builder; + status = color_builder.Append(5); + status = color_builder.Finish(&color_array); - std::vector> color_vec{color_array}; - arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } - - TEST(CHOROPLETHMAP_TEST, COUNT) { - // param1: wkt string - std::string wkt_string1 = - "POLYGON ((" - "200 200, " - "200 300, " - "300 300, " - "300 200, " - "200 200))"; - arrow::StringBuilder string_builder; - auto status = string_builder.Append(wkt_string1); - - std::shared_ptr string_array; - status = string_builder.Finish(&string_array); - - // param2: color - std::shared_ptr color_array; - arrow::DoubleBuilder color_builder; - status = color_builder.Append(5); - status = color_builder.Finish(&color_array); - - // param3: conf - const std::string vega = - "{\n" - " \"width\": 1900,\n" - " \"height\": 1410,\n" - " \"description\": \"choropleth_map\",\n" - " \"data\": [\n" - " {\n" - " \"name\": \"data\",\n" - " \"url\": \"data/data.csv\"\n" - " }\n" - " ],\n" - " \"scales\": [\n" - " {\n" - " \"name\": \"building\",\n" - " \"type\": \"linear\",\n" - " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" - " }\n" - " ],\n" - " \"marks\": [\n" - " {\n" - " \"encode\": {\n" - " \"enter\": {\n" - " \"bounding_box\": {\"value\": " - "[-73.984092,40.753893,-73.977588,40.756342]},\n" - " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" - " \"color_bound\": {\"value\": [2.5, 5]},\n" - " \"opacity\": {\"value\": 1.0},\n" - " \"aggregation_type\": {\"value\": \"count\"}\n" - " }\n" - " }\n" - " }\n" - " ]\n" - "}"; + // param3: conf + const std::string vega = + "{\n" + " \"width\": 1900,\n" + " \"height\": 1410,\n" + " \"description\": \"choropleth_map\",\n" + " \"data\": [\n" + " {\n" + " \"name\": \"data\",\n" + " \"url\": \"data/data.csv\"\n" + " }\n" + " ],\n" + " \"scales\": [\n" + " {\n" + " \"name\": \"building\",\n" + " \"type\": \"linear\",\n" + " \"domain\": {\"data\": \"data\", \"field\": \"c0\"}\n" + " }\n" + " ],\n" + " \"marks\": [\n" + " {\n" + " \"encode\": {\n" + " \"enter\": {\n" + " \"bounding_box\": {\"value\": " + "[-73.984092,40.753893,-73.977588,40.756342]},\n" + " \"color_gradient\": {\"value\": [\"#0000FF\", \"#FF0000\"]},\n" + " \"color_bound\": {\"value\": [2.5, 5]},\n" + " \"opacity\": {\"value\": 1.0},\n" + " \"aggregation_type\": {\"value\": \"count\"}\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; auto wkb = arctern::render::WktToWkb(string_array); std::vector> polygon_vec{wkb}; std::vector> color_vec{color_array}; arctern::render::choropleth_map(polygon_vec, color_vec, vega); - } +} TEST(CHOROPLETHMAP_TEST, STD) { // param1: wkt string diff --git a/cpp/unittest/render/weighted_pointmap_test.cpp b/cpp/unittest/render/weighted_pointmap_test.cpp index f8a244901..4a9dbeb85 100644 --- a/cpp/unittest/render/weighted_pointmap_test.cpp +++ b/cpp/unittest/render/weighted_pointmap_test.cpp @@ -19,7 +19,7 @@ #include "arrow/render_api.h" -//TEST(POINTMAP_RAW_POINT_TEST, SINGLE_COLOR_SINGLE_POINTSIZE) { +// TEST(POINTMAP_RAW_POINT_TEST, SINGLE_COLOR_SINGLE_POINTSIZE) { // // param1: x, y // arrow::UInt32Builder x_builder; // auto status = x_builder.Append(10); @@ -85,7 +85,7 @@ // arctern::render::weighted_point_map(x_array, y_array, vega); //} // -//TEST(POINTMAP_RAW_POINT_TEST, MULTIPLE_COLOR_SINGLE_POINTSIZE) { +// TEST(POINTMAP_RAW_POINT_TEST, MULTIPLE_COLOR_SINGLE_POINTSIZE) { // // param1: x, y // arrow::UInt32Builder x_builder; // auto status = x_builder.Append(10); @@ -162,7 +162,7 @@ // arctern::render::weighted_point_map(x_array, y_array, c_array, vega); //} // -//TEST(POINTMAP_RAW_POINT_TEST, SINGLE_COLOR_MULTIPLE_POINTSIZE) { +// TEST(POINTMAP_RAW_POINT_TEST, SINGLE_COLOR_MULTIPLE_POINTSIZE) { // // param1: x, y // arrow::UInt32Builder x_builder; // auto status = x_builder.Append(10); @@ -1207,7 +1207,7 @@ TEST(POINTMAP_RAW_POINT_TEST, DOUBLE) { arctern::render::weighted_point_map(x_array, y_array, c_array, s_array, vega); } -//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT8) { +// TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT8) { // // param1: x, y // arrow::UInt32Builder x_builder; // auto status = x_builder.Append(10); @@ -1284,7 +1284,7 @@ TEST(POINTMAP_RAW_POINT_TEST, DOUBLE) { // arctern::render::weighted_point_map(x_array, y_array, c_array, vega); //} // -//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT16) { +// TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT16) { // // param1: x, y // arrow::UInt32Builder x_builder; // auto status = x_builder.Append(10); @@ -1361,7 +1361,7 @@ TEST(POINTMAP_RAW_POINT_TEST, DOUBLE) { // arctern::render::weighted_point_map(x_array, y_array, c_array, vega); //} // -//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT32) { +// TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT32) { // // param1: x, y // arrow::UInt32Builder x_builder; // auto status = x_builder.Append(10); @@ -1438,7 +1438,7 @@ TEST(POINTMAP_RAW_POINT_TEST, DOUBLE) { // arctern::render::weighted_point_map(x_array, y_array, c_array, vega); //} // -//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT64) { +// TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, INT64) { // // param1: x, y // arrow::UInt32Builder x_builder; // auto status = x_builder.Append(10); @@ -1515,7 +1515,7 @@ TEST(POINTMAP_RAW_POINT_TEST, DOUBLE) { // arctern::render::weighted_point_map(x_array, y_array, c_array, vega); //} // -//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT8) { +// TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT8) { // // param1: x, y // arrow::UInt32Builder x_builder; // auto status = x_builder.Append(10); @@ -1592,7 +1592,7 @@ TEST(POINTMAP_RAW_POINT_TEST, DOUBLE) { // arctern::render::weighted_point_map(x_array, y_array, c_array, vega); //} // -//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT16) { +// TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT16) { // // param1: x, y // arrow::UInt32Builder x_builder; // auto status = x_builder.Append(10); @@ -1669,7 +1669,7 @@ TEST(POINTMAP_RAW_POINT_TEST, DOUBLE) { // arctern::render::weighted_point_map(x_array, y_array, c_array, vega); //} // -//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT32) { +// TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT32) { // // param1: x, y // arrow::UInt32Builder x_builder; // auto status = x_builder.Append(10); @@ -1746,7 +1746,7 @@ TEST(POINTMAP_RAW_POINT_TEST, DOUBLE) { // arctern::render::weighted_point_map(x_array, y_array, c_array, vega); //} // -//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT64) { +// TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, UINT64) { // // param1: x, y // arrow::UInt32Builder x_builder; // auto status = x_builder.Append(10); @@ -1823,7 +1823,7 @@ TEST(POINTMAP_RAW_POINT_TEST, DOUBLE) { // arctern::render::weighted_point_map(x_array, y_array, c_array, vega); //} // -//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, FLOAT) { +// TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, FLOAT) { // // param1: x, y // arrow::UInt32Builder x_builder; // auto status = x_builder.Append(10); @@ -1900,7 +1900,7 @@ TEST(POINTMAP_RAW_POINT_TEST, DOUBLE) { // arctern::render::weighted_point_map(x_array, y_array, c_array, vega); //} // -//TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, DOUBLE) { +// TEST(POINTMAP_RAW_POINT_TEST_MULTIPLE_COLOR, DOUBLE) { // // param1: x, y // arrow::UInt32Builder x_builder; // auto status = x_builder.Append(10); @@ -3257,7 +3257,7 @@ TEST(POINTMAP_WKT_TEST, INT16) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -3347,7 +3347,7 @@ TEST(POINTMAP_WKT_TEST, INT32) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -3437,7 +3437,7 @@ TEST(POINTMAP_WKT_TEST, INT64) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -3527,7 +3527,7 @@ TEST(POINTMAP_WKT_TEST, UINT8) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -3617,7 +3617,7 @@ TEST(POINTMAP_WKT_TEST, UINT16) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -3707,7 +3707,7 @@ TEST(POINTMAP_WKT_TEST, UINT32) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -3797,7 +3797,7 @@ TEST(POINTMAP_WKT_TEST, UINT64) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -3887,7 +3887,7 @@ TEST(POINTMAP_WKT_TEST, FLOAT) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -3973,11 +3973,11 @@ TEST(POINTMAP_WKT_TEST, DOUBLE) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - + std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -4067,7 +4067,7 @@ TEST(POINTMAP_WKT_TEST, MEAN) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -4157,7 +4157,7 @@ TEST(POINTMAP_WKT_TEST, SUM) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -4247,7 +4247,7 @@ TEST(POINTMAP_WKT_TEST, MAX) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -4337,7 +4337,7 @@ TEST(POINTMAP_WKT_TEST, MIN) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -4427,7 +4427,7 @@ TEST(POINTMAP_WKT_TEST, COUNT) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -4517,7 +4517,7 @@ TEST(POINTMAP_WKT_TEST, STD) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -4595,7 +4595,7 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, INT8) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -4673,7 +4673,7 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, INT16) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -4751,7 +4751,7 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, INT32) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -4829,7 +4829,7 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, INT64) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -4907,7 +4907,7 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, UINT8) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -4985,7 +4985,7 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, UINT16) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -5063,7 +5063,7 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, UINT32) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -5141,7 +5141,7 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, UINT64) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -5219,7 +5219,7 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, FLOAT) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -5297,7 +5297,7 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, DOUBLE) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -5375,7 +5375,7 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, MEAN) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -5450,10 +5450,10 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, SUM) { "}"; auto wkb = arctern::render::WktToWkb(string_array); - + std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -5531,7 +5531,7 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, MAX) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -5609,7 +5609,7 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, MIN) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -5687,7 +5687,7 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, COUNT) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -5765,7 +5765,7 @@ TEST(POINTMAP_WKT_TEST_MULTIPLE_COLOR, STD) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, vega); } @@ -5855,7 +5855,7 @@ TEST(POINTMAP_WKT_TEST, BLUE_TO_RED) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -5945,7 +5945,7 @@ TEST(POINTMAP_WKT_TEST, SKYBLUE_TO_RED) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -6035,7 +6035,7 @@ TEST(POINTMAP_WKT_TEST, PURPLE_TO_YELLOW) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -6125,7 +6125,7 @@ TEST(POINTMAP_WKT_TEST, RED_TRANSPARENCY) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -6215,7 +6215,7 @@ TEST(POINTMAP_WKT_TEST, BLUE_TRANSPARENCY) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -6305,7 +6305,7 @@ TEST(POINTMAP_WKT_TEST, BLUE_GREEN_YELLOW) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -6395,7 +6395,7 @@ TEST(POINTMAP_WKT_TEST, WHITE_BLUE) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -6485,7 +6485,7 @@ TEST(POINTMAP_WKT_TEST, BLUE_WHITE_RED) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } @@ -6575,6 +6575,6 @@ TEST(POINTMAP_WKT_TEST, GREEN_YELLOW_RED) { std::vector> point_vec{wkb}; std::vector> color_vec{c_array}; std::vector> size_vec{s_array}; - + arctern::render::weighted_point_map(point_vec, color_vec, size_vec, vega); } diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index 9afdce1e1..5c7cfc409 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1129,6 +1129,7 @@ def projection(geos, bottom_right, top_left, height, width): bounding_box_min = bytes(top_left, encoding="utf8") geos_rs = [] + # pylint: disable=c-extension-no-member if isinstance(geos, pa.lib.ChunkedArray): for chunk_idx in range(geos.num_chunks): geos_rs.append(geos.chunk(chunk_idx)) @@ -1191,6 +1192,7 @@ def point_map_layer(vega, points, transform=True): # transform and projection handler geos_rs = [] + # pylint: disable=c-extension-no-member if isinstance(geos, pa.lib.ChunkedArray): for chunk_idx in range(geos.num_chunks): geos_rs.append(geos.chunk(chunk_idx)) @@ -1233,6 +1235,7 @@ def weighted_point_map_layer(vega, points, transform=True, **kwargs): # transform and projection handler geos_rs = [] + # pylint: disable=c-extension-no-member if isinstance(geos, pa.lib.ChunkedArray): for chunk_idx in range(geos.num_chunks): geos_rs.append(geos.chunk(chunk_idx)) @@ -1317,6 +1320,7 @@ def heat_map_layer(vega, points, weights, transform=True): # transform and projection handler geos_rs = [] + # pylint: disable=c-extension-no-member if isinstance(geos, pa.lib.ChunkedArray): for chunk_idx in range(geos.num_chunks): geos_rs.append(geos.chunk(chunk_idx)) @@ -1367,6 +1371,7 @@ def choropleth_map_layer(vega, region_boundaries, weights, transform=True): # transform and projection handler geos_rs = [] + # pylint: disable=c-extension-no-member if isinstance(geos, pa.lib.ChunkedArray): for chunk_idx in range(geos.num_chunks): geos_rs.append(geos.chunk(chunk_idx)) @@ -1418,6 +1423,7 @@ def icon_viz_layer(vega, points, transform=True): # transform and projection handler geos_rs = [] + # pylint: disable=c-extension-no-member if isinstance(geos, pa.lib.ChunkedArray): for chunk_idx in range(geos.num_chunks): geos_rs.append(geos.chunk(chunk_idx)) From 1a89659786592b1d58810d08322803a72d9ef642 Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Wed, 29 Apr 2020 20:41:59 +0800 Subject: [PATCH 22/24] code format --- python/arctern/_wrapper_func.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index da88d633e..fad630170 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1298,6 +1298,7 @@ def point_map_layer(vega, points, transform=True): # pylint: disable=too-many-branches +# pylint: disable=too-many-statements def weighted_point_map_layer(vega, points, transform=True, **kwargs): import pyarrow as pa color_weights = kwargs.get('color_weights', None) From 032f38168a17656b70417f67cd563e2a16665e4e Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Wed, 29 Apr 2020 20:54:48 +0800 Subject: [PATCH 23/24] recommit --- python/arctern/_wrapper_func.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/arctern/_wrapper_func.py b/python/arctern/_wrapper_func.py index fad630170..0170bce32 100644 --- a/python/arctern/_wrapper_func.py +++ b/python/arctern/_wrapper_func.py @@ -1338,6 +1338,7 @@ def weighted_point_map_layer(vega, points, transform=True, **kwargs): if color_weights is None and size_weights is None: rs = arctern_core_.weighted_point_map(vega_string, geos_rs) + elif color_weights is not None and size_weights is not None: if color_weights.dtypes == 'float64': arr_c = pa.array(color_weights, type='double') @@ -1360,6 +1361,7 @@ def weighted_point_map_layer(vega, points, transform=True, **kwargs): else: size_weights_rs.append(arr_s) rs = arctern_core_.weighted_color_size_point_map(vega_string, geos_rs, color_weights_rs, size_weights_rs) + elif color_weights is None and size_weights is not None: if size_weights.dtypes == 'float64': arr_s = pa.array(size_weights, type='double') @@ -1372,6 +1374,7 @@ def weighted_point_map_layer(vega, points, transform=True, **kwargs): else: size_weights_rs.append(arr_s) rs = arctern_core_.weighted_size_point_map(vega_string, geos_rs, size_weights_rs) + else: if color_weights.dtypes == 'float64': arr_c = pa.array(color_weights, type='double') From fe9477f358561d81bcbe2f319bbb0528407bed0b Mon Sep 17 00:00:00 2001 From: bigsheeper <42060877+bigsheeper@users.noreply.github.com> Date: Wed, 29 Apr 2020 21:00:50 +0800 Subject: [PATCH 24/24] code format --- cpp/src/render/utils/render_utils.cpp | 2 +- cpp/src/render/utils/render_utils.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/render/utils/render_utils.cpp b/cpp/src/render/utils/render_utils.cpp index c91fa3b6e..695b0109f 100644 --- a/cpp/src/render/utils/render_utils.cpp +++ b/cpp/src/render/utils/render_utils.cpp @@ -15,8 +15,8 @@ */ #include #include -#include #include +#include #include #include "arrow/render_api.h" diff --git a/cpp/src/render/utils/render_utils.h b/cpp/src/render/utils/render_utils.h index e19118121..8e4669cbc 100644 --- a/cpp/src/render/utils/render_utils.h +++ b/cpp/src/render/utils/render_utils.h @@ -17,8 +17,8 @@ #include #include -#include #include +#include #include #include "arrow/render_api.h"