Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to generate random points on a route from one point to another. What I have till now is, given a source and a destination, I can get a route using Google's API. But how do I get the coordinates of random points on the route?

share|improve this question

2 Answers 2

I'm not sure what tool you are using, but look into linear referencing methods.

For example, if you are using PostGIS, here are 10 random points along a linestring:

SELECT ST_Line_Interpolate_Point('LINESTRING (10 20, 50 60, 80 30, 140 60)', random())
FROM generate_series(1,10)

Or if using Shapely:

from random import random
from shapely.geometry import LineString
line = LineString([(10, 20), (50, 60), (80, 30), (140, 60)])
for i in range(10):
    pt = line.interpolate(random(), True)
    print(pt.xy)
share|improve this answer
    
I am using Google JavaScript directions API. Right now, I am planning to use a python sdk and pass the directions data to shapely. –  Abhishek Chanda Apr 18 '12 at 15:54

Write a function that returns total length of a route, and another that interpolates a point at an arbitrary distance along a route. Use a random number generator that generates a random distance d along the route such that 0.0 < d < length and passes it to the second function.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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