This is an automated email from the ASF dual-hosted git repository.

jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git


The following commit(s) were added to refs/heads/master by this push:
     new 9c3c67dff [SEDONA-622] Improve SedonaPyDeck behavior (#1515)
9c3c67dff is described below

commit 9c3c67dffc3f85062d44c572c35f5454f63c5611
Author: Furqaan Khan <[email protected]>
AuthorDate: Tue Jul 9 13:06:14 2024 -0400

    [SEDONA-622] Improve SedonaPyDeck behavior (#1515)
    
    * feat: throw an error when column is not numeric and add stroked parameter
    
    * fix: tests
---
 docs/api/sql/Visualization_SedonaPyDeck.md |  8 ++++++--
 python/sedona/maps/SedonaPyDeck.py         | 23 +++++++++++++++++------
 python/tests/maps/test_sedonapydeck.py     |  5 +++--
 3 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/docs/api/sql/Visualization_SedonaPyDeck.md 
b/docs/api/sql/Visualization_SedonaPyDeck.md
index 0f6126f32..ad1c27a6a 100644
--- a/docs/api/sql/Visualization_SedonaPyDeck.md
+++ b/docs/api/sql/Visualization_SedonaPyDeck.md
@@ -24,7 +24,7 @@ Following are details on all the APIs exposed via 
SedonaPyDeck:
 ```python
 def create_geometry_map(df, fill_color="[85, 183, 177, 255]", line_color="[85, 
183, 177, 255]",
                    elevation_col=0, initial_view_state=None,
-                   map_style=None, map_provider=None, api_keys=None):
+                   map_style=None, map_provider=None, api_keys=None, 
stroked=True):
 ```
 
 The parameter `fill_color` can be given a list of RGB/RGBA values, or a string 
that contains RGB/RGBA values based on a column, and is used to color polygons 
or point geometries in the map
@@ -33,6 +33,8 @@ The parameter `line_color` can be given a list of RGB/RGBA 
values, or a string t
 
 The parameter `elevation_col` can be given a static elevation or elevation 
based on column values like `fill_color`, this only works for the polygon 
geometries in the map.
 
+The parameter `stroked` determines whether to draw an outline around polygons 
and points, accepts a boolean value. For more information, please refer to this 
[documentation of 
deck.gl](https://deck.gl/docs/api-reference/layers/geojson-layer#:~:text=%27circle%27.-,stroked,-(boolean%2C%20optional)).
+
 Optionally, parameters `initial_view_state`, `map_style`, `map_provider`, 
`api_keys` can be passed to configure the map as per user's liking.
 More details on the parameters and their default values can be found on the 
PyDeck website as well by deck.gl 
[here](https://github.com/visgl/deck.gl/blob/8.9-release/docs/api-reference/layers/geojson-layer.md)
 
@@ -40,11 +42,13 @@ More details on the parameters and their default values can 
be found on the PyDe
 
 ```python
 def create_choropleth_map(df, fill_color=None, plot_col=None, 
initial_view_state=None, map_style=None,
-                                                 map_provider=None, 
api_keys=None, elevation_col=0)
+                                                 map_provider=None, 
api_keys=None, elevation_col=0, stroked=True)
 ```
 
 The parameter `fill_color` can be given a list of RGB/RGBA values, or a string 
that contains RGB/RGBA values based on a column.
 
+The parameter `stroked` determines whether to draw an outline around polygons 
and points, accepts a boolean value. For more information please refer to this 
[documentation of 
deck.gl](https://deck.gl/docs/api-reference/layers/geojson-layer#:~:text=%27circle%27.-,stroked,-(boolean%2C%20optional)).
+
 For example, all these are valid values of fill_color:
 
 ```python
diff --git a/python/sedona/maps/SedonaPyDeck.py 
b/python/sedona/maps/SedonaPyDeck.py
index 29d2bbe03..7c2d8a763 100644
--- a/python/sedona/maps/SedonaPyDeck.py
+++ b/python/sedona/maps/SedonaPyDeck.py
@@ -16,6 +16,9 @@
 #  under the License.
 
 from types import ModuleType
+
+from pyspark.sql.types import FloatType, DoubleType, IntegerType, LongType, 
DecimalType, ShortType, ByteType
+
 from sedona.maps.SedonaMapUtils import SedonaMapUtils
 
 
@@ -24,7 +27,7 @@ class SedonaPyDeck:
     # User Facing APIs
     @classmethod
     def create_choropleth_map(cls, df, fill_color=None, plot_col=None, 
initial_view_state=None, map_style=None,
-                              map_provider=None, elevation_col=0, 
api_keys=None):
+                              map_provider=None, elevation_col=0, 
api_keys=None, stroked=True):
         """
         Create a pydeck map with a choropleth layer added
         :param elevation_col: Optional elevation for the polygons
@@ -38,6 +41,14 @@ class SedonaPyDeck:
         :param api_keys: Optional dictionary of API keys for Map providers
         :return: A pydeck Map object with choropleth layer added:
         """
+
+        for field in df.schema.fields:
+            if field.name == plot_col and field.dataType not in 
[IntegerType(), FloatType(), DoubleType(), LongType(),
+                                                                 
DecimalType(), ShortType(), ByteType()]:
+                message = (f"'{field.name}' must be of numeric type. \nIf you 
are importing data from csv set "
+                           f"'inferSchema' option as true")
+                raise TypeError(message) from None
+
         pdk = _try_import_pydeck()
 
         if initial_view_state is None:
@@ -56,7 +67,7 @@ class SedonaPyDeck:
             get_fill_color=fill_color,
             opacity=1.0,
             get_elevation=elevation_col,
-            stroked=False,
+            stroked=stroked,
             extruded=True,
             wireframe=True,
             pickable=True
@@ -68,7 +79,7 @@ class SedonaPyDeck:
     @classmethod
     def create_geometry_map(cls, df, fill_color="[85, 183, 177, 255]", 
line_color="[85, 183, 177, 255]",
                             elevation_col=0, initial_view_state=None,
-                            map_style=None, map_provider=None, api_keys=None):
+                            map_style=None, map_provider=None, api_keys=None, 
stroked=True):
         """
         Create a pydeck map with a GeoJsonLayer added for plotting given 
geometries.
         :param line_color:
@@ -92,7 +103,7 @@ class SedonaPyDeck:
         #         line_color = "[237, 119, 79]"
 
         layer = SedonaPyDeck._create_fat_layer_(gdf, fill_color=fill_color, 
elevation_col=elevation_col,
-                                                line_color=line_color)
+                                                line_color=line_color, 
stroked=stroked)
 
         if initial_view_state is None:
             initial_view_state = 
pdk.data_utils.compute_view(gdf['coordinate_array_sedona'])
@@ -229,7 +240,7 @@ class SedonaPyDeck:
             lambda val: 
list(SedonaMapUtils.__extract_coordinate__(val[geometry_col], type_list)), 
axis=1)
 
     @classmethod
-    def _create_fat_layer_(cls, gdf, fill_color, line_color, elevation_col):
+    def _create_fat_layer_(cls, gdf, fill_color, line_color, elevation_col, 
stroked):
         pdk = _try_import_pydeck()
         layer = pdk.Layer(
             'GeoJsonLayer',  # `type` positional argument is here
@@ -237,7 +248,7 @@ class SedonaPyDeck:
             auto_highlight=True,
             get_fill_color=fill_color,
             opacity=0.4,
-            stroked=False,
+            stroked=stroked,
             extruded=True,
             get_elevation=elevation_col,
             get_line_color=line_color,
diff --git a/python/tests/maps/test_sedonapydeck.py 
b/python/tests/maps/test_sedonapydeck.py
index e3151ddf6..b2631bb96 100644
--- a/python/tests/maps/test_sedonapydeck.py
+++ b/python/tests/maps/test_sedonapydeck.py
@@ -30,6 +30,7 @@ class TestVisualization(TestBase):
         buildings_csv_df = self.spark.read.format("csv"). \
             option("delimiter", ","). \
             option("header", "true"). \
+            option("inferSchema", "true"). \
             load(google_buildings_input_location)
         buildings_csv_df.createOrReplaceTempView("buildings_table")
         buildings_df = self.spark.sql(
@@ -43,7 +44,7 @@ class TestVisualization(TestBase):
             auto_highlight=True,
             get_fill_color=fill_color,
             opacity=1.0,
-            stroked=False,
+            stroked=True,
             extruded=True,
             wireframe=True,
             get_elevation=0,
@@ -70,7 +71,7 @@ class TestVisualization(TestBase):
             auto_highlight=True,
             get_fill_color="[85, 183, 177, 255]",
             opacity=0.4,
-            stroked=False,
+            stroked=True,
             extruded=True,
             get_elevation='confidence * 10',
             pickable=True,

Reply via email to