rgeo 0.5.1 → 0.5.2
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.
- checksums.yaml +4 -4
- data/ext/geos_c_impl/coordinates.c +65 -0
- data/ext/geos_c_impl/coordinates.h +2 -0
- data/ext/geos_c_impl/factory.c +995 -0
- data/ext/geos_c_impl/factory.h +238 -0
- data/ext/geos_c_impl/geometry.c +1028 -0
- data/ext/geos_c_impl/geometry.h +23 -0
- data/ext/geos_c_impl/geometry_collection.c +757 -0
- data/ext/geos_c_impl/geometry_collection.h +46 -0
- data/ext/geos_c_impl/line_string.c +675 -0
- data/ext/geos_c_impl/line_string.h +32 -0
- data/ext/geos_c_impl/main.c +40 -0
- data/ext/geos_c_impl/point.c +236 -0
- data/ext/geos_c_impl/point.h +30 -0
- data/ext/geos_c_impl/polygon.c +359 -0
- data/ext/geos_c_impl/polygon.h +43 -0
- data/ext/geos_c_impl/preface.h +38 -0
- data/ext/proj4_c_impl/main.c +315 -0
- data/lib/rgeo/version.rb +1 -1
- metadata +18 -1
@@ -0,0 +1,43 @@
|
|
1
|
+
/*
|
2
|
+
Polygon methods for GEOS wrapper
|
3
|
+
*/
|
4
|
+
|
5
|
+
|
6
|
+
#ifndef RGEO_GEOS_POLYGON_INCLUDED
|
7
|
+
#define RGEO_GEOS_POLYGON_INCLUDED
|
8
|
+
|
9
|
+
#include <ruby.h>
|
10
|
+
#include <geos_c.h>
|
11
|
+
|
12
|
+
#include "factory.h"
|
13
|
+
|
14
|
+
RGEO_BEGIN_C
|
15
|
+
|
16
|
+
|
17
|
+
/*
|
18
|
+
Initializes the polygon module. This should be called after
|
19
|
+
the geometry module is initialized.
|
20
|
+
*/
|
21
|
+
void rgeo_init_geos_polygon(RGeo_Globals* globals);
|
22
|
+
|
23
|
+
/*
|
24
|
+
Comopares the values of two GEOS polygons. The two given geometries MUST
|
25
|
+
be polygon types.
|
26
|
+
Returns Qtrue if the polygons are equal, Qfalse if they are inequal, or
|
27
|
+
Qnil if an error occurs.
|
28
|
+
*/
|
29
|
+
VALUE rgeo_geos_polygons_eql(GEOSContextHandle_t context, const GEOSGeometry* geom1, const GEOSGeometry* geom2, char check_z);
|
30
|
+
|
31
|
+
/*
|
32
|
+
A tool for building up hash values.
|
33
|
+
You must pass in the context, a geos geometry, and a seed hash.
|
34
|
+
Returns an updated hash.
|
35
|
+
This call is useful in sequence, and should be bracketed by calls to
|
36
|
+
rb_hash_start and rb_hash_end.
|
37
|
+
*/
|
38
|
+
st_index_t rgeo_geos_polygon_hash(GEOSContextHandle_t context, const GEOSGeometry* geom, st_index_t hash);
|
39
|
+
|
40
|
+
|
41
|
+
RGEO_END_C
|
42
|
+
|
43
|
+
#endif
|
@@ -0,0 +1,38 @@
|
|
1
|
+
/*
|
2
|
+
Preface header for GEOS wrapper
|
3
|
+
*/
|
4
|
+
|
5
|
+
|
6
|
+
#ifdef HAVE_GEOS_C_H
|
7
|
+
#ifdef HAVE_GEOSSETSRID_R
|
8
|
+
#define RGEO_GEOS_SUPPORTED
|
9
|
+
#endif
|
10
|
+
#endif
|
11
|
+
|
12
|
+
#ifdef HAVE_GEOSPREPAREDCONTAINS_R
|
13
|
+
#define RGEO_GEOS_SUPPORTS_PREPARED1
|
14
|
+
#endif
|
15
|
+
#ifdef HAVE_GEOSPREPAREDDISJOINT_R
|
16
|
+
#define RGEO_GEOS_SUPPORTS_PREPARED2
|
17
|
+
#endif
|
18
|
+
#ifdef HAVE_GEOSWKTWWRITER_SETOUTPUTDIMENSION_R
|
19
|
+
#define RGEO_GEOS_SUPPORTS_SETOUTPUTDIMENSION
|
20
|
+
#endif
|
21
|
+
#ifdef HAVE_RB_MEMHASH
|
22
|
+
#define RGEO_SUPPORTS_NEW_HASHING
|
23
|
+
#endif
|
24
|
+
|
25
|
+
#ifndef RGEO_SUPPORTS_NEW_HASHING
|
26
|
+
#define st_index_t int
|
27
|
+
#define rb_memhash(x,y) rgeo_internal_memhash(x,y)
|
28
|
+
#define rb_hash_start(x) ((st_index_t)(x ^ 0xdeadbeef))
|
29
|
+
#define rb_hash_end(x) ((st_index_t)(x ^ 0xbeefdead))
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#ifdef __cplusplus
|
33
|
+
#define RGEO_BEGIN_C extern "C" {
|
34
|
+
#define RGEO_END_C }
|
35
|
+
#else
|
36
|
+
#define RGEO_BEGIN_C
|
37
|
+
#define RGEO_END_C
|
38
|
+
#endif
|
@@ -0,0 +1,315 @@
|
|
1
|
+
/*
|
2
|
+
Main initializer for Proj4 wrapper
|
3
|
+
*/
|
4
|
+
|
5
|
+
#ifdef HAVE_PROJ_API_H
|
6
|
+
#ifdef HAVE_PJ_INIT_PLUS
|
7
|
+
#define RGEO_PROJ4_SUPPORTED
|
8
|
+
#endif
|
9
|
+
#endif
|
10
|
+
|
11
|
+
#ifdef __cplusplus
|
12
|
+
#define RGEO_BEGIN_C extern "C" {
|
13
|
+
#define RGEO_END_C }
|
14
|
+
#else
|
15
|
+
#define RGEO_BEGIN_C
|
16
|
+
#define RGEO_END_C
|
17
|
+
#endif
|
18
|
+
|
19
|
+
|
20
|
+
#ifdef RGEO_PROJ4_SUPPORTED
|
21
|
+
|
22
|
+
#include <ruby.h>
|
23
|
+
#include <proj_api.h>
|
24
|
+
|
25
|
+
#endif
|
26
|
+
|
27
|
+
|
28
|
+
RGEO_BEGIN_C
|
29
|
+
|
30
|
+
|
31
|
+
#ifdef RGEO_PROJ4_SUPPORTED
|
32
|
+
|
33
|
+
|
34
|
+
typedef struct {
|
35
|
+
projPJ pj;
|
36
|
+
VALUE original_str;
|
37
|
+
char uses_radians;
|
38
|
+
} RGeo_Proj4Data;
|
39
|
+
|
40
|
+
|
41
|
+
#define RGEO_PROJ4_DATA_PTR(obj) ((RGeo_Proj4Data*)DATA_PTR(obj))
|
42
|
+
|
43
|
+
|
44
|
+
// Destroy function for proj data.
|
45
|
+
|
46
|
+
static void destroy_proj4_func(RGeo_Proj4Data* data)
|
47
|
+
{
|
48
|
+
if (data->pj) {
|
49
|
+
pj_free(data->pj);
|
50
|
+
}
|
51
|
+
free(data);
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
static void mark_proj4_func(RGeo_Proj4Data* data)
|
56
|
+
{
|
57
|
+
if (!NIL_P(data->original_str)) {
|
58
|
+
rb_gc_mark(data->original_str);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
static VALUE alloc_proj4(VALUE klass)
|
64
|
+
{
|
65
|
+
VALUE result;
|
66
|
+
RGeo_Proj4Data* data;
|
67
|
+
|
68
|
+
result = Qnil;
|
69
|
+
data = ALLOC(RGeo_Proj4Data);
|
70
|
+
if (data) {
|
71
|
+
data->pj = NULL;
|
72
|
+
data->original_str = Qnil;
|
73
|
+
data->uses_radians = 0;
|
74
|
+
result = Data_Wrap_Struct(klass, mark_proj4_func, destroy_proj4_func, data);
|
75
|
+
}
|
76
|
+
return result;
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
static VALUE method_proj4_initialize_copy(VALUE self, VALUE orig)
|
81
|
+
{
|
82
|
+
RGeo_Proj4Data* self_data;
|
83
|
+
projPJ pj;
|
84
|
+
RGeo_Proj4Data* orig_data;
|
85
|
+
char* str;
|
86
|
+
|
87
|
+
// Clear out any existing value
|
88
|
+
self_data = RGEO_PROJ4_DATA_PTR(self);
|
89
|
+
pj = self_data->pj;
|
90
|
+
if (pj) {
|
91
|
+
pj_free(pj);
|
92
|
+
self_data->pj = NULL;
|
93
|
+
self_data->original_str = Qnil;
|
94
|
+
}
|
95
|
+
|
96
|
+
// Copy value from orig
|
97
|
+
orig_data = RGEO_PROJ4_DATA_PTR(orig);
|
98
|
+
if (!NIL_P(orig_data->original_str)) {
|
99
|
+
self_data->pj = pj_init_plus(RSTRING_PTR(orig_data->original_str));
|
100
|
+
}
|
101
|
+
else {
|
102
|
+
str = pj_get_def(orig_data->pj, 0);
|
103
|
+
self_data->pj = pj_init_plus(str);
|
104
|
+
pj_dalloc(str);
|
105
|
+
}
|
106
|
+
self_data->original_str = orig_data->original_str;
|
107
|
+
self_data->uses_radians = orig_data->uses_radians;
|
108
|
+
|
109
|
+
return self;
|
110
|
+
}
|
111
|
+
|
112
|
+
|
113
|
+
static VALUE method_proj4_set_value(VALUE self, VALUE str, VALUE uses_radians)
|
114
|
+
{
|
115
|
+
RGeo_Proj4Data* self_data;
|
116
|
+
projPJ pj;
|
117
|
+
|
118
|
+
Check_Type(str, T_STRING);
|
119
|
+
|
120
|
+
// Clear out any existing value
|
121
|
+
self_data = RGEO_PROJ4_DATA_PTR(self);
|
122
|
+
pj = self_data->pj;
|
123
|
+
if (pj) {
|
124
|
+
pj_free(pj);
|
125
|
+
self_data->pj = NULL;
|
126
|
+
self_data->original_str = Qnil;
|
127
|
+
}
|
128
|
+
|
129
|
+
// Set new data
|
130
|
+
self_data->pj = pj_init_plus(RSTRING_PTR(str));
|
131
|
+
self_data->original_str = str;
|
132
|
+
self_data->uses_radians = RTEST(uses_radians) ? 1 : 0;
|
133
|
+
|
134
|
+
return self;
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
static VALUE method_proj4_get_geographic(VALUE self)
|
139
|
+
{
|
140
|
+
VALUE result;
|
141
|
+
RGeo_Proj4Data* new_data;
|
142
|
+
RGeo_Proj4Data* self_data;
|
143
|
+
|
144
|
+
result = Qnil;
|
145
|
+
new_data = ALLOC(RGeo_Proj4Data);
|
146
|
+
if (new_data) {
|
147
|
+
self_data = RGEO_PROJ4_DATA_PTR(self);
|
148
|
+
new_data->pj = pj_latlong_from_proj(self_data->pj);
|
149
|
+
new_data->original_str = Qnil;
|
150
|
+
new_data->uses_radians = self_data->uses_radians;
|
151
|
+
result = Data_Wrap_Struct(CLASS_OF(self), mark_proj4_func, destroy_proj4_func, new_data);
|
152
|
+
}
|
153
|
+
return result;
|
154
|
+
}
|
155
|
+
|
156
|
+
|
157
|
+
static VALUE method_proj4_original_str(VALUE self)
|
158
|
+
{
|
159
|
+
return RGEO_PROJ4_DATA_PTR(self)->original_str;
|
160
|
+
}
|
161
|
+
|
162
|
+
|
163
|
+
static VALUE method_proj4_uses_radians(VALUE self)
|
164
|
+
{
|
165
|
+
return RGEO_PROJ4_DATA_PTR(self)->uses_radians ? Qtrue : Qfalse;
|
166
|
+
}
|
167
|
+
|
168
|
+
|
169
|
+
static VALUE method_proj4_canonical_str(VALUE self)
|
170
|
+
{
|
171
|
+
VALUE result;
|
172
|
+
projPJ pj;
|
173
|
+
char* str;
|
174
|
+
|
175
|
+
result = Qnil;
|
176
|
+
pj = RGEO_PROJ4_DATA_PTR(self)->pj;
|
177
|
+
if (pj) {
|
178
|
+
str = pj_get_def(pj, 0);
|
179
|
+
if (str) {
|
180
|
+
result = rb_str_new2(str);
|
181
|
+
pj_dalloc(str);
|
182
|
+
}
|
183
|
+
}
|
184
|
+
return result;
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
static VALUE method_proj4_is_geographic(VALUE self)
|
189
|
+
{
|
190
|
+
VALUE result;
|
191
|
+
projPJ pj;
|
192
|
+
|
193
|
+
result = Qnil;
|
194
|
+
pj = RGEO_PROJ4_DATA_PTR(self)->pj;
|
195
|
+
if (pj) {
|
196
|
+
result = pj_is_latlong(pj) ? Qtrue : Qfalse;
|
197
|
+
}
|
198
|
+
return result;
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
static VALUE method_proj4_is_geocentric(VALUE self)
|
203
|
+
{
|
204
|
+
VALUE result;
|
205
|
+
projPJ pj;
|
206
|
+
|
207
|
+
result = Qnil;
|
208
|
+
pj = RGEO_PROJ4_DATA_PTR(self)->pj;
|
209
|
+
if (pj) {
|
210
|
+
result = pj_is_geocent(pj) ? Qtrue : Qfalse;
|
211
|
+
}
|
212
|
+
return result;
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
static VALUE method_proj4_is_valid(VALUE self)
|
217
|
+
{
|
218
|
+
return RGEO_PROJ4_DATA_PTR(self)->pj ? Qtrue : Qfalse;
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
static VALUE cmethod_proj4_version(VALUE module)
|
223
|
+
{
|
224
|
+
return INT2NUM(PJ_VERSION);
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
static VALUE cmethod_proj4_transform(VALUE module, VALUE from, VALUE to, VALUE x, VALUE y, VALUE z)
|
229
|
+
{
|
230
|
+
VALUE result;
|
231
|
+
projPJ from_pj;
|
232
|
+
projPJ to_pj;
|
233
|
+
double xval, yval, zval;
|
234
|
+
int err;
|
235
|
+
|
236
|
+
result = Qnil;
|
237
|
+
from_pj = RGEO_PROJ4_DATA_PTR(from)->pj;
|
238
|
+
to_pj = RGEO_PROJ4_DATA_PTR(to)->pj;
|
239
|
+
if (from_pj && to_pj) {
|
240
|
+
xval = rb_num2dbl(x);
|
241
|
+
yval = rb_num2dbl(y);
|
242
|
+
zval = 0.0;
|
243
|
+
if (!NIL_P(z)) {
|
244
|
+
zval = rb_num2dbl(z);
|
245
|
+
}
|
246
|
+
err = pj_transform(from_pj, to_pj, 1, 1, &xval, &yval, NIL_P(z) ? NULL : &zval);
|
247
|
+
if (!err && xval != HUGE_VAL && yval != HUGE_VAL && (NIL_P(z) || zval != HUGE_VAL)) {
|
248
|
+
result = rb_ary_new2(NIL_P(z) ? 2 : 3);
|
249
|
+
rb_ary_push(result, rb_float_new(xval));
|
250
|
+
rb_ary_push(result, rb_float_new(yval));
|
251
|
+
if (!NIL_P(z)) {
|
252
|
+
rb_ary_push(result, rb_float_new(zval));
|
253
|
+
}
|
254
|
+
}
|
255
|
+
}
|
256
|
+
return result;
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
static VALUE cmethod_proj4_create(VALUE klass, VALUE str, VALUE uses_radians)
|
261
|
+
{
|
262
|
+
VALUE result;
|
263
|
+
RGeo_Proj4Data* data;
|
264
|
+
|
265
|
+
result = Qnil;
|
266
|
+
Check_Type(str, T_STRING);
|
267
|
+
data = ALLOC(RGeo_Proj4Data);
|
268
|
+
if (data) {
|
269
|
+
data->pj = pj_init_plus(RSTRING_PTR(str));
|
270
|
+
data->original_str = str;
|
271
|
+
data->uses_radians = RTEST(uses_radians) ? 1 : 0;
|
272
|
+
result = Data_Wrap_Struct(klass, mark_proj4_func, destroy_proj4_func, data);
|
273
|
+
}
|
274
|
+
return result;
|
275
|
+
}
|
276
|
+
|
277
|
+
|
278
|
+
static void rgeo_init_proj4()
|
279
|
+
{
|
280
|
+
VALUE rgeo_module;
|
281
|
+
VALUE coordsys_module;
|
282
|
+
VALUE proj4_class;
|
283
|
+
|
284
|
+
rgeo_module = rb_define_module("RGeo");
|
285
|
+
coordsys_module = rb_define_module_under(rgeo_module, "CoordSys");
|
286
|
+
proj4_class = rb_define_class_under(coordsys_module, "Proj4", rb_cObject);
|
287
|
+
|
288
|
+
rb_define_alloc_func(proj4_class, alloc_proj4);
|
289
|
+
rb_define_module_function(proj4_class, "_create", cmethod_proj4_create, 2);
|
290
|
+
rb_define_method(proj4_class, "initialize_copy", method_proj4_initialize_copy, 1);
|
291
|
+
rb_define_method(proj4_class, "_set_value", method_proj4_set_value, 2);
|
292
|
+
rb_define_method(proj4_class, "_original_str", method_proj4_original_str, 0);
|
293
|
+
rb_define_method(proj4_class, "_canonical_str", method_proj4_canonical_str, 0);
|
294
|
+
rb_define_method(proj4_class, "_valid?", method_proj4_is_valid, 0);
|
295
|
+
rb_define_method(proj4_class, "_geographic?", method_proj4_is_geographic, 0);
|
296
|
+
rb_define_method(proj4_class, "_geocentric?", method_proj4_is_geocentric, 0);
|
297
|
+
rb_define_method(proj4_class, "_radians?", method_proj4_uses_radians, 0);
|
298
|
+
rb_define_method(proj4_class, "_get_geographic", method_proj4_get_geographic, 0);
|
299
|
+
rb_define_module_function(proj4_class, "_transform_coords", cmethod_proj4_transform, 5);
|
300
|
+
rb_define_module_function(proj4_class, "_proj_version", cmethod_proj4_version, 0);
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
#endif
|
305
|
+
|
306
|
+
|
307
|
+
void Init_proj4_c_impl()
|
308
|
+
{
|
309
|
+
#ifdef RGEO_PROJ4_SUPPORTED
|
310
|
+
rgeo_init_proj4();
|
311
|
+
#endif
|
312
|
+
}
|
313
|
+
|
314
|
+
|
315
|
+
RGEO_END_C
|
data/lib/rgeo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgeo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma, Tee Parham
|
@@ -93,8 +93,25 @@ extensions:
|
|
93
93
|
extra_rdoc_files: []
|
94
94
|
files:
|
95
95
|
- LICENSE.txt
|
96
|
+
- ext/geos_c_impl/coordinates.c
|
97
|
+
- ext/geos_c_impl/coordinates.h
|
96
98
|
- ext/geos_c_impl/extconf.rb
|
99
|
+
- ext/geos_c_impl/factory.c
|
100
|
+
- ext/geos_c_impl/factory.h
|
101
|
+
- ext/geos_c_impl/geometry.c
|
102
|
+
- ext/geos_c_impl/geometry.h
|
103
|
+
- ext/geos_c_impl/geometry_collection.c
|
104
|
+
- ext/geos_c_impl/geometry_collection.h
|
105
|
+
- ext/geos_c_impl/line_string.c
|
106
|
+
- ext/geos_c_impl/line_string.h
|
107
|
+
- ext/geos_c_impl/main.c
|
108
|
+
- ext/geos_c_impl/point.c
|
109
|
+
- ext/geos_c_impl/point.h
|
110
|
+
- ext/geos_c_impl/polygon.c
|
111
|
+
- ext/geos_c_impl/polygon.h
|
112
|
+
- ext/geos_c_impl/preface.h
|
97
113
|
- ext/proj4_c_impl/extconf.rb
|
114
|
+
- ext/proj4_c_impl/main.c
|
98
115
|
- lib/rgeo.rb
|
99
116
|
- lib/rgeo/cartesian.rb
|
100
117
|
- lib/rgeo/cartesian/analysis.rb
|