Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import random
- import csv
- from shapely.geometry import Polygon, Point, LineString
- poly = Polygon([(23.641881537889,37.929053926155), (23.666295612031,37.942899212831),
- (23.68803937946,37.941695374075), (23.704824056742,37.915206015202),
- (23.750218956531,37.85436479936), (23.775080866712,37.833451364383),
- (23.752192655178,37.922010896235), (23.791022107604,37.978829639512),
- (23.835081854037,38.006198162822), (23.862523655673,38.033885868582),
- (23.822469306444,38.094878864117), (23.823222369487,38.125143309181),
- (23.720225543315,38.11373449824), (23.688220971962,38.092972349773),
- (23.694610606763,38.064907199052), (23.665842815668,38.034725935164),
- (23.649439609277,38.008420474693), (23.603281778183,37.960745968997),
- (23.609957492578,37.948408725358), (23.622736730746,37.942239326525),
- (23.638758455769,37.950214302858), (23.647532265301,37.944346007546),
- (23.636481660717,37.936852529986), (23.641881537889,37.929053926155)])
- def random_points_within(poly, num_points):
- min_x, min_y, max_x, max_y = poly.bounds
- points = []
- while len(points) < num_points:
- random_point = Point([random.uniform(min_x, max_x), random.uniform(min_y, max_y)])
- if (random_point.within(poly)):
- points.append(random_point)
- return points
- points = [random_points_within(poly, i) for i in range(10)]
- #save points to csv line by line (lat, lon)
- with open('results.csv', 'w', newline='') as csvfile:
- writer = csv.writer(csvfile, delimiter=',')
- for point in points:
- for p in point:
- writer.writerow([p.y, p.x])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement