data_dir = CITY_DATA_ROOT + area_name + "/" print "================================================================" print " Processing data for " + str(area_name) print "================================================================" # If folder already exists, continue. Otherwise create folder. if os.path.exists(CITY_DATA_ROOT + area_name) or os.path.exists(CITY_DATA_ROOT + "x" + area_name): print "Data for " + area_name + " already exists." continue else: os.makedirs(CITY_DATA_ROOT + area_name + "/") # Convert world coordinates of this area into Google tile coordinates. tile_x1, tile_y1, pix_x1, pix_y1 = lib.world_coordinates_to_tile_coordinates( ulc_lat, ulc_lng, zoom=ZOOM, tile_size=TILE_SIZE ) tile_x2, tile_y2, pix_x2, pix_y2 = lib.world_coordinates_to_tile_coordinates( lrc_lat, lrc_lng, zoom=ZOOM, tile_size=TILE_SIZE ) # Download aerial view images from Google for this area. try: lib.download_aerial_views(data_dir, ulc_lat, ulc_lng, lrc_lat, lrc_lng, ZOOM, TILE_SIZE, key) except lib.ServerException as exc: # If a server exception is encountered, rename the folder of this area's data and continue. print exc os.rename(CITY_DATA_ROOT + area_name, CITY_DATA_ROOT + "x" + area_name) continue # Assemble individual tile images to one big aerial image. img = lib.make_big_aerial_image(
lng2 = area[4] hgh_dict_entry = area[5] # highway tags identifier from coord. # Specify directory where data related to this aerial view image will be saved. data_dir = CITY_DATA_ROOT + area_name + '/' print '\n' + "--------Processing data for " + area_name + '----------' # If folder already exists, continue. Otherwise create folder. if os.path.exists(CITY_DATA_ROOT + area_name) or os.path.exists(CITY_DATA_ROOT + 'x' + area_name): print "Data for " + area_name + ' already exists.' else: os.makedirs(CITY_DATA_ROOT + area_name + '/') # Convert world coordinates of area into Google tile coordinates. tile_x1, tile_y1, pix_x1, pix_y1 = lib.world_coordinates_to_tile_coordinates(lat1, lng1, zoom=ZOOM, tile_size=TILE_SIZE) tile_x2, tile_y2, pix_x2, pix_y2 = lib.world_coordinates_to_tile_coordinates(lat2, lng2, zoom=ZOOM, tile_size=TILE_SIZE) # Download aerial view image from Google. try: lib.download_aerial_views(data_dir, lat1, lng1, lat2, lng2, ZOOM, 256, key) except lib.ServerException as exc: # If a server exception is encountered, rename the folder of this area's data and continue. print exc os.rename(CITY_DATA_ROOT + area_name, CITY_DATA_ROOT + 'x' + area_name) # Put individual tiles of aerial view image together to one big aerial view image. img = lib.make_big_aerial_image(data_dir, lat1, lng1, lat2, lng2, zoom=ZOOM, tile_size=256, ext='.png') img.save(data_dir + area_name + '_wholeSatImage.png') print "Saved image " + area_name + '_wholeSatImage.png in ' + data_dir + '.'