forked from geopandas/geopandas
/
geom_methods.py
104 lines (81 loc) · 3.76 KB
/
geom_methods.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import random
import numpy as np
from geopandas import GeoSeries
from shapely.geometry import Point, LineString, Polygon
def with_attributes(**attrs):
def decorator(func):
for key, value in attrs.items():
setattr(func, key, value)
return func
return decorator
class Bench:
def setup(self, *args):
self.points = GeoSeries([Point(i, i) for i in range(100000)])
triangles = GeoSeries([Polygon([(random.random(), random.random())
for _ in range(3)])
for _ in range(1000)])
triangles2 = triangles.copy().iloc[np.random.choice(1000, 1000)]
triangles3 = GeoSeries([Polygon([(random.random(), random.random())
for _ in range(3)])
for _ in range(10000)])
triangle = Polygon([(random.random(), random.random())
for _ in range(3)])
self.triangles, self.triangles2 = triangles, triangles2
self.triangles_big = triangles3
self.triangle = triangle
@with_attributes(param_names=['op'],
params=[('contains', 'crosses', 'disjoint', 'intersects',
'overlaps', 'touches', 'within', 'geom_equals',
'geom_almost_equals', 'geom_equals_exact')])
def time_binary_predicate(self, op):
getattr(self.triangles, op)(self.triangle)
@with_attributes(param_names=['op'],
params=[('contains', 'crosses', 'disjoint', 'intersects',
'overlaps', 'touches', 'within', 'geom_equals',
'geom_almost_equals')]) # 'geom_equals_exact')])
def time_binary_predicate_vector(self, op):
getattr(self.triangles, op)(self.triangles2)
@with_attributes(param_names=['op'],
params=[('distance')])
def time_binary_float(self, op):
getattr(self.triangles, op)(self.triangle)
@with_attributes(param_names=['op'],
params=[('distance')])
def time_binary_float_vector(self, op):
getattr(self.triangles, op)(self.triangles2)
@with_attributes(param_names=['op'],
params=[('difference', 'symmetric_difference', 'union',
'intersection')])
def time_binary_geo(self, op):
getattr(self.triangles, op)(self.triangle)
@with_attributes(param_names=['op'],
params=[('difference', 'symmetric_difference', 'union',
'intersection')])
def time_binary_geo_vector(self, op):
getattr(self.triangles, op)(self.triangles2)
@with_attributes(param_names=['op'],
params=[('is_valid', 'is_empty', 'is_simple', 'is_ring')])
def time_unary_predicate(self, op):
getattr(self.triangles, op)
@with_attributes(param_names=['op'],
params=[('area', 'length')])
def time_unary_float(self, op):
getattr(self.triangles_big, op)
@with_attributes(param_names=['op'],
params=[('boundary', 'centroid', 'convex_hull',
'envelope', 'exterior', 'interiors')])
def time_unary_geo(self, op):
getattr(self.triangles, op)
def time_unary_geo_representative_point(self, *args):
getattr(self.triangles, 'representative_point')()
def time_geom_type(self, *args):
self.triangles_big.geom_type
def time_bounds(self, *args):
self.triangles.bounds
def time_unary_union(self, *args):
self.triangles.unary_union
def time_buffer(self, *args):
self.points.buffer(2)
# TODO
# project, interpolate, affine_transform, translate, rotate, scale, skew, explode
# cx indexer