View Metadata¶
Install Package
To use the geoai-py
package, ensure it is installed in your environment. Uncomment the command below if needed.
# %pip install geoai-py
Import the package
import geoai
Define URLs for sample datasets: a NAIP imagery raster file and a building footprints vector file
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"
Download the raster file (NAIP imagery) and save it locally
raster_path = geoai.download_file(raster_url)
Download the vector file (building footprints) and save it locally
vector_path = geoai.download_file(vector_url)
Display metadata about the raster file, including dimensions, resolution, projection, and bands
geoai.get_raster_info(raster_path)["band_stats"]
geoai.print_raster_info(raster_path, figsize=(18, 10))
Display metadata about the vector file, including geometry type, feature count, extent, and attributes
geoai.print_vector_info(vector_path, figsize=(18, 10))
Analyze the "height" attribute of buildings to obtain statistical information
geoai.analyze_vector_attributes(vector_path, "height")
Create a visualization of building footprints colored by their height values
geoai.visualize_vector_by_attribute(vector_path, "height")
Clip the raster file to a specified extent
clip_raster_path = "naip_clip.tif"
geoai.clip_raster_by_bbox(
raster_path,
clip_raster_path,
bbox=(0, 0, 500, 500),
bands=[1, 2, 3],
bbox_type="pixel",
)
geoai.view_image(clip_raster_path)