@@ -45,3 +45,96 @@ To switch the geospatial output format in Databend, configure the `SET geometry_
4545``` sql
4646SET geometry_output_format = ' geojson' ;
4747```
48+
49+ ## Functions
50+
51+ Explore the links below to discover all the available geospatial functions organized by category.
52+
53+ - [ Geography Functions] ( ../../20-sql-functions/09-geo-functions/index.md )
54+ - [ Geometry Functions] ( ../../20-sql-functions/09-geometry-functions/index.md )
55+
56+ ## Examples
57+
58+ ``` sql
59+ -- Enable geospatial types
60+ SET enable_geo_create_table= 1 ;
61+
62+ -- Set the output format to WKT
63+ SET geometry_output_format= ' wkt' ;
64+
65+
66+ CREATE OR REPLACE TABLE test (id INT , geo GEOMETRY);
67+ INSERT INTO test VALUES
68+ (1 , ' POINT(66 12)' ),
69+ (2 , ' MULTIPOINT((45 21), (12 54))' ),
70+ (3 , ' LINESTRING(40 60, 50 50, 60 40)' ),
71+ (4 , ' MULTILINESTRING((1 1, 32 17), (33 12, 73 49, 87.1 6.1))' ),
72+ (5 , ' POLYGON((17 17, 17 30, 30 30, 30 17, 17 17))' ),
73+ (6 , ' MULTIPOLYGON(((-10 0,0 10,10 0,-10 0)),((-10 40,10 40,0 20,-10 40)))' ),
74+ (7 , ' GEOMETRYCOLLECTION(POLYGON((-10 0,0 10,10 0,-10 0)),LINESTRING(40 60, 50 50, 60 40), POINT(99 11))' );
75+
76+ SELECT id, geo FROM test;
77+ ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
78+ │ id │ geo │
79+ ├─────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────┤
80+ │ 1 │ POINT (66 12 ) │
81+ │ 2 │ MULTIPOINT(45 21 ,12 54 ) │
82+ │ 3 │ LINESTRING(40 60 ,50 50 ,60 40 ) │
83+ │ 4 │ MULTILINESTRING((1 1 ,32 17 ),(33 12 ,73 49 ,87 .1 6 .1 )) │
84+ │ 5 │ POLYGON ((17 17 ,17 30 ,30 30 ,30 17 ,17 17 )) │
85+ │ 6 │ MULTIPOLYGON(((- 10 0 ,0 10 ,10 0 ,- 10 0 )),((- 10 40 ,10 40 ,0 20 ,- 10 40 ))) │
86+ │ 7 │ GEOMETRYCOLLECTION(POLYGON ((- 10 0 ,0 10 ,10 0 ,- 10 0 )),LINESTRING(40 60 ,50 50 ,60 40 ),POINT (99 11 )) │
87+ └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
88+
89+ -- Convert to WKB format
90+ SELECT id, st_aswkb(geo) FROM test WHERE id= 1 ;
91+ ┌──────────────────────────────────────────────────────────────┐
92+ │ id │ st_aswkb(geo) │
93+ ├─────────────────┼────────────────────────────────────────────┤
94+ │ 1 │ 010100000000000000008050400000000000002840 │
95+ └──────────────────────────────────────────────────────────────┘
96+
97+ -- Convert to GeoJSON format
98+ SELECT id, st_asgeojson(geo) FROM test WHERE id= 1 ;
99+ ┌──────────────────────────────────────────────────────────┐
100+ │ id │ st_asgeojson(geo) │
101+ ├─────────────────┼────────────────────────────────────────┤
102+ │ 1 │ {" coordinates" :[66 ,12 ]," type" :" Point" } │
103+ └──────────────────────────────────────────────────────────┘
104+
105+ -- Get the X and Y coordinates of a Point
106+ SELECT id, st_x(geo), st_y(geo) FROM test WHERE id= 1 ;
107+ ┌─────────────────────────────────────────────────────────┐
108+ │ id │ st_x(geo) │ st_y(geo) │
109+ ├─────────────────┼───────────────────┼───────────────────┤
110+ │ 1 │ 66 │ 12 │
111+ └─────────────────────────────────────────────────────────┘
112+
113+ -- Get the dimension of the data
114+ SELECT id, st_dimension(geo) FROM test;
115+ ┌─────────────────────────────────────┐
116+ │ id │ st_dimension(geo) │
117+ ├─────────────────┼───────────────────┤
118+ │ 1 │ 0 │
119+ │ 2 │ 0 │
120+ │ 3 │ 1 │
121+ │ 4 │ 1 │
122+ │ 5 │ 2 │
123+ │ 6 │ 2 │
124+ │ 7 │ 2 │
125+ └─────────────────────────────────────┘
126+
127+ -- Transform the spatial reference system from 4326 to 3857
128+ SELECT id, st_transform(geo, 4326 , 3857 ) FROM test;
129+ ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
130+ │ id │ st_transform(geo, 4326 , 3857 ) │
131+ ├─────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
132+ │ 1 │ POINT (7347086 .392356 1345708 .408409 ) │
133+ │ 2 │ MULTIPOINT(5009377 .085697 2391878 .587944 ,1335833 .889519 7170156 .294 ) │
134+ │ 3 │ LINESTRING(4452779 .631731 8399737 .889818 ,5565974 .539664 6446275 .841017 ,6679169 .447596 4865942 .279503 ) │
135+ │ 4 │ MULTILINESTRING((111319 .490793 111325 .142866 ,3562223 .705385 1920825 .040377 ),(3673543 .196178 1345708 .408409 ,8126322 .827909 6274861 .394007 ,9695927 .648094 680335 .356476 )) │
136+ │ 5 │ POLYGON ((1892431 .343486 1920825 .040377 ,1892431 .343486 3503549 .843504 ,3339584 .723798 3503549 .843504 ,3339584 .723798 1920825 .040377 ,1892431 .343486 1920825 .040377 )) │
137+ │ 6 │ MULTIPOLYGON(((- 1113194 .907933 0 ,0 1118889 .974858 ,1113194 .907933 0 ,- 1113194 .907933 0 )),((- 1113194 .907933 4865942 .279503 ,1113194 .907933 4865942 .279503 ,0 2273030 .926988 ,- 1113194 .907933 4865942 .279503 ))) │
138+ │ 7 │ GEOMETRYCOLLECTION(POLYGON ((- 1113194 .907933 0 ,0 1118889 .974858 ,1113194 .907933 0 ,- 1113194 .907933 0 )),LINESTRING(4452779 .631731 8399737 .889818 ,5565974 .539664 6446275 .841017 ,6679169 .447596 4865942 .279503 ),POINT (11020629 .588534 1232106 .801897 )) │
139+ └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
140+ ```
0 commit comments