Observed since 21 Oct, 09:45 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Thư viện Python để chuyển đổi kết quả AI sang định dạng GIS
A lightweight Python library for converting results from AI (Computer Vision) models into georeferenced GIS (vector) formats.
AI models (like segmentation or object detection) typically return results in pixel-space (pixel coordinates, binary masks). However, GIS tools (QGIS, ArcGIS) and spatial analysis libraries work in geo-space (geographic coordinates like latitude/longitude or UTM).
This library provides a simple workflow to "georeference" these AI results and convert them into vector formats like GeoJSON or GeoPackage, making them immediately ready for use.
The library revolves around the main ConverterAI2GIS class, which has two initialization modes:
ConverterAI2GIS(geotiff_path=...): Uses a GeoTIFF file as a geographic reference.ConverterAI2GIS.from_array(...): Works directly with a numpy.ndarray and existing crs and transform information.create_polygons(): Converts a binary mask (raster) into vector polygons (for segmentation tasks).create_centerline(): Extracts a centerline from linear masks (rivers, roads).create_polygons_from_bins(): Converts continuous rasters (NDVI, heatmaps) into class-based polygons.create_polygons_from_bboxes(): Converts AI bounding boxes (pixel coords) into georeferenced polygons.create_points_from_coords(): Converts AI keypoints into georeferenced points.create_network_from_skeleton(): Builds node-edge networks from AI skeletons (pose estimation, roads)..gpkg, .geojson, or .shp.git clone https://gitlab.ctgroupvietnam.com/ctuav-data-ai/gis-conversion.git
cd gis-conversion
pip install -e .
Dependencies (like geopandas, rasterio, fiona, etc.) will be installed automatically.
from AI2GIS import ConverterAI2GIS
# Initialize the converter with a reference GeoTIFF
# Note: the image must include valid CRS and transform metadata
workflow = ConverterAI2GIS(geotiff_path="path/to/reference_image.tif")
# Inspect the loaded Coordinate Reference System (CRS)
print("Loaded CRS:", workflow.crs)
# Create polygons from a binary mask
# - connectivity: 4 or 8, defines pixel connectivity
# - min_area_pixels: remove small regions (in pixels)
# - simplify_tolerance: simplify geometry (pixel units)
gdf_polygons = workflow.create_polygons(connectivity=4, min_area_pixels=50, simplify_tolerance=0.5)
print(f"Created {len(gdf_polygons)} polygons")
# Extract centerlines from linear masks (roads/rivers)
# - dissolve: merge adjacent segments into continuous lines
# - min_path_length_m: discard segments shorter than this (meters)
# - simplify_tolerance_m: simplify lines (meters)
gdf_lines = workflow.create_centerline(dissolve=True, min_path_length_m=100.0, simplify_tolerance_m=2.0)
print(f"Created {len(gdf_lines)} dissolved centerlines")
bins = [-1.0, 0.2, 0.6, 1.0]
labels = ["Low", "Medium", "High"]
# Classify a continuous raster (e.g., NDVI) into bins and create polygons
# - bins: class thresholds (n+1 values for n classes)
# - labels: text label for each class (length = n)
# - sieve_threshold: remove small noisy regions (pixels)
# - simplify_tolerance: simplify polygons (in raster units)
gdf_zones = workflow.create_polygons_from_bins(bins=bins, labels=labels, sieve_threshold=100, simplify_tolerance=1e-5)
print(f"Created {len(gdf_zones)} NDVI zones")
bboxes = [[100, 150, 200, 250], [500, 300, 550, 350]]
attrs = [{"label": "tree", "score": 0.95}, {"label": "car", "score": 0.88}]
# Convert bounding boxes (pixels) into georeferenced polygons
# - bbox format: [x_min, y_min, x_max, y_max] in pixel coordinates
# - attributes: optional per-object attributes
gdf_bboxes = workflow.create_polygons_from_bboxes(bboxes=bboxes, attributes=attrs)
print(f"Created {len(gdf_bboxes)} polygons from bboxes")
points = [[150, 200], [525, 325]]
attrs = [{"type": "tree_top", "height_m": 15}, {"type": "tree_top", "height_m": 12}]
# Convert image pixel coordinates to georeferenced points
# - points: list of [x, y] in pixels
# - attributes: optional per-point attributes
gdf_points = workflow.create_points_from_coords(points=points, attributes=attrs)
print(f"Created {len(gdf_points)} points")
keypoints = [[100, 100], [200, 150], [150, 300]]
connections = [(0, 1), (1, 2)]
attrs = [{"type": "main_road", "lanes": 2}, {"type": "local_road", "lanes": 1}]
# Build a node-edge network from an AI-provided skeleton
# - keypoints: list of node pixel coordinates
# - connections: list of tuples (i, j) defining edges between nodes
# - attributes: optional attributes for edges/nodes
gdf_nodes, gdf_edges = workflow.create_network_from_skeleton(keypoints=keypoints, connections=connections, attributes=attrs)
print(f"Created {len(gdf_nodes)} nodes and {len(gdf_edges)} edges")
from AI2GIS import save_gpkg, save_geojson, save_shapefile
# Save results to common GIS formats
# - GeoPackage (.gpkg): supports multiple layers, modern standard
save_gpkg(gdf_polygons, "output/buildings.gpkg", layer_name="footprints")
# - GeoJSON (.geojson): lightweight, easy to share, default WGS84
save_geojson(gdf_polygons, "output/buildings.geojson", coordinate_precision=6)
# - Shapefile (.shp): legacy format, limited field names/lengths
save_shapefile(gdf_polygons, "output/buildings.shp")
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.1.1 | 4 Nov 2025 | 10 |
This describes our collected data; it is not a security assessment.
Observed since 21 Oct, 09:45 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:c025b5814c3920f46bf3bee957c6cf974b9f08deaad0f3d779ba0e7155b887d8