import json import random import csv from shapely.geometry import Point, Polygon # Load the GeoJSON data geojson_data = { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "coordinates": [ [ [ 75.75912927697229, 13.326875757359673 ], [ 75.75540555467836, 13.335138325609261 ], [ 75.75293619385427, 13.337749163755484 ], [ 75.74994054372351, 13.339433864266546 ], [ 75.74953791513842, 13.339587308855787 ], [ 75.74901207385386, 13.339920716401139 ], [ 75.74885195337906, 13.341170135464287 ], [ 75.7455579886016, 13.343716971174619 ], [ 75.74239660675771, 13.343448797078482 ], [ 75.7412493690326, 13.342798472330657 ], [ 75.74015926835042, 13.34273681584638 ], [ 75.73870751197148, 13.342070969247704 ], [ 75.73695743260552, 13.340790487001861 ], [ 75.7363433679553, 13.340781663580014 ], [ 75.73566205262145, 13.341413670118328 ], [ 75.73512861489081, 13.34175734661089 ], [ 75.73395226387629, 13.342005595653674 ], [ 75.73263389399159, 13.343231671166265 ], [ 75.7320918466194, 13.3433010724725 ], [ 75.73097417637706, 13.34280255039154 ], [ 75.72946714345738, 13.341282409642915 ], [ 75.72889088159579, 13.340529152113774 ], [ 75.72843138402445, 13.340645158990768 ], [ 75.72788882092544, 13.341378725996876 ], [ 75.72756906713812, 13.341550972065491 ], [ 75.72694952252326, 13.34148892613419 ], [ 75.72656474201699, 13.341599259094252 ], [ 75.72589247453911, 13.343073826186952 ], [ 75.72556131868694, 13.343172039275913 ], [ 75.72357983070691, 13.34271693119247 ], [ 75.72310301718514, 13.342704474282797 ], [ 75.72201899952097, 13.341556967970703 ], [ 75.72168689377804, 13.341466455755949 ], [ 75.72113432129078, 13.341478990835554 ], [ 75.72075353513742, 13.34121966032285 ], [ 75.72067087116596, 13.340616703241864 ], [ 75.72056862069016, 13.340408088089816 ], [ 75.71876802622762, 13.340504243433955 ], [ 75.71877595255506, 13.339892625176546 ], [ 75.71845874204834, 13.339722207017587 ], [ 75.71844648440893, 13.33960898087534 ], [ 75.7192385585551, 13.339355343732464 ], [ 75.7185268855022, 13.339093940694141 ], [ 75.71813627874931, 13.339236885565569 ], [ 75.71725121796726, 13.339035040230584 ], [ 75.71531349523099, 13.339359462336034 ], [ 75.71345576567794, 13.339352942133289 ], [ 75.71276056154781, 13.338749812646938 ], [ 75.71172800522507, 13.338425673907537 ], [ 75.71115890918085, 13.338435079236646 ], [ 75.71103076967833, 13.338848509257772 ], [ 75.71030161227466, 13.334449298755928 ], [ 75.70976785931285, 13.333471864304286 ], [ 75.70996599787287, 13.332620613899735 ], [ 75.71057748211857, 13.332113021060962 ], [ 75.71073115156833, 13.331597949333215 ], [ 75.70998868117644, 13.331083247388705 ], [ 75.70995094392282, 13.330894181154804 ], [ 75.70981180609564, 13.330687453763147 ], [ 75.70992192485144, 13.330570767115873 ], [ 75.71035523143502, 13.33062460821428 ], [ 75.71036693702007, 13.331038204293492 ], [ 75.7105793658337, 13.331056219480828 ], [ 75.71132013212971, 13.33128164022581 ], [ 75.71157955719792, 13.33134483475986 ], [ 75.71159561792794, 13.33112830757888 ], [ 75.71132411323205, 13.33075931807224 ], [ 75.7114329530711, 13.330588711430366 ], [ 75.71163983903475, 13.330149856705063 ], [ 75.71131258864565, 13.329614692419128 ], [ 75.71137592797879, 13.328809020887363 ], [ 75.71106226206203, 13.32804891457738 ], [ 75.70996328354164, 13.328094023273621 ], [ 75.70979544541396, 13.327787621480908 ], [ 75.71016069742231, 13.327204047171591 ], [ 75.7101390985818, 13.326712490522056 ], [ 75.7097783054983, 13.326196328201917 ], [ 75.71049127459338, 13.325956814321046 ], [ 75.7111622142539, 13.3262006890467 ], [ 75.71309908353024, 13.325537624096981 ], [ 75.71419972315772, 13.325161486002031 ], [ 75.71511445242871, 13.324202293206099 ], [ 75.71606605718483, 13.324124753966515 ], [ 75.71677534669311, 13.323634480439978 ], [ 75.71724358341513, 13.323608715202226 ], [ 75.7189187339201, 13.322960873300914 ], [ 75.71890180239552, 13.321768141776332 ], [ 75.71929890525854, 13.321435268921832 ], [ 75.71967469207581, 13.321664460612766 ], [ 75.72031804571373, 13.322918611458078 ], [ 75.72221217722392, 13.32389057260751 ], [ 75.72263251236998, 13.32392011099462 ], [ 75.72383852691866, 13.323250301230715 ], [ 75.7245185163647, 13.3235441601705 ], [ 75.72476866400604, 13.324327165778271 ], [ 75.72592991152595, 13.324654025077962 ], [ 75.72740168895325, 13.325241136372043 ], [ 75.72872794445925, 13.325315307230554 ], [ 75.72992946963424, 13.324962868976002 ], [ 75.73115084788151, 13.325036816491036 ], [ 75.73201879916476, 13.324589931054717 ], [ 75.73359172050189, 13.324173414025594 ], [ 75.7370606384055, 13.323131058860497 ], [ 75.74047637015596, 13.323168172474354 ], [ 75.74278588263917, 13.323577187109066 ], [ 75.74572776497831, 13.326705311923234 ], [ 75.74651745558631, 13.327077180448313 ], [ 75.74870616889731, 13.32704329849652 ], [ 75.75041138639341, 13.327178963725018 ], [ 75.75097503713044, 13.327178963725018 ], [ 75.75189350855277, 13.326998131479314 ], [ 75.75387636670715, 13.326817736372575 ], [ 75.7569283792698, 13.326764660744715 ], [ 75.75912927697229, 13.326875757359673 ] ] ], "type": "Polygon" } } ] } # Extract the coordinates of the polygon polygon_coords = geojson_data["features"][0]["geometry"]["coordinates"][0] polygon = Polygon(polygon_coords) # Generate random points inside the polygon def generate_random_points(polygon, num_points): points = [] min_x, min_y, max_x, max_y = polygon.bounds while len(points) < num_points: random_point = Point(random.uniform(min_x, max_x), random.uniform(min_y, max_y)) if polygon.contains(random_point): points.append(random_point) return points # Number of random points to generate num_points = 500 # Generate points random_points = generate_random_points(polygon, num_points) # Write points to CSV with open('random_points.csv', 'w', newline='') as csvfile: csvwriter = csv.writer(csvfile) csvwriter.writerow(['latitude', 'longitude']) for point in random_points: csvwriter.writerow([point.y, point.x])