Feature

Back to Vectors

class Feature(geometry, properties, id=None)[source]

An object matching the format of a GeoJSON Feature with geometry and properties.

geometry

If the Shapely package is installed, it will be a shapely shape, otherwise a dict of a simple GeoJSON geometry type. The geometry must be one of these GeoJSON types:

  • Point
  • MultiPoint
  • Polygon
  • MultiPolygon
  • LineString
  • MultiLineString
  • GeometryCollection
Type:shapely.geometry.Polygon or dict
properties

Fields describing the geometry. Values can be strings up to 256 characters, numeric types, or None.

Type:DotDict

Example

>>> polygon = {
...    'type': 'Polygon',
...    'coordinates': [[[-95, 42], [-93, 42], [-93, 40], [-95, 41], [-95, 42]]]}
>>> properties = {"temperature": 70.13, "size": "large"}
>>> Feature(geometry=polygon, properties=properties)  
Feature({
  'geometry': {
    'coordinates': (((-95.0, 42.0), (-93.0, 42.0), (-93.0, 40.0), (-95.0, 41.0), (-95.0, 42.0)),),
    'type': 'Polygon'
  },
  'id': None,
  'properties': {
    'size': 'large',
    'temperature': 70.13
  }
})

Attributes:

geojson Returns the Feature as a GeoJSON dict.
property geojson

Returns the Feature as a GeoJSON dict.

Returns:GeoJSON Feature as a dict with the following keys:
geometry:   GeoJSON geometry object. A dict with the following
            keys:

    coordinates: Coordinates of the GeoJSON object. A list,
                 list(list) or list(list(list)) depending on
                 the type of the geometry object.
    type:        GeoJSON object type.

properties: A dict with feature properties.
type:       "Feature"
Return type:dict

Example

>>> polygon = {
...    'type': 'Polygon',
...    'coordinates': [[[-95, 42], [-93, 42], [-93, 40], [-95, 41], [-95, 42]]]}
>>> properties = {"temperature": 70.13, "size": "large", "tags": None}
>>> feature = Feature(geometry=polygon, properties=properties)
>>> feature.geojson  
{'geometry': {'coordinates': (((-95.0, 42.0),
    (-93.0, 42.0),
    (-93.0, 40.0),
    (-95.0, 41.0),
    (-95.0, 42.0)),),
 'type': 'Polygon'},
 'id': None,
 'properties': {
   'size': 'large',
   'temperature': 70.13
 },
 'type': 'Feature'
}