[postgis-devel] RE: 40% faster st_distance and returning measurepoints :-)

nicklas.aven at jordogskog.no nicklas.aven at jordogskog.no
Thu Mar 12 08:12:08 PDT 2009


Hi again
 
I found that my modification crashed st_dwithin, but this version I think will work.
 
/Nicklas
 
 
 
 
Datum: 2009-03-11 13:46:35
Från: nicklas.aven at jordogskog.no
Till: 
Ämne: 40% faster st_distance and returning measurepoints :-)


Hallo
I'm new to this list and have done my first steps in writing c-code. Thanks to the very well-written and readable source-code I think I have succeded over my expectations.
What I have done is rewriting quite great parts of measures.c. My goal was to get the points out of st_distance from where the distance was calculated. 
The result was that st_distance worked about 40% faster on my small testmaterial. The points I wanted is also there, but I don't know the best way to output them.
The idea I have followed is just to store the shortest distance and it's points in a new structure I have called DISTLINE. 
Then I only do testing if a diastance is closer then the "earlier shortest" in "distance2d_pt_pt" so there is no testing in the looping of the other relateted functions. 
I think the progress in speed should make it interesting for implementing but someone experienced have to take a serious look at it. 
I also would be greatful if I could get some help with the output of my points. they are included in the structure DISTLINE like 
typedef struct
{
  double d;  /*distance*/
  POINT2D *p1;  /*1st measure point*/
  POINT2D *p2; /*2nd measure point*/
} DISTLINE;
and they will be present when the process returns to function:
lwgeom_mindistance2d_recursive
I attach my measure.c, libwgeom.h a small dataset with som roads in Norway and my resulting dll
The test I have done to compare speed is just 
select a.vegnummer,b.vegnummer, st_distance(a.the_geom,b.the_geom) as avstand from distancetest a,distancetest b;
on the attached dataset.
My result was:
original measure.c
Total query runtime: 3999 ms.
400 rows retrieved.
The new measure.c
Total query runtime: 2374 ms.
400 rows retrieved.
This increase in speed could be quite important on big "nearest neighbour" calculations.
I also mean som function like st_shortestline(geom1,geom2) would be nice and now the points for that line is ready to use.
Have a nice day
from a quite proud beginner
Nicklas Avén
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20090312/f1f7dbaa/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: distance.zip
Type: application/x-zip-compressed
Size: 475015 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20090312/f1f7dbaa/attachment.bin>


More information about the postgis-devel mailing list