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 + '.' # Delete individual tile images to save disc space. lib.delete_tile_images(image_dir=data_dir) print "Deleted small tile images in " + data_dir + '.' # Open aerial view image and get its pixel size.
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( data_dir, ulc_lat, ulc_lng, lrc_lat, lrc_lng, zoom=ZOOM, tile_size=TILE_SIZE, ext=".png" ) # Crop big aerial image according to 'pix_x1', 'pix_y1', 'pix_x2', 'pix_y2'. This is, we want # that our arial image corresponds exactly to the geographic coordinates, which are specified in # 'areas'. img_np = np.asarray(img)
# 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 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. try: lib.download_aerial_views(data_dir, ulc_lat, ulc_lng, lrc_lat, lrc_lng, 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) continue # Assemble individual tile images to one big aerial image. img = lib.make_big_aerial_image(data_dir, ulc_lat, ulc_lng, lrc_lat, lrc_lng, zoom=ZOOM, tile_size=256, ext='.png') # Crop big aerial image according to 'pix_x1', 'pix_y1', 'pix_x2', 'pix_y2'. This is, we want # that our arial image corresponds exactly to the geographic coordinate, which is specified in # 'zoom_info'. img_np = np.asarray(img) img_np_shape = img_np.shape