rgeo 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -57,7 +57,9 @@ RGEO_BEGIN_C
57
57
  void Init_geos_c_impl()
58
58
  {
59
59
  #ifdef RGEO_GEOS_SUPPORTED
60
- RGeo_Globals* globals = rgeo_init_geos_factory();
60
+ RGeo_Globals* globals;
61
+
62
+ globals = rgeo_init_geos_factory();
61
63
  rgeo_init_geos_geometry(globals);
62
64
  rgeo_init_geos_point(globals);
63
65
  rgeo_init_geos_line_string(globals);
@@ -51,8 +51,11 @@ RGEO_BEGIN_C
51
51
 
52
52
  static VALUE method_point_geometry_type(VALUE self)
53
53
  {
54
- VALUE result = Qnil;
55
- RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
54
+ VALUE result;
55
+ RGeo_GeometryData* self_data;
56
+
57
+ result = Qnil;
58
+ self_data = RGEO_GEOMETRY_DATA_PTR(self);
56
59
  if (self_data->geom) {
57
60
  result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_point;
58
61
  }
@@ -62,14 +65,20 @@ static VALUE method_point_geometry_type(VALUE self)
62
65
 
63
66
  static VALUE method_point_x(VALUE self)
64
67
  {
65
- VALUE result = Qnil;
66
- RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
67
- const GEOSGeometry* self_geom = self_data->geom;
68
+ VALUE result;
69
+ RGeo_GeometryData* self_data;
70
+ const GEOSGeometry* self_geom;
71
+ GEOSContextHandle_t self_context;
72
+ const GEOSCoordSequence* coord_seq;
73
+ double val;
74
+
75
+ result = Qnil;
76
+ self_data = RGEO_GEOMETRY_DATA_PTR(self);
77
+ self_geom = self_data->geom;
68
78
  if (self_geom) {
69
- GEOSContextHandle_t self_context = self_data->geos_context;
70
- const GEOSCoordSequence* coord_seq = GEOSGeom_getCoordSeq_r(self_context, self_geom);
79
+ self_context = self_data->geos_context;
80
+ coord_seq = GEOSGeom_getCoordSeq_r(self_context, self_geom);
71
81
  if (coord_seq) {
72
- double val;
73
82
  if (GEOSCoordSeq_getX_r(self_context, coord_seq, 0, &val)) {
74
83
  result = rb_float_new(val);
75
84
  }
@@ -81,14 +90,20 @@ static VALUE method_point_x(VALUE self)
81
90
 
82
91
  static VALUE method_point_y(VALUE self)
83
92
  {
84
- VALUE result = Qnil;
85
- RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
86
- const GEOSGeometry* self_geom = self_data->geom;
93
+ VALUE result;
94
+ RGeo_GeometryData* self_data;
95
+ const GEOSGeometry* self_geom;
96
+ GEOSContextHandle_t self_context;
97
+ const GEOSCoordSequence* coord_seq;
98
+ double val;
99
+
100
+ result = Qnil;
101
+ self_data = RGEO_GEOMETRY_DATA_PTR(self);
102
+ self_geom = self_data->geom;
87
103
  if (self_geom) {
88
- GEOSContextHandle_t self_context = self_data->geos_context;
89
- const GEOSCoordSequence* coord_seq = GEOSGeom_getCoordSeq_r(self_context, self_geom);
104
+ self_context = self_data->geos_context;
105
+ coord_seq = GEOSGeom_getCoordSeq_r(self_context, self_geom);
90
106
  if (coord_seq) {
91
- double val;
92
107
  if (GEOSCoordSeq_getY_r(self_context, coord_seq, 0, &val)) {
93
108
  result = rb_float_new(val);
94
109
  }
@@ -100,15 +115,21 @@ static VALUE method_point_y(VALUE self)
100
115
 
101
116
  static VALUE get_3d_point(VALUE self, int flag)
102
117
  {
103
- VALUE result = Qnil;
104
- RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
105
- const GEOSGeometry* self_geom = self_data->geom;
118
+ VALUE result;
119
+ RGeo_GeometryData* self_data;
120
+ const GEOSGeometry* self_geom;
121
+ GEOSContextHandle_t self_context;
122
+ const GEOSCoordSequence* coord_seq;
123
+ double val;
124
+
125
+ result = Qnil;
126
+ self_data = RGEO_GEOMETRY_DATA_PTR(self);
127
+ self_geom = self_data->geom;
106
128
  if (self_geom) {
107
129
  if (RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & flag) {
108
- GEOSContextHandle_t self_context = self_data->geos_context;
109
- const GEOSCoordSequence* coord_seq = GEOSGeom_getCoordSeq_r(self_context, self_geom);
130
+ self_context = self_data->geos_context;
131
+ coord_seq = GEOSGeom_getCoordSeq_r(self_context, self_geom);
110
132
  if (coord_seq) {
111
- double val;
112
133
  if (GEOSCoordSeq_getZ_r(self_context, coord_seq, 0, &val)) {
113
134
  result = rb_float_new(val);
114
135
  }
@@ -133,9 +154,12 @@ static VALUE method_point_m(VALUE self)
133
154
 
134
155
  static VALUE method_point_eql(VALUE self, VALUE rhs)
135
156
  {
136
- VALUE result = rgeo_geos_klasses_and_factories_eql(self, rhs);
157
+ VALUE result;
158
+ RGeo_GeometryData* self_data;
159
+
160
+ result = rgeo_geos_klasses_and_factories_eql(self, rhs);
137
161
  if (RTEST(result)) {
138
- RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
162
+ self_data = RGEO_GEOMETRY_DATA_PTR(self);
139
163
  result = rgeo_geos_coordseqs_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom, RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
140
164
  }
141
165
  return result;
@@ -151,7 +175,9 @@ static VALUE cmethod_create(VALUE module, VALUE factory, VALUE x, VALUE y, VALUE
151
175
 
152
176
  void rgeo_init_geos_point(RGeo_Globals* globals)
153
177
  {
154
- VALUE geos_point_class = rb_define_class_under(globals->geos_module, "PointImpl", globals->geos_geometry);
178
+ VALUE geos_point_class;
179
+
180
+ geos_point_class = rb_define_class_under(globals->geos_module, "PointImpl", globals->geos_geometry);
155
181
  globals->geos_point = geos_point_class;
156
182
  globals->feature_point = rb_const_get_at(globals->feature_module, rb_intern("Point"));
157
183
  rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
@@ -170,15 +196,21 @@ void rgeo_init_geos_point(RGeo_Globals* globals)
170
196
 
171
197
  VALUE rgeo_create_geos_point(VALUE factory, double x, double y, double z)
172
198
  {
173
- VALUE result = Qnil;
174
- RGeo_FactoryData* factory_data = RGEO_FACTORY_DATA_PTR(factory);
175
- GEOSContextHandle_t context = factory_data->geos_context;
176
- GEOSCoordSequence* coord_seq = GEOSCoordSeq_create_r(context, 1, 3);
199
+ VALUE result;
200
+ RGeo_FactoryData* factory_data;
201
+ GEOSContextHandle_t context;
202
+ GEOSCoordSequence* coord_seq;
203
+ GEOSGeometry* geom;
204
+
205
+ result = Qnil;
206
+ factory_data = RGEO_FACTORY_DATA_PTR(factory);
207
+ context = factory_data->geos_context;
208
+ coord_seq = GEOSCoordSeq_create_r(context, 1, 3);
177
209
  if (coord_seq) {
178
210
  if (GEOSCoordSeq_setX_r(context, coord_seq, 0, x)) {
179
211
  if (GEOSCoordSeq_setY_r(context, coord_seq, 0, y)) {
180
212
  if (GEOSCoordSeq_setZ_r(context, coord_seq, 0, z)) {
181
- GEOSGeometry* geom = GEOSGeom_createPoint_r(context, coord_seq);
213
+ geom = GEOSGeom_createPoint_r(context, coord_seq);
182
214
  if (geom) {
183
215
  result = rgeo_wrap_geos_geometry(factory, geom, factory_data->globals->geos_point);
184
216
  }
@@ -52,9 +52,12 @@ RGEO_BEGIN_C
52
52
 
53
53
  static VALUE method_polygon_eql(VALUE self, VALUE rhs)
54
54
  {
55
- VALUE result = rgeo_geos_klasses_and_factories_eql(self, rhs);
55
+ VALUE result;
56
+ RGeo_GeometryData* self_data;
57
+
58
+ result = rgeo_geos_klasses_and_factories_eql(self, rhs);
56
59
  if (RTEST(result)) {
57
- RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
60
+ self_data = RGEO_GEOMETRY_DATA_PTR(self);
58
61
  result = rgeo_geos_polygons_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom, RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
59
62
  }
60
63
  return result;
@@ -63,8 +66,11 @@ static VALUE method_polygon_eql(VALUE self, VALUE rhs)
63
66
 
64
67
  static VALUE method_polygon_geometry_type(VALUE self)
65
68
  {
66
- VALUE result = Qnil;
67
- RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
69
+ VALUE result;
70
+ RGeo_GeometryData* self_data;
71
+
72
+ result = Qnil;
73
+ self_data = RGEO_GEOMETRY_DATA_PTR(self);
68
74
  if (self_data->geom) {
69
75
  result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_polygon;
70
76
  }
@@ -74,11 +80,15 @@ static VALUE method_polygon_geometry_type(VALUE self)
74
80
 
75
81
  static VALUE method_polygon_area(VALUE self)
76
82
  {
77
- VALUE result = Qnil;
78
- RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
79
- const GEOSGeometry* self_geom = self_data->geom;
83
+ VALUE result;
84
+ RGeo_GeometryData* self_data;
85
+ const GEOSGeometry* self_geom;
86
+ double area;
87
+
88
+ result = Qnil;
89
+ self_data = RGEO_GEOMETRY_DATA_PTR(self);
90
+ self_geom = self_data->geom;
80
91
  if (self_geom) {
81
- double area;
82
92
  if (GEOSArea_r(self_data->geos_context, self_geom, &area)) {
83
93
  result = rb_float_new(area);
84
94
  }
@@ -89,9 +99,13 @@ static VALUE method_polygon_area(VALUE self)
89
99
 
90
100
  static VALUE method_polygon_centroid(VALUE self)
91
101
  {
92
- VALUE result = Qnil;
93
- RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
94
- const GEOSGeometry* self_geom = self_data->geom;
102
+ VALUE result;
103
+ RGeo_GeometryData* self_data;
104
+ const GEOSGeometry* self_geom;
105
+
106
+ result = Qnil;
107
+ self_data = RGEO_GEOMETRY_DATA_PTR(self);
108
+ self_geom = self_data->geom;
95
109
  if (self_geom) {
96
110
  result = rgeo_wrap_geos_geometry(self_data->factory, GEOSGetCentroid_r(self_data->geos_context, self_geom), RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_point);
97
111
  }
@@ -101,9 +115,13 @@ static VALUE method_polygon_centroid(VALUE self)
101
115
 
102
116
  static VALUE method_polygon_point_on_surface(VALUE self)
103
117
  {
104
- VALUE result = Qnil;
105
- RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
106
- const GEOSGeometry* self_geom = self_data->geom;
118
+ VALUE result;
119
+ RGeo_GeometryData* self_data;
120
+ const GEOSGeometry* self_geom;
121
+
122
+ result = Qnil;
123
+ self_data = RGEO_GEOMETRY_DATA_PTR(self);
124
+ self_geom = self_data->geom;
107
125
  if (self_geom) {
108
126
  result = rgeo_wrap_geos_geometry(self_data->factory, GEOSPointOnSurface_r(self_data->geos_context, self_geom), RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_point);
109
127
  }
@@ -113,9 +131,13 @@ static VALUE method_polygon_point_on_surface(VALUE self)
113
131
 
114
132
  static VALUE method_polygon_exterior_ring(VALUE self)
115
133
  {
116
- VALUE result = Qnil;
117
- RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
118
- const GEOSGeometry* self_geom = self_data->geom;
134
+ VALUE result;
135
+ RGeo_GeometryData* self_data;
136
+ const GEOSGeometry* self_geom;
137
+
138
+ result = Qnil;
139
+ self_data = RGEO_GEOMETRY_DATA_PTR(self);
140
+ self_geom = self_data->geom;
119
141
  if (self_geom) {
120
142
  result = rgeo_wrap_geos_geometry_clone(self_data->factory, GEOSGetExteriorRing_r(self_data->geos_context, self_geom), RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_linear_ring);
121
143
  }
@@ -125,11 +147,16 @@ static VALUE method_polygon_exterior_ring(VALUE self)
125
147
 
126
148
  static VALUE method_polygon_num_interior_rings(VALUE self)
127
149
  {
128
- VALUE result = Qnil;
129
- RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
130
- const GEOSGeometry* self_geom = self_data->geom;
150
+ VALUE result;
151
+ RGeo_GeometryData* self_data;
152
+ const GEOSGeometry* self_geom;
153
+ int num;
154
+
155
+ result = Qnil;
156
+ self_data = RGEO_GEOMETRY_DATA_PTR(self);
157
+ self_geom = self_data->geom;
131
158
  if (self_geom) {
132
- int num = GEOSGetNumInteriorRings_r(self_data->geos_context, self_geom);
159
+ num = GEOSGetNumInteriorRings_r(self_data->geos_context, self_geom);
133
160
  if (num >= 0) {
134
161
  result = INT2NUM(num);
135
162
  }
@@ -140,14 +167,21 @@ static VALUE method_polygon_num_interior_rings(VALUE self)
140
167
 
141
168
  static VALUE method_polygon_interior_ring_n(VALUE self, VALUE n)
142
169
  {
143
- VALUE result = Qnil;
144
- RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
145
- const GEOSGeometry* self_geom = self_data->geom;
170
+ VALUE result;
171
+ RGeo_GeometryData* self_data;
172
+ const GEOSGeometry* self_geom;
173
+ int i;
174
+ GEOSContextHandle_t self_context;
175
+ int num;
176
+
177
+ result = Qnil;
178
+ self_data = RGEO_GEOMETRY_DATA_PTR(self);
179
+ self_geom = self_data->geom;
146
180
  if (self_geom) {
147
- int i = NUM2INT(n);
181
+ i = NUM2INT(n);
148
182
  if (i >= 0) {
149
- GEOSContextHandle_t self_context = self_data->geos_context;
150
- int num = GEOSGetNumInteriorRings_r(self_context, self_geom);
183
+ self_context = self_data->geos_context;
184
+ num = GEOSGetNumInteriorRings_r(self_context, self_geom);
151
185
  if (i < num) {
152
186
  result = rgeo_wrap_geos_geometry_clone(self_data->factory,
153
187
  GEOSGetInteriorRingN_r(self_context, self_geom, i),
@@ -161,17 +195,25 @@ static VALUE method_polygon_interior_ring_n(VALUE self, VALUE n)
161
195
 
162
196
  static VALUE method_polygon_interior_rings(VALUE self)
163
197
  {
164
- VALUE result = Qnil;
165
- RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
166
- const GEOSGeometry* self_geom = self_data->geom;
198
+ VALUE result;
199
+ RGeo_GeometryData* self_data;
200
+ const GEOSGeometry* self_geom;
201
+ GEOSContextHandle_t self_context;
202
+ int count;
203
+ VALUE factory;
204
+ VALUE linear_ring_class;
205
+ int i;
206
+
207
+ result = Qnil;
208
+ self_data = RGEO_GEOMETRY_DATA_PTR(self);
209
+ self_geom = self_data->geom;
167
210
  if (self_geom) {
168
- GEOSContextHandle_t self_context = self_data->geos_context;
169
- int count = GEOSGetNumInteriorRings_r(self_context, self_geom);
211
+ self_context = self_data->geos_context;
212
+ count = GEOSGetNumInteriorRings_r(self_context, self_geom);
170
213
  if (count >= 0) {
171
214
  result = rb_ary_new2(count);
172
- VALUE factory = self_data->factory;
173
- VALUE linear_ring_class = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_linear_ring;
174
- int i;
215
+ factory = self_data->factory;
216
+ linear_ring_class = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_linear_ring;
175
217
  for (i=0; i<count; ++i) {
176
218
  rb_ary_store(result, i, rgeo_wrap_geos_geometry_clone(factory, GEOSGetInteriorRingN_r(self_context, self_geom, i), linear_ring_class));
177
219
  }
@@ -183,25 +225,35 @@ static VALUE method_polygon_interior_rings(VALUE self)
183
225
 
184
226
  static VALUE cmethod_create(VALUE module, VALUE factory, VALUE exterior, VALUE interior_array)
185
227
  {
228
+ RGeo_FactoryData* factory_data;
229
+ VALUE linear_ring_type;
230
+ GEOSGeometry* exterior_geom;
231
+ GEOSContextHandle_t context;
232
+ unsigned int len;
233
+ GEOSGeometry** interior_geoms;
234
+ unsigned int actual_len;
235
+ unsigned int i;
236
+ GEOSGeometry* interior_geom;
237
+ GEOSGeometry* polygon;
238
+
186
239
  Check_Type(interior_array, T_ARRAY);
187
- RGeo_FactoryData* factory_data = RGEO_FACTORY_DATA_PTR(factory);
188
- VALUE linear_ring_type = factory_data->globals->feature_linear_ring;
189
- GEOSGeometry* exterior_geom = rgeo_convert_to_detached_geos_geometry(exterior, factory, linear_ring_type, NULL);
240
+ factory_data = RGEO_FACTORY_DATA_PTR(factory);
241
+ linear_ring_type = factory_data->globals->feature_linear_ring;
242
+ exterior_geom = rgeo_convert_to_detached_geos_geometry(exterior, factory, linear_ring_type, NULL);
190
243
  if (exterior_geom) {
191
- GEOSContextHandle_t context = factory_data->geos_context;
192
- unsigned int len = (unsigned int)RARRAY_LEN(interior_array);
193
- GEOSGeometry** interior_geoms = ALLOC_N(GEOSGeometry*, len == 0 ? 1 : len);
244
+ context = factory_data->geos_context;
245
+ len = (unsigned int)RARRAY_LEN(interior_array);
246
+ interior_geoms = ALLOC_N(GEOSGeometry*, len == 0 ? 1 : len);
194
247
  if (interior_geoms) {
195
- unsigned int actual_len = 0;
196
- unsigned int i;
248
+ actual_len = 0;
197
249
  for (i=0; i<len; ++i) {
198
- GEOSGeometry* interior_geom = rgeo_convert_to_detached_geos_geometry(rb_ary_entry(interior_array, i), factory, linear_ring_type, NULL);
250
+ interior_geom = rgeo_convert_to_detached_geos_geometry(rb_ary_entry(interior_array, i), factory, linear_ring_type, NULL);
199
251
  if (interior_geom) {
200
252
  interior_geoms[actual_len++] = interior_geom;
201
253
  }
202
254
  }
203
255
  if (len == actual_len) {
204
- GEOSGeometry* polygon = GEOSGeom_createPolygon_r(context, exterior_geom, interior_geoms, actual_len);
256
+ polygon = GEOSGeom_createPolygon_r(context, exterior_geom, interior_geoms, actual_len);
205
257
  if (polygon) {
206
258
  free(interior_geoms);
207
259
  return rgeo_wrap_geos_geometry(factory, polygon, factory_data->globals->geos_polygon);
@@ -220,7 +272,9 @@ static VALUE cmethod_create(VALUE module, VALUE factory, VALUE exterior, VALUE i
220
272
 
221
273
  void rgeo_init_geos_polygon(RGeo_Globals* globals)
222
274
  {
223
- VALUE geos_polygon_class = rb_define_class_under(globals->geos_module, "PolygonImpl", globals->geos_geometry);
275
+ VALUE geos_polygon_class;
276
+
277
+ geos_polygon_class = rb_define_class_under(globals->geos_module, "PolygonImpl", globals->geos_geometry);
224
278
  globals->geos_polygon = geos_polygon_class;
225
279
  globals->feature_polygon = rb_const_get_at(globals->feature_module, rb_intern("Polygon"));
226
280
  rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
@@ -244,15 +298,19 @@ void rgeo_init_geos_polygon(RGeo_Globals* globals)
244
298
 
245
299
  VALUE rgeo_geos_polygons_eql(GEOSContextHandle_t context, const GEOSGeometry* geom1, const GEOSGeometry* geom2, char check_z)
246
300
  {
247
- VALUE result = Qnil;
301
+ VALUE result;
302
+ int len1;
303
+ int len2;
304
+ int i;
305
+
306
+ result = Qnil;
248
307
  if (geom1 && geom2) {
249
308
  result = rgeo_geos_coordseqs_eql(context, GEOSGetExteriorRing_r(context, geom1), GEOSGetExteriorRing_r(context, geom2), check_z);
250
309
  if (RTEST(result)) {
251
- int len1 = GEOSGetNumInteriorRings_r(context, geom1);
252
- int len2 = GEOSGetNumInteriorRings_r(context, geom2);
310
+ len1 = GEOSGetNumInteriorRings_r(context, geom1);
311
+ len2 = GEOSGetNumInteriorRings_r(context, geom2);
253
312
  if (len1 >= 0 && len2 >= 0) {
254
313
  if (len1 == len2) {
255
- int i;
256
314
  for (i=0; i<len1; ++i) {
257
315
  result = rgeo_geos_coordseqs_eql(context, GEOSGetInteriorRingN_r(context, geom1, i), GEOSGetInteriorRingN_r(context, geom2, i), check_z);
258
316
  if (!RTEST(result)) {
@@ -52,7 +52,7 @@ else
52
52
  '/opt/proj4/include',
53
53
  '/opt/include',
54
54
  '/Library/Frameworks/PROJ.framework/unix/include',
55
- ::Config::CONFIG['includedir'],
55
+ ::RbConfig::CONFIG['includedir'],
56
56
  '/usr/include',
57
57
  ]
58
58
  lib_dirs_ =
@@ -65,7 +65,7 @@ else
65
65
  '/opt/proj4/lib',
66
66
  '/opt/lib',
67
67
  '/Library/Frameworks/PROJ.framework/unix/lib',
68
- ::Config::CONFIG['libdir'],
68
+ ::RbConfig::CONFIG['libdir'],
69
69
  '/usr/lib',
70
70
  ]
71
71
  header_dirs_.delete_if{ |path_| !::File.directory?(path_) }
@@ -95,8 +95,11 @@ static void mark_proj4_func(RGeo_Proj4Data* data)
95
95
 
96
96
  static VALUE alloc_proj4(VALUE klass)
97
97
  {
98
- VALUE result = Qnil;
99
- RGeo_Proj4Data* data = ALLOC(RGeo_Proj4Data);
98
+ VALUE result;
99
+ RGeo_Proj4Data* data;
100
+
101
+ result = Qnil;
102
+ data = ALLOC(RGeo_Proj4Data);
100
103
  if (data) {
101
104
  data->pj = NULL;
102
105
  data->original_str = Qnil;
@@ -109,9 +112,14 @@ static VALUE alloc_proj4(VALUE klass)
109
112
 
110
113
  static VALUE method_proj4_initialize_copy(VALUE self, VALUE orig)
111
114
  {
115
+ RGeo_Proj4Data* self_data;
116
+ projPJ pj;
117
+ RGeo_Proj4Data* orig_data;
118
+ char* str;
119
+
112
120
  // Clear out any existing value
113
- RGeo_Proj4Data* self_data = RGEO_PROJ4_DATA_PTR(self);
114
- projPJ pj = self_data->pj;
121
+ self_data = RGEO_PROJ4_DATA_PTR(self);
122
+ pj = self_data->pj;
115
123
  if (pj) {
116
124
  pj_free(pj);
117
125
  self_data->pj = NULL;
@@ -119,12 +127,12 @@ static VALUE method_proj4_initialize_copy(VALUE self, VALUE orig)
119
127
  }
120
128
 
121
129
  // Copy value from orig
122
- RGeo_Proj4Data* orig_data = RGEO_PROJ4_DATA_PTR(orig);
130
+ orig_data = RGEO_PROJ4_DATA_PTR(orig);
123
131
  if (!NIL_P(orig_data->original_str)) {
124
132
  self_data->pj = pj_init_plus(RSTRING_PTR(orig_data->original_str));
125
133
  }
126
134
  else {
127
- char* str = pj_get_def(orig_data->pj, 0);
135
+ str = pj_get_def(orig_data->pj, 0);
128
136
  self_data->pj = pj_init_plus(str);
129
137
  pj_dalloc(str);
130
138
  }
@@ -137,11 +145,14 @@ static VALUE method_proj4_initialize_copy(VALUE self, VALUE orig)
137
145
 
138
146
  static VALUE method_proj4_set_value(VALUE self, VALUE str, VALUE uses_radians)
139
147
  {
148
+ RGeo_Proj4Data* self_data;
149
+ projPJ pj;
150
+
140
151
  Check_Type(str, T_STRING);
141
152
 
142
153
  // Clear out any existing value
143
- RGeo_Proj4Data* self_data = RGEO_PROJ4_DATA_PTR(self);
144
- projPJ pj = self_data->pj;
154
+ self_data = RGEO_PROJ4_DATA_PTR(self);
155
+ pj = self_data->pj;
145
156
  if (pj) {
146
157
  pj_free(pj);
147
158
  self_data->pj = NULL;
@@ -159,10 +170,14 @@ static VALUE method_proj4_set_value(VALUE self, VALUE str, VALUE uses_radians)
159
170
 
160
171
  static VALUE method_proj4_get_geographic(VALUE self)
161
172
  {
162
- VALUE result = Qnil;
163
- RGeo_Proj4Data* new_data = ALLOC(RGeo_Proj4Data);
173
+ VALUE result;
174
+ RGeo_Proj4Data* new_data;
175
+ RGeo_Proj4Data* self_data;
176
+
177
+ result = Qnil;
178
+ new_data = ALLOC(RGeo_Proj4Data);
164
179
  if (new_data) {
165
- RGeo_Proj4Data* self_data = RGEO_PROJ4_DATA_PTR(self);
180
+ self_data = RGEO_PROJ4_DATA_PTR(self);
166
181
  new_data->pj = pj_latlong_from_proj(self_data->pj);
167
182
  new_data->original_str = Qnil;
168
183
  new_data->uses_radians = self_data->uses_radians;
@@ -186,10 +201,14 @@ static VALUE method_proj4_uses_radians(VALUE self)
186
201
 
187
202
  static VALUE method_proj4_canonical_str(VALUE self)
188
203
  {
189
- VALUE result = Qnil;
190
- projPJ pj = RGEO_PROJ4_DATA_PTR(self)->pj;
204
+ VALUE result;
205
+ projPJ pj;
206
+ char* str;
207
+
208
+ result = Qnil;
209
+ pj = RGEO_PROJ4_DATA_PTR(self)->pj;
191
210
  if (pj) {
192
- char* str = pj_get_def(pj, 0);
211
+ str = pj_get_def(pj, 0);
193
212
  if (str) {
194
213
  result = rb_str_new2(str);
195
214
  pj_dalloc(str);
@@ -201,8 +220,11 @@ static VALUE method_proj4_canonical_str(VALUE self)
201
220
 
202
221
  static VALUE method_proj4_is_geographic(VALUE self)
203
222
  {
204
- VALUE result = Qnil;
205
- projPJ pj = RGEO_PROJ4_DATA_PTR(self)->pj;
223
+ VALUE result;
224
+ projPJ pj;
225
+
226
+ result = Qnil;
227
+ pj = RGEO_PROJ4_DATA_PTR(self)->pj;
206
228
  if (pj) {
207
229
  result = pj_is_latlong(pj) ? Qtrue : Qfalse;
208
230
  }
@@ -212,8 +234,11 @@ static VALUE method_proj4_is_geographic(VALUE self)
212
234
 
213
235
  static VALUE method_proj4_is_geocentric(VALUE self)
214
236
  {
215
- VALUE result = Qnil;
216
- projPJ pj = RGEO_PROJ4_DATA_PTR(self)->pj;
237
+ VALUE result;
238
+ projPJ pj;
239
+
240
+ result = Qnil;
241
+ pj = RGEO_PROJ4_DATA_PTR(self)->pj;
217
242
  if (pj) {
218
243
  result = pj_is_geocent(pj) ? Qtrue : Qfalse;
219
244
  }
@@ -229,17 +254,23 @@ static VALUE method_proj4_is_valid(VALUE self)
229
254
 
230
255
  static VALUE cmethod_proj4_transform(VALUE method, VALUE from, VALUE to, VALUE x, VALUE y, VALUE z)
231
256
  {
232
- VALUE result = Qnil;
233
- projPJ from_pj = RGEO_PROJ4_DATA_PTR(from)->pj;
234
- projPJ to_pj = RGEO_PROJ4_DATA_PTR(to)->pj;
257
+ VALUE result;
258
+ projPJ from_pj;
259
+ projPJ to_pj;
260
+ double xval, yval, zval;
261
+ int err;
262
+
263
+ result = Qnil;
264
+ from_pj = RGEO_PROJ4_DATA_PTR(from)->pj;
265
+ to_pj = RGEO_PROJ4_DATA_PTR(to)->pj;
235
266
  if (from_pj && to_pj) {
236
- double xval = rb_num2dbl(x);
237
- double yval = rb_num2dbl(y);
238
- double zval = 0.0;
267
+ xval = rb_num2dbl(x);
268
+ yval = rb_num2dbl(y);
269
+ zval = 0.0;
239
270
  if (!NIL_P(z)) {
240
271
  zval = rb_num2dbl(z);
241
272
  }
242
- int err = pj_transform(from_pj, to_pj, 1, 1, &xval, &yval, NIL_P(z) ? NULL : &zval);
273
+ err = pj_transform(from_pj, to_pj, 1, 1, &xval, &yval, NIL_P(z) ? NULL : &zval);
243
274
  if (!err && xval != HUGE_VAL && yval != HUGE_VAL && (NIL_P(z) || zval != HUGE_VAL)) {
244
275
  result = rb_ary_new2(NIL_P(z) ? 2 : 3);
245
276
  rb_ary_push(result, rb_float_new(xval));
@@ -255,9 +286,12 @@ static VALUE cmethod_proj4_transform(VALUE method, VALUE from, VALUE to, VALUE x
255
286
 
256
287
  static VALUE cmethod_proj4_create(VALUE klass, VALUE str, VALUE uses_radians)
257
288
  {
258
- VALUE result = Qnil;
289
+ VALUE result;
290
+ RGeo_Proj4Data* data;
291
+
292
+ result = Qnil;
259
293
  Check_Type(str, T_STRING);
260
- RGeo_Proj4Data* data = ALLOC(RGeo_Proj4Data);
294
+ data = ALLOC(RGeo_Proj4Data);
261
295
  if (data) {
262
296
  data->pj = pj_init_plus(RSTRING_PTR(str));
263
297
  data->original_str = str;
@@ -270,9 +304,13 @@ static VALUE cmethod_proj4_create(VALUE klass, VALUE str, VALUE uses_radians)
270
304
 
271
305
  static void rgeo_init_proj4()
272
306
  {
273
- VALUE rgeo_module = rb_define_module("RGeo");
274
- VALUE coordsys_module = rb_define_module_under(rgeo_module, "CoordSys");
275
- VALUE proj4_class = rb_define_class_under(coordsys_module, "Proj4", rb_cObject);
307
+ VALUE rgeo_module;
308
+ VALUE coordsys_module;
309
+ VALUE proj4_class;
310
+
311
+ rgeo_module = rb_define_module("RGeo");
312
+ coordsys_module = rb_define_module_under(rgeo_module, "CoordSys");
313
+ proj4_class = rb_define_class_under(coordsys_module, "Proj4", rb_cObject);
276
314
 
277
315
  rb_define_alloc_func(proj4_class, alloc_proj4);
278
316
  rb_define_module_function(proj4_class, "_create", cmethod_proj4_create, 2);