• API
• FAQ
• Tools
• Archive
daily pastebin goal
28%
SHARE
TWEET

# M Jansen

a guest Dec 22nd, 2008 313 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /*
2.  * Creates a star with given parameters (an optimized version exists).
3.  *
4.  * Needs both PostgreSQL and Postgis.
5.  *
7.  *
8.  * @language PL/PGSQL
9.  * @see selectoid.wordpress.com
11.  * @copyright 2008, M. Jansen jansen (at) terrestris (dot) de
12.  */
13. CREATE OR REPLACE FUNCTION ST_StarAtPoint(
14.     IN point geometry,
17.     IN number_of_spikes integer,
19. ) RETURNS GEOMETRY AS
20. \$body\$
21.     DECLARE
22.         star_geometry_wkt text := '';
23.         i integer := 0;
24.         angle numeric;
26.         baseline_inner geometry;
27.         baseline_outer geometry;
28.         rotation_point geometry := 'POINT(0 0)'::geometry;
29.     BEGIN
31.             RAISE EXCEPTION 'Inner radius must not be greater than outer radius.';
32.         END IF;
33.         IF (number_of_spikes < 3) THEN
34.             RAISE EXCEPTION 'A star must have at least three corners.';
35.         END IF;
36.
39.
42.
43.         WHILE (i < number_of_spikes) LOOP
44.             star_geometry_wkt = star_geometry_wkt || (ST_X(ST_EndPoint(ST_RotateZ(baseline_outer, angle * i))) + ST_X(point)) || ' ' || ST_Y(ST_EndPoint(ST_RotateZ(baseline_outer, angle * i))) + ST_Y(point)  || ',';
45.             star_geometry_wkt = star_geometry_wkt || (ST_X(ST_EndPoint(ST_RotateZ(baseline_inner, angle * i))) + ST_X(point)) || ' ' || ST_Y(ST_EndPoint(ST_RotateZ(baseline_inner, angle * i))) + ST_Y(point) || ',';
46.             i = i + 1;
47.         END LOOP;
48.         star_geometry_wkt = star_geometry_wkt ||  (ST_X(ST_EndPoint(baseline_outer)) + ST_X(point))  || ' ' ||  (ST_Y(ST_EndPoint(baseline_outer)) + ST_Y(point));
49.         star_geometry_wkt = 'POLYGON((' || star_geometry_wkt || '))';
50.         RETURN star_geometry_wkt::geometry;
51.     END;
52. \$body\$
53. LANGUAGE plpgsql;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top