In [ ]:
Copied!
# %pip install geoai-py smoothify
# %pip install geoai-py smoothify
Import libraries¶
In [ ]:
Copied!
import geoai
import leafmap
import geoai
import leafmap
Download sample data¶
In [ ]:
Copied!
image_url = "https://huggingface.co/datasets/giswqs/geospatial/resolve/main/wetland_prediction.tif"
image_path = geoai.download_file(image_url)
image_url = "https://huggingface.co/datasets/giswqs/geospatial/resolve/main/wetland_prediction.tif"
image_path = geoai.download_file(image_url)
Visualize sample data¶
In [ ]:
Copied!
m = leafmap.Map()
m.add_basemap("Esri.WorldImagery")
m.add_raster(image_path, nodata=0, opacity=0.5, layer_name="Raster")
m
m = leafmap.Map()
m.add_basemap("Esri.WorldImagery")
m.add_raster(image_path, nodata=0, opacity=0.5, layer_name="Raster")
m
Convert raster to vector¶
In [ ]:
Copied!
output_path = "wetland_prediction.geojson"
gdf = geoai.raster_to_vector(
image_path, output_path, min_area=1000, simplify_tolerance=None
)
output_path = "wetland_prediction.geojson"
gdf = geoai.raster_to_vector(
image_path, output_path, min_area=1000, simplify_tolerance=None
)
In [ ]:
Copied!
style = {"color": "red", "fillOpacity": 0, "weight": 2}
m.add_vector(output_path, style=style, layer_name="Vector", info_mode=None)
style = {"color": "red", "fillOpacity": 0, "weight": 2}
m.add_vector(output_path, style=style, layer_name="Vector", info_mode=None)
Smooth a vector data using smoothify¶
In [ ]:
Copied!
smoothed_gdf = geoai.smooth_vector(
gdf, smooth_iterations=3, output_path="wetland_prediction_smoothed.geojson"
)
smoothed_gdf = geoai.smooth_vector(
gdf, smooth_iterations=3, output_path="wetland_prediction_smoothed.geojson"
)
In [ ]:
Copied!
smoothed_style = {"color": "yellow", "fillOpacity": 0, "weight": 1}
m.add_gdf(
smoothed_gdf, style=smoothed_style, layer_name="Smoothed Vector", info_mode=None
)
m
smoothed_style = {"color": "yellow", "fillOpacity": 0, "weight": 1}
m.add_gdf(
smoothed_gdf, style=smoothed_style, layer_name="Smoothed Vector", info_mode=None
)
m