module documentation

GeoJSON utilities.

Copyright 2017-2025, Voxel51, Inc.

Class GeoJSONDatasetExporter Exporter for image or video datasets whose location data and labels are stored in GeoJSON format.
Class GeoJSONDatasetImporter Importer for image or video datasets whose location data and labels are stored in GeoJSON format.
Function extract_coordinates Extracts the coordinates from all geometries in the GeoJSON dictionary.
Function geo_within Creates a MongoDB query expression that tests whether the given location field is contained within the specified boundary shape.
Function load_location_data Loads geolocation data for the given samples from the given GeoJSON data.
Function parse_point Parses the point into GeoJSON dict representation.
Function parse_polygon Parses the polygon or multi-polygon into GeoJSON dict representation.
Function to_geo_json_geometry Returns a GeoJSON geometry dict representation for the given location.
Variable logger Undocumented
Function _ensure_type Undocumented
Function _make_geometry Undocumented
Function _parse_geometries Undocumented
Function _to_geo_collection Undocumented
Function _to_geo_primitive Undocumented
Function _to_multi_geo_collection Undocumented
def extract_coordinates(d): (source)

Extracts the coordinates from all geometries in the GeoJSON dictionary.

The dict can have any type supported by the GeoJSON spec, including Feature, FeatureCollection, GeometryCollection, and primitive geometries Point, LineString, Polygon, MultiPoint, MultiLineString, or MultiPolygon.

Parameters
da GeoJSON dict
Returns
a tuple of
  • points: a list of Point coordinates
  • lines: a list of LineString coordinates
  • points: a list of Polygon coordinates
def geo_within(location_field, boundary, strict=True): (source)

Creates a MongoDB query expression that tests whether the given location field is contained within the specified boundary shape.

Parameters
location_fieldthe embedded field containing GeoJSON data
boundarya fiftyone.core.labels.GeoLocation, fiftyone.core.labels.GeoLocations, GeoJSON dict, or list of coordinates that define a Polygon or MultiPolygon to search within
strict:Truewhether documents must exist entirely within (True) or intersect (False) the boundary
Returns
a MongoDB query dict
def load_location_data(samples, geojson_or_path, location_field=None, skip_missing=True, progress=None): (source)

Loads geolocation data for the given samples from the given GeoJSON data.

The GeoJSON data must be a FeatureCollection whose features have their filename properties populated, which are used to match the provided samples.

Example GeoJSON data:

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -73.99496451958454,
                    40.66338032487842
                ]
            },
            "properties": {
                "filename": "b1c66a42-6f7d68ca.jpg"
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "LineString",
                "coordinates": [
                    [
                        -73.80992143421788,
                        40.65611832778962
                    ],
                    [
                        -74.02930609818584,
                        40.60505054722865
                    ]
                ]
            },
            "properties": {
                "filename": "/path/to/b1c81faa-3df17267.jpg"
            }
        },
    ]
}
Parameters
samplesa fiftyone.core.collections.SampleCollection
geojson_or_patha GeoJSON FeatureCollection dict or the path to one on disk
location_field:Nonethe name of the location field in which to store the location data, which can be either a fiftyone.core.labels.GeoLocation or fiftyone.core.labels.GeoLocations field. If not specified, then, if there is an existing fiftyone.core.labels.GeoLocation field, that field is used, else a new "location" field is created
skip_missing:Truewhether to skip GeoJSON features with no filename properties (True) or raise an error (False)
progress:Nonewhether to render a progress bar (True/False), use the default value fiftyone.config.show_progress_bars (None), or a progress callback function to invoke instead
def parse_point(arg): (source)

Parses the point into GeoJSON dict representation.

Parameters
argUndocumented
point

a point specified in any of the following formats:

Returns
a GeoJSON dict of type Point
def parse_polygon(arg): (source)

Parses the polygon or multi-polygon into GeoJSON dict representation.

Parameters
arga fiftyone.core.labels.GeoLocation, fiftyone.core.labels.GeoLocations, GeoJSON dict, or list of coordinates that define a Polygon or MultiPolygon to search within
Returns
a GeoJSON dict of type Polygon or MultiPolygon
def to_geo_json_geometry(label): (source)

Returns a GeoJSON geometry dict representation for the given location.

Parameters
labela fiftyone.core.labels.GeoLocation o fiftyone.core.labels.GeoLocations instance
Returns
a GeoJSON dict

Undocumented

def _ensure_type(d, type_): (source)

Undocumented

def _make_geometry(type_, coordinates): (source)

Undocumented

def _parse_geometries(geometries): (source)

Undocumented

def _to_geo_collection(label): (source)

Undocumented

def _to_geo_primitive(label): (source)

Undocumented

def _to_multi_geo_collection(label): (source)

Undocumented