Feature

Luo_Suppe2026-08-15

gma.gio.Feature

[class] Feature(geom = None, values = [], gtype = None, ftypes = None, crs = None):

Create a Feature object.

Optional:

geom = None||Geometry. Default None.

The geometry of the feature. If None, create an empty geometry.

values = list. Default [].

The field values of the feature.

gtype = str||None. Default None.

The geometry type of the feature. See `dtypes.DefinedGeomTypes` for valid types. If None, use the geometry type of `geom`.

ftypes = None||list of FieldType. Default None.

The FieldTypes of the feature. If None, create an empty FieldTypes.

crs = str||int||None. Default None.

The projection of the geometry. If None, no projection is set.

Example

from gma import gio

ly = gio.open_vector('Australia.shp')
ft = ly.get_feature(0)                          # Western Australia

print('fid     :', ft.fid)
print('name    :', ft.fields['name'])
print('geometry:', ft.geom.gtype)

# Build a new Feature from the geometry and fields of an existing one
new_ft = gio.Feature(geom=ft.geom, values=list(ft.fields.values()), ftypes=ft.ftypes)
print('new ft  :', new_ft.fid, new_ft.fields['name'], repr(new_ft.crs))
fid     : 0
name    : Western Australia
geometry: MultiPolygon
new ft  : -1 Western Australia <CoordinateReferenceSystem:WGS 84>

Method

copy()

copy self. --> Feature

Returns:

Type: Feature.

An independent copy of this feature.

Example:

from gma import gio

ft = gio.open_vector('Australia.shp').get_feature(0)
cp = ft.copy()
cp.set_fid(999)

print('original:', ft.fid, ft.fields['name'])
print('copy    :', cp.fid, cp.fields['name'])
print('same object:', cp is ft)
original: 0 Western Australia
copy    : 999 Western Australia
same object: False

plot(ax = None, **kwargs)

Make plots of Geometry.

Optional:

ax = None||matplotlib. ~.AxesSubplot. Default None.

A matplotlib subplot. If None, a default axes will be created.

**kwargs

Other plotting parameters. For more, see:

~.carto.utils.PolyCollection/LineCollection/PointCollection.

Returns:

Type: Axes.

The matplotlib axes with the feature geometry plotted on it.

Example:

import matplotlib.pyplot as plt
from gma import gio

ly = gio.open_vector('Australia.shp')
ft = ly.get_feature(0)

fig, ax = plt.subplots(figsize=(6, 4.5))
ly.plot(ax=ax, facecolor='none', edgecolor='gray')                 # all features
ax = ft.plot(ax=ax, facecolor='none', edgecolor='red', linewidth=1.5)  # highlight one

print(type(ax).__name__)
Axes

Feature 0 (Western Australia) highlighted among all features

set_fid(fid)

Set the feature identifier.

Parameters:

fid: int.

the new feature identifier value to assign.

Returns:

Type: None.

Modify the feature identifier in place.

Example:

from gma import gio

ft = gio.open_vector('Australia.shp').get_feature(0)

print('Before:', ft.fid)
ft.set_fid(999)
print('After :', ft.fid)
Before: 0
After : 999

set_geom(geom)

Set feature geometry. This function updates the features geometry, except that this function does not assume ownership of the passed geometry, but instead makes a copy of it.

Parameters:

geom: Geometry.

new geometry to apply to feature.

Returns:

Type: None.

Replace the geometry in place; field values are unchanged.

Example:

from gma import gio

ly = gio.open_vector('Australia.shp')
ft = ly.get_feature(0)                  # Western Australia
new_geom = ly.get_feature(1).geom       # Northern Territory

print('Before:', ft.fields['name'], tuple(round(v, 2) for v in ft.geom.bounds))
ft.set_geom(new_geom)
print('After :', ft.fields['name'], tuple(round(v, 2) for v in ft.geom.bounds))
Before: Western Australia (112.91, -35.1, 129.0, -13.74)
After : Western Australia (129.0, -26.0, 138.0, -10.97)

Before / after replacing the geometry

update(other)

Set one feature from another. Overwrite the contents of this feature from the geometry and attributes of another.

Parameters:

other: Feature.

feature from which geometry and field values will be copied.

Returns:

Type: None.

Overwrite geometry and field values in place. The fid is not copied (-1).

Example:

from gma import gio

ly = gio.open_vector('Australia.shp')
ft = ly.get_feature(0)                  # Western Australia
other = ly.get_feature(2)               # South Australia

print('Before:', ft.fields['name'], tuple(round(v, 2) for v in ft.geom.bounds))
ft.update(other)
print('After :', ft.fields['name'], tuple(round(v, 2) for v in ft.geom.bounds))
print('fid   :', ft.fid)
Before: Western Australia (112.91, -35.1, 129.0, -13.74)
After : South Australia (129.0, -38.07, 141.03, -26.0)
fid   : -1

Before / after overwriting geometry and fields

Property

crs

Get coordinate reference system. --> CoordinateReferenceSystem

Example:

from gma import gio

ft = gio.open_vector('Australia.shp').get_feature(0)

print(ft.crs)
<CoordinateReferenceSystem:WGS 84>

fid

Get feature identifier. --> int

Example:

from gma import gio

ft = gio.open_vector('Australia.shp').get_feature(0)

print(ft.fid)
0

fields

Get fields for feature. --> dict

Example:

from gma import gio

ft = gio.open_vector('Australia.shp').get_feature(0)

print('number of fields:', len(ft.fields))
for key in ('name', 'iso_3166_2', 'type', 'scalerank'):
    print(key, ':', ft.fields[key])
number of fields: 123
name : Western Australia
iso_3166_2 : AU-WA
type : State
scalerank : 2

ftypes

Get field types for feature. --> FieldTypes

Example:

from gma import gio

ft = gio.open_vector('Australia.shp').get_feature(0)

print('number of field types:', len(ft.ftypes.names))
print('first five names     :', ft.ftypes.names[:5])
print('first field type     :', ft.ftypes[0])
number of field types: 123
first five names     : ['featurecla', 'scalerank', 'adm1_code', 'diss_me', 'iso_3166_2']
first field type     : "featurecla" - Type:"String", Width:80, Precision:0

geom

Get geometry for feature. --> Geometry

Example:

from gma import gio

ft = gio.open_vector('Australia.shp').get_feature(0)

print('type  :', ft.geom.gtype)
print('bounds:', tuple(round(v, 2) for v in ft.geom.bounds))
print('area  :', round(ft.geom.get_area(), 2))
type  : MultiPolygon
bounds: (112.91, -35.1, 129.0, -13.74)
area  : 227.81
Last Updated 11/21/2026, 2:33:17 AM