[postgis-tickets] [PostGIS] #1498: ST_CrossProduct ?

PostGIS trac at osgeo.org
Fri Feb 20 04:02:37 PST 2015


#1498: ST_CrossProduct ?
-------------------------+--------------------------------------------------
 Reporter:  strk         |       Owner:  pramsey       
     Type:  enhancement  |      Status:  new           
 Priority:  low          |   Milestone:  PostGIS Future
Component:  postgis      |     Version:  trunk         
 Keywords:               |  
-------------------------+--------------------------------------------------

Comment(by remic):

 Function (expect a ring of signed edge)

 -----

 DROP FUNCTION IF EXISTS topology.ST_SignedArea( ring_of_edges INT[] ) ;
 CREATE OR REPLACE FUNCTION topology.ST_SignedArea(  ring_of_edges INT[] ,
 OUT signedArea FLOAT)
  AS
 $BODY$
         /** @brief  given a ring (an ordered set of signed edge_id),
 compute the sum of angles between nodes
         */
         DECLARE
         BEGIN

         WITH input_data AS (
                 SELECT r.ordinality, r.value AS s_edge_id,  (count(*)
 over(partition by abs(r.value))  <>2) as is_simple
                 FROM rc_unnest_with_ordinality(ring_of_edges) as r
         )
         ,joined_to_edge AS (
                 SELECT ordinality, s_edge_id, edge_id, dmp.geom as
 pt_geom, path[1] as path
                 FROM input_data as id
                         LEFT OUTER JOIN bdtopo_topological.edge_data as ed
                                 ON (abs(id.s_edge_id) = ed.edge_id)
                         , ST_DumpPoints(geom) AS dmp
                 WHERE s_edge_id <0 AND is_simple = TRUE
                 UNION ALL
                 SELECT ordinality, s_edge_id, edge_id, dmp.geom as
 pt_geom, -path[1] as path
                 FROM input_data as id
                         LEFT OUTER JOIN bdtopo_topological.edge_data as ed
                                 ON (abs(id.s_edge_id) = ed.edge_id)
                         , ST_DumpPoints(geom) AS dmp
                 WHERE s_edge_id >0 AND is_simple = TRUE
         )
         ,getting_next_node AS (
                 SELECT ordinality, s_edge_id , pt_geom as pt,
 COALESCE(lead(pt_geom,1) OVER(w) , first(pt_geom) OVER(w )) as n_pt
                 FROM joined_to_edge
                 WINDOW w AS (ORDER BY ordinality ASC, path ASC)
         )
         SELECT sum(    (ST_X(n_pt)-ST_X(pt)) * (ST_Y(n_pt)+ST_Y(pt) )/2.0
 )  INTO signedArea
         FROM getting_next_node ;
          RETURN ;
         END ;
         $BODY$
 LANGUAGE plpgsql IMMUTABLE STRICT;
 -----

-- 
Ticket URL: <http://trac.osgeo.org/postgis/ticket/1498#comment:7>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list