forked from postgis/postgis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreference_accessor.xml
3145 lines (2516 loc) · 88.1 KB
/
reference_accessor.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8"?>
<sect1 id="Geometry_Accessors">
<title>Geometry Accessors</title>
<refentry id="GeometryType">
<refnamediv>
<refname>GeometryType</refname>
<refpurpose>Returns the type of the geometry as a string. Eg:
'LINESTRING', 'POLYGON', 'MULTIPOINT', etc.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>GeometryType</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the type of the geometry as a string. Eg:
'LINESTRING', 'POLYGON', 'MULTIPOINT', etc.</para>
<para>OGC SPEC s2.1.1.1 - Returns the name of the instantiable
subtype of Geometry of which this Geometry instance is a member.
The name of the instantiable subtype of Geometry is returned as a
string.</para>
<note>
<para>This function also indicates if the geometry is measured,
by returning a string of the form 'POINTM'.</para>
</note>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.</para>
<para>&sfs_compliant;</para>
<para>&curve_support;</para>
<para>&Z_support;</para>
<para>&P_support;</para>
<para>&T_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT GeometryType(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
geometrytype
--------------
LINESTRING
</programlisting>
<programlisting>SELECT ST_GeometryType(ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)), ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )'));
--result
POLYHEDRALSURFACE
</programlisting>
<programlisting>SELECT GeometryType(geom) as result
FROM
(SELECT
ST_GeomFromEWKT('TIN (((
0 0 0,
0 0 1,
0 1 0,
0 0 0
)), ((
0 0 0,
0 1 0,
1 1 0,
0 0 0
))
)') AS geom
) AS g;
result
--------
TIN </programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_GeometryType" /></para>
</refsection>
</refentry>
<refentry id="ST_Boundary">
<refnamediv>
<refname>ST_Boundary</refname>
<refpurpose>Returns the closure of the combinatorial boundary of this
Geometry.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Boundary</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the closure of the combinatorial boundary of this
Geometry. The combinatorial boundary is defined as described in
section 3.12.3.2 of the OGC SPEC. Because the result of this
function is a closure, and hence topologically closed, the
resulting boundary can be represented using representational
geometry primitives as discussed in the OGC SPEC, section
3.12.2.</para>
<para>Performed by the GEOS module</para>
<note> <para>Prior to 2.0.0, this function throws an exception if used with <varname>GEOMETRYCOLLECTION</varname>. From 2.0.0 up it will return NULL instead (unsupported input).</para></note>
<para>&sfs_compliant; OGC SPEC s2.1.1.1</para>
<para>&sqlmm_compliant; SQL-MM 3: 5.1.14</para>
<para>&Z_support;</para>
<para>Enhanced: 2.1.0 support for Triangle was introduced</para>
</refsection>
<refsection>
<title>Examples</title>
<informaltable>
<tgroup cols="2">
<tbody>
<row>
<entry><para><informalfigure>
<mediaobject>
<imageobject>
<imagedata fileref="images/st_boundary01.png" />
</imageobject>
<caption><para>Linestring with boundary points overlaid</para></caption>
</mediaobject>
</informalfigure>
<programlisting>SELECT ST_Boundary(geom)
FROM (SELECT 'LINESTRING(100 150,50 60, 70 80, 160 170)'::geometry As geom) As f;
</programlisting>
<screen>-- ST_AsText output
MULTIPOINT(100 150,160 170)
</screen>
</para></entry>
<entry><para><informalfigure>
<mediaobject>
<imageobject>
<imagedata fileref="images/st_boundary02.png" />
</imageobject>
<caption><para>polygon holes with boundary multilinestring</para></caption>
</mediaobject>
</informalfigure>
<programlisting>SELECT ST_Boundary(geom)
FROM (SELECT
'POLYGON (( 10 130, 50 190, 110 190, 140 150, 150 80, 100 10, 20 40, 10 130 ),
( 70 40, 100 50, 120 80, 80 110, 50 90, 70 40 ))'::geometry As geom) As f;
</programlisting>
<screen>-- ST_AsText output
MULTILINESTRING((10 130,50 190,110 190,140 150,150 80,100 10,20 40,10 130),
(70 40,100 50,120 80,80 110,50 90,70 40))
</screen>
</para></entry>
</row>
</tbody>
</tgroup>
</informaltable>
<programlisting>SELECT ST_AsText(ST_Boundary(ST_GeomFromText('LINESTRING(1 1,0 0, -1 1)')));
st_astext
-----------
MULTIPOINT(1 1,-1 1)
SELECT ST_AsText(ST_Boundary(ST_GeomFromText('POLYGON((1 1,0 0, -1 1, 1 1))')));
st_astext
----------
LINESTRING(1 1,0 0,-1 1,1 1)
--Using a 3d polygon
SELECT ST_AsEWKT(ST_Boundary(ST_GeomFromEWKT('POLYGON((1 1 1,0 0 1, -1 1 1, 1 1 1))')));
st_asewkt
-----------------------------------
LINESTRING(1 1 1,0 0 1,-1 1 1,1 1 1)
--Using a 3d multilinestring
SELECT ST_AsEWKT(ST_Boundary(ST_GeomFromEWKT('MULTILINESTRING((1 1 1,0 0 0.5, -1 1 1),(1 1 0.5,0 0 0.5, -1 1 0.5, 1 1 0.5) )')));
st_asewkt
----------
MULTIPOINT(-1 1 1,1 1 0.75)
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AsText" />, <xref linkend="ST_ExteriorRing" />, <xref linkend="ST_MakePolygon" /></para>
</refsection>
</refentry>
<refentry id="ST_CoordDim">
<refnamediv>
<refname>ST_CoordDim</refname>
<refpurpose>Return the coordinate dimension of the ST_Geometry value.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_CoordDim</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Return the coordinate dimension of the ST_Geometry value.</para>
<para>This is the MM compliant alias name for <xref linkend="ST_NDims" /></para>
<para>&sfs_compliant;</para>
<para>&sqlmm_compliant; SQL-MM 3: 5.1.3</para>
<para>&curve_support;</para>
<para>&Z_support;</para>
<para>&P_support;</para>
<para>&T_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_CoordDim('CIRCULARSTRING(1 2 3, 1 3 4, 5 6 7, 8 9 10, 11 12 13)');
---result--
3
SELECT ST_CoordDim(ST_Point(1,2));
--result--
2
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_NDims" /></para>
</refsection>
</refentry>
<refentry id="ST_Dimension">
<refnamediv>
<refname>ST_Dimension</refname>
<refpurpose>The inherent dimension of this Geometry object, which must
be less than or equal to the coordinate dimension. </refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_Dimension</function></funcdef>
<paramdef><type>geometry </type> <parameter>g</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>The inherent dimension of this Geometry object, which must
be less than or equal to the coordinate dimension. OGC SPEC
s2.1.1.1 - returns 0 for <varname>POINT</varname>, 1 for <varname>LINESTRING</varname>, 2 for <varname>POLYGON</varname>, and
the largest dimension of the components of a
<varname>GEOMETRYCOLLECTION</varname>.
If unknown (empty geometry) null is returned.
</para>
<para>&sqlmm_compliant; SQL-MM 3: 5.1.2</para>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces and TINs was introduced. No longer throws an exception if given empty geometry.</para>
<note> <para>Prior to 2.0.0, this function throws an exception if used with empty geometry. </para></note>
<para>&P_support;</para>
<para>&T_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_Dimension('GEOMETRYCOLLECTION(LINESTRING(1 1,0 0),POINT(0 0))');
ST_Dimension
-----------
1
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="ST_NDims" /></para>
</refsection>
</refentry>
<refentry id="ST_EndPoint">
<refnamediv>
<refname>ST_EndPoint</refname>
<refpurpose>Returns the last point of a <varname>LINESTRING</varname> or <varname>CIRCULARLINESTRING</varname>
geometry as a <varname>POINT</varname>.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>ST_EndPoint</function></funcdef>
<paramdef><type>geometry </type> <parameter>g</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the last point of a <varname>LINESTRING</varname> geometry
as a <varname>POINT</varname> or <varname>NULL</varname> if the input
parameter is not a <varname>LINESTRING</varname>.</para>
<para>&sqlmm_compliant; SQL-MM 3: 7.1.4</para>
<para>&Z_support;</para>
<!-- Optionally mention Circular String Support -->
<para>&curve_support;</para>
<note><para>Changed: 2.0.0 no longer works with single geometry multilinestrings. In older
versions of PostGIS -- a single line multilinestring would work happily with this
function and return the start point. In 2.0.0 it just returns NULL like any other multilinestring.
The older behavior was an undocumented feature, but people who assumed they had their data stored as LINESTRING
may experience these returning NULL in 2.0 now.</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>postgis=# SELECT ST_AsText(ST_EndPoint('LINESTRING(1 1, 2 2, 3 3)'::geometry));
st_astext
------------
POINT(3 3)
(1 row)
postgis=# SELECT ST_EndPoint('POINT(1 1)'::geometry) IS NULL AS is_null;
is_null
----------
t
(1 row)
--3d endpoint
SELECT ST_AsEWKT(ST_EndPoint('LINESTRING(1 1 2, 1 2 3, 0 0 5)'));
st_asewkt
--------------
POINT(0 0 5)
(1 row)</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="ST_PointN" />, <xref
linkend="ST_StartPoint" /></para>
</refsection>
</refentry>
<refentry id="ST_Envelope">
<refnamediv>
<refname>ST_Envelope</refname>
<refpurpose>Returns a geometry representing the double precision (float8) bounding box of the
supplied geometry.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Envelope</function></funcdef>
<paramdef><type>geometry </type> <parameter>g1</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the float8 minimum bounding box for the supplied geometry, as a geometry.
The polygon is defined by the corner points of the bounding box
((<varname>MINX</varname>, <varname>MINY</varname>),
(<varname>MINX</varname>, <varname>MAXY</varname>),
(<varname>MAXX</varname>, <varname>MAXY</varname>),
(<varname>MAXX</varname>, <varname>MINY</varname>),
(<varname>MINX</varname>, <varname>MINY</varname>)). (PostGIS will add a
<varname>ZMIN</varname>/<varname>ZMAX</varname> coordinate as
well).</para>
<para>Degenerate cases (vertical lines, points) will return a geometry of
lower dimension than <varname>POLYGON</varname>, ie.
<varname>POINT</varname> or <varname>LINESTRING</varname>.</para>
<para>Availability: 1.5.0 behavior changed to output double precision instead of float4</para>
<para>&sfs_compliant; s2.1.1.1</para>
<para>&sqlmm_compliant; SQL-MM 3: 5.1.15</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT ST_AsText(ST_Envelope('POINT(1 3)'::geometry));
st_astext
------------
POINT(1 3)
(1 row)
SELECT ST_AsText(ST_Envelope('LINESTRING(0 0, 1 3)'::geometry));
st_astext
--------------------------------
POLYGON((0 0,0 3,1 3,1 0,0 0))
(1 row)
SELECT ST_AsText(ST_Envelope('POLYGON((0 0, 0 1, 1.0000001 1, 1.0000001 0, 0 0))'::geometry));
st_astext
--------------------------------------------------------------
POLYGON((0 0,0 1,1.00000011920929 1,1.00000011920929 0,0 0))
(1 row)
SELECT ST_AsText(ST_Envelope('POLYGON((0 0, 0 1, 1.0000000001 1, 1.0000000001 0, 0 0))'::geometry));
st_astext
--------------------------------------------------------------
POLYGON((0 0,0 1,1.00000011920929 1,1.00000011920929 0,0 0))
(1 row)
SELECT Box3D(geom), Box2D(geom), ST_AsText(ST_Envelope(geom)) As envelopewkt
FROM (SELECT 'POLYGON((0 0, 0 1000012333334.34545678, 1.0000001 1, 1.0000001 0, 0 0))'::geometry As geom) As foo;
<!-- TODO: Fix examples to reflect new behavior -->
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="Box2D" />, <xref linkend="Box3D" /></para>
</refsection>
</refentry>
<refentry id="ST_BoundingDiagonal">
<refnamediv>
<refname>ST_BoundingDiagonal</refname>
<refpurpose>Returns the diagonal of the supplied geometry's bounding box.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_BoundingDiagonal</function></funcdef>
<paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>fits=false</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Returns the diagonal of the supplied geometry's bounding box as linestring.
If the input geometry is empty, the diagonal line is also empty, otherwise
it is a 2-points linestring with minimum values of each dimension in its
start point and maximum values in its end point.
</para>
<para>
The returned linestring geometry always retains SRID and dimensionality
(Z and M presence) of the input geometry.
</para>
<para>
The <varname>fits</varname> parameter specifies if the best fit is needed.
If false, the diagonal of a somewhat larger bounding box can be accepted
(is faster to obtain for geometries with a lot of vertices). In any case
the bounding box of the returned diagonal line always covers the input
geometry.
</para>
<note><para>
In degenerate cases (a single vertex in input) the returned linestring
will be topologically invalid (no interior). This does not make the
return semantically invalid.
</para></note>
<para>Availability: 2.2.0</para>
<para>&Z_support;</para>
<para>&M_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Get the minimum X in a buffer around a point
SELECT ST_X(ST_StartPoint(ST_BoundingDiagonal(
ST_Buffer(ST_MakePoint(0,0),10)
)));
st_x
------
-10
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para>
<xref linkend="ST_StartPoint" />,
<xref linkend="ST_EndPoint" />,
<xref linkend="ST_X" />,
<xref linkend="ST_Y" />,
<xref linkend="ST_Z" />,
<xref linkend="ST_M" />,
<xref linkend="geometry_overlaps_nd" />
</para>
</refsection>
</refentry>
<refentry id="ST_ExteriorRing">
<refnamediv>
<refname>ST_ExteriorRing</refname>
<refpurpose>Returns a line string representing the exterior ring of the <varname>POLYGON</varname> geometry. Return
NULL if the geometry is not a polygon. Will not work with MULTIPOLYGON</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_ExteriorRing</function></funcdef>
<paramdef><type>geometry </type> <parameter>a_polygon</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns a line string representing the exterior ring of the <varname>POLYGON</varname> geometry. Return
NULL if the geometry is not a polygon.</para>
<note><para>Only works with POLYGON geometry types</para></note>
<para>&sfs_compliant; 2.1.5.1</para>
<para>&sqlmm_compliant; SQL-MM 3: 8.2.3, 8.3.3</para>
<para>&Z_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
--If you have a table of polygons
SELECT gid, ST_ExteriorRing(the_geom) AS ering
FROM sometable;
--If you have a table of MULTIPOLYGONs
--and want to return a MULTILINESTRING composed of the exterior rings of each polygon
SELECT gid, ST_Collect(ST_ExteriorRing(the_geom)) AS erings
FROM (SELECT gid, (ST_Dump(the_geom)).geom As the_geom
FROM sometable) As foo
GROUP BY gid;
--3d Example
SELECT ST_AsEWKT(
ST_ExteriorRing(
ST_GeomFromEWKT('POLYGON((0 0 1, 1 1 1, 1 2 1, 1 1 1, 0 0 1))')
)
);
st_asewkt
---------
LINESTRING(0 0 1,1 1 1,1 2 1,1 1 1,0 0 1)
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para>
<xref linkend="ST_InteriorRingN" />,
<xref linkend="ST_Boundary" />,
<xref linkend="ST_NumInteriorRings" />
</para>
</refsection>
</refentry>
<refentry id="ST_GeometryN">
<refnamediv>
<refname>ST_GeometryN</refname>
<refpurpose>Return the 1-based Nth geometry if the geometry is a
GEOMETRYCOLLECTION, (MULTI)POINT, (MULTI)LINESTRING, MULTICURVE or (MULTI)POLYGON, POLYHEDRALSURFACE
Otherwise, return NULL.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_GeometryN</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
<paramdef><type>integer </type> <parameter>n</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Return the 1-based Nth geometry if the geometry is a
GEOMETRYCOLLECTION, (MULTI)POINT, (MULTI)LINESTRING, MULTICURVE or (MULTI)POLYGON, POLYHEDRALSURFACE
Otherwise, return NULL</para>
<note>
<para>Index is 1-based as for OGC specs since version 0.8.0.
Previous versions implemented this as 0-based instead.</para>
</note>
<note>
<para>If you want to extract all geometries, of a geometry, ST_Dump is more efficient and will also work for singular geoms.</para>
</note>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.</para>
<para>Changed: 2.0.0 Prior versions would return NULL for singular geometries. This was changed to return the geometry for ST_GeometryN(..,1) case.</para>
<para>&sfs_compliant;</para>
<para>&sqlmm_compliant; SQL-MM 3: 9.1.5</para>
<para>&Z_support;</para>
<para>&curve_support;</para>
<para>&P_support;</para>
<para>&T_support;</para>
</refsection>
<refsection>
<title>Standard Examples</title>
<programlisting>--Extracting a subset of points from a 3d multipoint
SELECT n, ST_AsEWKT(ST_GeometryN(the_geom, n)) As geomewkt
FROM (
VALUES (ST_GeomFromEWKT('MULTIPOINT(1 2 7, 3 4 7, 5 6 7, 8 9 10)') ),
( ST_GeomFromEWKT('MULTICURVE(CIRCULARSTRING(2.5 2.5,4.5 2.5, 3.5 3.5), (10 11, 12 11))') )
)As foo(the_geom)
CROSS JOIN generate_series(1,100) n
WHERE n <= ST_NumGeometries(the_geom);
n | geomewkt
---+-----------------------------------------
1 | POINT(1 2 7)
2 | POINT(3 4 7)
3 | POINT(5 6 7)
4 | POINT(8 9 10)
1 | CIRCULARSTRING(2.5 2.5,4.5 2.5,3.5 3.5)
2 | LINESTRING(10 11,12 11)
--Extracting all geometries (useful when you want to assign an id)
SELECT gid, n, ST_GeometryN(the_geom, n)
FROM sometable CROSS JOIN generate_series(1,100) n
WHERE n <= ST_NumGeometries(the_geom);</programlisting>
</refsection>
<refsection><title>Polyhedral Surfaces, TIN and Triangle Examples</title>
<programlisting>-- Polyhedral surface example
-- Break a Polyhedral surface into its faces
SELECT ST_AsEWKT(ST_GeometryN(p_geom,3)) As geom_ewkt
FROM (SELECT ST_GeomFromEWKT('POLYHEDRALSURFACE(
((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),
((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)),
((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1))
)') AS p_geom ) AS a;
geom_ewkt
------------------------------------------
POLYGON((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0))</programlisting>
<programlisting>-- TIN --
SELECT ST_AsEWKT(ST_GeometryN(geom,2)) as wkt
FROM
(SELECT
ST_GeomFromEWKT('TIN (((
0 0 0,
0 0 1,
0 1 0,
0 0 0
)), ((
0 0 0,
0 1 0,
1 1 0,
0 0 0
))
)') AS geom
) AS g;
-- result --
wkt
-------------------------------------
TRIANGLE((0 0 0,0 1 0,1 1 0,0 0 0))</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Dump" />, <xref linkend="ST_NumGeometries" /></para>
</refsection>
</refentry>
<refentry id="ST_GeometryType">
<refnamediv>
<refname>ST_GeometryType</refname>
<refpurpose>Return the geometry type of the ST_Geometry value.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>ST_GeometryType</function></funcdef>
<paramdef><type>geometry </type> <parameter>g1</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the type of the geometry as a string. EG: 'ST_Linestring', 'ST_Polygon','ST_MultiPolygon' etc. This function differs from GeometryType(geometry) in the case of the string and ST in front that is returned, as well as the fact that it will not indicate whether the geometry is measured.</para>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces was introduced.</para>
<para>&sqlmm_compliant; SQL-MM 3: 5.1.4</para>
<para>&Z_support;</para>
<para>&P_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_GeometryType(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
--result
ST_LineString</programlisting>
<programlisting>SELECT ST_GeometryType(ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)), ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )'));
--result
ST_PolyhedralSurface</programlisting>
<programlisting>SELECT ST_GeometryType(ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)), ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )'));
--result
ST_PolyhedralSurface</programlisting>
<programlisting>SELECT ST_GeometryType(geom) as result
FROM
(SELECT
ST_GeomFromEWKT('TIN (((
0 0 0,
0 0 1,
0 1 0,
0 0 0
)), ((
0 0 0,
0 1 0,
1 1 0,
0 0 0
))
)') AS geom
) AS g;
result
--------
ST_Tin </programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="GeometryType" /></para>
</refsection>
</refentry>
<refentry id="ST_InteriorRingN">
<refnamediv>
<refname>ST_InteriorRingN</refname>
<refpurpose>Return the Nth interior linestring ring of the polygon geometry.
Return NULL if the geometry is not a polygon or the given N is out
of range.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_InteriorRingN</function></funcdef>
<paramdef><type>geometry </type> <parameter>a_polygon</parameter></paramdef>
<paramdef><type>integer </type> <parameter>n</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Return the Nth interior linestring ring of the polygon geometry.
Return NULL if the geometry is not a polygon or the given N is out
of range. index starts at 1.</para>
<!-- optionally mention that this function uses indexes if appropriate -->
<note>
<para>This will not work for MULTIPOLYGONs. Use in conjunction with ST_Dump for MULTIPOLYGONS</para>
</note>
<para>&sfs_compliant;</para>
<para>&sqlmm_compliant; SQL-MM 3: 8.2.6, 8.3.5</para>
<para>&Z_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT ST_AsText(ST_InteriorRingN(the_geom, 1)) As the_geom
FROM (SELECT ST_BuildArea(
ST_Collect(ST_Buffer(ST_Point(1,2), 20,3),
ST_Buffer(ST_Point(1, 2), 10,3))) As the_geom
) as foo
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="ST_ExteriorRing" />
<xref linkend="ST_BuildArea" />,
<xref linkend="ST_Collect" />,
<xref linkend="ST_Dump" />,
<xref linkend="ST_NumInteriorRing" />,
<xref linkend="ST_NumInteriorRings" />
</para>
</refsection>
</refentry>
<refentry id="ST_IsPolygonCCW">
<refnamediv>
<refname>
ST_IsPolygonCCW
</refname>
<refpurpose>
Returns true if all exterior rings are oriented counter-clockwise and all interior rings are oriented clockwise.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
boolean
<function>ST_IsPolygonCCW</function>
</funcdef>
<paramdef>
<type>geometry</type>
<parameter>geom</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Returns true if all polygonal components of the input geometry use a counter-clockwise
orientation for their exterior ring, and a clockwise direction
for all interior rings.
</para>
<para>
Returns true if the geometry has no polygonal components.
</para>
<note>
<para>
Closed linestrings are not considered polygonal components,
so you would still get a true return by passing
a single closed linestring no matter its orientation.
</para>
</note>
<note>
<para>
If a polygonal geometry does not use reversed orientation
for interior rings (i.e., if one or more interior rings
are oriented in the same direction as an exterior ring)
then both ST_IsPolygonCW and ST_IsPolygonCCW will return false.
</para>
</note>
<para>&Z_support;</para>
<para>&M_support;</para>
</refsection>
<refsection>
<title>See Also</title>
<para>
<xref linkend="ST_ForcePolygonCW" />,
<xref linkend="ST_ForcePolygonCCW" />,
<xref linkend="ST_IsPolygonCW" />
</para>
</refsection>
</refentry>
<refentry id="ST_IsPolygonCW">
<refnamediv>
<refname>
ST_IsPolygonCW
</refname>
<refpurpose>
Returns true if all exterior rings are oriented clockwise and all interior rings are oriented counter-clockwise.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>
boolean
<function>ST_IsPolygonCW</function>
</funcdef>
<paramdef>
<type>geometry</type>
<parameter>geom</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Returns true if all polygonal components of the input geometry use a clockwise
orientation for their exterior ring, and a counter-clockwise direction
for all interior rings.
</para>
<para>
Returns true if the geometry has no polygonal components.
</para>
<note>
<para>
Closed linestrings are not considered polygonal components,
so you would still get a true return by passing
a single closed linestring no matter its orientation.
</para>
</note>
<note>
<para>
If a polygonal geometry does not use reversed orientation
for interior rings (i.e., if one or more interior rings
are oriented in the same direction as an exterior ring)
then both ST_IsPolygonCW and ST_IsPolygonCCW will return false.
</para>
</note>
<para>&Z_support;</para>