Lightweight Python bindings for the TG geometry library
Reason this release was yanked:
Unstable?
Project description
ToGo
ToGo - Python bindings for TG (Geometry library for C - Fast point-in-polygon)
How ToGo Works
Togo is a high-performance Python library for computational geometry, providing a Cython wrapper around the tg C library.
Installation
pip install togo
Features
- Fast and efficient geometric operations
- Support for standard geometry types: Point, Line, Ring, Polygon, and their multi-variants
- Geometric predicates: contains, intersects, covers, touches, etc.
- Format conversion between WKT, GeoJSON, WKB, and HEX
- Spatial indexing for accelerated queries
- Memory-efficient C implementation with Python-friendly interface
Basic Usage
from togo import Geometry, Point, Ring, Poly
# Create a geometry from GeoJSON
geom = Geometry('{"type":"Point","coordinates":[1.0,2.0]}')
# Create a point
point = Point(1.0, 2.0)
# Create a polygon
ring = Ring([(0,0), (10,0), (10,10), (0,10), (0,0)])
polygon = Poly(ring)
# Convert to various formats
wkt = polygon.as_geometry().to_wkt()
geojson = polygon.as_geometry().to_geojson()
# Perform spatial predicates
point_geom = point.as_geometry()
contains = polygon.as_geometry().contains(point_geom)
Core Classes
Geometry
The base class that wraps tg_geom structures and provides core operations:
# Create from various formats
g1 = Geometry('POINT(1 2)', fmt='wkt')
g2 = Geometry('{"type":"Point","coordinates":[1,2]}', fmt='geojson')
# Geometric predicates
g1.intersects(g2)
g1.contains(g2)
g1.within(g2)
# Format conversion
g1.to_wkt()
g1.to_geojson()
Point, Line, Ring, Poly
Building blocks for constructing geometries:
# Create a point
p = Point(1.0, 2.0)
# Create a line
line = Line([(0,0), (1,1), (2,2)])
# Create a ring (closed line)
ring = Ring([(0,0), (10,0), (10,10), (0,10), (0,0)])
# Create a polygon with holes
exterior = Ring([(0,0), (10,0), (10,10), (0,10), (0,0)])
hole = Ring([(2,2), (8,2), (8,8), (2,8), (2,2)])
poly = Poly(exterior, [hole])
MultiGeometries
Creating collections of geometries:
# Create a MultiPoint
multi_point = Geometry.from_multipoint([(0,0), (1,1), Point(2,2)])
# Create a MultiLineString
multi_line = Geometry.from_multilinestring([
[(0,0), (1,1)],
Line([(2,2), (3,3)])
])
# Create a MultiPolygon
poly1 = Poly(Ring([(0,0), (1,0), (1,1), (0,1), (0,0)]))
poly2 = Poly(Ring([(2,2), (3,2), (3,3), (2,3), (2,2)]))
multi_poly = Geometry.from_multipolygon([poly1, poly2])
Polygon Indexing
Togo supports different polygon indexing strategies for optimized spatial operations:
from togo import TGIndex, set_polygon_indexing_mode
# Set the indexing mode
set_polygon_indexing_mode(TGIndex.NATURAL) # or NONE, YSTRIPES
Performance Considerations
- Togo is optimized for speed and memory efficiency
- For large datasets, proper indexing can significantly improve performance
- Creating geometries with the appropriate format avoids unnecessary conversions
Soon there will be a full API documentation, for now please refer to the test suite for more usage examples.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file togo-0.1.0.tar.gz.
File metadata
- Download URL: togo-0.1.0.tar.gz
- Upload date:
- Size: 246.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11751cc1744c7eb9afead9476f7d9e353f949aa69b458deb5a1a75b8a5f4e7b0
|
|
| MD5 |
12aad987b47da09dee926545990cbba5
|
|
| BLAKE2b-256 |
4e23496df15dd959ac3c426dcd1e9d2a8e6427571ac36c462056c4efa1157d4b
|