-
Notifications
You must be signed in to change notification settings - Fork 1
/
geos_perf_test_intersection.c
103 lines (88 loc) · 3 KB
/
geos_perf_test_intersection.c
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
#include <stdio.h>
#include "geos_perf.h"
/*************************************************************************
* PERFORMANCE TEST
*/
/* Variables where data lives between the setup/run/cleanup stages */
static GEOSGeometryList watersheds;
static GEOSGeometryList watersheds_buffered;
static GEOSSTRtree* tree;
/* Read any data we need, and create any structures */
static void setup(void)
{
size_t i;
geomlist_init(&watersheds);
geomlist_init(&watersheds_buffered);
read_data_file("watersheds.wkt.gz", &watersheds);
/* Calculate buffers of the polygons */
for (i = 0; i < geomlist_size(&watersheds); i++)
{
const GEOSGeometry* geom = geomlist_get(&watersheds, i);
geomlist_push(&watersheds_buffered, GEOSBuffer(geom, 100.0, 16));
}
/* Populate tree with watersheds */
tree = GEOSSTRtree_create(10);
for (i = 0; i < geomlist_size(&watersheds); i++)
{
const GEOSGeometry* geom = geomlist_get(&watersheds, i);
GEOSSTRtree_insert(tree, geom, (void*)geom);
}
}
/* Callback to in-fill list of intersecting sheds */
static void tree_callback(void *item, void *userdata)
{
GEOSGeometryList* query_result = (GEOSGeometryList*)userdata;
GEOSGeometry* geom = (GEOSGeometry*)item;
geomlist_push(query_result, geom);
return;
}
/* For each buffered watershed, find all intersecting unbuffered
sheds, and then intersect those with the buffered watershed.
*/
static void run(void)
{
size_t i, j;
GEOSGeometryList query_result;
for (i = 0; i < geomlist_size(&watersheds_buffered); i++)
{
const GEOSGeometry* bufshed = geomlist_get(&watersheds_buffered, i);
geomlist_init(&query_result);
GEOSSTRtree_query(
tree, /* tree to query */
bufshed, /* geometry envelope to query with */
tree_callback, /* callback function to run for each find */
&query_result); /* extra user data to pass to callback */
for (j = 0; j < geomlist_size(&query_result); j++)
{
const GEOSGeometry* shed = geomlist_get(&query_result, j);
GEOSGeometry* inter = GEOSIntersection(shed, bufshed);
GEOSGeom_destroy(inter);
}
geomlist_release(&query_result);
}
}
/* Clean up any remaining memory */
static void cleanup(void)
{
GEOSSTRtree_destroy(tree);
geomlist_free(&watersheds_buffered);
geomlist_free(&watersheds);
}
/*************************************************************************
* CONFIGURATION CALLBACK FUNCTION
*/
gp_test config_intersection(void)
{
gp_test test;
test.name = "Watershed intersections";
test.description =
"Load and create an STRtree for the watersheds."
"Set up a list of buffered watersheds."
"For each buffered watershed, calculate intersection with"
"all watersheds found by querying the tree.";
test.func_setup = setup;
test.func_run = run;
test.func_cleanup = cleanup;
test.count = 1;
return test;
}