diff --git a/doc/constructors.sgm b/doc/constructors.sgm index e14dd3f..4f87651 100644 --- a/doc/constructors.sgm +++ b/doc/constructors.sgm @@ -268,22 +268,45 @@ Polygon + - The aggregate function + The functions spoly and spoly_deg + can be used to create spherical polygons. Function spoly + is overloaded and can accept arrays of float8 or spoint elements. + There are the same restrictions as for using the input function of + spherical polygon (see ). - - - spoly - spoint edge - - + - can be used to create a polygon from a set of spherical points. - There are the same restrictions as for using the input function of - spherical polygon (see ). The function - returns - NULL, if the polygon couldn't be created. + Create a spherical polygon from an array of pair-consecutive + numbers (lng, lat). The coordinates are specified in radians. + + SELECT spoly(ARRAY[0, 0, 0, 0.5, 0.5, 0.5, 0.5, 0])]]> + + + + Create a spherical polygon from an array of spoint elements. + + SELECT spoly(ARRAY[spoint(0, 0), spoint(0, 0.5), spoint(0.5, 0.5), spoint(0.5, 0)])]]> + + + + + Create a spherical polygon from an array of pair-consecutive + numbers (lng, lat). The coordinates are specified in degrees. + + SELECT spoly_deg(ARRAY[0, 0, 0, 10, 10, 10, 10, 0])]]> + + + + + The aggregate function spoly can be used to + create a polygon from a set of spherical points. The function + returns NULL, if the polygon could not be + created. + + Create a spherical polygon using a set of spherical points diff --git a/expected/poly.out b/expected/poly.out index 2d622b5..1ce3963 100644 --- a/expected/poly.out +++ b/expected/poly.out @@ -12,25 +12,25 @@ SELECT spoint '(0.15,0.10)' @ :poly; -- point inside polygon t (1 row) -SELECT spoint '(0.20,0.00)' @ :poly; -- point contained polygon +SELECT spoint '(0.20,0.00)' @ :poly; -- point contained polygon ?column? ---------- t (1 row) -SELECT spoint '(0.10,0.10)' @ :poly; -- point contained polygon +SELECT spoint '(0.10,0.10)' @ :poly; -- point contained polygon ?column? ---------- t (1 row) -SELECT spoint '(0.25,0.50)' @ :poly; -- point outside polygon +SELECT spoint '(0.25,0.50)' @ :poly; -- point outside polygon ?column? ---------- f (1 row) -SELECT spoint '(0.25,0.00)' @ :poly; -- point outside polygon +SELECT spoint '(0.25,0.00)' @ :poly; -- point outside polygon ?column? ---------- f @@ -42,13 +42,13 @@ SELECT scircle '<(0.15,0.10),0.03>' @ :poly; -- circle inside polygon t (1 row) -SELECT scircle '<(0.20,0.00),0.00>' @ :poly; -- circle contained polygon +SELECT scircle '<(0.20,0.00),0.00>' @ :poly; -- circle contained polygon ?column? ---------- t (1 row) -SELECT scircle '<(0.20,0.30),0.05>' @ :poly; -- circle outside polygon +SELECT scircle '<(0.20,0.30),0.05>' @ :poly; -- circle outside polygon ?column? ---------- f @@ -72,13 +72,13 @@ SELECT scircle '<(0.15,0.10),0.03>' && :poly; -- circle inside polygon t (1 row) -SELECT scircle '<(0.20,0.00),0.00>' && :poly; -- circle contained polygon +SELECT scircle '<(0.20,0.00),0.00>' && :poly; -- circle contained polygon ?column? ---------- t (1 row) -SELECT scircle '<(0.20,0.30),0.05>' && :poly; -- circle outside polygon +SELECT scircle '<(0.20,0.30),0.05>' && :poly; -- circle outside polygon ?column? ---------- f @@ -96,13 +96,13 @@ SELECT scircle '<(0.25,0.00),0.10>' && :poly; -- circle overlaps polyg t (1 row) -SELECT sline ( spoint '(0.00, 0.00)', spoint '(0.10,0.20)' ) @ :poly; -- line touches polygon +SELECT sline ( spoint '(0.00, 0.00)', spoint '(0.10,0.20)' ) @ :poly; -- line touches polygon ?column? ---------- f (1 row) -SELECT sline ( spoint '(0.00, 0.10)', spoint '(0.10,0.10)' ) @ :poly; -- line touches polygon +SELECT sline ( spoint '(0.00, 0.10)', spoint '(0.10,0.10)' ) @ :poly; -- line touches polygon ?column? ---------- f @@ -114,7 +114,7 @@ SELECT sline ( spoint '(0.50, 0.00)', spoint '(0.50,0.20)' ) @ :poly; -- line f (1 row) -SELECT sline ( spoint '(0.10, 0.20)', spoint '(0.20,0.00)' ) @ :poly; -- line touches and inside polygon +SELECT sline ( spoint '(0.10, 0.20)', spoint '(0.20,0.00)' ) @ :poly; -- line touches and inside polygon ?column? ---------- t @@ -138,13 +138,13 @@ SELECT sline ( spoint '(0.24, 0.17)', spoint '(0.25,0.14)' ) @ :poly; -- line t (1 row) -SELECT sline ( spoint '(0.00, 0.00)', spoint '(0.10,0.20)' ) && :poly; -- line touches polygon +SELECT sline ( spoint '(0.00, 0.00)', spoint '(0.10,0.20)' ) && :poly; -- line touches polygon ?column? ---------- t (1 row) -SELECT sline ( spoint '(0.00, 0.10)', spoint '(0.10,0.10)' ) && :poly; -- line touches polygon +SELECT sline ( spoint '(0.00, 0.10)', spoint '(0.10,0.10)' ) && :poly; -- line touches polygon ?column? ---------- t @@ -156,7 +156,7 @@ SELECT sline ( spoint '(0.50, 0.00)', spoint '(0.50,0.20)' ) && :poly; -- line t (1 row) -SELECT sline ( spoint '(0.10, 0.20)', spoint '(0.20,0.00)' ) && :poly; -- line touches and inside polygon +SELECT sline ( spoint '(0.10, 0.20)', spoint '(0.20,0.00)' ) && :poly; -- line touches and inside polygon ?column? ---------- t @@ -342,7 +342,32 @@ SELECT spoly_deg(ARRAY[10.0, 0.0, 10.0, 1.0, 15.0, 0.0]); {(10d , 0d),(10d , 1d),(15d , 0d)} (1 row) --- incorrect input ----- +--- Constructors +SELECT spoly(NULL::spoint[]); + spoly +------- + +(1 row) + +SELECT spoly(ARRAY[]::spoint[]); +ERROR: spherepoly_from_point_array: invalid number of arguments (must be >= 3) +SELECT spoly(ARRAY[spoint_deg(0, 0)]); +ERROR: spherepoly_from_point_array: invalid number of arguments (must be >= 3) +SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0)]); +ERROR: spherepoly_from_point_array: invalid number of arguments (must be >= 3) +SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0), spoint_deg(10, 10)]); + spoly +------------------------------------ + {(0d , 0d),(10d , 0d),(10d , 10d)} +(1 row) + +SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0), spoint_deg(10, 10), spoint_deg(0, 10)]); + spoly +----------------------------------------------- + {(0d , 0d),(10d , 0d),(10d , 10d),(0d , 10d)} +(1 row) + +--- incorrect input ----- SELECT spoly '{(10d,0d),(10d,1d)}'; ERROR: spherepoly_in: more than two points needed LINE 1: SELECT spoly '{(10d,0d),(10d,1d)}'; @@ -1211,7 +1236,7 @@ SELECT spoly '{(0d,-88d),(90d,-88d),(180d,-88d),(270d,-88d)}' @ spoly '{(0d,89d) (1 row) --- spoly ~ spoly ---- should be true +--- should be true SELECT spoly '{(-1d,-1d),(-1d,1d),(1d,1d),(1d,-1d)}' ~ spoly '{(0d,0d),(0d,0.5d),(0.5d,0.5d),(0.5d,0d)}'; ?column? ---------- @@ -1280,7 +1305,7 @@ SELECT spoly '{(0d,89d),(90d,89d),(180d,89d),(270d,89d)}' ~ spoly '{(0d,-88d),(9 (1 row) --- spoly && spoly ---- should be true +--- should be true SELECT spoly '{(0d,0d),(0d,0.5d),(0.5d,0.5d),(0.5d,0d)}' && spoly '{(-1d,-1d),(-1d,1d),(1d,1d),(1d,-1d)}'; ?column? ---------- @@ -1417,7 +1442,6 @@ SELECT spoly '{(-1d,-1d),(-1d,1d),(1d,1d),(1d,-1d)}' && spoly '{(179d,-1d),(179d -- -- ellipse and polygon -- - -- negators , commutator @,&& SELECT spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' @ sellipse '<{10d,5d},(280d,-20d),90d>'; ?column? @@ -1564,49 +1588,49 @@ SELECT sellipse '<{10d,5d},(280d,-20d),90d>' !&& spoly '{(280d,-11d),(280d,-12 (1 row) -- ellipse is point -SELECT spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' @ sellipse '<{0d,0d},(280d,-20d),90d>'; +SELECT spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' @ sellipse '<{0d,0d},(280d,-20d),90d>'; ?column? ---------- f (1 row) -SELECT spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}' @ sellipse '<{0d,0d},(280d,-20d),90d>'; +SELECT spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}' @ sellipse '<{0d,0d},(280d,-20d),90d>'; ?column? ---------- f (1 row) -SELECT spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' && sellipse '<{0d,0d},(280d,-20d),90d>'; +SELECT spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' && sellipse '<{0d,0d},(280d,-20d),90d>'; ?column? ---------- f (1 row) -SELECT spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}' && sellipse '<{0d,0d},(280d,-20d),90d>'; +SELECT spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}' && sellipse '<{0d,0d},(280d,-20d),90d>'; ?column? ---------- t (1 row) -SELECT sellipse '<{0d,0d},(280d,-20d),90d>' @ spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' ; +SELECT sellipse '<{0d,0d},(280d,-20d),90d>' @ spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' ; ?column? ---------- f (1 row) -SELECT sellipse '<{0d,0d},(280d,-20d),90d>' @ spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}'; +SELECT sellipse '<{0d,0d},(280d,-20d),90d>' @ spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}'; ?column? ---------- t (1 row) -SELECT sellipse '<{0d,0d},(280d,-20d),90d>' && spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' ; +SELECT sellipse '<{0d,0d},(280d,-20d),90d>' && spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' ; ?column? ---------- f (1 row) -SELECT sellipse '<{0d,0d},(280d,-20d),90d>' && spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}'; +SELECT sellipse '<{0d,0d},(280d,-20d),90d>' && spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}'; ?column? ---------- t diff --git a/pgs_polygon.sql.in b/pgs_polygon.sql.in index 3a5d801..0e73bec 100644 --- a/pgs_polygon.sql.in +++ b/pgs_polygon.sql.in @@ -948,6 +948,15 @@ CREATE FUNCTION spoly(float8[]) COMMENT ON FUNCTION spoly(float8[]) IS 'creates spoly from array of numbers in radians'; +CREATE FUNCTION spoly(spoint[]) + RETURNS spoly + AS 'MODULE_PATHNAME', 'spherepoly_from_point_array' + LANGUAGE 'c' + IMMUTABLE STRICT PARALLEL SAFE; + +COMMENT ON FUNCTION spoly(spoint[]) IS + 'creates spoly from an array of points'; + CREATE FUNCTION spoly_deg(float8[]) RETURNS spoly AS 'MODULE_PATHNAME', 'spherepoly_deg' @@ -987,7 +996,6 @@ CREATE AGGREGATE spoly ( finalfunc = spoly_add_points_fin_aggr ); - -- -- polygon is convex -- diff --git a/sql/poly.sql b/sql/poly.sql index a3f36d4..972674e 100644 --- a/sql/poly.sql +++ b/sql/poly.sql @@ -7,31 +7,31 @@ SET extra_float_digits = 0; \set poly 'spoly \'{(0.1,0),(0.2,0),(0.2,0.1),(0.3,0.1),(0.3,-0.1),(0.4,-0.1),(0.5,0.1),(0.4,0.2),(0.1,0.2)}\'' SELECT spoint '(0.15,0.10)' @ :poly; -- point inside polygon -SELECT spoint '(0.20,0.00)' @ :poly; -- point contained polygon -SELECT spoint '(0.10,0.10)' @ :poly; -- point contained polygon -SELECT spoint '(0.25,0.50)' @ :poly; -- point outside polygon -SELECT spoint '(0.25,0.00)' @ :poly; -- point outside polygon +SELECT spoint '(0.20,0.00)' @ :poly; -- point contained polygon +SELECT spoint '(0.10,0.10)' @ :poly; -- point contained polygon +SELECT spoint '(0.25,0.50)' @ :poly; -- point outside polygon +SELECT spoint '(0.25,0.00)' @ :poly; -- point outside polygon SELECT scircle '<(0.15,0.10),0.03>' @ :poly; -- circle inside polygon -SELECT scircle '<(0.20,0.00),0.00>' @ :poly; -- circle contained polygon -SELECT scircle '<(0.20,0.30),0.05>' @ :poly; -- circle outside polygon +SELECT scircle '<(0.20,0.00),0.00>' @ :poly; -- circle contained polygon +SELECT scircle '<(0.20,0.30),0.05>' @ :poly; -- circle outside polygon SELECT scircle '<(0.25,0.00),0.05>' @ :poly; -- circle overlaps polygon SELECT scircle '<(0.25,0.00),0.10>' @ :poly; -- circle overlaps polygon SELECT scircle '<(0.15,0.10),0.03>' && :poly; -- circle inside polygon -SELECT scircle '<(0.20,0.00),0.00>' && :poly; -- circle contained polygon -SELECT scircle '<(0.20,0.30),0.05>' && :poly; -- circle outside polygon +SELECT scircle '<(0.20,0.00),0.00>' && :poly; -- circle contained polygon +SELECT scircle '<(0.20,0.30),0.05>' && :poly; -- circle outside polygon SELECT scircle '<(0.25,0.00),0.05>' && :poly; -- circle overlaps polygon SELECT scircle '<(0.25,0.00),0.10>' && :poly; -- circle overlaps polygon -SELECT sline ( spoint '(0.00, 0.00)', spoint '(0.10,0.20)' ) @ :poly; -- line touches polygon -SELECT sline ( spoint '(0.00, 0.10)', spoint '(0.10,0.10)' ) @ :poly; -- line touches polygon +SELECT sline ( spoint '(0.00, 0.00)', spoint '(0.10,0.20)' ) @ :poly; -- line touches polygon +SELECT sline ( spoint '(0.00, 0.10)', spoint '(0.10,0.10)' ) @ :poly; -- line touches polygon SELECT sline ( spoint '(0.50, 0.00)', spoint '(0.50,0.20)' ) @ :poly; -- line touches polygon -SELECT sline ( spoint '(0.10, 0.20)', spoint '(0.20,0.00)' ) @ :poly; -- line touches and inside polygon +SELECT sline ( spoint '(0.10, 0.20)', spoint '(0.20,0.00)' ) @ :poly; -- line touches and inside polygon SELECT sline ( spoint '(0.45,-0.20)', spoint '(0.45,0.20)' ) @ :poly; -- line overlaps polygon SELECT sline ( spoint '(0.45, 0.10)', spoint '(0.45,0.20)' ) @ :poly; -- line overlaps polygon SELECT sline ( spoint '(0.24, 0.17)', spoint '(0.25,0.14)' ) @ :poly; -- line inside polygon -SELECT sline ( spoint '(0.00, 0.00)', spoint '(0.10,0.20)' ) && :poly; -- line touches polygon -SELECT sline ( spoint '(0.00, 0.10)', spoint '(0.10,0.10)' ) && :poly; -- line touches polygon +SELECT sline ( spoint '(0.00, 0.00)', spoint '(0.10,0.20)' ) && :poly; -- line touches polygon +SELECT sline ( spoint '(0.00, 0.10)', spoint '(0.10,0.10)' ) && :poly; -- line touches polygon SELECT sline ( spoint '(0.50, 0.00)', spoint '(0.50,0.20)' ) && :poly; -- line touches polygon -SELECT sline ( spoint '(0.10, 0.20)', spoint '(0.20,0.00)' ) && :poly; -- line touches and inside polygon +SELECT sline ( spoint '(0.10, 0.20)', spoint '(0.20,0.00)' ) && :poly; -- line touches and inside polygon SELECT sline ( spoint '(0.45,-0.20)', spoint '(0.45,0.20)' ) && :poly; -- line overlaps polygon SELECT sline ( spoint '(0.45, 0.10)', spoint '(0.45,0.20)' ) && :poly; -- line overlaps polygon SELECT sline ( spoint '(0.24, 0.17)', spoint '(0.25,0.14)' ) && :poly; -- line inside polygon @@ -86,7 +86,21 @@ SELECT spoly_deg(ARRAY[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]); SELECT spoly_deg(ARRAY[10.0, 0.0, 10.0, 1.0, 15.0, 0.0]); --- incorrect input ----- +--- Constructors + +SELECT spoly(NULL::spoint[]); + +SELECT spoly(ARRAY[]::spoint[]); + +SELECT spoly(ARRAY[spoint_deg(0, 0)]); + +SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0)]); + +SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0), spoint_deg(10, 10)]); + +SELECT spoly(ARRAY[spoint_deg(0, 0), spoint_deg(10, 0), spoint_deg(10, 10), spoint_deg(0, 10)]); + +--- incorrect input ----- SELECT spoly '{(10d,0d),(10d,1d)}'; @@ -457,7 +471,7 @@ SELECT spoly '{(0d,-88d),(90d,-88d),(180d,-88d),(270d,-88d)}' @ spoly '{(0d,89d) --- spoly ~ spoly ---- should be true +--- should be true SELECT spoly '{(-1d,-1d),(-1d,1d),(1d,1d),(1d,-1d)}' ~ spoly '{(0d,0d),(0d,0.5d),(0.5d,0.5d),(0.5d,0d)}'; @@ -485,7 +499,7 @@ SELECT spoly '{(0d,89d),(90d,89d),(180d,89d),(270d,89d)}' ~ spoly '{(0d,-88d),(9 --- spoly && spoly ---- should be true +--- should be true SELECT spoly '{(0d,0d),(0d,0.5d),(0.5d,0.5d),(0.5d,0d)}' && spoly '{(-1d,-1d),(-1d,1d),(1d,1d),(1d,-1d)}'; @@ -536,7 +550,7 @@ SELECT spoly '{(-1d,-1d),(-1d,1d),(1d,1d),(1d,-1d)}' && spoly '{(179d,-1d),(179d -- -- ellipse and polygon -- - + -- negators , commutator @,&& SELECT spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' @ sellipse '<{10d,5d},(280d,-20d),90d>'; @@ -565,14 +579,14 @@ SELECT sellipse '<{10d,5d},(280d,-20d),90d>' !&& spoly '{(280d, -9d),(280d,-12 SELECT sellipse '<{10d,5d},(280d,-20d),90d>' !&& spoly '{(280d,-11d),(280d,-12d),(279d, -12d)}'; -- ellipse is point -SELECT spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' @ sellipse '<{0d,0d},(280d,-20d),90d>'; -SELECT spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}' @ sellipse '<{0d,0d},(280d,-20d),90d>'; -SELECT spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' && sellipse '<{0d,0d},(280d,-20d),90d>'; -SELECT spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}' && sellipse '<{0d,0d},(280d,-20d),90d>'; -SELECT sellipse '<{0d,0d},(280d,-20d),90d>' @ spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' ; -SELECT sellipse '<{0d,0d},(280d,-20d),90d>' @ spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}'; -SELECT sellipse '<{0d,0d},(280d,-20d),90d>' && spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' ; -SELECT sellipse '<{0d,0d},(280d,-20d),90d>' && spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}'; +SELECT spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' @ sellipse '<{0d,0d},(280d,-20d),90d>'; +SELECT spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}' @ sellipse '<{0d,0d},(280d,-20d),90d>'; +SELECT spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' && sellipse '<{0d,0d},(280d,-20d),90d>'; +SELECT spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}' && sellipse '<{0d,0d},(280d,-20d),90d>'; +SELECT sellipse '<{0d,0d},(280d,-20d),90d>' @ spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' ; +SELECT sellipse '<{0d,0d},(280d,-20d),90d>' @ spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}'; +SELECT sellipse '<{0d,0d},(280d,-20d),90d>' && spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' ; +SELECT sellipse '<{0d,0d},(280d,-20d),90d>' && spoly '{(280d,-11d),(280d,-20d),(279d, -12d)}'; -- ellipse is circle SELECT spoly '{(280d, -9d),(280d, -8d),(279d, -8d)}' @ sellipse '<{5d,5d},(280d,-20d),90d>'; diff --git a/src/polygon.c b/src/polygon.c index 0ed6191..ac91c6e 100644 --- a/src/polygon.c +++ b/src/polygon.c @@ -61,7 +61,7 @@ PG_FUNCTION_INFO_V1(spheretrans_poly_inverse); PG_FUNCTION_INFO_V1(spherepoly_add_point); PG_FUNCTION_INFO_V1(spherepoly_add_points_finalize); PG_FUNCTION_INFO_V1(spherepoly_is_convex); - +PG_FUNCTION_INFO_V1(spherepoly_from_point_array); /* * Writes "center" of a polygon into 'v'. @@ -1007,6 +1007,32 @@ spherepoly_deg(PG_FUNCTION_ARGS) PG_RETURN_POINTER(spherepoly_from_array(points, np)); } +Datum +spherepoly_from_point_array(PG_FUNCTION_ARGS) +{ + SPoint *points; + ArrayType *inarr = PG_GETARG_ARRAYTYPE_P(0); + const int np = ArrayGetNItems(ARR_NDIM(inarr), ARR_DIMS(inarr)); + + if (np < 3) + { + elog(ERROR, "spherepoly_from_point_array: " + "invalid number of arguments (must be >= 3)"); + PG_RETURN_NULL(); + } + + if (ARR_HASNULL(inarr)) + { + elog(ERROR, "spherepoly_from_point_array: " + "input array is invalid because it has null values"); + PG_RETURN_NULL(); + } + + points = (SPoint *) ARR_DATA_PTR(inarr); + + PG_RETURN_POINTER(spherepoly_from_array(points, np)); +} + Datum spherepoly_equal(PG_FUNCTION_ARGS) { diff --git a/src/polygon.h b/src/polygon.h index e90b7c5..b8c754d 100644 --- a/src/polygon.h +++ b/src/polygon.h @@ -87,15 +87,22 @@ Datum spherepoly_get_point(PG_FUNCTION_ARGS); int8 poly_line_pos(const SPOLY *poly, const SLine *line); /* - * Input of a spherical from array of pair-consecutive numbers (lng, lat), in radians. + * Creates a spherical polygon (spoly) from an array of pair-consecutive + * numbers (lng, lat), in radians. */ Datum spherepoly_rad(PG_FUNCTION_ARGS); /* - * Input of a spherical from array of pair-consecutive numbers (lng, lat), in degrees. + * Creates a spherical polygon (spoly) from an array of pair-consecutive + * numbers (lng, lat), in degrees. */ Datum spherepoly_deg(PG_FUNCTION_ARGS); +/* + * Creates a spherical polygon (spoly) from an array of spoint elements. + */ +Datum spherepoly_from_point_array(PG_FUNCTION_ARGS); + /* * Input of a spherical polygon. */ diff --git a/upgrade_scripts/pg_sphere--1.3.1--1.3.2.sql.in b/upgrade_scripts/pg_sphere--1.3.1--1.3.2.sql.in index 3a80bc7..70f9506 100644 --- a/upgrade_scripts/pg_sphere--1.3.1--1.3.2.sql.in +++ b/upgrade_scripts/pg_sphere--1.3.1--1.3.2.sql.in @@ -27,6 +27,15 @@ CREATE FUNCTION spoly(float8[]) COMMENT ON FUNCTION spoly(float8[]) IS 'creates spoly from array of numbers in radians'; +CREATE FUNCTION spoly(spoint[]) + RETURNS spoly + AS 'MODULE_PATHNAME', 'spherepoly_from_point_array' + LANGUAGE 'c' + IMMUTABLE STRICT PARALLEL SAFE; + +COMMENT ON FUNCTION spoly(spoint[]) IS + 'creates spoly from an array of points'; + -- add PARALLEL SAFE to spoly_deg(float8[]) ALTER FUNCTION spoly_deg(float8[]) IMMUTABLE STRICT PARALLEL SAFE;