I'm trying to sample points along a linestring. The goal is to have the distance between 2 consecutive points to be at most X (eg. 50m).

I'm drawing linestring in openlayers and sending it to a geodjango app. I can do the "segmentization"/sampling in the client (openlayers) or in the server (geodjango: DB API or Geos API). I don't know yet where I will do it, so I'm interested in both solution (if they exist).

I've searched but have not found any simple solution to this really simple problem (at least, it looks very simple).

I've seen this one for example: How to interpolate GPS Positions in PostGIS but it uses complex postgis query to do the interpolation.

Isn't there any 'split(nseg)' function somewhere that would split a segment into nseg sub segments ? Something close to what shapely offers ? (http://gispython.org/shapely/docs/1.2/manual.html#linear-referencing-methods ). I could use shapely, but that would add another dependency (not really justified...).

EDIT: I guess I should have a look at linearref from GEOS (https://code.djangoproject.com/ticket/11948 for the geodjango part)

1 Answer 1


Here's a potential answer (at least, the one I've chosen to use).

My problem comes from the fact that current geodjango API does not use linearref features from GEOS. So, I've patched my django code (using linked patch in my question) to get the 'project()' and 'interpolate()' methods.

Then, I simply loop to interpolate the needed points. The key here is to use the linearref feature of GEOS:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.