Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import geopandas as gpd
- import pandas as pd
- from deepforest import utilities
- import os
- import matplotlib.pyplot as plt
- import rasterio as rio
- # Load the data
- df= gpd.read_file('/home/hawkeye/Desktop/qgis-tutorial/sequoia_stems_forBen.shp')
- def create_bounding_box(easting, northing, box_size=30):
- half_size = box_size / 2
- return {
- 'xmin': easting - half_size,
- 'xmax': easting + half_size,
- 'ymin': northing - half_size,
- 'ymax': northing + half_size
- }
- bounding_boxes = df.apply(lambda row: create_bounding_box(row['Easting'], row['Northng']), axis=1)
- # Convert bounding boxes to a DataFrame
- bounding_boxes_df = pd.DataFrame(list(bounding_boxes))
- # Combine with original data
- result_df = pd.concat([df, bounding_boxes_df], axis=1)
- url='https://map.dfg.ca.gov/arcgis/rest/services/Base_Remote_Sensing/NAIP_2022/ImageServer'
- print(result_df.head(1))
- for idx, row in result_df.iterrows():
- xmin, ymin, xmax, ymax = row['xmin'], row['ymin'], row['xmax'], row['ymax']
- print(xmin, ymin, xmax, ymax)
- tmp_dir='./naip_images'
- os.makedirs(tmp_dir, exist_ok=True)
- image_name = f"image_{idx}.tif"
- filename = utilities.download_ArcGIS_REST(url, xmin, ymin, xmax, ymax, savedir=tmp_dir, image_name=image_name)
- # Check the saved file exists
- assert os.path.exists(f"{tmp_dir}/{image_name}")
- # Confirm file has crs and show
- with rio.open("{}/{}".format(tmp_dir, image_name)) as src:
- assert src.crs is not None
- # Show
- plt.imshow(src.read().transpose(1,2,0))
- plt.show()
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement