forked from bnordgren/postgis
-
Notifications
You must be signed in to change notification settings - Fork 5
/
geography.sql.in.c
715 lines (597 loc) · 23 KB
/
geography.sql.in.c
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
---------------------------------------------------------------------------
-- $Id$
--
-- PostGIS - Spatial Types for PostgreSQL
-- Copyright 2009 Paul Ramsey <pramsey@cleverelephant.ca>
--
-- This is free software; you can redistribute and/or modify it under
-- the terms of the GNU General Public Licence. See the COPYING file.
--
---------------------------------------------------------------------------
-----------------------------------------------------------------------------
-- GEOGRAPHY TYPE
-----------------------------------------------------------------------------
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography_typmod_in(cstring[])
RETURNS integer
AS 'MODULE_PATHNAME','geography_typmod_in'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography_typmod_out(integer)
RETURNS cstring
AS 'MODULE_PATHNAME','postgis_typmod_out'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography_in(cstring, oid, integer)
RETURNS geography
AS 'MODULE_PATHNAME','geography_in'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography_out(geography)
RETURNS cstring
AS 'MODULE_PATHNAME','geography_out'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geography_recv(internal, oid, integer)
RETURNS geography
AS 'MODULE_PATHNAME','geography_recv'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geography_send(geography)
RETURNS bytea
AS 'MODULE_PATHNAME','geography_send'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography_analyze(internal)
RETURNS bool
AS 'MODULE_PATHNAME','geography_analyze'
LANGUAGE 'C' VOLATILE STRICT;
-- Availability: 1.5.0
CREATE TYPE geography (
internallength = variable,
input = geography_in,
output = geography_out,
receive = geography_recv,
send = geography_send,
typmod_in = geography_typmod_in,
typmod_out = geography_typmod_out,
delimiter = ':',
analyze = geography_analyze,
storage = main,
alignment = double
);
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography(geography, integer, boolean)
RETURNS geography
AS 'MODULE_PATHNAME','geography_enforce_typmod'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE CAST (geography AS geography) WITH FUNCTION geography(geography, integer, boolean) AS IMPLICIT;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION geography(bytea)
RETURNS geography
AS 'MODULE_PATHNAME','LWGEOM_from_bytea'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION bytea(geography)
RETURNS bytea
AS 'MODULE_PATHNAME','LWGEOM_to_bytea'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 2.0.0
CREATE CAST (bytea AS geography) WITH FUNCTION geography(bytea) AS IMPLICIT;
-- Availability: 2.0.0
CREATE CAST (geography AS bytea) WITH FUNCTION bytea(geography) AS IMPLICIT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_AsText(geography)
RETURNS TEXT
AS 'MODULE_PATHNAME','LWGEOM_asText'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
CREATE OR REPLACE FUNCTION ST_AsText(text)
RETURNS text AS
$$ SELECT ST_AsText($1::geometry); $$
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_GeographyFromText(text)
RETURNS geography
AS 'MODULE_PATHNAME','geography_from_text'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_GeogFromText(text)
RETURNS geography
AS 'MODULE_PATHNAME','geography_from_text'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_GeogFromWKB(bytea)
RETURNS geography
AS 'MODULE_PATHNAME','geography_from_binary'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION postgis_typmod_dims(integer)
RETURNS integer
AS 'MODULE_PATHNAME','postgis_typmod_dims'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION postgis_typmod_srid(integer)
RETURNS integer
AS 'MODULE_PATHNAME','postgis_typmod_srid'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION postgis_typmod_type(integer)
RETURNS text
AS 'MODULE_PATHNAME','postgis_typmod_type'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE VIEW geography_columns AS
SELECT
current_database() AS f_table_catalog,
n.nspname AS f_table_schema,
c.relname AS f_table_name,
a.attname AS f_geography_column,
postgis_typmod_dims(a.atttypmod) AS coord_dimension,
postgis_typmod_srid(a.atttypmod) AS srid,
postgis_typmod_type(a.atttypmod) AS type
FROM
pg_class c,
pg_attribute a,
pg_type t,
pg_namespace n
WHERE t.typname = 'geography'
AND a.attisdropped = false
AND a.atttypid = t.oid
AND a.attrelid = c.oid
AND c.relnamespace = n.oid
AND NOT pg_is_other_temp_schema(c.relnamespace);
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography(geometry)
RETURNS geography
AS 'MODULE_PATHNAME','geography_from_geometry'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE CAST (geometry AS geography) WITH FUNCTION geography(geometry) AS IMPLICIT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geometry(geography)
RETURNS geometry
AS 'MODULE_PATHNAME','geometry_from_geography'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE CAST (geography AS geometry) WITH FUNCTION geometry(geography) ;
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- GiST Support Functions
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography_gist_consistent(internal,geography,int4)
RETURNS bool
AS 'MODULE_PATHNAME' ,'gserialized_gist_consistent'
LANGUAGE 'C';
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography_gist_compress(internal)
RETURNS internal
AS 'MODULE_PATHNAME','gserialized_gist_compress'
LANGUAGE 'C';
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography_gist_penalty(internal,internal,internal)
RETURNS internal
AS 'MODULE_PATHNAME' ,'gserialized_gist_penalty'
LANGUAGE 'C';
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography_gist_picksplit(internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME' ,'gserialized_gist_picksplit'
LANGUAGE 'C';
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography_gist_union(bytea, internal)
RETURNS internal
AS 'MODULE_PATHNAME' ,'gserialized_gist_union'
LANGUAGE 'C';
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography_gist_same(box2d, box2d, internal)
RETURNS internal
AS 'MODULE_PATHNAME' ,'gserialized_gist_same'
LANGUAGE 'C';
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography_gist_decompress(internal)
RETURNS internal
AS 'MODULE_PATHNAME' ,'gserialized_gist_decompress'
LANGUAGE 'C';
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography_gist_selectivity (internal, oid, internal, int4)
RETURNS float8
AS 'MODULE_PATHNAME', 'geography_gist_selectivity'
LANGUAGE 'C';
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography_gist_join_selectivity(internal, oid, internal, smallint)
RETURNS float8
AS 'MODULE_PATHNAME', 'geography_gist_selectivity'
LANGUAGE 'C';
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION geography_overlaps(geography, geography)
RETURNS boolean
AS 'MODULE_PATHNAME' ,'gserialized_overlaps'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OPERATOR && (
LEFTARG = geography, RIGHTARG = geography, PROCEDURE = geography_overlaps,
COMMUTATOR = '&&',
RESTRICT = geography_gist_selectivity,
JOIN = geography_gist_join_selectivity
);
-- Availability: 1.5.0
CREATE OPERATOR CLASS gist_geography_ops
DEFAULT FOR TYPE geography USING GIST AS
STORAGE gidx,
OPERATOR 3 && ,
-- OPERATOR 6 ~= ,
-- OPERATOR 7 ~ ,
-- OPERATOR 8 @ ,
FUNCTION 1 geography_gist_consistent (internal, geography, int4),
FUNCTION 2 geography_gist_union (bytea, internal),
FUNCTION 3 geography_gist_compress (internal),
FUNCTION 4 geography_gist_decompress (internal),
FUNCTION 5 geography_gist_penalty (internal, internal, internal),
FUNCTION 6 geography_gist_picksplit (internal, internal),
FUNCTION 7 geography_gist_same (box2d, box2d, internal);
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- B-Tree Functions
-- For sorting and grouping
-- Availability: 1.5.0
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
CREATE OR REPLACE FUNCTION geography_lt(geography, geography)
RETURNS bool
AS 'MODULE_PATHNAME', 'geography_lt'
LANGUAGE 'C' IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION geography_le(geography, geography)
RETURNS bool
AS 'MODULE_PATHNAME', 'geography_le'
LANGUAGE 'C' IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION geography_gt(geography, geography)
RETURNS bool
AS 'MODULE_PATHNAME', 'geography_gt'
LANGUAGE 'C' IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION geography_ge(geography, geography)
RETURNS bool
AS 'MODULE_PATHNAME', 'geography_ge'
LANGUAGE 'C' IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION geography_eq(geography, geography)
RETURNS bool
AS 'MODULE_PATHNAME', 'geography_eq'
LANGUAGE 'C' IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION geography_cmp(geography, geography)
RETURNS integer
AS 'MODULE_PATHNAME', 'geography_cmp'
LANGUAGE 'C' IMMUTABLE STRICT;
--
-- Sorting operators for Btree
--
CREATE OPERATOR < (
LEFTARG = geography, RIGHTARG = geography, PROCEDURE = geography_lt,
COMMUTATOR = '>', NEGATOR = '>=',
RESTRICT = contsel, JOIN = contjoinsel
);
CREATE OPERATOR <= (
LEFTARG = geography, RIGHTARG = geography, PROCEDURE = geography_le,
COMMUTATOR = '>=', NEGATOR = '>',
RESTRICT = contsel, JOIN = contjoinsel
);
CREATE OPERATOR = (
LEFTARG = geography, RIGHTARG = geography, PROCEDURE = geography_eq,
COMMUTATOR = '=', -- we might implement a faster negator here
RESTRICT = contsel, JOIN = contjoinsel
);
CREATE OPERATOR >= (
LEFTARG = geography, RIGHTARG = geography, PROCEDURE = geography_ge,
COMMUTATOR = '<=', NEGATOR = '<',
RESTRICT = contsel, JOIN = contjoinsel
);
CREATE OPERATOR > (
LEFTARG = geography, RIGHTARG = geography, PROCEDURE = geography_gt,
COMMUTATOR = '<', NEGATOR = '<=',
RESTRICT = contsel, JOIN = contjoinsel
);
CREATE OPERATOR CLASS btree_geography_ops
DEFAULT FOR TYPE geography USING btree AS
OPERATOR 1 < ,
OPERATOR 2 <= ,
OPERATOR 3 = ,
OPERATOR 4 >= ,
OPERATOR 5 > ,
FUNCTION 1 geography_cmp (geography, geography);
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- Export Functions
-- Availability: 1.5.0
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
--
-- SVG OUTPUT
--
-- ST_AsSVG(geography, rel, precision)
-- rel int4 DEFAULT 0, maxdecimaldigits int4 DEFAULT 15
-- Changed 2.0.0 to use default args and named args
CREATE OR REPLACE FUNCTION ST_AsSVG(geog geography,rel int4 DEFAULT 0,maxdecimaldigits int4 DEFAULT 15)
RETURNS text
AS 'MODULE_PATHNAME','geography_as_svg'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
CREATE OR REPLACE FUNCTION ST_AsSVG(text)
RETURNS text AS
$$ SELECT ST_AsSVG($1::geometry,0,15); $$
LANGUAGE 'SQL' IMMUTABLE STRICT;
--
-- GML OUTPUT
--
-- _ST_AsGML(version, geography, precision, option)
CREATE OR REPLACE FUNCTION _ST_AsGML(int4, geography, int4, int4, text)
RETURNS text
AS 'MODULE_PATHNAME','geography_as_gml'
LANGUAGE 'C' IMMUTABLE;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
-- Change 2.0.0 to use base function
CREATE OR REPLACE FUNCTION ST_AsGML(text)
RETURNS text AS
$$ SELECT _ST_AsGML(2,$1::geometry,15,0, NULL); $$
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- ST_AsGML (geography, precision, option) / version=2
-- Availability: 1.5.0
-- Changed: 2.0.0 to use default args
CREATE OR REPLACE FUNCTION ST_AsGML(geog geography, maxdecimaldigits int4 DEFAULT 15, options int4 DEFAULT 0)
RETURNS text
AS 'SELECT _ST_AsGML(2, $1, $2, $3, null)'
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- ST_AsGML(version, geography, precision, option, prefix)
-- Changed: 2.0.0 to use default args and allow named args
CREATE OR REPLACE FUNCTION ST_AsGML(version int4, geog geography, maxdecimaldigits int4 DEFAULT 15, options int4 DEFAULT 0, nprefix text DEFAULT NULL)
RETURNS text
AS $$ SELECT _ST_AsGML($1, $2, $3, $4, $5);$$
LANGUAGE 'SQL' IMMUTABLE;
--
-- KML OUTPUT
--
-- _ST_AsKML(version, geography, precision)
CREATE OR REPLACE FUNCTION _ST_AsKML(int4, geography, int4, text)
RETURNS text
AS 'MODULE_PATHNAME','geography_as_kml'
LANGUAGE 'C' IMMUTABLE;
-- AsKML(geography,precision) / version=2
-- Changed: 2.0.0 to use default args and named args
CREATE OR REPLACE FUNCTION ST_AsKML(geog geography, maxdecimaldigits int4 DEFAULT 15)
RETURNS text
AS 'SELECT _ST_AsKML(2, $1, $2, null)'
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
-- Deprecated 2.0.0
CREATE OR REPLACE FUNCTION ST_AsKML(text)
RETURNS text AS
$$ SELECT _ST_AsKML(2, $1::geometry, 15, null); $$
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- ST_AsKML(version, geography, precision, prefix)
-- Availability: 2.0.0 nprefix added
-- Changed: 2.0.0 to use default args and named args
CREATE OR REPLACE FUNCTION ST_AsKML(version int4, geog geography, maxdecimaldigits int4 DEFAULT 15, nprefix text DEFAULT null)
RETURNS text
AS 'SELECT _ST_AsKML($1, $2, $3, $4)'
LANGUAGE 'SQL' IMMUTABLE;
--
-- GeoJson Output
--
CREATE OR REPLACE FUNCTION _ST_AsGeoJson(int4, geography, int4, int4)
RETURNS text
AS 'MODULE_PATHNAME','geography_as_geojson'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
-- Deprecated in 2.0.0
CREATE OR REPLACE FUNCTION ST_AsGeoJson(text)
RETURNS text AS
$$ SELECT _ST_AsGeoJson(1, $1::geometry,15,0); $$
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- ST_AsGeoJson(geography, precision, options) / version=1
-- Changed: 2.0.0 to use default args and named args
CREATE OR REPLACE FUNCTION ST_AsGeoJson(geog geography, maxdecimaldigits int4 DEFAULT 15, options int4 DEFAULT 0)
RETURNS text
AS $$ SELECT _ST_AsGeoJson(1, $1, $2, $3); $$
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- ST_AsGeoJson(version, geography, precision,options)
-- Changed: 2.0.0 to use default args and named args
CREATE OR REPLACE FUNCTION ST_AsGeoJson(gj_version int4, geog geography, maxdecimaldigits int4 DEFAULT 15, options int4 DEFAULT 0)
RETURNS text
AS $$ SELECT _ST_AsGeoJson($1, $2, $3, $4); $$
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- Measurement Functions
-- Availability: 1.5.0
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- Stop calculation and return immediately once distance is less than tolerance
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION _ST_Distance(geography, geography, float8, boolean)
RETURNS float8
AS 'MODULE_PATHNAME','geography_distance'
LANGUAGE 'C' IMMUTABLE STRICT
COST 100;
-- Stop calculation and return immediately once distance is less than tolerance
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION _ST_DWithin(geography, geography, float8, boolean)
RETURNS boolean
AS 'MODULE_PATHNAME','geography_dwithin'
LANGUAGE 'C' IMMUTABLE STRICT
COST 100;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_Distance(geography, geography, boolean)
RETURNS float8
AS 'SELECT _ST_Distance($1, $2, 0.0, $3)'
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- Currently defaulting to spheroid calculations
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_Distance(geography, geography)
RETURNS float8
AS 'SELECT _ST_Distance($1, $2, 0.0, true)'
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
CREATE OR REPLACE FUNCTION ST_Distance(text, text)
RETURNS float8 AS
$$ SELECT ST_Distance($1::geometry, $2::geometry); $$
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- Only expands the bounding box, the actual geometry will remain unchanged, use with care.
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION _ST_Expand(geography, float8)
RETURNS geography
AS 'MODULE_PATHNAME','geography_expand'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_DWithin(geography, geography, float8, boolean)
RETURNS boolean
AS 'SELECT $1 && _ST_Expand($2,$3) AND $2 && _ST_Expand($1,$3) AND _ST_DWithin($1, $2, $3, $4)'
LANGUAGE 'SQL' IMMUTABLE;
-- Currently defaulting to spheroid calculations
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_DWithin(geography, geography, float8)
RETURNS boolean
AS 'SELECT $1 && _ST_Expand($2,$3) AND $2 && _ST_Expand($1,$3) AND _ST_DWithin($1, $2, $3, true)'
LANGUAGE 'SQL' IMMUTABLE;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
CREATE OR REPLACE FUNCTION ST_DWithin(text, text, float8)
RETURNS boolean AS
$$ SELECT ST_DWithin($1::geometry, $2::geometry, $3); $$
LANGUAGE 'SQL' IMMUTABLE;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_Area(geog geography, use_spheroid boolean DEFAULT true)
RETURNS float8
AS 'MODULE_PATHNAME','geography_area'
LANGUAGE 'C' IMMUTABLE STRICT
COST 100;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
CREATE OR REPLACE FUNCTION ST_Area(text)
RETURNS float8 AS
$$ SELECT ST_Area($1::geometry); $$
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_Length(geog geography, use_spheroid boolean DEFAULT true)
RETURNS float8
AS 'MODULE_PATHNAME','geography_length'
LANGUAGE 'C' IMMUTABLE STRICT
COST 100;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
CREATE OR REPLACE FUNCTION ST_Length(text)
RETURNS float8 AS
$$ SELECT ST_Length($1::geometry); $$
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION ST_Project(geog geography, distance float8, azimuth float8)
RETURNS geography
AS 'MODULE_PATHNAME','geography_project'
LANGUAGE 'C' IMMUTABLE
COST 100;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION ST_Azimuth(geog1 geography, geog2 geography)
RETURNS float8
AS 'MODULE_PATHNAME','geography_azimuth'
LANGUAGE 'C' IMMUTABLE STRICT
COST 100;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION ST_Perimeter(geog geography, use_spheroid boolean DEFAULT true)
RETURNS float8
AS 'MODULE_PATHNAME','geography_perimeter'
LANGUAGE 'C' IMMUTABLE STRICT
COST 100;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION _ST_PointOutside(geography)
RETURNS geography
AS 'MODULE_PATHNAME','geography_point_outside'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Only implemented for polygon-over-point
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION _ST_Covers(geography, geography)
RETURNS boolean
AS 'MODULE_PATHNAME','geography_covers'
LANGUAGE 'C' IMMUTABLE STRICT
COST 100;
-- Only implemented for polygon-over-point
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_Covers(geography, geography)
RETURNS boolean
AS 'SELECT $1 && $2 AND _ST_Covers($1, $2)'
LANGUAGE 'SQL' IMMUTABLE;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
CREATE OR REPLACE FUNCTION ST_Covers(text, text)
RETURNS boolean AS
$$ SELECT ST_Covers($1::geometry, $2::geometry); $$
LANGUAGE 'SQL' IMMUTABLE ;
-- Only implemented for polygon-over-point
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_CoveredBy(geography, geography)
RETURNS boolean
AS 'SELECT $1 && $2 AND _ST_Covers($2, $1)'
LANGUAGE 'SQL' IMMUTABLE ;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
CREATE OR REPLACE FUNCTION ST_CoveredBy(text, text)
RETURNS boolean AS
$$ SELECT ST_CoveredBy($1::geometry, $2::geometry); $$
LANGUAGE 'SQL' IMMUTABLE ;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_Intersects(geography, geography)
RETURNS boolean
AS 'SELECT $1 && $2 AND _ST_Distance($1, $2, 0.0, false) < 0.00001'
LANGUAGE 'SQL' IMMUTABLE ;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
CREATE OR REPLACE FUNCTION ST_Intersects(text, text)
RETURNS boolean AS
$$ SELECT ST_Intersects($1::geometry, $2::geometry); $$
LANGUAGE 'SQL' IMMUTABLE ;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION _ST_BestSRID(geography, geography)
RETURNS integer
AS 'MODULE_PATHNAME','geography_bestsrid'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION _ST_BestSRID(geography)
RETURNS integer
AS 'SELECT _ST_BestSRID($1,$1)'
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_Buffer(geography, float8)
RETURNS geography
AS 'SELECT geography(ST_Transform(ST_Buffer(ST_Transform(geometry($1), _ST_BestSRID($1)), $2), 4326))'
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
CREATE OR REPLACE FUNCTION ST_Buffer(text, float8)
RETURNS geometry AS
$$ SELECT ST_Buffer($1::geometry, $2); $$
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_Intersection(geography, geography)
RETURNS geography
AS 'SELECT geography(ST_Transform(ST_Intersection(ST_Transform(geometry($1), _ST_BestSRID($1, $2)), ST_Transform(geometry($2), _ST_BestSRID($1, $2))), 4326))'
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
CREATE OR REPLACE FUNCTION ST_Intersection(text, text)
RETURNS geometry AS
$$ SELECT ST_Intersection($1::geometry, $2::geometry); $$
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_AsBinary(geography)
RETURNS bytea
AS 'MODULE_PATHNAME','LWGEOM_asBinary'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION ST_AsBinary(geography,text)
RETURNS bytea AS
$$ SELECT ST_AsBinary($1::geometry, $2); $$
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION ST_AsEWKT(geography)
RETURNS TEXT
AS 'MODULE_PATHNAME','LWGEOM_asEWKT'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 2.0.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
CREATE OR REPLACE FUNCTION ST_AsEWKT(text)
RETURNS text AS
$$ SELECT ST_AsEWKT($1::geometry); $$
LANGUAGE 'SQL' IMMUTABLE STRICT;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION GeometryType(geography)
RETURNS text
AS 'MODULE_PATHNAME', 'LWGEOM_getTYPE'
LANGUAGE 'C' IMMUTABLE STRICT;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION ST_Summary(geography)
RETURNS text
AS 'MODULE_PATHNAME', 'LWGEOM_summary'
LANGUAGE 'C' IMMUTABLE STRICT;
-----------------------------------------------------------------------------