Skip to content

Instantly share code, notes, and snippets.

@Zia-
Created August 13, 2016 10:56
Show Gist options
  • Save Zia-/66b56083f9ede96dc984b52880020662 to your computer and use it in GitHub Desktop.
Save Zia-/66b56083f9ede96dc984b52880020662 to your computer and use it in GitHub Desktop.
import osgeo.ogr
shapefile = osgeo.ogr.Open("/Users/zia/Documents/journals/My_WriteUp/pgr_TPP_5Algos/data/citySelection/majorCountriesCityShapefile/selectedworldcityshapes.shp")
layer = shapefile.GetLayer(0)
f = open("/Users/zia/Documents/journals/My_WriteUp/pgr_TPP_5Algos/data/citySelection/testCode/osmCityDownloadLinks.txt", 'w')
for i in range(layer.GetFeatureCount()):
feature = layer.GetFeature(i)
attributes = feature.items() #items() method is making a dictionary of features
aa = attributes['BBOXTEXT'][9:]
aa = aa[:-2]
aa = aa.replace(",", " ")
aa = aa.split()
aa = [float(x) for x in aa]
longitude = sorted(aa[::2])
latitude = sorted(aa[1::2])
longMin = longitude[0]
longMax = longitude[-1]
latMin = latitude[0]
latMax = latitude[-1]
osmURL = "http://overpass.osm.rambler.ru/cgi/xapi_meta?*[bbox=" + str(longMin) + "," + str(latMin) + "," + str(longMax) + "," + str(latMax) +"]"
strr = str(i+1)
strr += " "
strr += attributes['CITYNAME'].lstrip()
f.write(strr)
f.write(osmURL)
f.write("\n")
f.write("\n")
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment