togo 0.1.5__cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of togo might be problematic. Click here for more details.

@@ -0,0 +1,275 @@
1
+ Metadata-Version: 2.4
2
+ Name: togo
3
+ Version: 0.1.5
4
+ Summary: Lightweight Python bindings for the TG geometry library
5
+ Author-email: Giorgio Salluzzo <giorgio.salluzzo@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/mindflayer/togo
8
+ Project-URL: Source, https://github.com/mindflayer/togo
9
+ Project-URL: Tracker, https://github.com/mindflayer/togo/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: C
12
+ Classifier: Operating System :: POSIX :: Linux
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Topic :: Scientific/Engineering :: GIS
15
+ Requires-Python: >=3.8
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Dynamic: license
19
+ Dynamic: license-file
20
+
21
+ # ToGo
22
+ Python bindings for [TG](https://github.com/tidwall/tg)
23
+ (Geometry library for C - Fast point-in-polygon)
24
+
25
+ ToGo is a high-performance Python library for computational geometry, providing a Cython wrapper around the above-mentioned C library.
26
+
27
+ The main goal is to offer a Pythonic, object-oriented, fast and memory-efficient library for geometric operations, including spatial predicates, format conversions, and spatial indexing.
28
+
29
+ While ToGo's API interfaces are still a work in progress, the underling C library is stable and well-tested.
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install togo
35
+ ```
36
+
37
+ ## Features
38
+
39
+ - Fast and efficient geometric operations
40
+ - Support for standard geometry types: Point, Line, Ring, Polygon, and their multi-variants
41
+ - Geometric predicates: contains, intersects, covers, touches, etc.
42
+ - Format conversion between WKT, GeoJSON, WKB, and HEX
43
+ - Spatial indexing for accelerated queries
44
+ - Memory-efficient C implementation with Python-friendly interface
45
+
46
+ ## Basic Usage
47
+
48
+ ```python
49
+ from togo import Geometry, Point, Ring, Poly
50
+
51
+ # Create a geometry from GeoJSON
52
+ geom = Geometry('{"type":"Point","coordinates":[1.0,2.0]}')
53
+
54
+ # Create a point
55
+ point = Point(1.0, 2.0)
56
+
57
+ # Create a polygon
58
+ ring = Ring([(0,0), (10,0), (10,10), (0,10), (0,0)])
59
+ polygon = Poly(ring)
60
+
61
+ # Convert to various formats
62
+ wkt = polygon.as_geometry().to_wkt()
63
+ geojson = polygon.as_geometry().to_geojson()
64
+
65
+ # Perform spatial predicates
66
+ point_geom = point.as_geometry()
67
+ contains = polygon.as_geometry().contains(point_geom)
68
+ ```
69
+
70
+ ## Core Classes
71
+
72
+ ### Geometry
73
+
74
+ The base class that wraps tg_geom structures and provides core operations:
75
+
76
+ ```python
77
+ # Create from various formats
78
+ g1 = Geometry('POINT(1 2)', fmt='wkt')
79
+ g2 = Geometry('{"type":"Point","coordinates":[1,2]}', fmt='geojson')
80
+
81
+ # Geometric predicates
82
+ g1.intersects(g2)
83
+ g1.contains(g2)
84
+ g1.within(g2)
85
+
86
+ # Format conversion
87
+ g1.to_wkt()
88
+ g1.to_geojson()
89
+
90
+ # Access sub-geometries by index (e.g., for GeometryCollection, MultiPoint, etc.)
91
+ gc = Geometry('GEOMETRYCOLLECTION(POINT(1 2),POINT(3 4))', fmt='wkt')
92
+ first = gc[0] # Bound to TG function call tg_geom_geometry_at(idx)
93
+ second = gc[1]
94
+ print(first.type_string()) # 'Point'
95
+ ```
96
+
97
+ ### Point
98
+
99
+ ```python
100
+ from togo import Point
101
+
102
+ # Create a point
103
+ p = Point(1.0, 2.0)
104
+
105
+ # Access coordinates
106
+ print(f"X: {p.x}, Y: {p.y}")
107
+
108
+ # Get as a tuple
109
+ print(p.as_tuple())
110
+
111
+ # Convert to a Geometry object
112
+ geom = p.as_geometry()
113
+ print(geom.type_string())
114
+ ```
115
+
116
+ ### Segment
117
+
118
+ ```python
119
+ from togo import Segment, Point
120
+
121
+ # Create a segment from two points (or tuples)
122
+ seg = Segment(Point(0, 0), Point(1, 1))
123
+ # Or using tuples
124
+ tuple_seg = Segment((0, 0), (1, 1))
125
+
126
+ # Access endpoints
127
+ print(seg.a) # Point(0, 0)
128
+ print(seg.b) # Point(1, 1)
129
+
130
+ # Get the bounding rectangle
131
+ rect = seg.rect()
132
+ print(rect) # ((0.0, 0.0), (1.0, 1.0))
133
+
134
+ # Check intersection with another segment
135
+ other = Segment((1, 1), (2, 2))
136
+ print(seg.intersects(other)) # True or False
137
+ ```
138
+
139
+ ### Line
140
+
141
+ ```python
142
+ from togo import Line
143
+
144
+ # Create a line from a list of tuples
145
+ line = Line([(0,0), (1,1), (2,0)])
146
+
147
+ # Get number of points
148
+ print(f"Number of points: {line.num_points()}")
149
+
150
+ # Get all points as a list of tuples
151
+ print(f"Points: {line.points()}")
152
+
153
+ # Get the length of the line
154
+ print(f"Length: {line.length()}")
155
+
156
+ # Get the bounding box
157
+ print(f"Bounding box: {line.rect()}")
158
+
159
+ # Get a point by index
160
+ print(f"First point: {line[0].as_tuple()}")
161
+ ```
162
+
163
+ ### Ring
164
+
165
+ ```python
166
+ from togo import Ring
167
+
168
+ # Create a ring (must be closed)
169
+ ring = Ring([(0,0), (10,0), (10,10), (0,10), (0,0)])
170
+
171
+ # Get area and perimeter
172
+ print(f"Area: {ring.area()}")
173
+ print(f"Perimeter: {ring.perimeter()}")
174
+
175
+ # Check if it's convex or clockwise
176
+ print(f"Is convex: {ring.is_convex()}")
177
+ print(f"Is clockwise: {ring.is_clockwise()}")
178
+
179
+ # Get bounding box
180
+ min_pt, max_pt = ring.rect().min, ring.rect().max
181
+ print(f"Bounding box: {min_pt.as_tuple()}, {max_pt.as_tuple()}")
182
+ ```
183
+
184
+ ### Poly
185
+
186
+ ```python
187
+ from togo import Poly, Ring, Point
188
+
189
+ # Create a polygon with one exterior ring and one interior hole
190
+ exterior = Ring([(0,0), (10,0), (10,10), (0,10), (0,0)])
191
+ hole1 = Ring([(1,1), (2,1), (2,2), (1,2), (1,1)])
192
+ poly = Poly(exterior, holes=[hole1])
193
+
194
+ # Get the exterior ring
195
+ ext_ring = poly.exterior()
196
+ print(f"Exterior has {ext_ring.num_points()} points")
197
+
198
+ # Get number of holes
199
+ print(f"Number of holes: {poly.num_holes()}")
200
+
201
+ # Get a hole by index
202
+ h = poly.hole(0)
203
+ print(f"Hole area: {h.area()}")
204
+
205
+ # A polygon is a geometry, so you can use geometry methods
206
+ geom = poly.as_geometry()
207
+ print(f"Contains point (5,5): {geom.contains(Point(5,5).as_geometry())}")
208
+ # Point is inside the hole, so it is not contained by the polygon
209
+ print(f"Contains point (1.5,1.5): {geom.contains(Point(1.5,1.5).as_geometry())}")
210
+ ```
211
+
212
+ ### MultiGeometries
213
+
214
+ Creating collections of geometries:
215
+
216
+ ```python
217
+ from togo import Geometry, Point, Line, Poly, Ring
218
+
219
+ # Create a MultiPoint
220
+ multi_point = Geometry.from_multipoint([(0,0), (1,1), Point(2,2)])
221
+
222
+ # Create a MultiLineString
223
+ multi_line = Geometry.from_multilinestring([
224
+ [(0,0), (1,1)],
225
+ Line([(2,2), (3,3)])
226
+ ])
227
+
228
+ # Create a MultiPolygon
229
+ poly1 = Poly(Ring([(0,0), (1,0), (1,1), (0,1), (0,0)]))
230
+ poly2 = Poly(Ring([(2,2), (3,2), (3,3), (2,3), (2,2)]))
231
+ multi_poly = Geometry.from_multipolygon([poly1, poly2])
232
+ ```
233
+
234
+ ## Polygon Indexing
235
+
236
+ Togo supports different polygon indexing strategies for optimized spatial operations:
237
+
238
+ ```python
239
+ from togo import TGIndex, set_polygon_indexing_mode
240
+
241
+ # Set the indexing mode
242
+ set_polygon_indexing_mode(TGIndex.NATURAL) # or NONE, YSTRIPES
243
+ ```
244
+
245
+ ## Integration with tgx and libgeos
246
+
247
+ Togo integrates with the [tgx](https://github.com/tidwall/tgx) extension and [libgeos](https://libgeos.org/) to provide advanced geometry operations, such as topological unions and conversions between TG and GEOS geometry formats. This allows you to leverage the speed of TG for basic operations and the flexibility of GEOS for more complex tasks.
248
+
249
+ ### Example: Unary Union (GEOS integration)
250
+
251
+ The `unary_union` method demonstrates this integration. It combines multiple geometries into a single geometry using GEOS's topological union, with all conversions handled automatically:
252
+
253
+ ```python
254
+ from togo import Geometry, Point, Poly, Ring
255
+
256
+ # Create several polygons
257
+ poly1 = Poly(Ring([(0,0), (2,0), (2,2), (0,2), (0,0)]))
258
+ poly2 = Poly(Ring([(1,1), (3,1), (3,3), (1,3), (1,1)]))
259
+
260
+ # Perform unary union (requires tgx and libgeos)
261
+ union = Geometry.unary_union([poly1, poly2])
262
+
263
+ # The result is a single geometry representing the union of the input polygons
264
+ print(union.to_wkt())
265
+ ```
266
+
267
+ This operation uses `tgx` to convert `TG` geometries to `GEOS`, applies the union in `libgeos`, and converts the result back to `TG` format for further use in `ToGo`.
268
+
269
+ ## Performance Considerations
270
+
271
+ - Togo is optimized for speed and memory efficiency
272
+ - For large datasets, proper indexing can significantly improve performance
273
+ - Creating geometries with the appropriate format avoids unnecessary conversions
274
+
275
+ Soon there will be a full API documentation, for now please refer to the test suite for more usage examples.
@@ -0,0 +1,6 @@
1
+ togo.cpython-310-x86_64-linux-gnu.so,sha256=82tAcTPc-MBJGJRCkweoSP2pbkMRe4vykBaBhDE3Do8,9236600
2
+ togo-0.1.5.dist-info/METADATA,sha256=J4BU0w5iNSqsEQ56hodktVSrffMKO8xItT6zCuGfk9s,7722
3
+ togo-0.1.5.dist-info/WHEEL,sha256=HeTPKmtWRHAcGMCPCdnU4FtSZuvZBNNr3hB4MNGY2JY,152
4
+ togo-0.1.5.dist-info/top_level.txt,sha256=bldd6tssR8THqoSDFauQQdh_pg79DMHBDhiNKgS4ttM,5
5
+ togo-0.1.5.dist-info/RECORD,,
6
+ togo-0.1.5.dist-info/licenses/LICENSE,sha256=OfTFHFMDSt9X89g-BWUVis-GuTPWAdjplg2z9d2dBCw,1073
@@ -0,0 +1,6 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp310-cp310-manylinux_2_24_x86_64
5
+ Tag: cp310-cp310-manylinux_2_28_x86_64
6
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Giorgio Salluzzo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ togo
Binary file