shapelib 0.7.0 → 0.7.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 +7 -0
- data/README.md +7 -23
- data/Rakefile +4 -3
- data/ext/shapelib_ext/main.c +34 -0
- data/ext/shapelib_ext/sfcode.h +21 -25
- data/ext/shapelib_ext/spcode.h +26 -26
- data/ext/shapelib_ext/splist.h +0 -18
- data/ext/shapelib_ext/spwkt.h +5 -5
- data/ext/shapelib_ext/valconv.h +0 -9
- data/lib/shapelib/shape.rb +4 -0
- data/lib/shapelib/version.rb +2 -2
- data/shapelib.gemspec +58 -0
- data/test/data/ZillowNeighborhoods-CA/ZillowNeighborhoods-CA.dbf +0 -0
- data/test/data/ZillowNeighborhoods-CA/ZillowNeighborhoods-CA.prj +1 -0
- data/test/data/ZillowNeighborhoods-CA/ZillowNeighborhoods-CA.shp +0 -0
- data/test/data/ZillowNeighborhoods-CA/ZillowNeighborhoods-CA.shp.xml +3 -0
- data/test/data/ZillowNeighborhoods-CA/ZillowNeighborhoods-CA.shx +0 -0
- data/test/test_zillow_data.rb +17 -0
- metadata +45 -62
- data/test/libtest.rb +0 -80
- data/test/zsample1.rb +0 -168
- data/test/ztest1.rb +0 -253
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d4b63230d6b9cb35b579690564efd7332e6ef11233cc9776a2fe481e0a3711df
|
|
4
|
+
data.tar.gz: 28037b023308d67c24e028c3d8127ea1e59b3f183b87ed144136dbd854f2d045
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d671c1e27a6ae74ede90fd6d68cef7337384e11d31aa71ec01e3253306ab0a1a385ce5b5a35cb95cfd476817a43f8f0c2797bc5c2a1ed9950124cd7e77fbb9af
|
|
7
|
+
data.tar.gz: 4ad801f9c17ffcc949e959ab1ca459ec4af1d204ca6a0550e64a72579e5e01c57e988921182821284d74beec7e6c744603a3870ad53f1e150f4b374f7ffc2e48
|
data/README.md
CHANGED
|
@@ -7,7 +7,7 @@ prasinos@users.sourceforge.net.
|
|
|
7
7
|
How to install
|
|
8
8
|
-----------------
|
|
9
9
|
|
|
10
|
-
*
|
|
10
|
+
* Install the shapelib C library with your Unix package management system.
|
|
11
11
|
* It is expected to run on all ruby-running environments. But it is tested
|
|
12
12
|
only on RedHat Enterprise Linux 4.0 and Vine Linux 3.0.
|
|
13
13
|
|
|
@@ -18,35 +18,19 @@ Install MacPorts. Use it to install the shapelib C library:
|
|
|
18
18
|
|
|
19
19
|
sudo port install shapelib
|
|
20
20
|
|
|
21
|
-
Now install the
|
|
21
|
+
Now install the Rubygem:
|
|
22
22
|
|
|
23
|
-
gem
|
|
24
|
-
gem install shapelib-X.X.X.gem -- --with-opt-dir=/opt/local
|
|
25
|
-
|
|
26
|
-
Quick directions
|
|
27
|
-
----------------
|
|
28
|
-
|
|
29
|
-
$ tar xvfz ruby-shapelib.tar.gz (you did it if you see this file)
|
|
30
|
-
$ cd ruby-shapelib
|
|
31
|
-
$ ruby ./extconf.rb
|
|
32
|
-
$ make
|
|
33
|
-
# make install
|
|
34
|
-
|
|
23
|
+
gem install shapelib
|
|
35
24
|
|
|
36
25
|
Troubleshooting
|
|
37
26
|
---------------
|
|
38
27
|
|
|
39
|
-
* I have
|
|
40
|
-
|
|
41
|
-
Some Linux distributions divide Ruby into several packages such as
|
|
42
|
-
"ruby" and "ruby-devel". You may have to install additional packages.
|
|
43
|
-
|
|
44
|
-
* I have shapelib installed but extconf.rb fails
|
|
28
|
+
* I have shapelib installed but the build fails
|
|
45
29
|
|
|
46
|
-
Try --with-shapelib-include= and --with-shapelib-lib= options
|
|
30
|
+
Try --with-shapelib-include= and --with-shapelib-lib= options:
|
|
31
|
+
gem install shapelib -- --with-shapelib-include=...
|
|
47
32
|
|
|
48
|
-
If above advice doesn't help, please visit
|
|
49
|
-
http://sourceforge.net/projects/ruby-shapelib and post a message.
|
|
33
|
+
If above advice doesn't help, please visit http://github.com/mperham/shapelib and post an issue.
|
|
50
34
|
|
|
51
35
|
How to use
|
|
52
36
|
==========
|
data/Rakefile
CHANGED
|
@@ -9,9 +9,9 @@ begin
|
|
|
9
9
|
gem.name = "shapelib"
|
|
10
10
|
gem.summary = %Q{Simple wrapper around the shapelib library}
|
|
11
11
|
gem.description = gem.summary
|
|
12
|
-
gem.email = %q{
|
|
12
|
+
gem.email = %q{nick@nickstoys.com}
|
|
13
13
|
gem.homepage = "http://github.com/mperham/shapelib"
|
|
14
|
-
gem.authors = ["prasinos@users.sourceforge.net", "Mike Mangino", "Mike Perham"]
|
|
14
|
+
gem.authors = ["prasinos@users.sourceforge.net", "Mike Mangino", "Mike Perham", "Nick Estes"]
|
|
15
15
|
gem.add_development_dependency 'rake-compiler', '>= 0.7.0'
|
|
16
16
|
gem.has_rdoc = false
|
|
17
17
|
gem.version = Shapelib::VERSION
|
|
@@ -32,7 +32,8 @@ end
|
|
|
32
32
|
task :test => :check_dependencies
|
|
33
33
|
task :default => :test
|
|
34
34
|
|
|
35
|
-
require 'rake/rdoctask'
|
|
35
|
+
#require 'rake/rdoctask'
|
|
36
|
+
require 'rdoc/task'
|
|
36
37
|
Rake::RDocTask.new do |rdoc|
|
|
37
38
|
rdoc.rdoc_dir = 'rdoc'
|
|
38
39
|
rdoc.title = "shapelib"
|
data/ext/shapelib_ext/main.c
CHANGED
|
@@ -37,6 +37,24 @@ static VALUE cMultiPatch;
|
|
|
37
37
|
|
|
38
38
|
/* code begins here */
|
|
39
39
|
|
|
40
|
+
static void shape_free(void *ptr)
|
|
41
|
+
{
|
|
42
|
+
shape_close(ptr);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static void shapefile_free(void *ptr)
|
|
46
|
+
{
|
|
47
|
+
shapefile_close(ptr);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static const rb_data_type_t shape_data_type = {
|
|
51
|
+
"Shapelib::Shape", { 0, shape_free, 0 }
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
static const rb_data_type_t shapefile_data_type = {
|
|
55
|
+
"Shapelib::ShapeFile", { 0, shapefile_free, 0 }
|
|
56
|
+
};
|
|
57
|
+
|
|
40
58
|
#include "valconv.h"
|
|
41
59
|
#include "sfcode.h"
|
|
42
60
|
#include "sflist.h"
|
|
@@ -64,20 +82,36 @@ void Init_shapelib_ext()
|
|
|
64
82
|
{
|
|
65
83
|
mShapeLib = rb_define_module("Shapelib");
|
|
66
84
|
cShapeFile = rb_define_class_under(mShapeLib, "ShapeFile", rb_cObject);
|
|
85
|
+
rb_undef_alloc_func(cShapeFile);
|
|
67
86
|
cShape = rb_define_class_under(mShapeLib, "Shape", rb_cObject);
|
|
87
|
+
rb_undef_alloc_func(cShape);
|
|
68
88
|
cPoint = rb_define_class_under(mShapeLib, "Point", cShape);
|
|
89
|
+
rb_undef_alloc_func(cPoint);
|
|
69
90
|
cPointM = rb_define_class_under(mShapeLib, "PointM", cPoint);
|
|
91
|
+
rb_undef_alloc_func(cPointM);
|
|
70
92
|
cPointZ = rb_define_class_under(mShapeLib, "PointZ", cPointM);
|
|
93
|
+
rb_undef_alloc_func(cPointZ);
|
|
71
94
|
cArc = rb_define_class_under(mShapeLib, "Arc", cShape);
|
|
95
|
+
rb_undef_alloc_func(cArc);
|
|
72
96
|
cArcM = rb_define_class_under(mShapeLib, "ArcM", cArc);
|
|
97
|
+
rb_undef_alloc_func(cArcM);
|
|
73
98
|
cArcZ = rb_define_class_under(mShapeLib, "ArcZ", cArcM);
|
|
99
|
+
rb_undef_alloc_func(cArcZ);
|
|
74
100
|
cPolygon = rb_define_class_under(mShapeLib, "Polygon", cShape);
|
|
101
|
+
rb_undef_alloc_func(cPolygon);
|
|
75
102
|
cPolygonM = rb_define_class_under(mShapeLib, "PolygonM", cPolygon);
|
|
103
|
+
rb_undef_alloc_func(cPolygonM);
|
|
76
104
|
cPolygonZ = rb_define_class_under(mShapeLib, "PolygonZ", cPolygonM);
|
|
105
|
+
rb_undef_alloc_func(cPolygonZ);
|
|
77
106
|
cMultiPoint = rb_define_class_under(mShapeLib, "MultiPoint", cShape);
|
|
107
|
+
rb_undef_alloc_func(cMultiPoint);
|
|
78
108
|
cMultiPointM = rb_define_class_under(mShapeLib, "MultiPointM", cMultiPoint);
|
|
109
|
+
rb_undef_alloc_func(cMultiPointM);
|
|
79
110
|
cMultiPointZ = rb_define_class_under(mShapeLib, "MultiPointZ", cMultiPointM);
|
|
111
|
+
rb_undef_alloc_func(cMultiPointZ);
|
|
80
112
|
cMultiPatch = rb_define_class_under(mShapeLib, "MultiPatch", cShape);
|
|
113
|
+
rb_undef_alloc_func(cMultiPatch);
|
|
114
|
+
|
|
81
115
|
rb_define_module_function(mShapeLib, "new_point", sl_m_new_point, -1);
|
|
82
116
|
rb_define_singleton_method(cShapeFile, "new", sf_s_new, -1);
|
|
83
117
|
rb_define_singleton_method(cShapeFile, "open", sf_s_open, -1);
|
data/ext/shapelib_ext/sfcode.h
CHANGED
|
@@ -11,7 +11,6 @@ static VALUE sf_add_field(int argc, VALUE *args, VALUE obj)
|
|
|
11
11
|
|
|
12
12
|
rb_scan_args(argc, args, "31",
|
|
13
13
|
&name, &field_type, &field_width, &decimal_place);
|
|
14
|
-
SECURE(name);
|
|
15
14
|
StringValue(name);
|
|
16
15
|
atype = Ruby2FieldType(field_type);
|
|
17
16
|
width = NUM2INT(field_width);
|
|
@@ -19,7 +18,7 @@ static VALUE sf_add_field(int argc, VALUE *args, VALUE obj)
|
|
|
19
18
|
if (atype == FTDouble && argc == 3) {
|
|
20
19
|
rb_raise(rb_eArgError, "specify decimal places for Float attribute");
|
|
21
20
|
}
|
|
22
|
-
|
|
21
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
23
22
|
r = shapefile_add_field(self, RSTRING_PTR(name), atype, width, wdeci);
|
|
24
23
|
return obj;
|
|
25
24
|
}
|
|
@@ -27,7 +26,7 @@ static VALUE sf_add_field(int argc, VALUE *args, VALUE obj)
|
|
|
27
26
|
static VALUE sf_close(VALUE obj)
|
|
28
27
|
{
|
|
29
28
|
shapefile_t *self;
|
|
30
|
-
|
|
29
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
31
30
|
return INT2FIX(shapefile_close(self));
|
|
32
31
|
}
|
|
33
32
|
|
|
@@ -35,7 +34,7 @@ static VALUE sf_field_count(VALUE obj)
|
|
|
35
34
|
{
|
|
36
35
|
shapefile_t *self;
|
|
37
36
|
int r;
|
|
38
|
-
|
|
37
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
39
38
|
r = shapefile_field_count(self);
|
|
40
39
|
return INT2FIX(r);
|
|
41
40
|
}
|
|
@@ -45,7 +44,6 @@ static int Ruby2FieldIndex(shapefile_t *sfile, VALUE field)
|
|
|
45
44
|
if (FIXNUM_P(field)) {
|
|
46
45
|
return FIX2INT(field);
|
|
47
46
|
} else {
|
|
48
|
-
SECURE(field);
|
|
49
47
|
return shapefile_field_index(sfile, StringValuePtr(field));
|
|
50
48
|
}
|
|
51
49
|
}
|
|
@@ -53,7 +51,7 @@ static int Ruby2FieldIndex(shapefile_t *sfile, VALUE field)
|
|
|
53
51
|
static VALUE sf_delete_shape(VALUE obj, VALUE ishape)
|
|
54
52
|
{
|
|
55
53
|
shapefile_t *self;
|
|
56
|
-
|
|
54
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
57
55
|
shapefile_delete_shape(self, NUM2INT(ishape));
|
|
58
56
|
return Qnil;
|
|
59
57
|
}
|
|
@@ -62,7 +60,7 @@ static VALUE sf_field_index(VALUE obj, VALUE name)
|
|
|
62
60
|
{
|
|
63
61
|
shapefile_t *self;
|
|
64
62
|
int ifield;
|
|
65
|
-
|
|
63
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
66
64
|
ifield = Ruby2FieldIndex(self, name);
|
|
67
65
|
return (ifield < 0) ? Qnil : INT2FIX(ifield);
|
|
68
66
|
}
|
|
@@ -71,7 +69,7 @@ static VALUE sf_field_name(VALUE obj, VALUE index)
|
|
|
71
69
|
{
|
|
72
70
|
shapefile_t *self;
|
|
73
71
|
const char *name;
|
|
74
|
-
|
|
72
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
75
73
|
name = shapefile_field_name(self, NUM2INT(index));
|
|
76
74
|
return name ? rb_str_new2(name) : Qnil;
|
|
77
75
|
}
|
|
@@ -80,7 +78,7 @@ static VALUE sf_field_type(VALUE obj, VALUE field)
|
|
|
80
78
|
{
|
|
81
79
|
shapefile_t *self;
|
|
82
80
|
int ifield;
|
|
83
|
-
|
|
81
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
84
82
|
ifield = Ruby2FieldIndex(self, field);
|
|
85
83
|
return FieldType2Ruby(shapefile_field_type(self, ifield));
|
|
86
84
|
}
|
|
@@ -89,7 +87,7 @@ static VALUE sf_field_width(VALUE obj, VALUE field)
|
|
|
89
87
|
{
|
|
90
88
|
shapefile_t *self;
|
|
91
89
|
int ifield;
|
|
92
|
-
|
|
90
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
93
91
|
ifield = Ruby2FieldIndex(self, field);
|
|
94
92
|
return INT2FIX(shapefile_field_width(self, ifield));
|
|
95
93
|
}
|
|
@@ -98,7 +96,7 @@ static VALUE sf_field_decimals(VALUE obj, VALUE field)
|
|
|
98
96
|
{
|
|
99
97
|
shapefile_t *self;
|
|
100
98
|
int ifield;
|
|
101
|
-
|
|
99
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
102
100
|
ifield = Ruby2FieldIndex(self, field);
|
|
103
101
|
return INT2FIX(shapefile_field_decimals(self, ifield));
|
|
104
102
|
}
|
|
@@ -108,7 +106,7 @@ static VALUE sf_fields(VALUE obj)
|
|
|
108
106
|
shapefile_t *self;
|
|
109
107
|
VALUE r;
|
|
110
108
|
int fc, i;
|
|
111
|
-
|
|
109
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
112
110
|
fc = shapefile_field_count(self);
|
|
113
111
|
if (fc < 0)
|
|
114
112
|
return Qnil;
|
|
@@ -126,7 +124,7 @@ static VALUE sf_maxbound(VALUE obj)
|
|
|
126
124
|
shapefile_t *self;
|
|
127
125
|
double bound[4];
|
|
128
126
|
double z;
|
|
129
|
-
|
|
127
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
130
128
|
shapefile_bound(self, NULL, bound);
|
|
131
129
|
z = bound[2];
|
|
132
130
|
bound[2] = bound[3];
|
|
@@ -139,7 +137,7 @@ static VALUE sf_minbound(VALUE obj)
|
|
|
139
137
|
shapefile_t *self;
|
|
140
138
|
double bound[4];
|
|
141
139
|
double z;
|
|
142
|
-
|
|
140
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
143
141
|
shapefile_bound(self, bound, NULL);
|
|
144
142
|
z = bound[2];
|
|
145
143
|
bound[2] = bound[3];
|
|
@@ -154,19 +152,19 @@ static VALUE sf_read(int argc, VALUE *args, VALUE obj)
|
|
|
154
152
|
VALUE ishape, r;
|
|
155
153
|
int irec;
|
|
156
154
|
rb_scan_args(argc, args, "01", &ishape);
|
|
157
|
-
|
|
155
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
158
156
|
irec = NIL_P(ishape) ? -1 : NUM2INT(ishape);
|
|
159
157
|
s = shapefile_read(self, irec);
|
|
160
158
|
if (s == NULL)
|
|
161
159
|
return Qnil;
|
|
162
|
-
r =
|
|
160
|
+
r = TypedData_Wrap_Struct(cShape, &shape_data_type, s);
|
|
163
161
|
return r;
|
|
164
162
|
}
|
|
165
163
|
|
|
166
164
|
static VALUE sf_rewind(VALUE obj)
|
|
167
165
|
{
|
|
168
166
|
shapefile_t *self;
|
|
169
|
-
|
|
167
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
170
168
|
self->irec = 0;
|
|
171
169
|
return obj;
|
|
172
170
|
}
|
|
@@ -187,7 +185,7 @@ static VALUE sf_each(VALUE obj)
|
|
|
187
185
|
static VALUE sf_shape_type(VALUE obj)
|
|
188
186
|
{
|
|
189
187
|
shapefile_t *self;
|
|
190
|
-
|
|
188
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
191
189
|
return ShapeType2Ruby(shapefile_shape_type(self));
|
|
192
190
|
}
|
|
193
191
|
|
|
@@ -195,7 +193,7 @@ static VALUE sf_size(VALUE obj)
|
|
|
195
193
|
{
|
|
196
194
|
shapefile_t *self;
|
|
197
195
|
int r;
|
|
198
|
-
|
|
196
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
199
197
|
r = shapefile_size(self);
|
|
200
198
|
if (r < 0)
|
|
201
199
|
rb_raise(rb_eRuntimeError, "size %d", r);
|
|
@@ -210,8 +208,8 @@ static VALUE sf_write(int argc, VALUE *args, VALUE obj)
|
|
|
210
208
|
if (argc < 1 || argc > 2) {
|
|
211
209
|
rb_raise(rb_eArgError, "usage: Shapefile#write shape, [irec = -1]");
|
|
212
210
|
}
|
|
213
|
-
|
|
214
|
-
|
|
211
|
+
TypedData_Get_Struct(obj, shapefile_t, &shapefile_data_type, self);
|
|
212
|
+
TypedData_Get_Struct(args[0], shape_t, &shape_data_type, shape);
|
|
215
213
|
irec = ((argc == 2) ? NUM2INT(args[1]) : -1);
|
|
216
214
|
r = shapefile_write(self, irec, shape);
|
|
217
215
|
return INT2FIX(r);
|
|
@@ -237,11 +235,10 @@ static VALUE sf_s_open(int argc, VALUE *argv, VALUE klass)
|
|
|
237
235
|
VALUE fnam, mode, sf, proc;
|
|
238
236
|
shapefile_t *sfile;
|
|
239
237
|
rb_scan_args(argc, argv, "11&", &fnam, &mode, &proc);
|
|
240
|
-
SECURE(fnam);
|
|
241
238
|
sfile = shapefile_open(StringValuePtr(fnam),
|
|
242
239
|
(NIL_P(mode) ? "rb" : StringValuePtr(mode))
|
|
243
240
|
);
|
|
244
|
-
sf =
|
|
241
|
+
sf = TypedData_Wrap_Struct(klass, &shapefile_data_type, sfile);
|
|
245
242
|
return YieldIfPossible(proc, sf);
|
|
246
243
|
}
|
|
247
244
|
|
|
@@ -257,7 +254,6 @@ static VALUE sf_s_new(int argc, VALUE *argv, VALUE klass)
|
|
|
257
254
|
return Qnil;
|
|
258
255
|
}
|
|
259
256
|
rb_scan_args(argc, argv, "21&", &fnam, &shapetype, &attrs, &proc);
|
|
260
|
-
SECURE(fnam);
|
|
261
257
|
if ((stype = Ruby2ShapeType(shapetype)) == -1) {
|
|
262
258
|
rb_raise(rb_eArgError, "shapetype must be Shape subclass");
|
|
263
259
|
}
|
|
@@ -270,7 +266,7 @@ static VALUE sf_s_new(int argc, VALUE *argv, VALUE klass)
|
|
|
270
266
|
if (sfile == NULL) {
|
|
271
267
|
rb_raise(rb_eRuntimeError, "shapefile_new failed");
|
|
272
268
|
}
|
|
273
|
-
sf =
|
|
269
|
+
sf = TypedData_Wrap_Struct(klass, &shapefile_data_type, sfile);
|
|
274
270
|
if (argc > 2) {
|
|
275
271
|
for (i = 0; i < RARRAY_LEN(attrs); i++) {
|
|
276
272
|
VALUE p = RARRAY_PTR(attrs)[i];
|
data/ext/shapelib_ext/spcode.h
CHANGED
|
@@ -105,7 +105,7 @@ static VALUE sp_s_new(VALUE klass, VALUE hash)
|
|
|
105
105
|
if (yvals) free(yvals);
|
|
106
106
|
if (zvals) free(zvals);
|
|
107
107
|
if (mvals) free(mvals);
|
|
108
|
-
vshape =
|
|
108
|
+
vshape = TypedData_Wrap_Struct(qlass, &shape_data_type, shape);
|
|
109
109
|
HashLoadAttrib(vshape, hash);
|
|
110
110
|
return vshape;
|
|
111
111
|
}
|
|
@@ -280,7 +280,7 @@ static VALUE NewShape(int argc, VALUE *argv, VALUE klass, int shapetype)
|
|
|
280
280
|
} else {
|
|
281
281
|
shape = NewSinglePart(argc, argv, klass, shapetype);
|
|
282
282
|
}
|
|
283
|
-
return
|
|
283
|
+
return TypedData_Wrap_Struct(klass, &shape_data_type, shape);
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
static VALUE MultiPointNew(int argc, VALUE *argv, VALUE klass, int shapetype)
|
|
@@ -300,7 +300,7 @@ static VALUE MultiPointNew(int argc, VALUE *argv, VALUE klass, int shapetype)
|
|
|
300
300
|
CollectPoints(argc, argv, x, y, m, z);
|
|
301
301
|
shape = shape_new_obj(shapetype, 1, part_start, NULL, n_vert, x, y, m, z);
|
|
302
302
|
free(dblock);
|
|
303
|
-
return
|
|
303
|
+
return TypedData_Wrap_Struct(klass, &shape_data_type, shape);
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
static VALUE arc_s_new(int argc, VALUE *argv, VALUE klass) {
|
|
@@ -372,7 +372,7 @@ static VALUE pt_s_new(int argc, VALUE *argv, VALUE klass)
|
|
|
372
372
|
rb_scan_args(argc, argv, "21", &vx, &vy, &attrs);
|
|
373
373
|
shape = shape_new_point(SHPT_POINT,
|
|
374
374
|
NUM2DBLo(vx), NUM2DBLo(vy), 0.0, 0.0);
|
|
375
|
-
pt =
|
|
375
|
+
pt = TypedData_Wrap_Struct(klass, &shape_data_type, shape);
|
|
376
376
|
if (!NIL_P(attrs)) {
|
|
377
377
|
PointAddAttr(pt, attrs);
|
|
378
378
|
}
|
|
@@ -386,7 +386,7 @@ static VALUE ptm_s_new(int argc, VALUE *argv, VALUE klass)
|
|
|
386
386
|
rb_scan_args(argc, argv, "31", &vx, &vy, &vm, &attrs);
|
|
387
387
|
shape = shape_new_point(SHPT_POINTM,
|
|
388
388
|
NUM2DBLo(vx), NUM2DBLo(vy), SHP_NUM2DBL(vm), 0.0);
|
|
389
|
-
pt =
|
|
389
|
+
pt = TypedData_Wrap_Struct(klass, &shape_data_type, shape);
|
|
390
390
|
if (!NIL_P(attrs)) {
|
|
391
391
|
PointAddAttr(pt, attrs);
|
|
392
392
|
}
|
|
@@ -400,7 +400,7 @@ static VALUE ptz_s_new(int argc, VALUE *argv, VALUE klass)
|
|
|
400
400
|
rb_scan_args(argc, argv, "41", &vx, &vy, &vm, &vz, &attrs);
|
|
401
401
|
shape = shape_new_point(SHPT_POINTZ,
|
|
402
402
|
NUM2DBLo(vx), NUM2DBLo(vy), SHP_NUM2DBL(vm), NUM2DBLo(vz));
|
|
403
|
-
pt =
|
|
403
|
+
pt = TypedData_Wrap_Struct(klass, &shape_data_type, shape);
|
|
404
404
|
if (!NIL_P(attrs)) {
|
|
405
405
|
PointAddAttr(pt, attrs);
|
|
406
406
|
}
|
|
@@ -431,7 +431,7 @@ static void Attr_to_Hash(VALUE h, VALUE obj)
|
|
|
431
431
|
{
|
|
432
432
|
shape_t *self;
|
|
433
433
|
int i;
|
|
434
|
-
|
|
434
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
435
435
|
if (self->nattr <= 0)
|
|
436
436
|
return;
|
|
437
437
|
for (i = 0; i < self->nattr; i++) {
|
|
@@ -466,7 +466,7 @@ static VALUE sp_field_get(VALUE obj, VALUE name)
|
|
|
466
466
|
char *cname;
|
|
467
467
|
int ofs;
|
|
468
468
|
|
|
469
|
-
|
|
469
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
470
470
|
cname = StringValuePtr(name);
|
|
471
471
|
ofs = shape_attrib_index(self, cname, 0);
|
|
472
472
|
if (ofs < 0) {
|
|
@@ -494,7 +494,7 @@ static VALUE sp_field_set(VALUE obj, VALUE name, VALUE val)
|
|
|
494
494
|
char *cname;
|
|
495
495
|
int ofs;
|
|
496
496
|
|
|
497
|
-
|
|
497
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
498
498
|
cname = StringValuePtr(name);
|
|
499
499
|
ofs = shape_attrib_index(self, cname, 1);
|
|
500
500
|
if (ofs < 0) {
|
|
@@ -527,7 +527,7 @@ static VALUE sp_maxbound(VALUE obj)
|
|
|
527
527
|
{
|
|
528
528
|
shape_t *self;
|
|
529
529
|
double buf[4];
|
|
530
|
-
|
|
530
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
531
531
|
buf[0] = self->obj->dfXMax;
|
|
532
532
|
buf[1] = self->obj->dfYMax;
|
|
533
533
|
buf[2] = self->obj->dfMMax;
|
|
@@ -539,7 +539,7 @@ static VALUE sp_minbound(VALUE obj)
|
|
|
539
539
|
{
|
|
540
540
|
shape_t *self;
|
|
541
541
|
double buf[4];
|
|
542
|
-
|
|
542
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
543
543
|
buf[0] = self->obj->dfXMin;
|
|
544
544
|
buf[1] = self->obj->dfYMin;
|
|
545
545
|
buf[2] = self->obj->dfMMin;
|
|
@@ -550,28 +550,28 @@ static VALUE sp_minbound(VALUE obj)
|
|
|
550
550
|
static VALUE sp_mvals(VALUE obj)
|
|
551
551
|
{
|
|
552
552
|
shape_t *self;
|
|
553
|
-
|
|
553
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
554
554
|
return DoubleUnpackM(self->obj->padfM, self->obj->nVertices, -1);
|
|
555
555
|
}
|
|
556
556
|
|
|
557
557
|
static VALUE sp_n_parts(VALUE obj)
|
|
558
558
|
{
|
|
559
559
|
shape_t *self;
|
|
560
|
-
|
|
560
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
561
561
|
return INT2NUM(self->obj->nParts);
|
|
562
562
|
}
|
|
563
563
|
|
|
564
564
|
static VALUE sp_n_vertices(VALUE obj)
|
|
565
565
|
{
|
|
566
566
|
shape_t *self;
|
|
567
|
-
|
|
567
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
568
568
|
return INT2NUM(self->obj->nVertices);
|
|
569
569
|
}
|
|
570
570
|
|
|
571
571
|
static VALUE sp_part_start(VALUE obj)
|
|
572
572
|
{
|
|
573
573
|
shape_t *self;
|
|
574
|
-
|
|
574
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
575
575
|
if (self->obj->nParts == 0)
|
|
576
576
|
return Qnil;
|
|
577
577
|
return IntUnpack(self->obj->panPartStart, self->obj->nParts);
|
|
@@ -582,7 +582,7 @@ static VALUE sp_part_type(VALUE obj)
|
|
|
582
582
|
shape_t *self;
|
|
583
583
|
VALUE ary;
|
|
584
584
|
int i;
|
|
585
|
-
|
|
585
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
586
586
|
if (self->obj->nParts == 0)
|
|
587
587
|
return Qnil;
|
|
588
588
|
#if 0
|
|
@@ -598,42 +598,42 @@ static VALUE sp_part_type(VALUE obj)
|
|
|
598
598
|
static VALUE sp_shape_id(VALUE obj)
|
|
599
599
|
{
|
|
600
600
|
shape_t *self;
|
|
601
|
-
|
|
601
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
602
602
|
return (self->obj->nShapeId < 0) ? Qnil : INT2NUM(self->obj->nShapeId);
|
|
603
603
|
}
|
|
604
604
|
|
|
605
605
|
static VALUE sp_shape_type(VALUE obj)
|
|
606
606
|
{
|
|
607
607
|
shape_t *self;
|
|
608
|
-
|
|
608
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
609
609
|
return ShapeType2Ruby(self->obj->nSHPType);
|
|
610
610
|
}
|
|
611
611
|
|
|
612
612
|
static VALUE sp_rewind(VALUE obj)
|
|
613
613
|
{
|
|
614
614
|
shape_t *self;
|
|
615
|
-
|
|
615
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
616
616
|
return SHPRewindObject(NULL, self->obj) ? Qtrue : Qfalse;
|
|
617
617
|
}
|
|
618
618
|
|
|
619
619
|
static VALUE sp_xvals(VALUE obj)
|
|
620
620
|
{
|
|
621
621
|
shape_t *self;
|
|
622
|
-
|
|
622
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
623
623
|
return DoubleUnpack(self->obj->padfX, self->obj->nVertices);
|
|
624
624
|
}
|
|
625
625
|
|
|
626
626
|
static VALUE sp_yvals(VALUE obj)
|
|
627
627
|
{
|
|
628
628
|
shape_t *self;
|
|
629
|
-
|
|
629
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
630
630
|
return DoubleUnpack(self->obj->padfY, self->obj->nVertices);
|
|
631
631
|
}
|
|
632
632
|
|
|
633
633
|
static VALUE sp_zvals(VALUE obj)
|
|
634
634
|
{
|
|
635
635
|
shape_t *self;
|
|
636
|
-
|
|
636
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
637
637
|
return DoubleUnpack(self->obj->padfZ, self->obj->nVertices);
|
|
638
638
|
}
|
|
639
639
|
|
|
@@ -644,7 +644,7 @@ static VALUE sp_zvals(VALUE obj)
|
|
|
644
644
|
static VALUE pt_x(VALUE obj)
|
|
645
645
|
{
|
|
646
646
|
shape_t *self;
|
|
647
|
-
|
|
647
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
648
648
|
switch (self->obj->nSHPType) {
|
|
649
649
|
case SHPT_POINT:
|
|
650
650
|
case SHPT_POINTM:
|
|
@@ -659,7 +659,7 @@ static VALUE pt_x(VALUE obj)
|
|
|
659
659
|
static VALUE pt_y(VALUE obj)
|
|
660
660
|
{
|
|
661
661
|
shape_t *self;
|
|
662
|
-
|
|
662
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
663
663
|
switch (self->obj->nSHPType) {
|
|
664
664
|
case SHPT_POINT:
|
|
665
665
|
case SHPT_POINTM:
|
|
@@ -674,7 +674,7 @@ static VALUE pt_y(VALUE obj)
|
|
|
674
674
|
static VALUE pt_m(VALUE obj)
|
|
675
675
|
{
|
|
676
676
|
shape_t *self;
|
|
677
|
-
|
|
677
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
678
678
|
switch (self->obj->nSHPType) {
|
|
679
679
|
case SHPT_POINTM:
|
|
680
680
|
case SHPT_POINTZ:
|
|
@@ -690,7 +690,7 @@ static VALUE pt_m(VALUE obj)
|
|
|
690
690
|
static VALUE pt_z(VALUE obj)
|
|
691
691
|
{
|
|
692
692
|
shape_t *self;
|
|
693
|
-
|
|
693
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
694
694
|
switch (self->obj->nSHPType) {
|
|
695
695
|
case SHPT_POINTZ:
|
|
696
696
|
return rb_float_new(self->obj->padfM[0]);
|
data/ext/shapelib_ext/splist.h
CHANGED
|
@@ -21,27 +21,9 @@ static VALUE sp_to_h(VALUE obj)
|
|
|
21
21
|
return h;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
static VALUE sp_inspect(VALUE obj)
|
|
25
|
-
{
|
|
26
|
-
VALUE tos;
|
|
27
|
-
static ID inspect = 0;
|
|
28
|
-
static ID id_plus, id_class, id_to_s;
|
|
29
|
-
static VALUE classnm;
|
|
30
|
-
if (inspect == 0) {
|
|
31
|
-
inspect = rb_intern("inspect");
|
|
32
|
-
id_plus = rb_intern("+");
|
|
33
|
-
id_class = rb_intern("class");
|
|
34
|
-
id_to_s = rb_intern("to_s");
|
|
35
|
-
}
|
|
36
|
-
classnm = rb_funcall(rb_funcall(obj, id_class, 0), id_to_s, 0);
|
|
37
|
-
tos = rb_funcall(sp_to_h(obj), inspect, 0);
|
|
38
|
-
return rb_funcall(classnm, id_plus, 1, tos);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
24
|
static method_table_entry sp_methods[] = {
|
|
42
25
|
{ "[]", sp_field_get, 1 },
|
|
43
26
|
{ "[]=", sp_field_set, 2 },
|
|
44
|
-
{ "inspect", sp_inspect, 0 },
|
|
45
27
|
{ "maxbound", sp_maxbound, 0 },
|
|
46
28
|
{ "minbound", sp_minbound, 0 },
|
|
47
29
|
{ "mvals", sp_mvals, 0 },
|
data/ext/shapelib_ext/spwkt.h
CHANGED
|
@@ -28,7 +28,7 @@ static VALUE pt_wkt(VALUE obj)
|
|
|
28
28
|
size_t buflen;
|
|
29
29
|
char *buf, *cur, *stop;
|
|
30
30
|
VALUE wkt;
|
|
31
|
-
|
|
31
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
32
32
|
buflen = wkt_dlen * 2 + 9;
|
|
33
33
|
cur = buf = xmalloc(buflen + 1);
|
|
34
34
|
stop = buf + buflen;
|
|
@@ -49,7 +49,7 @@ static VALUE mp_wkt(VALUE obj)
|
|
|
49
49
|
size_t buflen;
|
|
50
50
|
char *buf, *cur, *stop;
|
|
51
51
|
int iv;
|
|
52
|
-
|
|
52
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
53
53
|
buflen = (2 * wkt_dlen + 3) * self->obj->nVertices + 11;
|
|
54
54
|
cur = buf = xmalloc(buflen + 1);
|
|
55
55
|
stop = buf + buflen;
|
|
@@ -104,7 +104,7 @@ static VALUE WKTSinglePolygon(SHPObject *obj)
|
|
|
104
104
|
static VALUE pl_wkt(VALUE obj)
|
|
105
105
|
{
|
|
106
106
|
shape_t *self;
|
|
107
|
-
|
|
107
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
108
108
|
/* === BUG ===
|
|
109
109
|
* following code doesn't consider the possibilities:
|
|
110
110
|
* - there may be multiple outer loop in a Polygon Shape.
|
|
@@ -177,7 +177,7 @@ static VALUE WKTMultiArc(SHPObject *obj)
|
|
|
177
177
|
static VALUE arc_wkt(VALUE obj)
|
|
178
178
|
{
|
|
179
179
|
shape_t *self;
|
|
180
|
-
|
|
180
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
181
181
|
if (self->obj->nParts > 1) {
|
|
182
182
|
return WKTMultiArc(self->obj);
|
|
183
183
|
} else {
|
|
@@ -188,7 +188,7 @@ static VALUE arc_wkt(VALUE obj)
|
|
|
188
188
|
static VALUE sp_wkt(VALUE obj)
|
|
189
189
|
{
|
|
190
190
|
shape_t *self;
|
|
191
|
-
|
|
191
|
+
TypedData_Get_Struct(obj, shape_t, &shape_data_type, self);
|
|
192
192
|
switch (self->obj->nSHPType) {
|
|
193
193
|
case SHPT_POINT:
|
|
194
194
|
case SHPT_POINTM:
|
data/ext/shapelib_ext/valconv.h
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/* valconv.h */
|
|
2
2
|
|
|
3
|
-
#define SECURE(obj) SecureObject((obj), #obj)
|
|
4
|
-
|
|
5
3
|
#define SHP_NODATA_LIM -1.0e-38
|
|
6
4
|
#define SHP_NODATA -2.0e-38
|
|
7
5
|
#define SHP_NUM2DBL(value) (NIL_P(value) ? SHP_NODATA : NUM2DBL(value))
|
|
@@ -304,10 +302,3 @@ static VALUE IntUnpack(int *up, unsigned num)
|
|
|
304
302
|
return rb_funcall(buf, unpackid, 1, unpackfmt);
|
|
305
303
|
}
|
|
306
304
|
|
|
307
|
-
static VALUE SecureObject(VALUE obj, const char *name) {
|
|
308
|
-
if (OBJ_TAINTED(obj) && rb_safe_level() >= 1) {
|
|
309
|
-
rb_raise(rb_eSecurityError, "tainted %s", name);
|
|
310
|
-
}
|
|
311
|
-
return obj;
|
|
312
|
-
}
|
|
313
|
-
|
data/lib/shapelib/shape.rb
CHANGED
data/lib/shapelib/version.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
module Shapelib
|
|
2
|
-
VERSION = "0.7.
|
|
3
|
-
end
|
|
2
|
+
VERSION = "0.7.2"
|
|
3
|
+
end
|