Created
August 13, 2016 10:56
-
-
Save Zia-/66b56083f9ede96dc984b52880020662 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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