CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-fiona

Fiona reads and writes spatial data files

88

1.10x
Overview
Eval results
Files

task.mdevals/scenario-8/

Feature Lookup Module

Build a Python module that retrieves specific geographic features from a spatial data file by their unique identifiers.

Requirements

The module should provide a function that:

  • Accepts a path to a spatial data file (supporting common GIS formats like Shapefile, GeoPackage, GeoJSON)
  • Accepts a list of feature IDs to retrieve
  • Opens the spatial data file in read mode
  • Retrieves each requested feature by its ID
  • Returns a list of retrieved features as dictionaries
  • For feature IDs that do not exist, skips them without raising an error

Test Cases

  • Given a shapefile with 5 features (IDs 0-4), retrieving ID 2 returns that specific feature. @test
  • Given a GeoPackage with 10 features, retrieving IDs 3, 7, and 9 returns exactly those three features. @test
  • Given a spatial file with features having IDs 0-9, attempting to retrieve ID 15 prints a warning and returns an empty result. @test
  • Given a spatial file with 100 features, retrieving ID 0 and ID 99 returns both the first and last features. @test

Implementation

@generates

API

def retrieve_features_by_id(filepath: str, feature_ids: list[int]) -> list[dict]:
    """
    Retrieve geographic features from a spatial data file by their IDs.

    Args:
        filepath: Path to the spatial data file
        feature_ids: List of feature IDs to retrieve

    Returns:
        List of feature dictionaries (GeoJSON-like structure)
    """
    pass

Dependencies { .dependencies }

fiona { .dependency }

Provides GIS data reading capabilities and random access to features by ID.

Install with Tessl CLI

npx tessl i tessl/pypi-fiona

tile.json