Vector Data Strategies

This module contains strategies for handling vector data in OCLI. These strategies are designed to be reusable for any AIKP that produces vector output.

Overview

The vector data strategies module provides three main strategies:

  1. MakeGeoJSON Strategy: Creates a GeoJSON file from vector data (shapefile, KML, GeoJSON) with appropriate styling information.

  2. Publish Strategy: Publishes vector data to a document database.

  3. Upload Strategy: Uploads vector data to a cloud storage service.

These strategies follow the same pattern as the existing strategies for raster data (e.g., ai makecog), but are specifically designed for vector data.

Usage

CLI Commands

The vector data strategies are exposed through the following CLI commands:

# Create a GeoJSON file from vector data
ai makegeojson --file-path /path/to/vector/file.shp

# Publish vector data to a document database
ai publish

# Upload vector data to a cloud storage service
ai upload

The ai makegeojson command is designed to work with both raster and vector data. It automatically detects the data type based on the file extension or the AIKP template and applies the appropriate strategy.

In AIKPs

To use these strategies in an AIKP, you can either:

  1. Use the default implementations by calling the CLI commands.

  2. Provide custom implementations by creating the appropriate modules in your AIKP template.

Using Default Implementations

The default implementations handle common vector data formats (shapefile, KML, GeoJSON) and provide basic styling based on a grouping column.

Providing Custom Implementations

To provide a custom implementation, create the appropriate module in your AIKP template:

# In your AIKP template
RECIPE_DEFAULTS = {
    'makegeojson': 'make_geo_json',  # Path to your custom makegeojson module
    'publish': 'publish',            # Path to your custom publish module
    'upload': 'upload'               # Path to your custom upload module
}

Then create the corresponding modules with an execute() function:

# make_geo_json.py
def execute(task):
    # Your custom makegeojson implementation
    pass

# publish.py
def execute(task, dry_run=False, print_json=False):
    # Your custom publish implementation
    pass

# upload.py
def execute(task, cos_key=None, dry_run=False):
    # Your custom upload implementation
    pass

Examples

Creating a GeoJSON File from a Shapefile

ai makegeojson --file-path /path/to/shapefile.shp --friendly-name "My Vector Layer"

This command will:

  1. Read the shapefile

  2. Add colors based on a grouping column

  3. Create a GeoJSON file with appropriate styling

  4. Create a GeoJSON metadata file for the database

Publishing Vector Data

ai publish

This command will publish the GeoJSON metadata file to a document database, making it available for visualization in the UI.

Uploading Vector Data

ai upload

This command will upload the vector data file and its GeoJSON metadata file to a cloud storage service, making them available for visualization in the UI.