aws.osml.features¶
Working with geospatial features (detections, annotations) derived from imagery. This package
covers converting image-coordinate features to geographic coordinates (geolocation), the inverse
projection (geographic to image), spatial indexing for efficient region queries, and a property
accessor facade for the imaged-feature GeoJSON convention. It does not include the sensor
model mathematics themselves (photogrammetry) or pixel extraction and display logic
(image_processing).
Dependencies: Imports from photogrammetry (SensorModel, ElevationModel,
GeodeticWorldCoordinate, ImageCoordinate). Uses geojson, shapely, and scipy
(for bilinear interpolation). Does not import image_processing or metadata.
Design abstractions¶
The package is organized around a small set of collaborating abstractions:
Imaged-feature GeoJSON convention — Features carry image-coordinate geometry in
properties.imageGeometry and properties.imageBBox. The Geolocator populates the standard
GeoJSON geometry field by projecting these through a sensor model and elevation model. The
Projector performs the inverse operation (geographic to image).
ImagedFeaturePropertyAccessor — A facade that encapsulates how image coordinates are encoded in feature properties, isolating the rest of the package from the specific JSON schema.
LocationGridInterpolator — Pre-computes a bilinear interpolation grid of sensor model results over a tile extent, amortizing the cost of sensor model evaluation and providing O(1) per-feature geolocation within that tile.
Feature2DSpatialIndex (ABC) and STRFeature2DSpatialIndex — A query-only spatial index backed by Shapely’s STR-tree. Operates in either image-pixel or geographic coordinate space, enabling efficient region-based feature retrieval without scanning the full collection.
Geolocation pipeline¶
flowchart LR
A[pixel detections<br/>imageGeometry] --> B[Geolocator<br/>sensor model + elevation]
B --> C[GeoJSON features<br/>geometry]
C --> D[SpatialIndex]
D --> E[query results]
Contributor rules¶
New query or filter operations belong on the spatial index or in a new class — not inlined at call sites.
Coordinate transforms must go through
GeolocatororProjector, not raw sensor model calls.No pixel-reading or display logic belongs in this package.
Geolocation¶
- class aws.osml.features.Geolocator(property_accessor, sensor_model, elevation_model=None, approximation_grid_size=11, force=False)¶
Bases:
objectA Geolocator is a class that assign geographic coordinates for the features that are currently defined in image coordinates.
- geolocate_features(features)¶
Update the features to contain additional information from the context provided.
When force=False (default), features that already have a non-None geometry property are skipped. When force=True, all features are re-geolocated regardless of existing geometry.
- static radians_coordinate_to_degrees(coordinate)¶
GeoJSON coordinate order is a decimal longitude, latitude with an optional height as a 3rd value (i.e. [lon, lat, ht]). The WorldCoordinate uses the same ordering but the longitude and latitude are expressed in radians rather than degrees.
- Parameters:
coordinate (
GeodeticWorldCoordinate) – GeodeticWorldCoordinate = the geodetic world coordinate (longitude, latitude, elevation)- Return type:
- Returns:
Tuple[float, float, float] = degrees(longitude), degrees(latitude), elevation
Spatial Indexing¶
- class aws.osml.features.Feature2DSpatialIndex¶
Bases:
ABCA query-only spatial index allowing clients to lookup features using 2D geometries
- abstract find_intersects(geometry)¶
Return the features intersecting the input geometry.
- Parameters:
geometry (
Geometry) – geometry to query the index- Return type:
Iterable[Feature]- Returns:
the features
- abstract find_nearest(geometry, max_distance=None)¶
Return the nearest feature for the input geometry based on distance within two-dimensional Cartesian space.
- class aws.osml.features.STRFeature2DSpatialIndex(feature_collection, use_image_geometries=True, property_accessor=<aws.osml.features.imaged_feature_property_accessor.ImagedFeaturePropertyAccessor object>)¶
Bases:
Feature2DSpatialIndexImplementation of the 2D spatial index for GeoJSON features using Shapely’s Sort-Tile-Recursive (STR) tree datastructure.
- find_intersects(geometry)¶
Return the features intersecting the input geometry.
- Parameters:
geometry (
Geometry) – geometry to query the index- Return type:
Iterable[Feature]- Returns:
the features
- find_nearest(geometry, max_distance=None)¶
Return the nearest feature for the input geometry based on distance within two-dimensional Cartesian space.
Property Accessors¶
- class aws.osml.features.ImagedFeaturePropertyAccessor(allow_deprecated=True)¶
Bases:
objectThis class contains utility functions that ensure the property names / values for features derived from imagery are consistently implemented. These specifications are still evolving so the intent is to encapsulate all of the names in this one class so that changes do not ripple through the rest of the software baseline.
- IMAGE_GEOMETRY = 'imageGeometry'¶
- IMAGE_BBOX = 'imageBBox'¶
- BOUNDS_IMCORDS = 'bounds_imcoords'¶
- GEOM_IMCOORDS = 'geom_imcoords'¶
- DETECTION = 'detection'¶
- TYPE = 'type'¶
- COORDINATES = 'coordinates'¶
- PIXEL_COORDINATES = 'pixelCoordinates'¶
- find_image_geometry(feature)¶
This function searches through the properties of a GeoJSON feature that are known to contain the geometry of the feature in image coordinates. If found an appropriate 2D shape is constructed and returned. Note that this search is conducted in priority order giving preference to the current preferred “imageGeometry” and “bboxGeometry” properties. If neither of those is available and the accessor has been configured to search deprecated properties then the “geom_imcoords”, “detection”, and “bounds_imcoords” properties are searched in that order.
- Parameters:
feature (
Feature) – a GeoJSON feature that might contain an image geometry property- Return type:
Optional[Geometry]- Returns:
a 2D shape representing the image geometry or None
- update_existing_image_geometries(feature, geometry)¶
This function searches through the properties of a GeoJSON feature that are known to contain the geometry of the feature in image coordinates. If found each property is overwritten with information from the geometry provided. Note that for bounding box properties the bounds of the input geometry are used.
- Parameters:
feature (
Feature) – a GeoJSON feature that might contain an image geometry propertygeometry (
Geometry) – the geometry to set property values for.
- Return type:
- classmethod set_image_geometry(feature, geometry)¶
Add or set the “imageGeometry” property for a feature. This is a 2D geometry that supports a variety of types (points, lines, polygons, etc.)
- Parameters:
feature (
Feature) – a GeoJSON feature that will contain the propertygeometry (
Geometry) – the geometry value
- Return type: