If I wanted to generate a set of points spaced equally within the polygon, here's how I would do it using shapely (based off of this answer):
import numpy as np
from shapely.geometry import Point, Polygon
def get_evenly_spaced_points_in_polygon(poly, spacing):
"""Get a list of (lat, long) pairs spaced evenly through poly."""
points = []
minx, miny, maxx, maxy = poly.bounds
for x in np.arange(minx, maxx, spacing):
for y in np.arange(miny, maxy, spacing):
p = Point(x, y)
points.append((p.y, p.x) if poly.contains(p))
return points
lons = [run.gdt1[1], run.gdt2[1], run.target_area[1]]
lats = [run.gdt1[0], run.gdt2[0], run.target_area[0]]
poly = Polygon(list(zip(lons, lats)))
spacing = 0.1 # set to whatever you want the spacing to be between points
points = get_evenly_spaced_points_in_polygon(poly, spacing)
For example, if you have three points at long/lat of (1, 5)
, (2, 8)
, and (1, 8)
and use spacing=0.1
:
lons = [1, 2, 1]
lats = [5, 8, 8]
poly = Polygon(list(zip(lons, lats)))
points = get_evenly_spaced_points_in_polygon(poly, spacing=0.1)
print(points)
gives
[(5.399999999999999, 1.1), (5.499999999999998, 1.1), (5.599999999999998, 1.1), (5.6999999999999975, 1.1), (5.799999999999997, 1.1), (5.899999999999997, 1.1), (5.9999999999999964, 1.1), (6.099999999999996, 1.1), (6.199999999999996, 1.1), (6.299999999999995, 1.1), (6.399999999999995, 1.1), (6.499999999999995, 1.1), (6.599999999999994, 1.1), (6.699999999999994, 1.1), (6.799999999999994, 1.1), (6.899999999999993, 1.1), (6.999999999999993, 1.1), (7.0999999999999925, 1.1), (7.199999999999992, 1.1), (7.299999999999992, 1.1), (7.3999999999999915, 1.1), (7.499999999999991, 1.1), (7.599999999999991, 1.1), (7.69999999999999, 1.1), (7.79999999999999, 1.1), (7.89999999999999, 1.1), (5.6999999999999975, 1.2000000000000002), (5.799999999999997, 1.2000000000000002), (5.899999999999997, 1.2000000000000002), (5.9999999999999964, 1.2000000000000002), (6.099999999999996, 1.2000000000000002), (6.199999999999996, 1.2000000000000002), (6.299999999999995, 1.2000000000000002), (6.399999999999995, 1.2000000000000002), (6.499999999999995, 1.2000000000000002), (6.599999999999994, 1.2000000000000002), (6.699999999999994, 1.2000000000000002), (6.799999999999994, 1.2000000000000002), (6.899999999999993, 1.2000000000000002), (6.999999999999993, 1.2000000000000002), (7.0999999999999925, 1.2000000000000002), (7.199999999999992, 1.2000000000000002), (7.299999999999992, 1.2000000000000002), (7.3999999999999915, 1.2000000000000002), (7.499999999999991, 1.2000000000000002), (7.599999999999991, 1.2000000000000002), (7.69999999999999, 1.2000000000000002), (7.79999999999999, 1.2000000000000002), (7.89999999999999, 1.2000000000000002), (5.9999999999999964, 1.3000000000000003), (6.099999999999996, 1.3000000000000003), (6.199999999999996, 1.3000000000000003), (6.299999999999995, 1.3000000000000003), (6.399999999999995, 1.3000000000000003), (6.499999999999995, 1.3000000000000003), (6.599999999999994, 1.3000000000000003), (6.699999999999994, 1.3000000000000003), (6.799999999999994, 1.3000000000000003), (6.899999999999993, 1.3000000000000003), (6.999999999999993, 1.3000000000000003), (7.0999999999999925, 1.3000000000000003), (7.199999999999992, 1.3000000000000003), (7.299999999999992, 1.3000000000000003), (7.3999999999999915, 1.3000000000000003), (7.499999999999991, 1.3000000000000003), (7.599999999999991, 1.3000000000000003), (7.69999999999999, 1.3000000000000003), (7.79999999999999, 1.3000000000000003), (7.89999999999999, 1.3000000000000003), (6.299999999999995, 1.4000000000000004), (6.399999999999995, 1.4000000000000004), (6.499999999999995, 1.4000000000000004), (6.599999999999994, 1.4000000000000004), (6.699999999999994, 1.4000000000000004), (6.799999999999994, 1.4000000000000004), (6.899999999999993, 1.4000000000000004), (6.999999999999993, 1.4000000000000004), (7.0999999999999925, 1.4000000000000004), (7.199999999999992, 1.4000000000000004), (7.299999999999992, 1.4000000000000004), (7.3999999999999915, 1.4000000000000004), (7.499999999999991, 1.4000000000000004), (7.599999999999991, 1.4000000000000004), (7.69999999999999, 1.4000000000000004), (7.79999999999999, 1.4000000000000004), (7.89999999999999, 1.4000000000000004), (6.599999999999994, 1.5000000000000004), (6.699999999999994, 1.5000000000000004), (6.799999999999994, 1.5000000000000004), (6.899999999999993, 1.5000000000000004), (6.999999999999993, 1.5000000000000004), (7.0999999999999925, 1.5000000000000004), (7.199999999999992, 1.5000000000000004), (7.299999999999992, 1.5000000000000004), (7.3999999999999915, 1.5000000000000004), (7.499999999999991, 1.5000000000000004), (7.599999999999991, 1.5000000000000004), (7.69999999999999, 1.5000000000000004), (7.79999999999999, 1.5000000000000004), (7.89999999999999, 1.5000000000000004), (6.899999999999993, 1.6000000000000005), (6.999999999999993, 1.6000000000000005), (7.0999999999999925, 1.6000000000000005), (7.199999999999992, 1.6000000000000005), (7.299999999999992, 1.6000000000000005), (7.3999999999999915, 1.6000000000000005), (7.499999999999991, 1.6000000000000005), (7.599999999999991, 1.6000000000000005), (7.69999999999999, 1.6000000000000005), (7.79999999999999, 1.6000000000000005), (7.89999999999999, 1.6000000000000005), (7.199999999999992, 1.7000000000000006), (7.299999999999992, 1.7000000000000006), (7.3999999999999915, 1.7000000000000006), (7.499999999999991, 1.7000000000000006), (7.599999999999991, 1.7000000000000006), (7.69999999999999, 1.7000000000000006), (7.79999999999999, 1.7000000000000006), (7.89999999999999, 1.7000000000000006), (7.499999999999991, 1.8000000000000007), (7.599999999999991, 1.8000000000000007), (7.69999999999999, 1.8000000000000007), (7.79999999999999, 1.8000000000000007), (7.89999999999999, 1.8000000000000007), (7.79999999999999, 1.9000000000000008), (7.89999999999999, 1.9000000000000008)]
(if you wanted, you could use numpy.round_ to prevent the annoying floating point stuff)