0

I want to create 100000 coordinates within my region bounds. The points should look like GPS data, minimum distance of consecutive points should be within 10m - 1000m, minimum distance should also be randomized. What condition I can apply to the code in order to get points close to one another?

# find the bounds of your geodataframe
x_min, y_min, x_max, y_max = tallinn84.total_bounds

# set sample size
n = 10000
# generate random data within the bounds
x = np.random.uniform(x_min, x_max, n)
y = np.random.uniform(y_min, y_max, n)

# convert them to a points GeoSeries
gdf_points = gpd.GeoSeries(gpd.points_from_xy(x, y))
# only keep those points within polygons
gdf_points = gdf_points[gdf_points.within(tallinn84.unary_union)] 

This code works fine but it provides random points where distance between two points are higher. Please provide your suggestion and code if possible

  • You are filtering out a lot of data. You may want to check https://stackoverflow.com/questions/5837572/generate-a-random-point-within-a-circle-uniformly . But your other constrain (10m-1000m) is difficult to have. Discard the smaller, redo the simulation if you have larger gaps. – Giacomo Catenazzi Jun 29 '22 at 12:05
  • @GiacomoCatenazzi Thanks for ur opinion. My main problem is generating the points with closer distance, I already generated point within larger ROI. After generating the coordinates, i have to join it other csv file containing user and timestamps. is there any way to indicate the constrain by code? – Sourav Karmakar Jun 29 '22 at 12:51
  • create a function: `nearest()`, and giving also the index of actual point. You need to iterate for all other points, but for 100_000 it is feasible (and most GIS tools do in such manner). If you want to be smart, return the square and compare just the square of distance: you get a huge speed-up improvement. Then you interact every point to find the `nearest()`. -- If it is too slow, divide the radius, and allocate random only on a "torus" (and check only elements in this and in the nearest torus). – Giacomo Catenazzi Jun 29 '22 at 13:32

0 Answers0