Annotation¶
- class Annotation(geometry=None, properties=None, wkb=None)[source]¶
An annotation: a geometry and associated properties.
- geometry¶
The geometry of the annotation as a Shapely object.
- Type:
Geometry
Create a new annotation.
Must be initialized with either a Shapely geometry object or WKB bytes.
- Parameters:
Methods
Decode WKB to a NumPy array of flat (alternating x, y) coordinates.
Return a feature representation of this annotation.
Return a GeoJSON string representation of this annotation.
Returns the geometry as Well-Known Binary (WKB).
Returns the geometry as Well-Know Text (WKT).
Attributes
The annotation geometry as a flat array of 2D coordinates.
Return the shapely geometry of the annotation.
Return the geometry type of the annotation.
Return the WKB representation of the annotation.
- property coords: ndarray | list[ndarray] | list[list[ndarray]]¶
The annotation geometry as a flat array of 2D coordinates.
Returns a numpy array of coordinates for point and line string. For polygons, returns a list of numpy arrays, one for each ring. For multi-geometries, returns a list with one element for each geometry.
- Returns:
The coordinates of the annotation geometry.
- Return type:
np.array or list
- static decode_wkb(wkb, geom_type)[source]¶
Decode WKB to a NumPy array of flat (alternating x, y) coordinates.
Polygons return a list of NumPy arrays (one array per ring) and multi-part geometries return a list with one element per child geometry e.g. a list of arrays for Multi-Line and a list of lists of arrays for multi-polyon.
- Parameters:
- Return type:
Examples
>>> from tiatoolbox.annotation.storage import AnnotationStore >>> # Point(1, 2).wkb >>> wkb = ( ... b"\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00" ... b"\xf0?\x00\x00\x00\x00\x00\x00\x00@" ... ) >>> AnnotationStore.decode_wkb(wkb, 1) array([0., 0.])
>>> from tiatoolbox.annotation.storage import AnnotationStore >>> # Polygon([[0, 0], [1, 1], [1, 0]]).wkb >>> wkb = ( ... b"\x01\x03\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00" ... b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ... b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00" ... b"\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\x00" ... b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ... b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ... ) >>> AnnotationStore.decode_wkb(wkb, 3) array([[0., 0.], [1., 1.], [1., 0.], [0., 0.]])
- Raises:
ValueError – If the geometry type is not supported.
- Returns:
An array of coordinates, a list of coordinates, or a list of lists of coordinates.
- Return type:
np.ndarray or list
- Parameters:
- property geometry: Point | LineString | Polygon¶
Return the shapely geometry of the annotation.
- property geometry_type: GeometryType¶
Return the geometry type of the annotation.
- to_feature()[source]¶
Return a feature representation of this annotation.
A feature representation is a Python dictionary with the same schema as a geoJSON feature.
- Returns:
A feature representation of this annotation.
- Return type:
- Parameters:
self (Annotation)
- to_geojson()[source]¶
Return a GeoJSON string representation of this annotation.
- Returns:
A GeoJSON representation of this annotation.
- Return type:
- Parameters:
self (Annotation)
- to_wkb()[source]¶
Returns the geometry as Well-Known Binary (WKB).
- Returns:
The annotation as a WKB geometry.
- Return type:
- Parameters:
self (Annotation)
- to_wkt()[source]¶
Returns the geometry as Well-Know Text (WKT).
- Returns:
The annotation as a WKT geometry.
- Return type:
- Parameters:
self (Annotation)