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

[ISSUE #16] Implemented a function and tests to extract vertices from spoly by index#37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vitcpp merged 1 commit intopostgrespro:masterfromdura0ok:get_nth_dot_spoly
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 87 additions & 2 deletionsdoc/functions.sgm
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -463,7 +463,7 @@
Positions at a path
</title>
<para>
<application>pgSphere</application> providestwo functions to
<application>pgSphere</application> providesthree functions to
get points at a path.
</para>
<funcsynopsis>
Expand All@@ -477,6 +477,10 @@
<paramdef>spath <parameter>path</parameter></paramdef>
<paramdef>float8 <parameter>f</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef><function>spath_as_array</function></funcdef>
<paramdef>spath <parameter>path</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
The first function returns the <parameter>i</parameter>-th
Expand All@@ -495,6 +499,36 @@
<![CDATA[ spoint]]>
<![CDATA[------------]]>
<![CDATA[ (15d , 0d)]]>
<![CDATA[(1 row)]]>
</programlisting>
</example>
<example>
<title>
Get i-th point of a path
</title>
<programlisting>
<![CDATA[sql> SELECT spoint( spath '{(0, 0),(1, 1)}', 1 );]]>
<![CDATA[ spoint ]]>
<![CDATA[------------]]>
<![CDATA[ (0 , 0) ]]>
<![CDATA[(1 row)]]>
<![CDATA[]]>
<![CDATA[sql> SELECT spoint( spath '{(0, 0),(1, 1)}', 2 );]]>
<![CDATA[ spoint ]]>
<![CDATA[------------]]>
<![CDATA[ (1 , 1) ]]>
<![CDATA[(1 row)]]>
</programlisting>
</example>
<example>
<title>
Get array representation of points
</title>
<programlisting>
<![CDATA[sql> SELECT spath_as_array( spath '{(0, 0),(1, 1)}');]]>
<![CDATA[ spath_as_array ]]>
<![CDATA[-----------------------]]>
<![CDATA[ {"(0 , 0)","(1 , 1)"}]]>
<![CDATA[(1 row)]]>
</programlisting>
</example>
Expand DownExpand Up@@ -532,7 +566,58 @@
</example>

</sect3>

<sect3 id="funcs.spoly.pos">
<title>
Positions at a polygon
</title>
<para>
<application>pgSphere</application> provides two functions to
get points at a path.
</para>
<funcsynopsis>
<funcprototype>
<funcdef><function>spoint</function></funcdef>
<paramdef>spoly <parameter>path</parameter></paramdef>
<paramdef>int4 <parameter>i</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef><function>spoly_as_array</function></funcdef>
<paramdef>spath <parameter>path</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<example>
<title>Get by index</title>
<programlisting>
<![CDATA[sql> SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 1 );]]>
<![CDATA[ spoint ]]>
<![CDATA[---------]]>
<![CDATA[ (0 , 0)]]>
<![CDATA[ (1 row)]]>
<![CDATA[]]>
<![CDATA[sql> SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 2 );]]>
<![CDATA[ spoint ]]>
<![CDATA[---------]]>
<![CDATA[ (1 , 0)]]>
<![CDATA[ (1 row)]]>
<![CDATA[]]>
<![CDATA[sql> SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 3 );]]>
<![CDATA[ spoint ]]>
<![CDATA[---------]]>
<![CDATA[ (1 , 1)]]>
<![CDATA[ (1 row)]]>
</programlisting>
</example>
<example>
<title>Represent points as array</title>
<programlisting>
<![CDATA[sql> SELECT spoly_as_array( spoly '{(0,0),(1,0),(1,1)}' );]]>
<![CDATA[ spoly_as_array ]]>
<![CDATA[---------------------------------]]>
<![CDATA[ {"(0 , 0)","(1 , 0)","(1 , 1)"}]]>
<![CDATA[(1 row)]]>
</programlisting>
</example>
</sect3>
</sect2>

<sect2 id="funcs.sbox">
Expand Down
14 changes: 7 additions & 7 deletionsexpected/init_test.out.in
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,12 +24,12 @@ psql:pg_sphere.test.sql:158: NOTICE: argument type spath is only a shell
psql:pg_sphere.test.sql:177: NOTICE: type "sbox" is not yet defined
DETAIL: Creating a shell type definition.
psql:pg_sphere.test.sql:184: NOTICE: argument type sbox is only a shell
psql:pg_sphere.test.sql:8568: NOTICE: type "spherekey" is not yet defined
psql:pg_sphere.test.sql:8594: NOTICE: type "spherekey" is not yet defined
DETAIL: Creating a shell type definition.
psql:pg_sphere.test.sql:8575: NOTICE: argument type spherekey is only a shell
psql:pg_sphere.test.sql:8589: NOTICE: type "pointkey" is not yet defined
psql:pg_sphere.test.sql:8601: NOTICE: argument type spherekey is only a shell
psql:pg_sphere.test.sql:8615: NOTICE: type "pointkey" is not yet defined
DETAIL: Creating a shell type definition.
psql:pg_sphere.test.sql:8596: NOTICE: argument type pointkey is only a shell
psql:pg_sphere.test.sql:8602: NOTICE: argument type pointkey is only a shell
psql:pg_sphere.test.sql:8608: NOTICE: argument type pointkey is only a shell
psql:pg_sphere.test.sql:8614: NOTICE: argument type pointkey is only a shell
psql:pg_sphere.test.sql:8622: NOTICE: argument type pointkey is only a shell
psql:pg_sphere.test.sql:8628: NOTICE: argument type pointkey is only a shell
psql:pg_sphere.test.sql:8634: NOTICE: argument type pointkey is only a shell
psql:pg_sphere.test.sql:8640: NOTICE: argument type pointkey is only a shell
4 changes: 2 additions & 2 deletionsexpected/init_test_healpix.out.in
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
psql:pg_sphere.test.sql:9181: NOTICE: return type smoc is only a shell
psql:pg_sphere.test.sql:9187: NOTICE: argument type smoc is only a shell
psql:pg_sphere.test.sql:9207: NOTICE: return type smoc is only a shell
psql:pg_sphere.test.sql:9213: NOTICE: argument type smoc is only a shell
25 changes: 25 additions & 0 deletionsexpected/path.out
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -468,3 +468,28 @@ SELECT spoint(p,2) FROM spheretmp6 WHERE id=2;
(1d , -5d)
(1 row)

SELECT set_sphere_output( 'RAD' );
set_sphere_output
-------------------
SET RAD
(1 row)

-- get n-th point and array representation path points tests
SELECT spoint( spath '{(0, 0),(1, 1)}', 1 );
spoint
---------
(0 , 0)
(1 row)

SELECT spoint( spath '{(0, 0),(1, 1)}', 2 );
spoint
---------
(1 , 1)
(1 row)

SELECT spath_as_array( spath '{(0, 0),(1, 1)}');
spath_as_array
-----------------------
{"(0 , 0)","(1 , 1)"}
(1 row)

30 changes: 30 additions & 0 deletionsexpected/poly.out
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1760,3 +1760,33 @@ SELECT npoints( spoly '{
4
(1 row)

SELECT set_sphere_output( 'RAD' );
set_sphere_output
-------------------
SET RAD
(1 row)

SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 1 );
spoint
---------
(0 , 0)
(1 row)

SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 2 );
spoint
---------
(1 , 0)
(1 row)

SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 3 );
spoint
---------
(1 , 1)
(1 row)

SELECT spoly_as_array( spoly '{(0,0),(1,0),(1,1)}' );
spoly_as_array
---------------------------------
{"(0 , 0)","(1 , 0)","(1 , 1)"}
(1 row)

8 changes: 8 additions & 0 deletionspgs_path.sql.in
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,6 +34,14 @@ CREATE FUNCTION spoint(spath, float8)
COMMENT ON FUNCTION spoint(spath, float8) IS
'returns n-th point of spherical path using linear interpolation';

CREATE FUNCTION spath_as_array(spath)
RETURNS spoint[]
AS 'MODULE_PATHNAME', 'spherepath_get_array'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;

COMMENT ON FUNCTION spath_as_array(spath) IS
'returns spath as array of points';

-- ******************************
--
Expand Down
18 changes: 18 additions & 0 deletionspgs_polygon.sql.in
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,24 @@ CREATE FUNCTION npoints(spoly)
COMMENT ON FUNCTION npoints(spoly) IS
'returns number of points of spherical polygon';

CREATE FUNCTION spoint(spoly, int4)
RETURNS spoint
AS 'MODULE_PATHNAME', 'spherepoly_get_point'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;

COMMENT ON FUNCTION spoint(spoly, int4) IS
'returns n-th point of spherical polygon';

CREATE FUNCTION spoly_as_array(spoly)
RETURNS spoint[]
AS 'MODULE_PATHNAME', 'spherepoly_get_array'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;

COMMENT ON FUNCTION spoly_as_array(spoly) IS
'returns spoly as array of points';

CREATE FUNCTION area(spoly)
RETURNS FLOAT8
AS 'MODULE_PATHNAME', 'spherepoly_area'
Expand Down
6 changes: 6 additions & 0 deletionssql/path.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -104,3 +104,9 @@ SELECT set_sphere_output( 'DEG' );
-- test stored data
SELECT spoint(p,2) FROM spheretmp6 WHERE id=2;

SELECT set_sphere_output( 'RAD' );

-- get n-th point and array representation path points tests
SELECT spoint( spath '{(0, 0),(1, 1)}', 1 );
SELECT spoint( spath '{(0, 0),(1, 1)}', 2 );
SELECT spath_as_array( spath '{(0, 0),(1, 1)}');
7 changes: 7 additions & 0 deletionssql/poly.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -603,3 +603,10 @@ SELECT npoints( spoly '{
(1.5121581120647 , -1.93925472462553e-05),
(1.51214841579108 , -1.93925472462553e-05)
}');

SELECT set_sphere_output( 'RAD' );

SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 1 );
SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 2 );
SELECT spoint( spoly '{(0,0),(1,0),(1,1)}', 3 );
SELECT spoly_as_array( spoly '{(0,0),(1,0),(1,1)}' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I hate to nitpick whitespace, but I recommend removing one of the two spaces after the SELECTs on lines 599, 601, 603, and 605.

Otherwise, it looks good to me! But if you're adding a function, shouldn't there be an upgrade script and version number bump? Or will that be done in a separate PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Of course, but which version should we put?@vitcpp

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As we discussed before, the master branch is the development branch. Once the API is changed I propose to assign a new version 1.3.0. Upgrade script should be named as pg_sphere--1.2.3--1.3.0.sql.in. The same as I proposed in#22.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Concerning the use of blank lines for queries separation. I propose to follow the same coding style. There are no blank lines in sql/path.sql but there are blank lines in sql/poly.sql. I propose to remove these redundant blank lines.

Copy link
Contributor

@esabolesabolAug 1, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Except PR#38 already bumps the version to 1.3.0 and adds an upgrade script. I propose merging PR#38 first and then git rebase this PR on the new master to add this functionality to the future 1.3.0.

dura0ok and vitcpp reacted with thumbs up emoji
27 changes: 27 additions & 0 deletionssrc/path.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
#include "path.h"
#include "point.h"
#include <catalog/namespace.h>

/*
* Path functions
Expand DownExpand Up@@ -50,6 +52,7 @@ PG_FUNCTION_INFO_V1(spheretrans_path);
PG_FUNCTION_INFO_V1(spheretrans_path_inverse);
PG_FUNCTION_INFO_V1(spherepath_add_point);
PG_FUNCTION_INFO_V1(spherepath_add_points_finalize);
PG_FUNCTION_INFO_V1(spherepath_get_array);


/*
Expand DownExpand Up@@ -555,6 +558,30 @@ spherepath_get_point(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
}

Datum
spherepath_get_array(PG_FUNCTION_ARGS)
{
SPATH *path = PG_GETARG_SPATH(0);
Datum *datum_arr = (Datum *) palloc(sizeof(Datum) * path->npts);
ArrayType *res;
SPoint *p = (SPoint *) palloc(sizeof(SPoint) * path->npts);

for (size_t i = 0; i < path->npts; i++)
{
if (!spath_get_point(&p[i], path, i))
{
pfree(p);
pfree(datum_arr);
PG_RETURN_NULL();
}
datum_arr[i] = PointerGetDatum(&p[i]);
}

res = construct_array(datum_arr, path->npts, get_spoint_type_oid(), sizeof(SPoint), false, 'd');

PG_RETURN_ARRAYTYPE_P(res);
}

Datum
spherepath_point(PG_FUNCTION_ARGS)
{
Expand Down
5 changes: 5 additions & 0 deletionssrc/path.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,11 @@ Datumspherepath_in(PG_FUNCTION_ARGS);
*/
Datumspherepath_get_point(PG_FUNCTION_ARGS);

/*
* Returns spath as array of points
*/
Datumspherepath_get_array(PG_FUNCTION_ARGS);

/*
* This function interpolates between points of path. Returns the
* n-th point of a path where n is a float.
Expand Down
12 changes: 12 additions & 0 deletionssrc/point.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
#include "point.h"
#include "pgs_util.h"
#include <catalog/namespace.h>

/* This file contains definitions for spherical point functions. */

Expand All@@ -15,6 +16,17 @@ PG_FUNCTION_INFO_V1(spherepoint_z);
PG_FUNCTION_INFO_V1(spherepoint_xyz);
PG_FUNCTION_INFO_V1(spherepoint_equal);

static Oid point_id = InvalidOid;

Oidget_spoint_type_oid(void)
{
if (point_id == InvalidOid)
{
point_id = TypenameGetTypid("spoint");
}
return point_id;
}

bool
spoint_eq(const SPoint *p1, const SPoint *p2)
{
Expand Down
2 changes: 2 additions & 0 deletionssrc/point.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,8 @@ typedef struct
float8lat;/* latitude value in radians */
} SPoint;

Oidget_spoint_type_oid(void);

/*
* Calculate the distance between two spherical points in radians.
*/
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp