-
Notifications
You must be signed in to change notification settings - Fork 771
[SEDONA-730] Add to_wkt() to sedona.geopandas API #1914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6dbe422
profiling1
prantogg cb6539f
profiling4
prantogg eaa686d
Merge remote-tracking branch 'origin/master'
prantogg 0127688
profiling...
prantogg 0eff217
profiling 8
prantogg 7362862
Merge remote-tracking branch 'origin/master'
prantogg 43fef83
Merge remote-tracking branch 'origin/master'
prantogg 5a351fe
implement to_wkt()
prantogg 10e53ef
remove debug statements
prantogg 8666402
undo pom changes
prantogg 186e1e6
lint fix
prantogg 9cb388e
lint fix 2
prantogg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -580,6 +580,73 @@ def sjoin( | |
| **kwargs, | ||
| ) | ||
|
|
||
| def to_wkt(self, **kwargs) -> "GeoSeries": | ||
| """ | ||
| Convert GeoSeries geometries to WKT | ||
|
|
||
| Parameters | ||
| ---------- | ||
| kwargs | ||
| rounding_precision | ||
|
|
||
| Returns | ||
| ------- | ||
| Series | ||
| WKT representations of the geometries | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> from shapely.geometry import Point | ||
| >>> import geopandas as gpd | ||
| >>> from sedona.geopandas import GeoSeries | ||
|
|
||
| >>> s = GeoSeries([Point(1, 1), Point(2, 2), Point(3, 3)]) | ||
| >>> s | ||
| 0 POINT (1 1) | ||
| 1 POINT (2 2) | ||
| 2 POINT (3 3) | ||
| dtype: geometry | ||
|
|
||
| >>> s.to_wkt() | ||
| 0 POINT (1 1) | ||
| 1 POINT (2 2) | ||
| 2 POINT (3 3) | ||
| dtype: object | ||
|
|
||
| """ | ||
|
|
||
| # Find the first column with BinaryType or GeometryType | ||
| first_col = self.get_first_geometry_column() | ||
|
|
||
| # Read the keyword arguments | ||
| rounding_precision = kwargs.get("rounding_precision", None) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
|
|
||
| if self.get_first_geometry_column(): | ||
| data_type = self._internal.spark_frame.schema[first_col].dataType | ||
|
|
||
| # Start with the base expression. | ||
| if isinstance(data_type, BinaryType): | ||
| base_expr = f"ST_GeomFromWKB(`{first_col}`)" | ||
| else: | ||
| base_expr = f"`{first_col}`" | ||
|
|
||
| # Chain transformations if the keyword argument is provided. | ||
| if rounding_precision is not None: | ||
| base_expr = f"ST_ReducePrecision({base_expr}, {rounding_precision})" | ||
|
|
||
| wkt_expr = f"ST_AsEWKT({base_expr}) as wkt" | ||
|
|
||
| sdf = self._internal.spark_frame.selectExpr(wkt_expr) | ||
| internal = InternalFrame( | ||
| spark_frame=sdf, | ||
| index_spark_columns=None, | ||
| column_labels=[self._column_label], | ||
| data_spark_columns=[scol_for(sdf, "wkt")], | ||
| data_fields=[self._internal.data_fields[0]], | ||
| column_label_names=self._internal.column_label_names, | ||
| ) | ||
| return _to_geo_series(first_series(PandasOnSparkDataFrame(internal))) | ||
|
|
||
| # ----------------------------------------------------------------------------- | ||
| # # Utils | ||
| # ----------------------------------------------------------------------------- | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the default should be 6 as per shapely.to_wkt() to replicate GeoPandas behavior. What do you think?
And we should also add support for the
output_dimensionparameter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO we should not stray sedona.geopandas' default behavior from sedona's default behavior. Open to suggestions cc. @jiayuasu @zhangfengcdt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to keep it as close as possible to the geopandas' behavior. The main goal of this project is to allow people to use their existing geopandas code with minimum changes in outcomes.