Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita75e806

Browse files
author
stepan-neretin7
committed
Implemented a function and tests to extract vertices from spoly by index
1 parent612f06b commita75e806

17 files changed

+336
-12
lines changed

‎Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ DATA_built = $(RELEASE_SQL) \
2727
pg_sphere--1.1.5beta4gavo--1.2.0.sql\
2828
pg_sphere--1.2.0--1.2.1.sql\
2929
pg_sphere--1.2.1--1.2.2.sql\
30-
pg_sphere--1.2.2--1.2.3.sql
30+
pg_sphere--1.2.2--1.2.3.sql\
31+
pg_sphere--1.2.3--1.3.0.sql
3132

3233
DOCS = README.pg_sphere COPYRIGHT.pg_sphere
3334
REGRESS = init tables points euler circle line ellipse poly path box index\
@@ -260,6 +261,12 @@ endif
260261
pg_sphere--1.2.2--1.2.3.sql:
261262
cat upgrade_scripts/$@.in>$@
262263

264+
<<<<<<< HEAD
265+
=======
266+
pg_sphere--1.2.3--1.3.0.sql:
267+
cat upgrade_scripts/$@.in>$@
268+
269+
>>>>>>> c0cea51 (Implemented a function and tests to extract vertices from spoly by index)
263270
# end of local stuff
264271

265272
src/sscan.o : src/sparse.c

‎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> providestwo functions to
466+
<application>pgSphere</application> providesthree 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:159: NOTICE: argument type spath is only a shell
2424
psql:pg_sphere.test.sql:178: NOTICE: type "sbox" is not yet defined
2525
DETAIL: Creating a shell type definition.
2626
psql:pg_sphere.test.sql:185: NOTICE: argument type sbox is only a shell
27-
psql:pg_sphere.test.sql:8540: NOTICE: type "spherekey" is not yet defined
27+
psql:pg_sphere.test.sql:8566: NOTICE: type "spherekey" is not yet defined
2828
DETAIL: Creating a shell type definition.
29-
psql:pg_sphere.test.sql:8547: NOTICE: argument type spherekey is only a shell
30-
psql:pg_sphere.test.sql:8561: NOTICE: type "pointkey" is not yet defined
29+
psql:pg_sphere.test.sql:8573: NOTICE: argument type spherekey is only a shell
30+
psql:pg_sphere.test.sql:8587: NOTICE: type "pointkey" is not yet defined
3131
DETAIL: Creating a shell type definition.
32-
psql:pg_sphere.test.sql:8568: NOTICE: argument type pointkey is only a shell
33-
psql:pg_sphere.test.sql:8574: NOTICE: argument type pointkey is only a shell
34-
psql:pg_sphere.test.sql:8580: NOTICE: argument type pointkey is only a shell
35-
psql:pg_sphere.test.sql:8586: NOTICE: argument type pointkey is only a shell
32+
psql:pg_sphere.test.sql:8594: NOTICE: argument type pointkey is only a shell
33+
psql:pg_sphere.test.sql:8600: NOTICE: argument type pointkey is only a shell
34+
psql:pg_sphere.test.sql:8606: NOTICE: argument type pointkey is only a shell
35+
psql:pg_sphere.test.sql:8612: 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:9153: NOTICE: return type smoc is only a shell
2-
psql:pg_sphere.test.sql:9159: NOTICE: argument type smoc is only a shell
1+
psql:pg_sphere.test.sql:9179: NOTICE: return type smoc is only a shell
2+
psql:pg_sphere.test.sql:9185: 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
@@ -1738,3 +1738,33 @@ SELECT npoints( spoly '{
17381738
4
17391739
(1 row)
17401740

1741+
SELECT set_sphere_output( 'RAD' );
1742+
set_sphere_output
1743+
-------------------
1744+
SET RAD
1745+
(1 row)
1746+
1747+
SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 1 );
1748+
spoint
1749+
---------
1750+
(0 , 0)
1751+
(1 row)
1752+
1753+
SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 2 );
1754+
spoint
1755+
---------
1756+
(1 , 0)
1757+
(1 row)
1758+
1759+
SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 3 );
1760+
spoint
1761+
---------
1762+
(1 , 1)
1763+
(1 row)
1764+
1765+
SELECT spoly_as_array( spoly '{(0,0),(1,0),(1,1)}' );
1766+
spoly_as_array
1767+
---------------------------------
1768+
{"(0 , 0)","(1 , 0)","(1 , 1)"}
1769+
(1 row)
1770+

‎pgs_path.sql.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ CREATE FUNCTION spoint(spath, float8)
3434
COMMENT ON FUNCTION spoint(spath, float8) IS
3535
'returns n-th point of spherical path using linear interpolation';
3636

37+
CREATE FUNCTION spath_as_array(spath)
38+
RETURNS spoint[]
39+
AS 'MODULE_PATHNAME', 'spherepath_get_array'
40+
LANGUAGE 'c'
41+
IMMUTABLE STRICT PARALLEL SAFE;
42+
43+
COMMENT ON FUNCTION spath_as_array(spath) IS
44+
'returns spath as array of points';
3745

3846
-- ******************************
3947
--

‎pgs_polygon.sql.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ CREATE FUNCTION npoints(spoly)
1111
COMMENT ON FUNCTION npoints(spoly) IS
1212
'returns number of points of spherical polygon';
1313

14+
CREATE FUNCTION spoint(spoly, int4)
15+
RETURNS spoint
16+
AS 'MODULE_PATHNAME', 'spherepoly_get_point'
17+
LANGUAGE 'c'
18+
IMMUTABLE STRICT PARALLEL SAFE;
19+
20+
COMMENT ON FUNCTION spoint(spoly, int4) IS
21+
'returns n-th point of spherical polygon';
22+
23+
CREATE FUNCTION spoly_as_array(spoly)
24+
RETURNS spoint[]
25+
AS 'MODULE_PATHNAME', 'spherepoly_get_array'
26+
LANGUAGE 'c'
27+
IMMUTABLE STRICT PARALLEL SAFE;
28+
29+
COMMENT ON FUNCTION spoly_as_array(spoly) IS
30+
'returns spoly as array of points';
31+
1432
CREATE FUNCTION area(spoly)
1533
RETURNS FLOAT8
1634
AS 'MODULE_PATHNAME', 'spherepoly_area'

‎sql/path.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,9 @@ SELECT set_sphere_output( 'DEG' );
104104
-- test stored data
105105
SELECT spoint(p,2)FROM spheretmp6WHERE id=2;
106106

107+
SELECT set_sphere_output('RAD' );
108+
109+
-- get n-th point and array representation path points tests
110+
SELECT spoint( spath'{(0, 0),(1, 1)}',1 );
111+
SELECT spoint( spath'{(0, 0),(1, 1)}',2 );
112+
SELECT spath_as_array( spath'{(0, 0),(1, 1)}');

‎sql/poly.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,3 +593,10 @@ SELECT npoints( spoly '{
593593
(1.5121581120647 , -1.93925472462553e-05),
594594
(1.51214841579108 , -1.93925472462553e-05)
595595
}');
596+
597+
SELECT set_sphere_output('RAD' );
598+
599+
SELECT spoint( spoly'{(0,0),(1,0),(1,1)}',1 );
600+
SELECT spoint( spoly'{(0,0),(1,0),(1,1)}',2 );
601+
SELECT spoint( spoly'{(0,0),(1,0),(1,1)}',3 );
602+
SELECT spoly_as_array( spoly'{(0,0),(1,0),(1,1)}' );

‎src/path.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include"path.h"
2+
#include"point.h"
3+
#include<catalog/namespace.h>
24

35
/*
46
* Path functions
@@ -50,6 +52,7 @@ PG_FUNCTION_INFO_V1(spheretrans_path);
5052
PG_FUNCTION_INFO_V1(spheretrans_path_inverse);
5153
PG_FUNCTION_INFO_V1(spherepath_add_point);
5254
PG_FUNCTION_INFO_V1(spherepath_add_points_finalize);
55+
PG_FUNCTION_INFO_V1(spherepath_get_array);
5356

5457

5558
/*
@@ -555,6 +558,31 @@ spherepath_get_point(PG_FUNCTION_ARGS)
555558
PG_RETURN_NULL();
556559
}
557560

561+
Datum
562+
spherepath_get_array(PG_FUNCTION_ARGS)
563+
{
564+
SPATH*path=PG_GETARG_SPATH(0);
565+
Datum*datum_arr= (Datum*)palloc(sizeof(Datum)*path->npts);
566+
ArrayType*res;
567+
SPoint*p= (SPoint*)palloc(sizeof(SPoint)*path->npts);
568+
for (size_ti=0;i<path->npts;i++)
569+
{
570+
if (!spath_get_point(&p[i],path,i))
571+
{
572+
// Clean up and return NULL
573+
for (size_tj=0;j<i;j++)
574+
pfree(DatumGetPointer(datum_arr[j]));
575+
pfree(datum_arr);
576+
PG_RETURN_NULL();
577+
}
578+
datum_arr[i]=PointerGetDatum(&p[i]);
579+
}
580+
581+
res=construct_array(datum_arr,path->npts,get_point_id(),sizeof(SPoint), false,'d');
582+
583+
PG_RETURN_ARRAYTYPE_P(res);
584+
}
585+
558586
Datum
559587
spherepath_point(PG_FUNCTION_ARGS)
560588
{

‎src/path.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ Datumspherepath_in(PG_FUNCTION_ARGS);
7171
*/
7272
Datumspherepath_get_point(PG_FUNCTION_ARGS);
7373

74+
/*
75+
* Returns spath as array of points
76+
*/
77+
Datumspherepath_get_array(PG_FUNCTION_ARGS);
78+
7479
/*
7580
* This function interpolates between points of path. Returns the
7681
* n-th point of a path where n is a float.

‎src/point.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ PG_FUNCTION_INFO_V1(spherepoint_z);
1313
PG_FUNCTION_INFO_V1(spherepoint_xyz);
1414
PG_FUNCTION_INFO_V1(spherepoint_equal);
1515

16+
Oidget_point_id(void){
17+
if(POINT_ID==InvalidOid){
18+
POINT_ID=TypenameGetTypid("spoint");
19+
}
20+
returnPOINT_ID;
21+
}
22+
1623
bool
1724
spoint_eq(constSPoint*p1,constSPoint*p2)
1825
{

‎src/point.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include"vector3d.h"
55
#include"sbuffer.h"
6+
#include<catalog/namespace.h>
7+
#include<utils/resowner.h>
68

79
/* This file contains declarations for spherical point and functions. */
810

@@ -15,6 +17,11 @@ typedef struct
1517
float8lat;/* latitude value in radians */
1618
}SPoint;
1719

20+
__attribute__((unused))
21+
staticOidPOINT_ID=InvalidOid;
22+
23+
Oidget_point_id(void);
24+
1825
/*
1926
* Calculate the distance between two spherical points in radians.
2027
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp