shp 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NWM3ZjQ1MmRkMjEzNmQ4Y2NlOWQ5ODk2Mjk2MWZjYTJiMTVkMDQ3OA==
4
+ NjNiZWRkYzhhNjE3OGQ5YWExMWRmNzM1ODg3OTIwM2RmZTAzMWEyYg==
5
5
  data.tar.gz: !binary |-
6
- ODIyOTkxM2M2NGIwOTFjOThlYWE2N2Y5NDgxMzdkNDdlYjBhZjE2Mg==
6
+ MmFkMTAxZGFiMDU3MmU1NTJiMDQ2ZjcwMzE5M2Y0NjhjNGE2MmIwZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzAzNzc4NDc3YmRmZWM4NDcwNGI3ODNhZjE1YzY5M2ZlYzU1ZjQwMjkyMGIw
10
- ZTlkY2IyZGIxYmQ2NDkzYjFiMDk3NzNiZjNiNzlmZjIxMGY5NjgyZWQwMjNj
11
- M2EyNmZmYjQxYjM4ZWRmMTBmMWRlYjRiNDljNWU4NWI4MTZiM2M=
9
+ NmViNzUwY2FhYjBkZTVmNzMwYzc0NjhhYTY4N2VjMTU4ODY4NTY5N2E0ZGFj
10
+ NjIxZjE0MDczNmRiODQ4MzkwNzZmMDY3MjQ1N2IzM2EwODUwOGNjM2I4OWRj
11
+ NzM1NmViMTA5YTI2NWMxZGQ5NjJiOGRkMmY4YjVmOWQyNjA3YmU=
12
12
  data.tar.gz: !binary |-
13
- MjRiYTM3NGFjZDM2Y2FiM2QzOThlNjlhZTliYjMxNzY0OGRlMjM4YWUzODIy
14
- ZDE1Yzk1N2QwODcwNjVhNDIzNWNiZGU2ODUzOTdhYjU1MGMyZjNmYjYwYzBj
15
- NmQ4M2Q1MGUzYTg1NzdjNjgwYzk5NDM3N2ZmMGVkOGI4MTgwOGM=
13
+ MmRkNjhjYmM5MjEyZmVkOTYzM2U5NjVmOWY2MTVjYjUxZGE0YjE3OGFkNzY2
14
+ OWEwMDIzMjhiNGJmZTEwYzg0ZGRlNjJhZDc4ZjhhZDBlOTJhMmJhY2E2NzE0
15
+ NTA3NjgzNGMxOTE2NjA1NDY3MmVlNDAxOWI5YTFjNWJlMjk1M2U=
@@ -46,11 +46,251 @@ VALUE shape_object::destroy(VALUE self)
46
46
  return Qnil;
47
47
  }
48
48
 
49
+ VALUE shape_object::get_shape_type(VALUE self)
50
+ {
51
+ shape_object *object = unwrap(self);
52
+
53
+ CHECK_VALID_HANDLE(object->value());
54
+
55
+ return INT2FIX(object->value()->nSHPType);
56
+ }
57
+
58
+ VALUE shape_object::get_shape_id(VALUE self)
59
+ {
60
+ shape_object *object = unwrap(self);
61
+
62
+ CHECK_VALID_HANDLE(object->value());
63
+
64
+ return INT2FIX(object->value()->nShapeId);
65
+ }
66
+
67
+ VALUE shape_object::get_shape_parts(VALUE self)
68
+ {
69
+ shape_object *object = unwrap(self);
70
+
71
+ CHECK_VALID_HANDLE(object->value());
72
+
73
+ return INT2FIX(object->value()->nParts);
74
+ }
75
+
76
+ VALUE shape_object::get_shape_part_starts(VALUE self)
77
+ {
78
+ shape_object *object = unwrap(self);
79
+
80
+ CHECK_VALID_HANDLE(object->value());
81
+
82
+ VALUE result = rb_ary_new();
83
+
84
+ SHPObject *obj = object->value();
85
+
86
+ if (obj && obj->panPartStart) {
87
+ for (int i = 0; i < obj->nParts; ++i) {
88
+ rb_ary_push(result, INT2FIX(obj->panPartStart[i]));
89
+ }
90
+ }
91
+
92
+ return result;
93
+ }
94
+
95
+ VALUE shape_object::get_shape_part_types(VALUE self)
96
+ {
97
+ shape_object *object = unwrap(self);
98
+
99
+ CHECK_VALID_HANDLE(object->value());
100
+
101
+ VALUE result = rb_ary_new();
102
+
103
+ SHPObject *obj = object->value();
104
+
105
+ if (obj && obj->panPartType) {
106
+ for (int i = 0; i < obj->nParts; ++i) {
107
+ rb_ary_push(result, INT2FIX(obj->panPartType[i]));
108
+ }
109
+ }
110
+
111
+ return result;
112
+ }
113
+
114
+ VALUE shape_object::get_vertex_count(VALUE self)
115
+ {
116
+ shape_object *object = unwrap(self);
117
+
118
+ CHECK_VALID_HANDLE(object->value());
119
+
120
+ return INT2FIX(object->value()->nVertices);
121
+ }
122
+
123
+ VALUE shape_object::get_x(VALUE self)
124
+ {
125
+ shape_object *object = unwrap(self);
126
+
127
+ CHECK_VALID_HANDLE(object->value());
128
+
129
+ VALUE result = rb_ary_new();
130
+
131
+ SHPObject *obj = object->value();
132
+
133
+ if (obj && obj->padfX) {
134
+ for (int i = 0; i < obj->nVertices; ++i) {
135
+ rb_ary_push(result, rb_float_new(obj->padfX[i]));
136
+ }
137
+ }
138
+
139
+ return result;
140
+ }
141
+
142
+ VALUE shape_object::get_y(VALUE self)
143
+ {
144
+ shape_object *object = unwrap(self);
145
+
146
+ CHECK_VALID_HANDLE(object->value());
147
+
148
+ VALUE result = rb_ary_new();
149
+
150
+ SHPObject *obj = object->value();
151
+
152
+ if (obj && obj->padfY) {
153
+ for (int i = 0; i < obj->nVertices; ++i) {
154
+ rb_ary_push(result, rb_float_new(obj->padfY[i]));
155
+ }
156
+ }
157
+
158
+ return result;
159
+ }
160
+
161
+ VALUE shape_object::get_z(VALUE self)
162
+ {
163
+ shape_object *object = unwrap(self);
164
+
165
+ CHECK_VALID_HANDLE(object->value());
166
+
167
+ VALUE result = rb_ary_new();
168
+
169
+ SHPObject *obj = object->value();
170
+
171
+ if (obj && obj->padfZ) {
172
+ for (int i = 0; i < obj->nVertices; ++i) {
173
+ rb_ary_push(result, rb_float_new(obj->padfZ[i]));
174
+ }
175
+ }
176
+
177
+ return result;
178
+ }
179
+
180
+ VALUE shape_object::get_m(VALUE self)
181
+ {
182
+ shape_object *object = unwrap(self);
183
+
184
+ CHECK_VALID_HANDLE(object->value());
185
+
186
+ VALUE result = rb_ary_new();
187
+
188
+ SHPObject *obj = object->value();
189
+
190
+ if (obj && obj->padfM) {
191
+ for (int i = 0; i < obj->nVertices; ++i) {
192
+ rb_ary_push(result, rb_float_new(obj->padfM[i]));
193
+ }
194
+ }
195
+
196
+ return result;
197
+ }
198
+
199
+ VALUE shape_object::get_x_min(VALUE self)
200
+ {
201
+ shape_object *object = unwrap(self);
202
+
203
+ CHECK_VALID_HANDLE(object->value());
204
+
205
+ return rb_float_new(object->value()->dfXMin);
206
+ }
207
+
208
+ VALUE shape_object::get_y_min(VALUE self)
209
+ {
210
+ shape_object *object = unwrap(self);
211
+
212
+ CHECK_VALID_HANDLE(object->value());
213
+
214
+ return rb_float_new(object->value()->dfYMin);
215
+ }
216
+
217
+ VALUE shape_object::get_z_min(VALUE self)
218
+ {
219
+ shape_object *object = unwrap(self);
220
+
221
+ CHECK_VALID_HANDLE(object->value());
222
+
223
+ return rb_float_new(object->value()->dfZMin);
224
+ }
225
+
226
+ VALUE shape_object::get_m_min(VALUE self)
227
+ {
228
+ shape_object *object = unwrap(self);
229
+
230
+ CHECK_VALID_HANDLE(object->value());
231
+
232
+ return rb_float_new(object->value()->dfMMin);
233
+ }
234
+
235
+ VALUE shape_object::get_x_max(VALUE self)
236
+ {
237
+ shape_object *object = unwrap(self);
238
+
239
+ CHECK_VALID_HANDLE(object->value());
240
+
241
+ return rb_float_new(object->value()->dfXMax);
242
+ }
243
+
244
+ VALUE shape_object::get_y_max(VALUE self)
245
+ {
246
+ shape_object *object = unwrap(self);
247
+
248
+ CHECK_VALID_HANDLE(object->value());
249
+
250
+ return rb_float_new(object->value()->dfYMax);
251
+ }
252
+
253
+ VALUE shape_object::get_z_max(VALUE self)
254
+ {
255
+ shape_object *object = unwrap(self);
256
+
257
+ CHECK_VALID_HANDLE(object->value());
258
+
259
+ return rb_float_new(object->value()->dfZMax);
260
+ }
261
+
262
+ VALUE shape_object::get_m_max(VALUE self)
263
+ {
264
+ shape_object *object = unwrap(self);
265
+
266
+ CHECK_VALID_HANDLE(object->value());
267
+
268
+ return rb_float_new(object->value()->dfMMax);
269
+ }
270
+
49
271
  void shape_object::define(VALUE module)
50
272
  {
51
273
  shape_object::_klass = rb_define_class_under(module, "ShapeObject", rb_cObject);
52
274
  base::define(shape_object::_klass, false);
53
275
  rb_define_method(shape_object::_klass, "compute_extents", SHP_METHOD(shape_object::compute_extents), 0);
276
+ rb_define_method(shape_object::_klass, "get_shape_type", SHP_METHOD(shape_object::get_shape_type), 0);
277
+ rb_define_method(shape_object::_klass, "get_shape_id", SHP_METHOD(shape_object::get_shape_id), 0);
278
+ rb_define_method(shape_object::_klass, "get_shape_parts", SHP_METHOD(shape_object::get_shape_parts), 0);
279
+ rb_define_method(shape_object::_klass, "get_shape_part_starts", SHP_METHOD(shape_object::get_shape_part_starts), 0);
280
+ rb_define_method(shape_object::_klass, "get_shape_part_types", SHP_METHOD(shape_object::get_shape_part_types), 0);
281
+ rb_define_method(shape_object::_klass, "get_vertex_count", SHP_METHOD(shape_object::get_vertex_count), 0);
282
+ rb_define_method(shape_object::_klass, "get_x", SHP_METHOD(shape_object::get_x), 0);
283
+ rb_define_method(shape_object::_klass, "get_y", SHP_METHOD(shape_object::get_y), 0);
284
+ rb_define_method(shape_object::_klass, "get_z", SHP_METHOD(shape_object::get_z), 0);
285
+ rb_define_method(shape_object::_klass, "get_m", SHP_METHOD(shape_object::get_m), 0);
286
+ rb_define_method(shape_object::_klass, "get_x_min", SHP_METHOD(shape_object::get_x_min), 0);
287
+ rb_define_method(shape_object::_klass, "get_y_min", SHP_METHOD(shape_object::get_y_min), 0);
288
+ rb_define_method(shape_object::_klass, "get_z_min", SHP_METHOD(shape_object::get_z_min), 0);
289
+ rb_define_method(shape_object::_klass, "get_m_min", SHP_METHOD(shape_object::get_m_min), 0);
290
+ rb_define_method(shape_object::_klass, "get_x_max", SHP_METHOD(shape_object::get_x_max), 0);
291
+ rb_define_method(shape_object::_klass, "get_y_max", SHP_METHOD(shape_object::get_y_max), 0);
292
+ rb_define_method(shape_object::_klass, "get_z_max", SHP_METHOD(shape_object::get_z_max), 0);
293
+ rb_define_method(shape_object::_klass, "get_m_max", SHP_METHOD(shape_object::get_m_max), 0);
54
294
  rb_define_method(shape_object::_klass, "destroy", SHP_METHOD(shape_object::destroy), 0);
55
295
  }
56
296
 
@@ -13,6 +13,25 @@ namespace shp {
13
13
  static VALUE compute_extents(VALUE self);
14
14
  static VALUE destroy(VALUE self);
15
15
 
16
+ static VALUE get_shape_type(VALUE self);
17
+ static VALUE get_shape_id(VALUE self);
18
+ static VALUE get_shape_parts(VALUE self);
19
+ static VALUE get_shape_part_starts(VALUE self);
20
+ static VALUE get_shape_part_types(VALUE self);
21
+ static VALUE get_vertex_count(VALUE self);
22
+ static VALUE get_x(VALUE self);
23
+ static VALUE get_y(VALUE self);
24
+ static VALUE get_z(VALUE self);
25
+ static VALUE get_m(VALUE self);
26
+ static VALUE get_x_min(VALUE self);
27
+ static VALUE get_y_min(VALUE self);
28
+ static VALUE get_z_min(VALUE self);
29
+ static VALUE get_m_min(VALUE self);
30
+ static VALUE get_x_max(VALUE self);
31
+ static VALUE get_y_max(VALUE self);
32
+ static VALUE get_z_max(VALUE self);
33
+ static VALUE get_m_max(VALUE self);
34
+
16
35
  virtual VALUE klass();
17
36
  static VALUE _klass;
18
37
 
data/lib/shp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SHP
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/spec/shp_spec.rb CHANGED
@@ -127,6 +127,98 @@ describe "SHP" do
127
127
  lambda { file.close }.should_not raise_error
128
128
  lambda { file.get_info }.should raise_error
129
129
  end
130
- end
131
130
 
131
+ context 'shp' do
132
+ before(:each) do
133
+ sni_office = [ [ -82.72932529449463, 27.93789618055838 ],
134
+ [ -82.72932529449463, 27.93768765436987 ],
135
+ [ -82.72909998893738, 27.93767817589719 ],
136
+ [ -82.72911071777344, 27.93719003343022 ],
137
+ [ -82.72869229316710, 27.93717581565543 ],
138
+ [ -82.72868156433105, 27.93741277832466 ],
139
+ [ -82.72886931896210, 27.93741751757274 ],
140
+ [ -82.72886931896210, 27.93788670210399 ],
141
+ [ -82.72932529449463, 27.93789618055838 ] ]
142
+
143
+ x_values = sni_office.map { |v| v[0] }
144
+ y_values = sni_office.map { |v| v[1] }
145
+
146
+ @shp = SHP::Shapefile.create('testfile_polygons', 5)
147
+ @shape = SHP::Shapefile.create_simple_object(5, x_values.count, x_values, y_values, nil)
148
+ @shp.write_object(-1, @shape)
149
+ @obj = @shp.read_object(0)
150
+ end
151
+
152
+ it 'should return the shape type' do
153
+ @obj.get_shape_type.should eq(5)
154
+ end
155
+
156
+ it 'should return the shape id' do
157
+ @obj.get_shape_id.should eq(0)
158
+ end
159
+
160
+ it 'should return the shape part count' do
161
+ @obj.get_shape_parts.should eq(1)
162
+ end
163
+
164
+ it 'should return the shape part start offsets' do
165
+ @obj.get_shape_part_starts.should eq([0])
166
+ end
167
+
168
+ it 'should return the shape part types' do
169
+ @obj.get_shape_part_types.should eq([5]) # [SHPP_RING]
170
+ end
171
+
172
+ it 'should return the vertex count' do
173
+ @obj.get_vertex_count.should eq(9)
174
+ end
175
+
176
+ it 'should return the x values' do
177
+ @obj.get_x.should eq([-82.72932529449463, -82.72932529449463, -82.72909998893738, -82.72911071777344, -82.7286922931671, -82.72868156433105, -82.7288693189621, -82.7288693189621, -82.72932529449463])
178
+ end
179
+
180
+ it 'should return the y values' do
181
+ @obj.get_y.should eq([27.93789618055838, 27.93768765436987, 27.93767817589719, 27.93719003343022, 27.93717581565543, 27.93741277832466, 27.93741751757274, 27.93788670210399, 27.93789618055838])
182
+ end
183
+
184
+ it 'should return the z values' do
185
+ @obj.get_z.should eq([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
186
+ end
132
187
 
188
+ it 'should return the m values' do
189
+ @obj.get_z.should eq([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
190
+ end
191
+
192
+ it 'should return the x min' do
193
+ @obj.get_x_min.should eq(-82.72932529449463)
194
+ end
195
+
196
+ it 'should return the y min' do
197
+ @obj.get_y_min.should eq(27.93717581565543)
198
+ end
199
+
200
+ it 'should return the z min' do
201
+ @obj.get_z_min.should eq(0)
202
+ end
203
+
204
+ it 'should return the m min' do
205
+ @obj.get_m_min.should eq(0)
206
+ end
207
+
208
+ it 'should return the x max' do
209
+ @obj.get_x_max.should eq(-82.72868156433105)
210
+ end
211
+
212
+ it 'should return the y max' do
213
+ @obj.get_y_max.should eq(27.93789618055838)
214
+ end
215
+
216
+ it 'should return the z max' do
217
+ @obj.get_z_max.should eq(0)
218
+ end
219
+
220
+ it 'should return the m max' do
221
+ @obj.get_m_max.should eq(0)
222
+ end
223
+ end
224
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zac McCormick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-26 00:00:00.000000000 Z
11
+ date: 2013-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake