File: reference_validation.xml

package info (click to toggle)
postgis 3.1.1%2Bdfsg-1%2Bdeb11u2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 83,792 kB
  • sloc: ansic: 151,982; sql: 146,734; xml: 51,051; sh: 6,186; cpp: 6,110; perl: 4,852; makefile: 3,002; python: 1,205; yacc: 447; lex: 133; javascript: 6
file content (400 lines) | stat: -rw-r--r-- 13,935 bytes parent folder | download
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
<?xml version="1.0" encoding="UTF-8"?>

  <sect1 id="Geometry_Validation">

	  <sect1info>
	    <abstract>
			<para>These functions test whether geometries are valid according to
			the OGC SFS standard.
            They also provide information about the nature and location of invalidity.
            There is also a function to create a valid geometry out of an invalid one.
			</para>
   	</abstract>
    </sect1info>

	<title>Geometry Validation</title>

	<refentry id="ST_IsValid">
	  <refnamediv>
		<refname>ST_IsValid</refname>

		<refpurpose>Tests if a geometry is well-formed in 2D.
		</refpurpose>
	  </refnamediv>

	  <refsynopsisdiv>
		<funcsynopsis>
		  <funcprototype>
			<funcdef>boolean <function>ST_IsValid</function></funcdef>

			<paramdef><type>geometry </type> <parameter>g</parameter></paramdef>
		  </funcprototype>
		  <funcprototype>
			<funcdef>boolean <function>ST_IsValid</function></funcdef>

			<paramdef><type>geometry </type> <parameter>g</parameter></paramdef>
			<paramdef><type>integer </type> <parameter>flags</parameter></paramdef>
		  </funcprototype>
		</funcsynopsis>
	  </refsynopsisdiv>

	  <refsection>
		<title>Description</title>

		<para>
                  Test if an ST_Geometry value is well-formed in 2D according to the OGC rules.
		  For geometries that are invalid, the PostgreSQL NOTICE will provide details of why it is not valid.
                  For geometries with 3 and 4 dimensions, the validity still only tested in 2 dimensions.
                </para>
		<para>
For the version with flags,
supported <varname>flags</varname> are documented in <xref linkend="ST_IsValidDetail" />
This version does not print a NOTICE explaining invalidity.
		</para>
		<para>For more information on the definition of geometry validity, refer
			to <link linkend="OGC_Validity">"Ensuring OpenGIS compliancy of geometries"</link>
		</para>
		<note>
			<para>SQL-MM defines the result of ST_IsValid(NULL) to be 0, while
			PostGIS returns NULL.</para>
		</note>
	  <para>Performed by the GEOS module.</para>

		<para>The version accepting flags is available starting with 2.0.0.		</para>


		<para>&sfs_compliant;</para>
		<para>&sqlmm_compliant; SQL-MM 3: 5.1.9</para>

		<note>
			<para>
Neither OGC-SFS nor SQL-MM specifications include a flag argument
for ST_IsValid. The flag is a PostGIS extension.
			</para>
		</note>


	  </refsection>

	  <refsection>
		<title>Examples</title>

		<programlisting>SELECT ST_IsValid(ST_GeomFromText('LINESTRING(0 0, 1 1)')) As good_line,
	ST_IsValid(ST_GeomFromText('POLYGON((0 0, 1 1, 1 2, 1 1, 0 0))')) As bad_poly
--results
NOTICE:  Self-intersection at or near point 0 0
 good_line | bad_poly
-----------+----------
 t         | f
</programlisting>
	  </refsection>

	  <refsection>
		<title>See Also</title>

		<para>
<xref linkend="ST_IsSimple" />,
<xref linkend="ST_IsValidReason" />,
<xref linkend="ST_IsValidDetail" />,
<xref linkend="ST_Summary" />
</para>
	  </refsection>
	</refentry>


	<refentry id="ST_IsValidDetail">
	  <refnamediv>
		<refname>ST_IsValidDetail</refname>

		<refpurpose>Returns a <varname>valid_detail</varname> row stating if a geometry is valid, and if not a reason why and a location.</refpurpose>
	  </refnamediv>

	  <refsynopsisdiv>
		<funcsynopsis>
		  <funcprototype>
			<funcdef>valid_detail <function>ST_IsValidDetail</function></funcdef>
			<paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
			<paramdef choice="opt"><type>integer </type> <parameter>flags</parameter></paramdef>
		  </funcprototype>
		</funcsynopsis>
	  </refsynopsisdiv>

	  <refsection>
		<title>Description</title>

		<para>Returns a valid_detail row, formed by a boolean (valid) stating if a geometry is valid, a varchar (reason) stating a reason why it is invalid and a geometry (location) pointing out where it is invalid.</para>

		<para>Useful to substitute and improve the combination of ST_IsValid and ST_IsValidReason to generate a detailed report of invalid geometries.</para>

		<para>
The 'flags' argument is a bitfield. It can have the following values:
			<itemizedlist>
				<listitem>
<para>
1: Consider self-intersecting rings forming holes as valid.
   This is also know as "the ESRI flag".
   Note that this is against the OGC model.
</para>
				</listitem>
			</itemizedlist>
		</para>
		<para>Performed by the GEOS module.</para>
		<para>Availability: 2.0.0</para>
	  </refsection>

	  <refsection>
		<title>Examples</title>

		<programlisting>
--First 3 Rejects from a successful quintuplet experiment
SELECT gid, reason(ST_IsValidDetail(the_geom)), ST_AsText(location(ST_IsValidDetail(the_geom))) as location
FROM
(SELECT ST_MakePolygon(ST_ExteriorRing(e.buff), array_agg(f.line)) As the_geom, gid
FROM (SELECT ST_Buffer(ST_MakePoint(x1*10,y1), z1) As buff, x1*10 + y1*100 + z1*1000 As gid
	FROM generate_series(-4,6) x1
	CROSS JOIN generate_series(2,5) y1
	CROSS JOIN generate_series(1,8) z1
	WHERE x1 &gt; y1*0.5 AND z1 &lt; x1*y1) As e
	INNER JOIN (SELECT ST_Translate(ST_ExteriorRing(ST_Buffer(ST_MakePoint(x1*10,y1), z1)),y1*1, z1*2) As line
	FROM generate_series(-3,6) x1
	CROSS JOIN generate_series(2,5) y1
	CROSS JOIN generate_series(1,10) z1
	WHERE x1 &gt; y1*0.75 AND z1 &lt; x1*y1) As f
ON (ST_Area(e.buff) &gt; 78 AND ST_Contains(e.buff, f.line))
GROUP BY gid, e.buff) As quintuplet_experiment
WHERE ST_IsValid(the_geom) = false
ORDER BY gid
LIMIT 3;

 gid  |      reason       |  location
------+-------------------+-------------
 5330 | Self-intersection | POINT(32 5)
 5340 | Self-intersection | POINT(42 5)
 5350 | Self-intersection | POINT(52 5)

 --simple example
SELECT * FROM ST_IsValidDetail('LINESTRING(220227 150406,2220227 150407,222020 150410)');

 valid | reason | location
-------+--------+----------
 t     |        |

		</programlisting>
	  </refsection>

	  <!-- Optionally add a "See Also" section -->
	  <refsection>
		<title>See Also</title>

		<para>
<xref linkend="ST_IsValid" />,
<xref linkend="ST_IsValidReason" />
</para>
	  </refsection>
	</refentry>

	<refentry id="ST_IsValidReason">
	  <refnamediv>
		<refname>ST_IsValidReason</refname>

		<refpurpose>Returns text stating if a geometry is valid, or a reason for invalidity.</refpurpose>
	  </refnamediv>

	  <refsynopsisdiv>
		<funcsynopsis>
		  <funcprototype>
			<funcdef>text <function>ST_IsValidReason</function></funcdef>
			<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
			<paramdef><type>integer </type> <parameter>flags</parameter></paramdef>
		  </funcprototype>

		  <funcprototype>
			<funcdef>text <function>ST_IsValidReason</function></funcdef>
			<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
		  </funcprototype>
		</funcsynopsis>
	  </refsynopsisdiv>

	  <refsection>
		<title>Description</title>

		<para>Returns text stating if a geometry is valid or not an if not valid, a reason why.</para>

		<para>Useful in combination with ST_IsValid to generate a detailed report of invalid geometries and reasons.</para>

		<para>
Allowed <varname>flags</varname> are documented in <xref linkend="ST_IsValidDetail" />.
		</para>
		<para>Performed by the GEOS module.</para>
		<para>Availability: 1.4</para>
		<para>Availability: 2.0 version taking flags.</para>
	  </refsection>
	  <refsection>
		<title>Examples</title>

		<programlisting>
--First 3 Rejects from a successful quintuplet experiment
SELECT gid, ST_IsValidReason(the_geom) as validity_info
FROM
(SELECT ST_MakePolygon(ST_ExteriorRing(e.buff), array_agg(f.line)) As the_geom, gid
FROM (SELECT ST_Buffer(ST_MakePoint(x1*10,y1), z1) As buff, x1*10 + y1*100 + z1*1000 As gid
	FROM generate_series(-4,6) x1
	CROSS JOIN generate_series(2,5) y1
	CROSS JOIN generate_series(1,8) z1
	WHERE x1 &gt; y1*0.5 AND z1 &lt; x1*y1) As e
	INNER JOIN (SELECT ST_Translate(ST_ExteriorRing(ST_Buffer(ST_MakePoint(x1*10,y1), z1)),y1*1, z1*2) As line
	FROM generate_series(-3,6) x1
	CROSS JOIN generate_series(2,5) y1
	CROSS JOIN generate_series(1,10) z1
	WHERE x1 &gt; y1*0.75 AND z1 &lt; x1*y1) As f
ON (ST_Area(e.buff) &gt; 78 AND ST_Contains(e.buff, f.line))
GROUP BY gid, e.buff) As quintuplet_experiment
WHERE ST_IsValid(the_geom) = false
ORDER BY gid
LIMIT 3;

 gid  |      validity_info
------+--------------------------
 5330 | Self-intersection [32 5]
 5340 | Self-intersection [42 5]
 5350 | Self-intersection [52 5]

 --simple example
SELECT ST_IsValidReason('LINESTRING(220227 150406,2220227 150407,222020 150410)');

 st_isvalidreason
------------------
 Valid Geometry

		</programlisting>
	  </refsection>

	  <!-- Optionally add a "See Also" section -->
	  <refsection>
		<title>See Also</title>

		<para><xref linkend="ST_IsValid" />, <xref linkend="ST_Summary" /></para>
	  </refsection>
	</refentry>

    <refentry id="ST_MakeValid">
      <refnamediv>
        <refname>ST_MakeValid</refname>
        <refpurpose>Attempts to make an invalid geometry valid without losing vertices.</refpurpose>
      </refnamediv>

      <refsynopsisdiv>
        <funcsynopsis>
          <funcprototype>
            <funcdef>geometry <function>ST_MakeValid</function></funcdef>
            <paramdef><type>geometry</type> <parameter>input</parameter></paramdef>
          </funcprototype>
        </funcsynopsis>
      </refsynopsisdiv>

      <refsection>
        <title>Description</title>
    <para>
    The function attempts to create a valid representation of a given invalid
    geometry without losing any of the input vertices.
    Already-valid geometries are returned without further intervention.
    </para>

    <para>
    Supported inputs are: POINTS, MULTIPOINTS, LINESTRINGS,
    MULTILINESTRINGS, POLYGONS, MULTIPOLYGONS and GEOMETRYCOLLECTIONS
    containing any mix of them.
    </para>

    <para>
    In case of full or partial dimensional collapses, the output geometry
    may be a collection of lower-to-equal dimension geometries or a
    geometry of lower dimension.
    </para>

    <para>
    Single polygons may become multi-geometries in case of self-intersections.
    </para>
        <para>Performed by the GEOS module.</para>

    <para>Availability: 2.0.0</para>
    <para>Enhanced: 2.0.1, speed improvements</para>
    <para>Enhanced: 2.1.0, added support for GEOMETRYCOLLECTION and MULTIPOINT.</para>
    <para>Enhanced: 3.1.0, added removal of Coordinates with NaN values.</para>

    <para>&Z_support;</para>

          </refsection>
          <refsection>
            <title>Examples</title>
            <informaltable>
                  <tgroup cols="1">
                    <tbody>
                    <row>
                        <entry><para><informalfigure>
                            <mediaobject>
                              <imageobject>
                                <imagedata fileref="images/st_makevalid01.png" />
                              </imageobject>
                              <caption><para>before_geom: MULTIPOLYGON of 2 overlapping polygons</para></caption>
                            </mediaobject>
                          </informalfigure>
                          <informalfigure>
                            <mediaobject>
                              <imageobject>
                                <imagedata fileref="images/st_makevalid02.png" />
                              </imageobject>
                              <caption><para>after_geom: MULTIPOLYGON of 4 non-overlapping polygons</para>
                              </caption>
                            </mediaobject>
                          </informalfigure>
                <programlisting>SELECT f.geom AS before_geom, ST_MakeValid( f.geom) AS after_geom
FROM (SELECT 'MULTIPOLYGON(((186 194,187 194,188 195,189 195,190 195,
191 195,192 195,193 194,194 194,194 193,195 192,195 191,
195 190,195 189,195 188,194 187,194 186,14 6,13 6,12 5,11 5,
10 5,9 5,8 5,7 6,6 6,6 7,5 8,5 9,5 10,5 11,5 12,6 13,6 14,186 194)),
((150 90,149 80,146 71,142 62,135 55,128 48,119 44,110 41,100 40,
90 41,81 44,72 48,65 55,58 62,54 71,51 80,50 90,51 100,
54 109,58 118,65 125,72 132,81 136,90 139,100 140,110 139,
119 136,128 132,135 125,142 118,146 109,149 100,150 90)))'::geometry AS geom) AS f;</programlisting>
            </para>
            </entry>
        </row>
        <row>
            <entry><para>
                <informalfigure>
                <mediaobject>
                    <imageobject><imagedata fileref="images/st_makevalid03.png" /></imageobject>
                    <caption><para>before_geom: MULTIPOLYGON of 6 overlapping polygons</para></caption>
                </mediaobject>
                </informalfigure>
                <informalfigure>
                <mediaobject>
                    <imageobject><imagedata fileref="images/st_makevalid04.png" /></imageobject>
                    <caption><para>after_geom: MULTIPOLYGON of 14 Non-overlapping polygons</para></caption>
                </mediaobject>
                </informalfigure>
                <programlisting>SELECT c.geom AS before_geom, ST_MakeValid(c.geom) AS after_geom
	FROM (SELECT 'MULTIPOLYGON(((91 50,79 22,51 10,23 22,11 50,23 78,51 90,79 78,91 50)),
		  ((91 100,79 72,51 60,23 72,11 100,23 128,51 140,79 128,91 100)),
		  ((91 150,79 122,51 110,23 122,11 150,23 178,51 190,79 178,91 150)),
		  ((141 50,129 22,101 10,73 22,61 50,73 78,101 90,129 78,141 50)),
		  ((141 100,129 72,101 60,73 72,61 100,73 128,101 140,129 128,141 100)),
		  ((141 150,129 122,101 110,73 122,61 150,73 178,101 190,129 178,141 150)))'::geometry AS geom) AS c;</programlisting>
            </para></entry>
        </row>
    </tbody>
    </tgroup>
</informaltable>
</refsection>
          <refsection>
            <title>See Also</title>
            <para>
                <xref linkend="ST_IsValid" />,
                <xref linkend="ST_Collect" />,
                <xref linkend="ST_CollectionExtract" />
            </para>
          </refsection>
    </refentry>

  </sect1>