Skip to content

Instantly share code, notes, and snippets.

@TimMcCauley
Last active November 8, 2020 19:33
Show Gist options
  • Save TimMcCauley/673bf34a55e166a419574a079729da1d to your computer and use it in GitHub Desktop.
Save TimMcCauley/673bf34a55e166a419574a079729da1d to your computer and use it in GitHub Desktop.
import random
import json
from shapely.geometry import mapping, shape, Point
UK_SOME_POLY_BOUNDS='{"type": "Polygon","coordinates": [[[-0.280487,53.337084],[0.051368,52.540633],[0.228357,51.301708],[0.073491,51.146843],[-1.187557,51.168966],[-1.497288,51.080472],[-2.094627,51.080472],[-2.271616,51.345956],[-2.397953,51.653954],[-2.545269,52.095901],[-2.686179,52.76843],[-2.743825,53.120707],[-2.711799,53.351288],[-2.743825,53.665135],[-2.743825,53.69716],[-2.602914,54.23198],[-2.289067,54.302436],[-1.116946,54.385701],[-0.94401,54.340866],[-0.280487,53.337084]]]}'
#LONDON_BOUNDS='{"type":"Polygon","coordinates":[[[-0.071151117801821,51.51029343697843],[-0.07113642319992,51.5101295110986],[-0.071146828383437,51.50984908079782],[-0.071168171767067,51.50978737577289],[-0.071222527763646,51.50972891182979],[-0.07130137074254,51.50963667479025],[-0.071378125542731,51.50959386835587],[-0.071527914823977,51.50959633179286],[-0.071908376952806,51.509597191836676],[-0.072220312690561,51.50958253431118],[-0.072436887593084,51.509539327583944],[-0.072584214872495,51.509497680389764],[-0.072808824955538,51.509434819051144],[-0.073005422363042,51.509455137765976],[-0.073221880466734,51.509482977389055],[-0.073799321509762,51.50929010709916],[-0.073954037695234,51.509244082747145],[-0.07397154842406,51.50923897417429],[-0.074008881518165,51.50927646124723],[-0.074028325087953,51.509293868495845],[-0.074081046412285,51.509342400641756],[-0.074086693793182,51.509345191482176],[-0.074145972381278,51.50937494466085],[-0.074163671756958,51.509570397181996],[-0.074168902052344,51.50961724997116],[-0.074469618289514,51.50959520730004],[-0.074538412060875,51.50994618919796],[-0.074560054388546,51.50994564519193],[-0.074663945135047,51.509942854159064],[-0.074673118117345,51.51003294108674],[-0.07494628177681,51.510014941620234],[-0.075283007749594,51.50999348798574],[-0.075281566777774,51.50995928853543],[-0.075274097420125,51.509828758281735],[-0.075270267706562,51.509748652101514],[-0.075306804625147,51.5097024849068],[-0.075465766670103,51.509692502776865],[-0.075965772763777,51.50966113571261],[-0.076177189403102,51.50960344765003],[-0.076351005192088,51.50951456405768],[-0.076554532893948,51.50937040705386],[-0.076785988701789,51.509144865701835],[-0.076890059215319,51.50900087565348],[-0.076903017805563,51.5089327365754],[-0.07693197451514,51.50892961399777],[-0.077270434707701,51.50890098823948],[-0.077350388135493,51.50861090553464],[-0.077437106193775,51.508605132411645],[-0.077487132032078,51.508546594616185],[-0.077477163775946,51.50854373310036],[-0.07713615809202,51.50842752023826],[-0.077178791520052,51.50833918236964],[-0.077124781223128,51.50832120883331],[-0.077109127748221,51.508316455334224],[-0.077124287134312,51.50829871665269],[-0.077259205145829,51.50814084229302],[-0.077435011757505,51.507901796115505],[-0.077442738007348,51.507820980103325],[-0.077490674726933,51.507709345625486],[-0.077631262489847,51.50738248351377],[-0.077733026073049,51.507395843461374],[-0.077767434790232,51.50733165335835],[-0.077792596819709,51.507281701483095],[-0.077938090835474,51.50721483539727],[-0.078145205112713,51.50708782236096],[-0.078168891452793,51.50707292138546],[-0.07857799444358,51.50635833619736],[-0.078683471601504,51.5063861459947],[-0.079164845185458,51.506488465319066],[-0.079448075164191,51.50653897197807],[-0.079785768610304,51.50659666535858],[-0.080309630572498,51.50668258780477],[-0.081057334973819,51.50679195714796],[-0.081854959498689,51.50691382999834],[-0.082323944310345,51.50696826738887],[-0.082595621533304,51.50701947683229],[-0.0832796660968,51.507134985891916],[-0.083576130849216,51.50717940330826],[-0.084064559902995,51.50721706358917],[-0.084165148875687,51.50722410321447],[-0.084490072588662,51.50724290175416],[-0.085156261358096,51.50730324702984],[-0.086048642411141,51.50736548185659],[-0.086139188161781,51.50737145649814],[-0.086146351613472,51.50737247277469],[-0.086487580857254,51.507414915301474],[-0.087012557439033,51.50747474433339],[-0.087358560731219,51.50750646985122],[-0.087453164153362,51.507518805191886],[-0.087891879928259,51.507573625898736],[-0.088716015261668,51.507648217954625],[-0.089494302799973,51.50775083681802],[-0.090317542174534,51.5078469876585],[-0.090750553708444,51.50793498110666],[-0.091040406255701,51.507999957221195],[-0.091212985658736,51.508043237794695],[-0.091560387413484,51.50814512382071],[-0.092403593474084,51.508384583336664],[-0.093338746361252,51.50859675220057],[-0.093693996418251,51.50868347030934],[-0.094119708767619,51.50877403063828],[-0.094405963425542,51.508821852026074],[-0.09524000573217,51.508936130867774],[-0.096122743450174,51.509023314169866],[-0.096935509932542,51.509094965516034],[-0.097706660467282,51.50916233868028],[-0.098342071076251,51.509201424140855],[-0.098600911950425,51.5092155143386],[-0.099978282117463,51.509296297875146],[-0.101691505494218,51.50930695621594],[-0.102004257661136,51.50934169751312],[-0.102570631535574,51.50934276884988],[-0.102573929403569,51.509159352766254],[-0.102428102566291,51.50913091168437],[-0.102448789555466,51.509118655393195],[-0.102594984903902,51.509068858088675],[-0.102587359302319,51.50862804826619],[-0.102479952369143,51.50857684551825],[-0.102604205716045,51.50853478739588],[-0.102614214179092,51.508293920819916],[-0.10262615325106,51.50811064452385],[-0.10259670322917,51.507986955668095],[-0.102595444722871,51.5079131877686],[-0.103078863531267,51.50789852471118],[-0.1031251441283,51.50796402728305],[-0.103132746098189,51.50805858306521],[-0.103093021909129,51.50811280145277],[-0.103075266016461,51.50850553458941],[-0.103073399215871,51.50855047239466],[-0.103133986994992,51.508583829427366],[-0.103155105791004,51.50859586271917],[-0.103079726038092,51.508606335062595],[-0.103048030739576,51.5089529753198],[-0.103050773208117,51.50909511856298],[-0.10313419816023,51.509099166130945],[-0.103141063603758,51.50910737142401],[-0.1031630629075,51.50913290935433],[-0.103052405805482,51.50915989889141],[-0.103048047584971,51.509160727750974],[-0.103030967484248,51.509363706807264],[-0.103569976061883,51.5093643306337],[-0.103978797781635,51.50937633752861],[-0.104903248243609,51.50939667699027],[-0.105377331914823,51.50939894133981],[-0.105750818092649,51.50939418267081],[-0.106313021361169,51.50939157111182],[-0.106885865702136,51.50937563825041],[-0.107579732537345,51.509360756324696],[-0.108330478348314,51.509329700014426],[-0.108773619655581,51.50931346429834],[-0.109008686993271,51.50931006025134],[-0.109465013938965,51.5092886383935],[-0.109855384173264,51.50925895679429],[-0.109965917413479,51.51024463720086],[-0.109978242929985,51.51039952560397],[-0.109965710980588,51.51080673324009],[-0.109948942425947,51.510933272587565],[-0.109921958390825,51.511132495354836],[-0.109958679743123,51.51122032501936],[-0.110102244116753,51.51144298170731],[-0.110162208501094,51.51149161409274],[-0.110278963539145,51.51145662187993],[-0.110549114562964,51.511755065216676],[-0.110558676537454,51.51176781030213],[-0.110580532498918,51.5117969419232],[-0.110449856497779,51.511820018468],[-0.110592106404697,51.5120048802647],[-0.110806431712899,51.51225925427952],[-0.110738983295192,51.51228694715488],[-0.110766452454905,51.51231976660212],[-0.110605479301341,51.51237832957752],[-0.110729090631639,51.51252601717788],[-0.110130089474837,51.51268544490062],[-0.110249746389462,51.51296347627731],[-0.110372157422653,51.51317499935542],[-0.109723449226772,51.51328146128182],[-0.109492857821696,51.51331551723147],[-0.109529085217616,51.51345010568213],[-0.10980155270867,51.51428460563535],[-0.109943807069633,51.51471319432638],[-0.109967242645507,51.51477382904535],[-0.109998141134449,51.51482828852537],[-0.110260098163667,51.51529028342287],[-0.110524664319467,51.51568936463409],[-0.110545267556504,51.515713979258706],[-0.111252296538808,51.51653299203798],[-0.11184006282566,51.51713423430849],[-0.112110591309541,51.51742458538655],[-0.112133891446413,51.51745373991937],[-0.112178438501738,51.51759655554865],[-0.112204007204277,51.51771028621223],[-0.112212530131823,51.51774819643202],[-0.111421162920806,51.517782221647124],[-0.110730431920911,51.5177531090238],[-0.110017694709412,51.51769845565459],[-0.108867087354412,51.517565688518765],[-0.107923269264086,51.5174173599902],[-0.107424774156763,51.51737604007692],[-0.106582522530623,51.51728150252666],[-0.10621744230103,51.51725582177523],[-0.10598215725644,51.51733296434679],[-0.105796931893069,51.51738483362178],[-0.105439990278055,51.51751037414488],[-0.104921763656427,51.51766658371163],[-0.104590464009995,51.51776465590629],[-0.104227903196081,51.517886504515566],[-0.103740405703167,51.51803151397602],[-0.103731612911564,51.51803496923662],[-0.103146531804138,51.51823865536698],[-0.10164698480459,51.51869734721247],[-0.100474068664954,51.51906597889832],[-0.100210832176432,51.51915614762619],[-0.099965143858585,51.5192403045616],[-0.099462613832496,51.51939944256277],[-0.09919265693194,51.519477808446666],[-0.098819984078555,51.519599476567855],[-0.098647352283778,51.51962545737289],[-0.09850003456393,51.51963206246665],[-0.098044344263343,51.51977396669453],[-0.097738067452206,51.51985893509292],[-0.097291578343358,51.51998749527542],[-0.096840935605005,51.52007731391877],[-0.096059689267274,51.52021302756204],[-0.09601362032823,51.520522558590386],[-0.0959576001424,51.5207941549406],[-0.095906179593818,51.52109370607053],[-0.095792704543467,51.52108376942419],[-0.095782598200326,51.52111868033809],[-0.095764029405654,51.52121820770803],[-0.095773149055322,51.521345165427086],[-0.095901581155248,51.521722283451666],[-0.096029538995029,51.521972583976975],[-0.096090546036848,51.52206530900981],[-0.096176698607793,51.52217732874618],[-0.096291178310552,51.5223014999011],[-0.096323002429897,51.52233349404115],[-0.0963619176603,51.52236830135033],[-0.095175629208063,51.522812209733],[-0.095103157115216,51.522683323647186],[-0.095087068932193,51.522654282844556],[-0.095073989974675,51.52265676848497],[-0.095012992334814,51.52266746937092],[-0.094859135317442,51.52231242136327],[-0.094406663752541,51.522445370314095],[-0.094376844506153,51.522399917835536],[-0.093477793292646,51.522628132996175],[-0.093011964473554,51.52180394109745],[-0.092799277266382,51.52123568476307],[-0.092733813307621,51.520973805879116],[-0.092264372946236,51.52103002501541],[-0.092004390923826,51.52107615976897],[-0.091982216134774,51.5209858630375],[-0.091803662515928,51.52101533490732],[-0.091690575861096,51.52082372994233],[-0.090905706718143,51.5209764382739],[-0.090763413740041,51.52051814643524],[-0.090565018693606,51.52050502348392],[-0.090210345994791,51.520471368200106],[-0.089760854970845,51.520429871926076],[-0.089315036159307,51.520369547190285],[-0.088652322635823,51.52029039692148],[-0.088082113026565,51.52020555610806],[-0.088093289186312,51.52017965686235],[-0.088392987424583,51.519460557341965],[-0.088169183719383,51.51940024939777],[-0.087691664374302,51.51927105022714],[-0.086517863366968,51.518901153559675],[-0.085931342717979,51.51869012550731],[-0.084745443357754,51.518334403195965],[-0.084615746999634,51.51829900864681],[-0.084292859760522,51.518779389526976],[-0.084202018637451,51.518917306517835],[-0.083944312907531,51.519321406194415],[-0.083764601440401,51.51961885643021],[-0.0836060239035,51.5198249169391],[-0.081713437240422,51.51930472259994],[-0.081121806737172,51.51955855653479],[-0.080713580864012,51.5198045968527],[-0.08040501787801,51.520045971584224],[-0.080182767500265,51.52022310512626],[-0.080150015289165,51.52024775107753],[-0.079937061291107,51.52051227437668],[-0.079671840746855,51.52092253733761],[-0.079437980151279,51.52144393467949],[-0.079146581535723,51.52137980445722],[-0.078156719592032,51.52116123126422],[-0.076858799971754,51.521000553714124],[-0.077117939128941,51.52052994003763],[-0.07719837019526,51.520229073312954],[-0.077230665780572,51.520146861553336],[-0.077227973843432,51.52014232061061],[-0.077377500500412,51.51960425576689],[-0.077561096635142,51.51894173793523],[-0.077817287737947,51.51833527073828],[-0.076721821736646,51.51843512674723],[-0.076470027301796,51.51845797793732],[-0.076435585991986,51.51797535505946],[-0.076534300821041,51.51795898693692],[-0.076353238157482,51.517740170227654],[-0.076190565684324,51.51759810067432],[-0.076121493317698,51.51752681731933],[-0.076073688251254,51.517463977082954],[-0.076030696263297,51.51735534832469],[-0.075790344112587,51.51693589959289],[-0.075757855377904,51.5168859015953],[-0.075305446709518,51.516196760887226],[-0.075244982851558,51.51612651762655],[-0.075206505946858,51.516081817354134],[-0.074821324729032,51.51574722742875],[-0.073533291569054,51.51484380069258],[-0.07320097203981,51.51458921754461],[-0.072829160008097,51.51428002265326],[-0.072693687714126,51.514177067630875],[-0.072356183631129,51.51394308214478],[-0.072051248624369,51.51362059417066],[-0.071874445218905,51.51316530769651],[-0.071778979723623,51.512866048820676],[-0.071776326699816,51.51286060901855],[-0.071654526487089,51.51243410678418],[-0.071530162284891,51.51182948828008],[-0.071450295201094,51.51129755044218],[-0.071431124227228,51.51117132427916],[-0.071370646238919,51.51093109896397],[-0.071303645991137,51.51074292941613],[-0.071214244323775,51.51057327800092],[-0.071158314480488,51.51036190698478],[-0.071151117801821,51.51029343697843]]]}'
#BER_BOUNDS='{"type": "Polygon","coordinates": [[[13.5296630859375,52.62972886718355],[13.5186767578125,52.70634714950862],[13.260498046875,52.67305135923188],[13.0078125,52.60971939156648],[12.9693603515625,52.45600939264076],[13.2989501953125,52.328625488430184],[13.677978515625,52.35211857272093],[13.699951171875,52.399067302933304],[13.6614990234375,52.51287794429001],[13.5296630859375,52.62972886718355]]]}'
def generate_random(polygon):
minx, miny, maxx, maxy = polygon.bounds
pnt = Point(random.uniform(minx, maxx), random.uniform(miny, maxy))
return [pnt.x, pnt.y]
if __name__ == "__main__":
poly = shape(json.loads(UK_SOME_POLY_BOUNDS))
for i in range(100000):
r_coord = generate_random(poly)
print(r_coord)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment