ST_GeomFromShape

ST_GeomFromShape takes a binary column and returns a geometry column. The input binary column must contain the shapefile representation of geometries. You can optionally specify a spatial reference for the result geometry column. The sr parameter value must be a valid SRID or WKT string.

This function should only be used when you don't know the geometry type represented by the input column or when the input column contains more than one geometry type. In other cases, use the function specific to the geometry type of your input data (i.e. ST_PointFromShape, ST_LineFromShape, ST_MPointFromShape, or ST_PolyFromShape).

FunctionSyntax
Pythongeom_from_shape(shp,sr=None)
SQLST_GeomFromShape(shp,sr)
ScalageomFromShape(shp,sr)

For more details, go to the GeoAnalytics Engine API reference for geom_from_shape.

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
from geoanalytics.sql import functions as ST

point_shape= bytearray(b'\x01\x00\x00\x00\xb8\x1e\x85\x8bz\x81\\\xc1\x14\xaeG\x01I\xccSA')
line_shape = bytearray(b'\x03\x00\x00\x00\\\x8f\xc2\xb5\x0e\x92\\\xc1\n\xd7\xa3\xa0;\xbfSA\xb8\x1e\x85[\xfez\\\xc1R\xb8\x1e\xb5`\xc2SA\x01\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\\\x8f\xc2\xb5\x0e\x92\\\xc1\xaeG\xe1\xeaf\xc1SAH\xe1zD\x1a\x83\\\xc1\n\xd7\xa3\xa0;\xbfSA\xb8\x1e\x85[\xfez\\\xc1R\xb8\x1e\xb5`\xc2SA')

df = spark.createDataFrame([(point_shape,),(line_shape,)],["shape"])

df.select(ST.geom_from_shape("shape", sr=8857).alias("geom_from_shape")).show(truncate=False)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
+----------------------------------------------------------------------------------------+
|geom_from_shape                                                                         |
+----------------------------------------------------------------------------------------+
|{"x":-7472618.18,"y":5189924.02}                                                        |
|{"paths":[[[-7489594.84,5178779.67],[-7474281.07,5176558.51],[-7465977.43,5179778.83]]]}|
+----------------------------------------------------------------------------------------+

Version table

ReleaseNotes

1.0.0

Python and SQL functions introduced

1.5.0

Scala function introduced

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.