[postgis-devel] Interpolating a point along a line

David Blasby dblasby at refractions.net
Wed Jan 21 09:00:39 PST 2004


This is a good function - but I think we should make 2 minor changes to 
it.


+	/* This should never happen! */
+	PG_RETURN_NULL();

I think this (at the very end of the function) should be replaced with 
(ie. the "distance == 1" clause from above):

PG_RETURN_POINTER(
+				make_oneobj_geometry(sizeof(POINT3D),
+					(char*)&(line->points[line->npoints-1]), POINTTYPE,
+					geom->is3d, geom->SRID, geom->scale, geom->offsetX, geom->offsetY
+					)
+				);


The reason for this is because the "if( distance < tlength + slength )" 
clause might be very slightly off if distance is very close to 1 (esp if 
there's lots of segments in the linestring).

You should also change the line:

+	line = (LINE3D*)&(geom->objData[0]);

to the more standard:

	offsets1 = (int32 *) ( ((char *) &(geom1->objType[0] ))+ sizeof(int32) 
* geom1->nobjs ) ;


	line = (LINE3D *) ( (char *) geom1 +offsets1[0]);

(this is less likely to break on solaris or machines with weird memory 
alignment)


If this is okay, make the changes, re-submit the patch, and we'll get 
strk to apply the patch and make sure its working.

dave




More information about the postgis-devel mailing list