Skip to content

Instantly share code, notes, and snippets.

@salvah22
Created April 7, 2022 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salvah22/e643304a881c5efb8c50ae1c9c2801ba to your computer and use it in GitHub Desktop.
Save salvah22/e643304a881c5efb8c50ae1c9c2801ba to your computer and use it in GitHub Desktop.
import json, random
from osgeo import ogr
if __name__ == "__main__":
word_file = "/usr/share/dict/american-english"
WORDS = open(word_file).read().splitlines()
### SHP
f1 = ogr.Open("~/addresses_wgs84.shp")
shape = f1.GetLayer(0)
json_dict = {}
json_dict["type"] = "FeatureCollection"
json_dict["name"] = "project_dummy_data"
features = []
for i in range(100):
feature = {}
feature["type"] = "Feature"
properties = {}
properties["name"] = WORDS[random.randint(1, 123000)]
properties["rent"] = random.triangular(1000, 10000, 4000)
properties["rank"] = random.uniform(1, 100)
properties["type"] = random.choice(["house", "apartment", "trailer"])
shpFeature = shape.GetFeature(random.randint(1, 15515))
first = shpFeature.ExportToJson()
test1 = json.loads(first)
properties["address"] = test1['properties']['BELADRESS']
feature["properties"] = properties
geometry = {}
geometry["type"] = "Point"
#geometry["coordinates"] = [random.uniform(13.14456, 13.25383), random.uniform(55.67256, 55.73406)]
geometry["coordinates"] = test1['geometry']['coordinates']
feature["geometry"] = geometry
features.append(feature)
json_dict["features"] = features
output = json.dumps(json_dict, indent=3)
with open("dummy.json", "w") as f:
f.write(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment