forked from geopandas/geopandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeom_methods.py
149 lines (125 loc) · 4.2 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import random
import numpy as np
from geopandas import GeoSeries
from shapely.geometry import Point, Polygon, MultiPolygon
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)
]
)
triangles4 = GeoSeries(
[
MultiPolygon(
[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.multi_triangles = triangles4
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_union_all(self, *args):
self.triangles.union_all()
def time_buffer(self, *args):
self.points.buffer(2)
def time_explode(self, *args):
self.multi_triangles.explode()
# TODO
# project, interpolate, affine_transform, translate, rotate, scale, skew
# cx indexer