InĀ [1]:
Copied!
# %pip install geoai-py
# %pip install geoai-py
Import Packages¶
InĀ [2]:
Copied!
import geoai
import geoai
Download sample data¶
InĀ [3]:
Copied!
raster_url = (
"https://huggingface.co/datasets/giswqs/geospatial/resolve/main/naip_train.tif"
)
vector_url = "https://huggingface.co/datasets/giswqs/geospatial/resolve/main/naip_train_buildings.geojson"
raster_url = (
"https://huggingface.co/datasets/giswqs/geospatial/resolve/main/naip_train.tif"
)
vector_url = "https://huggingface.co/datasets/giswqs/geospatial/resolve/main/naip_train_buildings.geojson"
InĀ [4]:
Copied!
raster_path = geoai.download_file(raster_url)
raster_path = geoai.download_file(raster_url)
File already exists: naip_train.tif
InĀ [5]:
Copied!
vector_path = geoai.download_file(vector_url)
vector_path = geoai.download_file(vector_url)
naip_train_buildings.geojson: 0%| | 0.00/334k [00:00<?, ?B/s]
naip_train_buildings.geojson: 100%|āāāāāāāāāā| 334k/334k [00:00<00:00, 51.4MB/s]
Preview data¶
InĀ [6]:
Copied!
geoai.view_image(raster_path, figsize=(18, 10))
geoai.view_image(raster_path, figsize=(18, 10))
InĀ [7]:
Copied!
geoai.view_vector(vector_path, basemap=True, alpha=0.5, figsize=(18, 10))
geoai.view_vector(vector_path, basemap=True, alpha=0.5, figsize=(18, 10))
Out[7]:
<Axes: >
InĀ [8]:
Copied!
geoai.view_vector_interactive(vector_path)
geoai.view_vector_interactive(vector_path)
Out[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Convert vector to raster¶
InĀ [9]:
Copied!
output_path = vector_path.replace(".geojson", ".tif")
geoai.vector_to_raster(vector_path, output_path, reference_raster=raster_path)
output_path = vector_path.replace(".geojson", ".tif")
geoai.vector_to_raster(vector_path, output_path, reference_raster=raster_path)
Reprojecting vector data from EPSG:4326 to EPSG:26911
Rasterized data saved to naip_train_buildings.tif
Out[9]:
array([[0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], ..., [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0]], shape=(1126, 2503), dtype=uint8)
InĀ [10]:
Copied!
geoai.view_image(output_path, figsize=(18, 10))
geoai.view_image(output_path, figsize=(18, 10))
Generate image chips¶
InĀ [11]:
Copied!
tiles = geoai.export_geotiff_tiles(
in_raster=raster_path,
out_folder="output",
in_class_data=vector_path,
tile_size=512,
stride=256,
buffer_radius=0,
create_overview=True,
)
tiles = geoai.export_geotiff_tiles(
in_raster=raster_path,
out_folder="output",
in_class_data=vector_path,
tile_size=512,
stride=256,
buffer_radius=0,
create_overview=True,
)
Raster info for naip_train.tif: CRS: EPSG:26911 Dimensions: 2503 x 1126 Resolution: (0.5999999999999953, 0.5999999999996691) Bands: 4 Bounds: BoundingBox(left=454780.8, bottom=5277567.0, right=456282.6, top=5278242.6) Loaded 735 features from naip_train_buildings.geojson Vector CRS: EPSG:4326 Reprojecting features from EPSG:4326 to EPSG:26911 Found 1 unique classes: ['building']
Generating tiles: 0%| | 0/36 [00:00<?, ?it/s]
Generated: 1, With features: 1: 3%|ā | 1/36 [00:00<00:02, 12.61it/s]
Generated: 1, With features: 1: 6%|ā | 2/36 [00:00<00:02, 13.86it/s]
Generated: 2, With features: 2: 6%|ā | 2/36 [00:00<00:02, 13.86it/s]
Generated: 3, With features: 3: 8%|ā | 3/36 [00:00<00:02, 13.86it/s]
Generated: 3, With features: 3: 11%|ā | 4/36 [00:00<00:02, 11.66it/s]
Generated: 4, With features: 4: 11%|ā | 4/36 [00:00<00:02, 11.66it/s]
Generated: 5, With features: 5: 14%|āā | 5/36 [00:00<00:02, 11.66it/s]
Generated: 5, With features: 5: 17%|āā | 6/36 [00:00<00:03, 8.68it/s]
Generated: 6, With features: 6: 17%|āā | 6/36 [00:00<00:03, 8.68it/s]
Generated: 6, With features: 6: 19%|āā | 7/36 [00:00<00:03, 8.40it/s]
Generated: 7, With features: 7: 19%|āā | 7/36 [00:00<00:03, 8.40it/s]
Generated: 7, With features: 7: 22%|āāā | 8/36 [00:00<00:03, 7.67it/s]
Generated: 8, With features: 8: 22%|āāā | 8/36 [00:00<00:03, 7.67it/s]
Generated: 8, With features: 8: 25%|āāā | 9/36 [00:01<00:03, 7.29it/s]
Generated: 9, With features: 9: 25%|āāā | 9/36 [00:01<00:03, 7.29it/s]
Generated: 10, With features: 10: 28%|āāā | 10/36 [00:01<00:03, 7.29it/s]
Generated: 10, With features: 10: 31%|āāā | 11/36 [00:01<00:03, 8.15it/s]
Generated: 11, With features: 11: 31%|āāā | 11/36 [00:01<00:03, 8.15it/s]
Generated: 11, With features: 11: 33%|āāāā | 12/36 [00:01<00:02, 8.34it/s]
Generated: 12, With features: 12: 33%|āāāā | 12/36 [00:01<00:02, 8.34it/s]
Generated: 12, With features: 12: 36%|āāāā | 13/36 [00:01<00:02, 8.39it/s]
Generated: 13, With features: 13: 36%|āāāā | 13/36 [00:01<00:02, 8.39it/s]
Generated: 13, With features: 13: 39%|āāāā | 14/36 [00:01<00:02, 7.80it/s]
Generated: 14, With features: 14: 39%|āāāā | 14/36 [00:01<00:02, 7.80it/s]
Generated: 14, With features: 14: 42%|āāāāā | 15/36 [00:01<00:02, 7.27it/s]
Generated: 15, With features: 15: 42%|āāāāā | 15/36 [00:01<00:02, 7.27it/s]
Generated: 15, With features: 15: 44%|āāāāā | 16/36 [00:02<00:03, 6.59it/s]
Generated: 16, With features: 16: 44%|āāāāā | 16/36 [00:02<00:03, 6.59it/s]
Generated: 16, With features: 16: 47%|āāāāā | 17/36 [00:02<00:03, 6.22it/s]
Generated: 17, With features: 17: 47%|āāāāā | 17/36 [00:02<00:03, 6.22it/s]
Generated: 17, With features: 17: 50%|āāāāā | 18/36 [00:02<00:02, 6.03it/s]
Generated: 18, With features: 18: 50%|āāāāā | 18/36 [00:02<00:02, 6.03it/s]
Generated: 18, With features: 18: 53%|āāāāāā | 19/36 [00:02<00:02, 6.55it/s]
Generated: 19, With features: 19: 53%|āāāāāā | 19/36 [00:02<00:02, 6.55it/s]
Generated: 19, With features: 19: 56%|āāāāāā | 20/36 [00:02<00:02, 6.79it/s]
Generated: 20, With features: 20: 56%|āāāāāā | 20/36 [00:02<00:02, 6.79it/s]
Generated: 20, With features: 20: 58%|āāāāāā | 21/36 [00:02<00:02, 6.95it/s]
Generated: 21, With features: 21: 58%|āāāāāā | 21/36 [00:02<00:02, 6.95it/s]
Generated: 21, With features: 21: 61%|āāāāāā | 22/36 [00:02<00:01, 7.64it/s]
Generated: 22, With features: 22: 61%|āāāāāā | 22/36 [00:02<00:01, 7.64it/s]
Generated: 22, With features: 22: 64%|āāāāāāā | 23/36 [00:03<00:01, 7.63it/s]
Generated: 23, With features: 23: 64%|āāāāāāā | 23/36 [00:03<00:01, 7.63it/s]
Generated: 23, With features: 23: 67%|āāāāāāā | 24/36 [00:03<00:01, 7.25it/s]
Generated: 24, With features: 24: 67%|āāāāāāā | 24/36 [00:03<00:01, 7.25it/s]
Generated: 24, With features: 24: 69%|āāāāāāā | 25/36 [00:03<00:01, 6.80it/s]
Generated: 25, With features: 25: 69%|āāāāāāā | 25/36 [00:03<00:01, 6.80it/s]
Generated: 25, With features: 25: 72%|āāāāāāāā | 26/36 [00:03<00:01, 6.80it/s]
Generated: 26, With features: 26: 72%|āāāāāāāā | 26/36 [00:03<00:01, 6.80it/s]
Generated: 26, With features: 26: 75%|āāāāāāāā | 27/36 [00:03<00:01, 6.48it/s]
Generated: 27, With features: 27: 75%|āāāāāāāā | 27/36 [00:03<00:01, 6.48it/s]
Generated: 27, With features: 27: 78%|āāāāāāāā | 28/36 [00:03<00:01, 7.08it/s]
Generated: 28, With features: 28: 78%|āāāāāāāā | 28/36 [00:03<00:01, 7.08it/s]
Generated: 28, With features: 28: 81%|āāāāāāāā | 29/36 [00:03<00:01, 6.87it/s]
Generated: 29, With features: 29: 81%|āāāāāāāā | 29/36 [00:03<00:01, 6.87it/s]
Generated: 29, With features: 29: 83%|āāāāāāāāā | 30/36 [00:04<00:00, 7.12it/s]
Generated: 30, With features: 30: 83%|āāāāāāāāā | 30/36 [00:04<00:00, 7.12it/s]
Generated: 31, With features: 31: 86%|āāāāāāāāā | 31/36 [00:04<00:00, 7.12it/s]
Generated: 31, With features: 31: 89%|āāāāāāāāā | 32/36 [00:04<00:00, 7.81it/s]
Generated: 32, With features: 32: 89%|āāāāāāāāā | 32/36 [00:04<00:00, 7.81it/s]
Generated: 32, With features: 32: 92%|āāāāāāāāāā| 33/36 [00:04<00:00, 7.17it/s]
Generated: 33, With features: 33: 92%|āāāāāāāāāā| 33/36 [00:04<00:00, 7.17it/s]
Generated: 33, With features: 33: 94%|āāāāāāāāāā| 34/36 [00:04<00:00, 7.12it/s]
Generated: 34, With features: 34: 94%|āāāāāāāāāā| 34/36 [00:04<00:00, 7.12it/s]
Generated: 34, With features: 34: 97%|āāāāāāāāāā| 35/36 [00:04<00:00, 6.76it/s]
Generated: 35, With features: 35: 97%|āāāāāāāāāā| 35/36 [00:04<00:00, 6.76it/s]
Generated: 35, With features: 35: 100%|āāāāāāāāāā| 36/36 [00:04<00:00, 6.51it/s]
Generated: 36, With features: 36: 100%|āāāāāāāāāā| 36/36 [00:04<00:00, 6.51it/s]
Generated: 36, With features: 36: 100%|āāāāāāāāāā| 36/36 [00:04<00:00, 7.31it/s]
Overview image saved to output/overview.png ------- Export Summary ------- Total tiles exported: 36 Tiles with features: 36 (100.0%) Average feature pixels per tile: 46795.0 Output saved to: output ------- Georeference Verification -------
Preview image chips¶
InĀ [12]:
Copied!
geoai.view_image("output/overview.png", figsize=(18, 10))
geoai.view_image("output/overview.png", figsize=(18, 10))
InĀ [13]:
Copied!
geoai.view_image("output/images/tile_000000.tif")
geoai.view_image("output/images/tile_000000.tif")
InĀ [14]:
Copied!
geoai.view_image("output/labels/tile_000000.tif")
geoai.view_image("output/labels/tile_000000.tif")
InĀ [15]:
Copied!
geoai.view_image("output/images/tile_000001.tif")
geoai.view_image("output/images/tile_000001.tif")
InĀ [16]:
Copied!
geoai.view_image("output/labels/tile_000001.tif")
geoai.view_image("output/labels/tile_000001.tif")