Skip to content

Commit 0642734

Browse files
author
stepan-neretin7
committed
[ISSUE #16] Implemented a function and tests to extract vertices from spoly by index
1 parent 04456c7 commit 0642734

18 files changed

+747
-11
lines changed

doc/functions.sgm

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@
463463
Positions at a path
464464
</title>
465465
<para>
466-
<application>pgSphere</application> provides two functions to
466+
<application>pgSphere</application> provides three functions to
467467
get points at a path.
468468
</para>
469469
<funcsynopsis>
@@ -477,6 +477,10 @@
477477
<paramdef>spath <parameter>path</parameter></paramdef>
478478
<paramdef>float8 <parameter>f</parameter></paramdef>
479479
</funcprototype>
480+
<funcprototype>
481+
<funcdef><function>spath_as_array</function></funcdef>
482+
<paramdef>spath <parameter>path</parameter></paramdef>
483+
</funcprototype>
480484
</funcsynopsis>
481485
<para>
482486
The first function returns the <parameter>i</parameter>-th
@@ -495,6 +499,36 @@
495499
<![CDATA[ spoint]]>
496500
<![CDATA[------------]]>
497501
<![CDATA[ (15d , 0d)]]>
502+
<![CDATA[(1 row)]]>
503+
</programlisting>
504+
</example>
505+
<example>
506+
<title>
507+
Get i-th point of a path
508+
</title>
509+
<programlisting>
510+
<![CDATA[sql> SELECT spoint( spath '{(0, 0),(1, 1)}', 1 );]]>
511+
<![CDATA[ spoint ]]>
512+
<![CDATA[------------]]>
513+
<![CDATA[ (0 , 0) ]]>
514+
<![CDATA[(1 row)]]>
515+
<![CDATA[]]>
516+
<![CDATA[sql> SELECT spoint( spath '{(0, 0),(1, 1)}', 2 );]]>
517+
<![CDATA[ spoint ]]>
518+
<![CDATA[------------]]>
519+
<![CDATA[ (1 , 1) ]]>
520+
<![CDATA[(1 row)]]>
521+
</programlisting>
522+
</example>
523+
<example>
524+
<title>
525+
Get array representation of points
526+
</title>
527+
<programlisting>
528+
<![CDATA[sql> SELECT spath_as_array( spath '{(0, 0),(1, 1)}');]]>
529+
<![CDATA[ spath_as_array ]]>
530+
<![CDATA[-----------------------]]>
531+
<![CDATA[ {"(0 , 0)","(1 , 1)"}]]>
498532
<![CDATA[(1 row)]]>
499533
</programlisting>
500534
</example>
@@ -532,7 +566,58 @@
532566
</example>
533567

534568
</sect3>
535-
569+
<sect3 id="funcs.spoly.pos">
570+
<title>
571+
Positions at a polygon
572+
</title>
573+
<para>
574+
<application>pgSphere</application> provides two functions to
575+
get points at a path.
576+
</para>
577+
<funcsynopsis>
578+
<funcprototype>
579+
<funcdef><function>spoint</function></funcdef>
580+
<paramdef>spoly <parameter>path</parameter></paramdef>
581+
<paramdef>int4 <parameter>i</parameter></paramdef>
582+
</funcprototype>
583+
<funcprototype>
584+
<funcdef><function>spoly_as_array</function></funcdef>
585+
<paramdef>spath <parameter>path</parameter></paramdef>
586+
</funcprototype>
587+
</funcsynopsis>
588+
<example>
589+
<title>Get by index</title>
590+
<programlisting>
591+
<![CDATA[sql> SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 1 );]]>
592+
<![CDATA[ spoint ]]>
593+
<![CDATA[---------]]>
594+
<![CDATA[ (0 , 0)]]>
595+
<![CDATA[ (1 row)]]>
596+
<![CDATA[]]>
597+
<![CDATA[sql> SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 2 );]]>
598+
<![CDATA[ spoint ]]>
599+
<![CDATA[---------]]>
600+
<![CDATA[ (1 , 0)]]>
601+
<![CDATA[ (1 row)]]>
602+
<![CDATA[]]>
603+
<![CDATA[sql> SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 3 );]]>
604+
<![CDATA[ spoint ]]>
605+
<![CDATA[---------]]>
606+
<![CDATA[ (1 , 1)]]>
607+
<![CDATA[ (1 row)]]>
608+
</programlisting>
609+
</example>
610+
<example>
611+
<title>Represent points as array</title>
612+
<programlisting>
613+
<![CDATA[sql> SELECT spoly_as_array( spoly '{(0,0),(1,0),(1,1)}' );]]>
614+
<![CDATA[ spoly_as_array ]]>
615+
<![CDATA[---------------------------------]]>
616+
<![CDATA[ {"(0 , 0)","(1 , 0)","(1 , 1)"}]]>
617+
<![CDATA[(1 row)]]>
618+
</programlisting>
619+
</example>
620+
</sect3>
536621
</sect2>
537622

538623
<sect2 id="funcs.sbox">

expected/init_test.out.in

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ psql:pg_sphere.test.sql:158: NOTICE: argument type spath is only a shell
2424
psql:pg_sphere.test.sql:177: NOTICE: type "sbox" is not yet defined
2525
DETAIL: Creating a shell type definition.
2626
psql:pg_sphere.test.sql:184: NOTICE: argument type sbox is only a shell
27-
psql:pg_sphere.test.sql:8568: NOTICE: type "spherekey" is not yet defined
27+
psql:pg_sphere.test.sql:8594: NOTICE: type "spherekey" is not yet defined
2828
DETAIL: Creating a shell type definition.
29-
psql:pg_sphere.test.sql:8575: NOTICE: argument type spherekey is only a shell
30-
psql:pg_sphere.test.sql:8589: NOTICE: type "pointkey" is not yet defined
29+
psql:pg_sphere.test.sql:8601: NOTICE: argument type spherekey is only a shell
30+
psql:pg_sphere.test.sql:8615: NOTICE: type "pointkey" is not yet defined
3131
DETAIL: Creating a shell type definition.
32-
psql:pg_sphere.test.sql:8596: NOTICE: argument type pointkey is only a shell
33-
psql:pg_sphere.test.sql:8602: NOTICE: argument type pointkey is only a shell
34-
psql:pg_sphere.test.sql:8608: NOTICE: argument type pointkey is only a shell
35-
psql:pg_sphere.test.sql:8614: NOTICE: argument type pointkey is only a shell
32+
psql:pg_sphere.test.sql:8622: NOTICE: argument type pointkey is only a shell
33+
psql:pg_sphere.test.sql:8628: NOTICE: argument type pointkey is only a shell
34+
psql:pg_sphere.test.sql:8634: NOTICE: argument type pointkey is only a shell
35+
psql:pg_sphere.test.sql:8640: NOTICE: argument type pointkey is only a shell

expected/init_test_healpix.out.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
psql:pg_sphere.test.sql:9181: NOTICE: return type smoc is only a shell
2-
psql:pg_sphere.test.sql:9187: NOTICE: argument type smoc is only a shell
1+
psql:pg_sphere.test.sql:9207: NOTICE: return type smoc is only a shell
2+
psql:pg_sphere.test.sql:9213: NOTICE: argument type smoc is only a shell

expected/path.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,28 @@ SELECT spoint(p,2) FROM spheretmp6 WHERE id=2;
468468
(1d , -5d)
469469
(1 row)
470470

471+
SELECT set_sphere_output( 'RAD' );
472+
set_sphere_output
473+
-------------------
474+
SET RAD
475+
(1 row)
476+
477+
-- get n-th point and array representation path points tests
478+
SELECT spoint( spath '{(0, 0),(1, 1)}', 1 );
479+
spoint
480+
---------
481+
(0 , 0)
482+
(1 row)
483+
484+
SELECT spoint( spath '{(0, 0),(1, 1)}', 2 );
485+
spoint
486+
---------
487+
(1 , 1)
488+
(1 row)
489+
490+
SELECT spath_as_array( spath '{(0, 0),(1, 1)}');
491+
spath_as_array
492+
-----------------------
493+
{"(0 , 0)","(1 , 1)"}
494+
(1 row)
495+

expected/poly.out

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,3 +1760,33 @@ SELECT npoints( spoly '{
17601760
4
17611761
(1 row)
17621762

1763+
SELECT set_sphere_output( 'RAD' );
1764+
set_sphere_output
1765+
-------------------
1766+
SET RAD
1767+
(1 row)
1768+
1769+
SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 1 );
1770+
spoint
1771+
---------
1772+
(0 , 0)
1773+
(1 row)
1774+
1775+
SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 2 );
1776+
spoint
1777+
---------
1778+
(1 , 0)
1779+
(1 row)
1780+
1781+
SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 3 );
1782+
spoint
1783+
---------
1784+
(1 , 1)
1785+
(1 row)
1786+
1787+
SELECT spoly_as_array( spoly '{(0,0),(1,0),(1,1)}' );
1788+
spoly_as_array
1789+
---------------------------------
1790+
{"(0 , 0)","(1 , 0)","(1 , 1)"}
1791+
(1 row)
1792+

log/initdb.log

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Running in no-clean mode. Mistakes will not be cleaned up.
2+
The files belonging to this database system will be owned by user "durachok".
3+
This user must also own the server process.
4+
5+
The database cluster will be initialized with this locale configuration:
6+
provider: libc
7+
LC_COLLATE: ru_RU.UTF-8
8+
LC_CTYPE: ru_RU.UTF-8
9+
LC_MESSAGES: C
10+
LC_MONETARY: ru_RU.UTF-8
11+
LC_NUMERIC: ru_RU.UTF-8
12+
LC_TIME: ru_RU.UTF-8
13+
The default database encoding has accordingly been set to "UTF8".
14+
The default text search configuration will be set to "russian".
15+
16+
Data page checksums are disabled.
17+
18+
creating directory /home/durachok/workspace/pgsphere/tmp_check/data ... ok
19+
creating subdirectories ... ok
20+
selecting dynamic shared memory implementation ... posix
21+
selecting default max_connections ... 100
22+
selecting default shared_buffers ... 128MB
23+
selecting default time zone ... Asia/Novosibirsk
24+
creating configuration files ... ok
25+
running bootstrap script ... ok
26+
performing post-bootstrap initialization ... ok
27+
28+
Sync to disk skipped.
29+
The data directory might become corrupt if the operating system crashes.
30+
31+
initdb: warning: enabling "trust" authentication for local connections
32+
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
33+
34+
Success. You can now start the database server using:
35+
36+
/home/durachok/.postgres/install/bin/pg_ctl -D /home/durachok/workspace/pgsphere/tmp_check/data -l logfile start
37+

0 commit comments

Comments
 (0)