Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions geojson/base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import geojson
from geojson.mapping import to_mapping

from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Literal


class GeoJSON(dict):
"""
A class representing a GeoJSON object.
"""
# https://datatracker.ietf.org/doc/html/rfc7946#section-3 has 'type'
# https://datatracker.ietf.org/doc/html/rfc7946#section-1.4 allowed values
type: Literal["Feature", "FeatureCollection", "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection"]

def __init__(self, iterable=(), **extra):
"""
Expand Down
10 changes: 10 additions & 0 deletions geojson/feature.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
from geojson.base import GeoJSON

from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import List, Literal, Optional, Union, Dict, Any
from .geometry import Geometry

class Feature(GeoJSON):
"""
Represents a WGS84 GIS feature.
"""
# https://datatracker.ietf.org/doc/html/rfc7946#section-3.2
type: Literal["Feature"]
geometry: Optional[Geometry]
properties: Dict[str, Any]
id: Optional[Union[int, str]]

def __init__(self, id=None, geometry=None, properties=None, **extra):
"""
Expand Down Expand Up @@ -34,6 +43,7 @@ class FeatureCollection(GeoJSON):
"""
Represents a FeatureCollection, a set of multiple Feature objects.
"""
features: List[Feature]

def __init__(self, features, **extra):
"""
Expand Down