[postgis-users] Addpoint function

Matthew Pulis mpulis at gmail.com
Mon Apr 14 08:40:14 PDT 2008


Hi,

 

I am using pgRouting for my road routing. However, the results are not
correct enough. The results starts from the start of the road
(MULTILINESTRING) where the source Point is and finish till the end of the
road (MULTILINESTRING) where the destination Point is.

 

What I would like to do is :

 

-          Add a point to the starting of the MULTILINESTRING (thus to its
first LINESTRING), so as to have a line between the source POINT till the
Starting Point of the mentioned MULTILINESTRING.

 

This is what I tried to achieve :

      var_id := 1;

 

      FOR rec_shooting_star IN

                    EXECUTE var_text_shootingstar

 

        LOOP

                                IF var_id = 1 THEN

                                                RAISE NOTICE '--CHANGING the
Starting Point--';

                                                RAISE NOTICE 'Geometry type
working on is : %, and as text :
%',geometrytype(rec_shooting_star.the_geom),
astext(rec_shooting_star.the_geom);

                        var_num_geoms :=
NumGeometries(rec_shooting_star.the_geom);

                        RAISE NOTICE 'Total Number of Geometries :
%',var_num_geoms;

                        FOR var_i IN 1 .. var_num_geoms 

                            LOOP

                                RAISE NOTICE 'Inside the Geometry array
filling';

 
array_geoms[var_i] := geometryN (rec_shooting_star.the_geom, var_i);

                            END LOOP;

 

                                                var_first_linestring :=
geometryN (rec_shooting_star.the_geom, 1);

                                        RAISE NOTICE 'Old start point is :
%',astext(startpoint(var_first_linestring));

                                                var_start_point :=
addpoint(var_first_linestring, var_source_geom, 0 ); 

                                                RAISE NOTICE 'New start
point is : %',astext(startpoint(var_first_linestring));

                                                rec_path_result.id       :=
var_id ;

                                                rec_path_result.gid      :=
rec_shooting_star.gid;

 

                        final_geom := Collect ( var_first_linestring ,
geometryN (rec_shooting_star.the_geom, 2)  );

 

                        FOR var_i IN 2 .. var_num_geoms

                            LOOP

                                final_geom := Collect ( geometryN
(rec_shooting_star.the_geom, var_i) , geometryN (rec_shooting_star.the_geom,
var_i+1) );

                            END LOOP;

                        

                        rec_path_result.the_geom := final_geom;

                        RETURN NEXT rec_path_result;

                

                                ELSE

                

                                                rec_path_result.id       :=
rec_shooting_star.id;

                                                RAISE NOTICE 'Working on ID
: % <><> And stored as %',rec_shooting_star.id, rec_path_result.id;

                                                rec_path_result.gid      :=
rec_shooting_star.gid;

                                                rec_path_result.the_geom :=
rec_shooting_star.the_geom; 

                                                

RAISE NOTICE 'New Geometry is : %',astext(final_geom);

                                                rec_path_result.the_geom :=
final_geom;

                                                RETURN NEXT rec_path_result;

 

                                END IF;

 

                                var_id := var_id + 1;

 

        END LOOP;

 

Which can be seen better here : http://yancho.pastebin.com/fcabc96 (Syntax
highlighted). 

 

The problem is it is resulting in this :

 

NOTICE:  --CHANGING the Starting Point--

NOTICE:  Geometry type working on is : MULTILINESTRING, and as text :
MULTILINESTRING((638719.79994641 229671.605809093,638724.201247709
229706.542025738,638731.190301309 229766.511648145,638736.856451988
229811.628146638,638739.718554099 229843.373135036))

NOTICE:  Total Number of Geometries : 1

NOTICE:  Inside the Geometry array filling

NOTICE:  Old start point is : POINT(638719.79994641 229671.605809093)

NOTICE:  New start point is : POINT(638719.79994641 229671.605809093)

NOTICE:  New Geometry is : LINESTRING(638719.79994641
229671.605809093,638724.201247709 229706.542025738,638731.190301309
229766.511648145,638736.856451988 229811.628146638,638739.718554099
229843.373135036)

 

So the errors are :

1) The new point is not being set

2) The result is being given as a LINESTRING instead of a MULTILINESTRING

 

Problem is there are some MULTILINESTRINGS which are formed by just 1
LINESTRING but I have also ones which are formed by more than 1.

 

Any idea on how to fix this problem is extremely appreciated, since I am
really not sure what I should change else.

 

Thanks and regards

 

Matthew 

 

  _____  

I am using the free version of SPAMfighter for private users.
It has removed 26496 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter <http://www.spamfighter.com/len>  for free now!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20080414/16e4f71b/attachment.html>


More information about the postgis-users mailing list