[postgis-users] Finding the center of a street

Jaak Laineste jaak at nutiteq.com
Mon Jul 20 05:46:41 PDT 2009


 I had the same problem, and I finally solved it outside of Postgis, with
own algorithm. The algorithm was that 

1. I took all segments. With segment mean here simple, "straight" line.
2. Found half or the total length of the street segments
3. Found center segment: stepped by segments until walked distance was
larger than the target length
4. Took the last segment, and calculated how far from one end the center
should be
5. Found coordinates of the point

 I assume that this algorithm should work fine also with multi-part
polylines, as it cannot give point outside of target line. 

 I implemented it in PHP (it just more convenient for me), but it should be
possible to be implemented as a PL-pgsql function as well, why not as a
general function in postgis. 

/Jaak


> Hi Luigi,
> 
> 
> 
> The problem is that when I have T junctions, I have more than one
> segment (i.e. linestring) and even if I use ST_LineMerge, I get a set
> of linestrings (instead of only one), which I can't pass to
> ST_line_interpolate_point (the function I'm using to calculate the
> middle point).
> 
> 
> 
> For the use case I have, the calculated middle point must be part of
> the street (i.e. part of the multilinestring that I have initially).
> 
> 
> 
> Thanks,
> 
> 
> 
> Nelson
> 
> 
> 
> 
> 
> From: luigi.cardeles at gmail.com
> Date: Sat, 18 Jul 2009 01:51:58 -0300
> To: postgis-users at postgis.refractions.net
> Subject: Re: [postgis-users] Finding the center of a street
> 	
> Hi Nelson,
> 
> i don't understand the problem with the T junctions but with the non-
> contiguous sections you could create a contiguous linestring and use
> that to find the middle point but you may get middle points that don't
> intersects with then. Is this a problem?
> 
> []'sLuigi Castro Cardeles
> 
> 
> 
> 2009/7/16 Nelson Correia <nelsonwc7 at hotmail.com>
> 
> 
> Hi all,
> 
> I have a database of streets, wich is composed by multilinestring
> segments. I want to find the centre of the street (i.e. the point that
> is in the middle and contained in the street geometry) and not the
> centroid (which may not be in the street).
> 
> I can do this with linemerge (to obtain a linestring instead of a
> multilinestring) and then use the st_line_interpolate_point to
> calculate the middle point.
> 
> The problem is with streets that have T junctions in the middle or that
> are composed by non-contiguous sections, for what I can't find a way to
> obtain a linestring to calculate the middle point.
> 
> Anyone had a similar problem or know a solution to this problem?
> 
> Thanks in advance!
> 
> Nelson
> 
> 




More information about the postgis-users mailing list