shp 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +34 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/LICENSE +28 -0
- data/README.md +30 -0
- data/Rakefile +23 -0
- data/ext/shp/base.hpp +113 -0
- data/ext/shp/dbf.cpp +381 -0
- data/ext/shp/dbf.hpp +44 -0
- data/ext/shp/extconf.rb +13 -0
- data/ext/shp/shape_object.cpp +58 -0
- data/ext/shp/shape_object.hpp +27 -0
- data/ext/shp/shapefile.cpp +299 -0
- data/ext/shp/shapefile.hpp +35 -0
- data/ext/shp/shapelib/.cvsignore +15 -0
- data/ext/shp/shapelib/ChangeLog +450 -0
- data/ext/shp/shapelib/HOWTO-RELEASE +16 -0
- data/ext/shp/shapelib/LICENSE.LGPL +483 -0
- data/ext/shp/shapelib/Makefile +113 -0
- data/ext/shp/shapelib/README +41 -0
- data/ext/shp/shapelib/README.tree +172 -0
- data/ext/shp/shapelib/contrib/.cvsignore +12 -0
- data/ext/shp/shapelib/contrib/Makefile +66 -0
- data/ext/shp/shapelib/contrib/ShapeFileII.pas +234 -0
- data/ext/shp/shapelib/contrib/Shape_PointInPoly.cpp +238 -0
- data/ext/shp/shapelib/contrib/Shape_PointInPoly_README.txt +59 -0
- data/ext/shp/shapelib/contrib/csv2shp.c +558 -0
- data/ext/shp/shapelib/contrib/dbfcat.c +166 -0
- data/ext/shp/shapelib/contrib/dbfinfo.c +106 -0
- data/ext/shp/shapelib/contrib/makefile.vc +34 -0
- data/ext/shp/shapelib/contrib/my_nan.h +46 -0
- data/ext/shp/shapelib/contrib/shpcat.c +100 -0
- data/ext/shp/shapelib/contrib/shpcentrd.c +159 -0
- data/ext/shp/shapelib/contrib/shpdata.c +129 -0
- data/ext/shp/shapelib/contrib/shpdxf.c +340 -0
- data/ext/shp/shapelib/contrib/shpfix.c +110 -0
- data/ext/shp/shapelib/contrib/shpgeo.c +1595 -0
- data/ext/shp/shapelib/contrib/shpgeo.h +154 -0
- data/ext/shp/shapelib/contrib/shpinfo.c +113 -0
- data/ext/shp/shapelib/contrib/shpproj.c +260 -0
- data/ext/shp/shapelib/contrib/shpsort.c +605 -0
- data/ext/shp/shapelib/contrib/shpsort.txt +44 -0
- data/ext/shp/shapelib/contrib/shpwkb.c +123 -0
- data/ext/shp/shapelib/contrib/tests/shpproj.sh +38 -0
- data/ext/shp/shapelib/dbfopen.c +2221 -0
- data/ext/shp/shapelib/makefile.vc +86 -0
- data/ext/shp/shapelib/makeshape.sh +21 -0
- data/ext/shp/shapelib/mkdist.sh +37 -0
- data/ext/shp/shapelib/mkinstalldirs +38 -0
- data/ext/shp/shapelib/mkrelease.sh +55 -0
- data/ext/shp/shapelib/safileio.c +286 -0
- data/ext/shp/shapelib/shapefil.h +647 -0
- data/ext/shp/shapelib/shapelib.def +46 -0
- data/ext/shp/shapelib/shpopen.c +2388 -0
- data/ext/shp/shapelib/shptree.c +1187 -0
- data/ext/shp/shapelib/shputils.c +1072 -0
- data/ext/shp/shapelib/stream1.out +1465 -0
- data/ext/shp/shapelib/stream1.sh +28 -0
- data/ext/shp/shapelib/stream2.out +530 -0
- data/ext/shp/shapelib/stream2.sh +11 -0
- data/ext/shp/shapelib/stream3.out +37 -0
- data/ext/shp/shapelib/web/.cvsignore +2 -0
- data/ext/shp/shapelib/web/codepage.html +403 -0
- data/ext/shp/shapelib/web/dbf_api.html +436 -0
- data/ext/shp/shapelib/web/index.html +235 -0
- data/ext/shp/shapelib/web/license.html +78 -0
- data/ext/shp/shapelib/web/manifest.html +87 -0
- data/ext/shp/shapelib/web/release.html +80 -0
- data/ext/shp/shapelib/web/shapelib-tools.html +352 -0
- data/ext/shp/shapelib/web/shp_api.html +376 -0
- data/ext/shp/shp.cpp +19 -0
- data/ext/shp/shp.hpp +47 -0
- data/lib/shp.rb +35 -0
- data/lib/shp/version.rb +3 -0
- data/shp.gemspec +23 -0
- data/spec/shp_spec.rb +127 -0
- metadata +176 -0
data/ext/shp/dbf.hpp
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#ifndef __SHP_DBF_HPP__
|
2
|
+
#define __SHP_DBF_HPP__
|
3
|
+
|
4
|
+
#include "shp.hpp"
|
5
|
+
#include "base.hpp"
|
6
|
+
|
7
|
+
namespace shp {
|
8
|
+
class dbf : public base<dbf> {
|
9
|
+
public:
|
10
|
+
dbf() : base<dbf>(), _handle(0) {};
|
11
|
+
dbf(DBFHandle handle);
|
12
|
+
static void define(VALUE module);
|
13
|
+
static VALUE create(VALUE klass, VALUE filename);
|
14
|
+
static VALUE open(VALUE klass, VALUE filename, VALUE access);
|
15
|
+
static VALUE add_field(VALUE self, VALUE fieldName, VALUE fieldType, VALUE fieldWidth, VALUE fieldDecimals);
|
16
|
+
static VALUE write_integer_attribute(VALUE self, VALUE recordIndex, VALUE fieldIndex, VALUE fieldValue);
|
17
|
+
static VALUE write_double_attribute(VALUE self, VALUE recordIndex, VALUE fieldIndex, VALUE fieldValue);
|
18
|
+
static VALUE write_string_attribute(VALUE self, VALUE recordIndex, VALUE fieldIndex, VALUE fieldValue);
|
19
|
+
static VALUE write_null_attribute(VALUE self, VALUE recordIndex, VALUE fieldIndex);
|
20
|
+
static VALUE read_integer_attribute(VALUE self, VALUE recordIndex, VALUE fieldIndex);
|
21
|
+
static VALUE read_double_attribute(VALUE self, VALUE recordIndex, VALUE fieldIndex);
|
22
|
+
static VALUE read_string_attribute(VALUE self, VALUE recordIndex, VALUE fieldIndex);
|
23
|
+
static VALUE is_attribute_null(VALUE self, VALUE recordIndex, VALUE fieldIndex);
|
24
|
+
static VALUE close(VALUE self);
|
25
|
+
static VALUE get_field_count(VALUE self);
|
26
|
+
static VALUE get_record_count(VALUE self);
|
27
|
+
static VALUE get_field_index(VALUE self, VALUE fieldName);
|
28
|
+
static VALUE get_field_info(VALUE self, VALUE fieldIndex);
|
29
|
+
static VALUE is_record_deleted(VALUE self, VALUE recordIndex);
|
30
|
+
static VALUE mark_record_deleted(VALUE self, VALUE recordIndex, VALUE isDeleted);
|
31
|
+
static VALUE get_native_field_type(VALUE self, VALUE fieldIndex);
|
32
|
+
|
33
|
+
virtual VALUE klass();
|
34
|
+
static VALUE _klass;
|
35
|
+
|
36
|
+
DBFHandle value() { return _handle; }
|
37
|
+
|
38
|
+
virtual ~dbf();
|
39
|
+
private:
|
40
|
+
DBFHandle _handle;
|
41
|
+
};
|
42
|
+
}
|
43
|
+
|
44
|
+
#endif
|
data/ext/shp/extconf.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
shapelib_path = File.expand_path("#{File.dirname(__FILE__)}/shapelib")
|
4
|
+
|
5
|
+
system "cd #{shapelib_path} && make clean && make && cd #{Dir.pwd}"
|
6
|
+
|
7
|
+
dir_config '', shapelib_path, shapelib_path
|
8
|
+
|
9
|
+
have_library 'shp' or raise 'libshp not found'
|
10
|
+
|
11
|
+
$libs = append_library $libs, 'shp'
|
12
|
+
|
13
|
+
create_makefile 'shp/shp'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
#include "shape_object.hpp"
|
3
|
+
|
4
|
+
namespace shp {
|
5
|
+
|
6
|
+
VALUE shape_object::_klass = Qnil;
|
7
|
+
|
8
|
+
VALUE shape_object::klass() {
|
9
|
+
return shape_object::_klass;
|
10
|
+
}
|
11
|
+
|
12
|
+
shape_object::shape_object(SHPObject *handle)
|
13
|
+
: _handle(handle)
|
14
|
+
{
|
15
|
+
}
|
16
|
+
|
17
|
+
shape_object::~shape_object() {
|
18
|
+
if (_handle) {
|
19
|
+
SHPDestroyObject(_handle);
|
20
|
+
_handle = NULL;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
VALUE shape_object::compute_extents(VALUE self)
|
25
|
+
{
|
26
|
+
shape_object *object = unwrap(self);
|
27
|
+
|
28
|
+
CHECK_VALID_HANDLE(object->value());
|
29
|
+
|
30
|
+
SHPComputeExtents(object->value());
|
31
|
+
|
32
|
+
return object->wrapped();
|
33
|
+
}
|
34
|
+
|
35
|
+
VALUE shape_object::destroy(VALUE self)
|
36
|
+
{
|
37
|
+
shape_object *object = unwrap(self);
|
38
|
+
|
39
|
+
CHECK_VALID_HANDLE(object->value());
|
40
|
+
|
41
|
+
if (object->value()) {
|
42
|
+
SHPDestroyObject(object->value());
|
43
|
+
object->_handle = NULL;
|
44
|
+
}
|
45
|
+
|
46
|
+
return Qnil;
|
47
|
+
}
|
48
|
+
|
49
|
+
void shape_object::define(VALUE module)
|
50
|
+
{
|
51
|
+
shape_object::_klass = rb_define_class_under(module, "ShapeObject", rb_cObject);
|
52
|
+
base::define(shape_object::_klass, false);
|
53
|
+
rb_define_method(shape_object::_klass, "compute_extents", SHP_METHOD(shape_object::compute_extents), 0);
|
54
|
+
rb_define_method(shape_object::_klass, "destroy", SHP_METHOD(shape_object::destroy), 0);
|
55
|
+
}
|
56
|
+
|
57
|
+
}
|
58
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#ifndef __SHP_SHAPE_OBJECT_HPP__
|
2
|
+
#define __SHP_SHAPE_OBJECT_HPP__
|
3
|
+
|
4
|
+
#include "shp.hpp"
|
5
|
+
#include "base.hpp"
|
6
|
+
|
7
|
+
namespace shp {
|
8
|
+
class shape_object : public base<shape_object> {
|
9
|
+
public:
|
10
|
+
shape_object() : base<shape_object>(), _handle(0) {};
|
11
|
+
shape_object(SHPObject *handle);
|
12
|
+
static void define(VALUE module);
|
13
|
+
static VALUE compute_extents(VALUE self);
|
14
|
+
static VALUE destroy(VALUE self);
|
15
|
+
|
16
|
+
virtual VALUE klass();
|
17
|
+
static VALUE _klass;
|
18
|
+
|
19
|
+
SHPObject *value() { return _handle; }
|
20
|
+
|
21
|
+
virtual ~shape_object();
|
22
|
+
private:
|
23
|
+
SHPObject *_handle;
|
24
|
+
};
|
25
|
+
}
|
26
|
+
|
27
|
+
#endif
|
@@ -0,0 +1,299 @@
|
|
1
|
+
|
2
|
+
#include "shapefile.hpp"
|
3
|
+
#include "shape_object.hpp"
|
4
|
+
|
5
|
+
namespace shp {
|
6
|
+
|
7
|
+
VALUE shapefile::_klass = Qnil;
|
8
|
+
|
9
|
+
VALUE shapefile::klass() {
|
10
|
+
return shapefile::_klass;
|
11
|
+
}
|
12
|
+
|
13
|
+
shapefile::shapefile(SHPHandle handle)
|
14
|
+
: _handle(handle)
|
15
|
+
{
|
16
|
+
}
|
17
|
+
|
18
|
+
shapefile::~shapefile() {
|
19
|
+
if (_handle) {
|
20
|
+
SHPClose(_handle);
|
21
|
+
_handle = NULL;
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
VALUE shapefile::create(VALUE klass, VALUE filename, VALUE shapeType)
|
26
|
+
{
|
27
|
+
CHECK_ARGUMENT_STRING(filename);
|
28
|
+
CHECK_ARGUMENT_FIXNUM(shapeType);
|
29
|
+
|
30
|
+
SHPHandle handle = SHPCreate(RSTRING_PTR(filename), FIX2INT(shapeType));
|
31
|
+
|
32
|
+
if (handle == NULL) {
|
33
|
+
SHP_FATAL("Failed to create shapefile.");
|
34
|
+
return Qnil;
|
35
|
+
}
|
36
|
+
|
37
|
+
shapefile *shp = new shapefile(handle);
|
38
|
+
|
39
|
+
return shp->wrapped();
|
40
|
+
}
|
41
|
+
|
42
|
+
VALUE shapefile::create_simple_object(VALUE klass, VALUE shapeType, VALUE numberOfVertices, VALUE arrayOfX, VALUE arrayOfY, VALUE arrayOfZ)
|
43
|
+
{
|
44
|
+
CHECK_ARGUMENT_FIXNUM(shapeType);
|
45
|
+
CHECK_ARGUMENT_FIXNUM(numberOfVertices);
|
46
|
+
CHECK_ARGUMENT_ARRAY(arrayOfX);
|
47
|
+
CHECK_ARGUMENT_ARRAY(arrayOfY);
|
48
|
+
|
49
|
+
double *xVertices = new double[FIX2INT(numberOfVertices)];
|
50
|
+
double *yVertices = new double[FIX2INT(numberOfVertices)];
|
51
|
+
double *zVertices = NULL;
|
52
|
+
|
53
|
+
if (!NIL_P(arrayOfZ)) {
|
54
|
+
CHECK_ARGUMENT_ARRAY(arrayOfZ);
|
55
|
+
zVertices = new double[FIX2INT(numberOfVertices)];
|
56
|
+
}
|
57
|
+
|
58
|
+
for (int i = 0; i < FIX2INT(numberOfVertices); ++i) {
|
59
|
+
xVertices[i] = NUM2DBL(rb_ary_entry(arrayOfX, i));
|
60
|
+
yVertices[i] = NUM2DBL(rb_ary_entry(arrayOfY, i));
|
61
|
+
|
62
|
+
if (zVertices) {
|
63
|
+
zVertices[i] = NUM2DBL(rb_ary_entry(arrayOfZ, i));
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
SHPObject *object = SHPCreateSimpleObject(FIX2INT(shapeType),
|
68
|
+
FIX2INT(numberOfVertices),
|
69
|
+
xVertices,
|
70
|
+
yVertices,
|
71
|
+
zVertices);
|
72
|
+
|
73
|
+
delete [] xVertices;
|
74
|
+
delete [] yVertices;
|
75
|
+
|
76
|
+
if (zVertices) {
|
77
|
+
delete [] zVertices;
|
78
|
+
}
|
79
|
+
|
80
|
+
if (object == NULL) {
|
81
|
+
SHP_FATAL("Failed to create shape object.");
|
82
|
+
return Qnil;
|
83
|
+
}
|
84
|
+
|
85
|
+
shape_object *shape = new shape_object(object);
|
86
|
+
|
87
|
+
return shape->wrapped();
|
88
|
+
}
|
89
|
+
|
90
|
+
|
91
|
+
VALUE shapefile::create_object(VALUE klass, VALUE shapeType, VALUE shapeIndex, VALUE numberOfParts,
|
92
|
+
VALUE arrayOfPartStarts, VALUE arrayOfPartTypes, VALUE numberOfVertices,
|
93
|
+
VALUE arrayOfX, VALUE arrayOfY, VALUE arrayOfZ, VALUE arrayOfM)
|
94
|
+
{
|
95
|
+
CHECK_ARGUMENT_FIXNUM(shapeType);
|
96
|
+
CHECK_ARGUMENT_FIXNUM(shapeIndex);
|
97
|
+
CHECK_ARGUMENT_FIXNUM(numberOfParts);
|
98
|
+
CHECK_ARGUMENT_FIXNUM(numberOfVertices);
|
99
|
+
CHECK_ARGUMENT_ARRAY(arrayOfX);
|
100
|
+
CHECK_ARGUMENT_ARRAY(arrayOfY);
|
101
|
+
|
102
|
+
double *xVertices = new double[FIX2INT(numberOfVertices)];
|
103
|
+
double *yVertices = new double[FIX2INT(numberOfVertices)];
|
104
|
+
double *zVertices = NULL;
|
105
|
+
double *mVertices = NULL;
|
106
|
+
|
107
|
+
int *nativeArrayOfPartStarts = NULL;
|
108
|
+
int *nativeArrayOfPartTypes = NULL;
|
109
|
+
|
110
|
+
if (!NIL_P(arrayOfZ)) {
|
111
|
+
CHECK_ARGUMENT_ARRAY(arrayOfZ);
|
112
|
+
zVertices = new double[FIX2INT(numberOfVertices)];
|
113
|
+
}
|
114
|
+
|
115
|
+
if (!NIL_P(arrayOfM)) {
|
116
|
+
CHECK_ARGUMENT_ARRAY(arrayOfM);
|
117
|
+
mVertices = new double[FIX2INT(numberOfVertices)];
|
118
|
+
}
|
119
|
+
|
120
|
+
if (!NIL_P(arrayOfPartStarts)) {
|
121
|
+
CHECK_ARGUMENT_ARRAY(arrayOfPartStarts);
|
122
|
+
nativeArrayOfPartStarts = new int[FIX2INT(numberOfParts)];
|
123
|
+
|
124
|
+
for (int i = 0; i < FIX2INT(numberOfParts); ++i) {
|
125
|
+
nativeArrayOfPartStarts[i] = FIX2INT(rb_ary_entry(arrayOfPartStarts, i));
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
if (!NIL_P(arrayOfPartTypes)) {
|
130
|
+
CHECK_ARGUMENT_ARRAY(arrayOfPartTypes);
|
131
|
+
nativeArrayOfPartTypes = new int[FIX2INT(numberOfParts)];
|
132
|
+
|
133
|
+
for (int i = 0; i < FIX2INT(numberOfParts); ++i) {
|
134
|
+
nativeArrayOfPartTypes[i] = FIX2INT(rb_ary_entry(arrayOfPartTypes, i));
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
SHPObject *object = SHPCreateObject(FIX2INT(shapeType),
|
139
|
+
FIX2INT(shapeIndex),
|
140
|
+
FIX2INT(numberOfParts),
|
141
|
+
nativeArrayOfPartStarts,
|
142
|
+
nativeArrayOfPartTypes,
|
143
|
+
FIX2INT(numberOfVertices),
|
144
|
+
xVertices,
|
145
|
+
yVertices,
|
146
|
+
zVertices,
|
147
|
+
mVertices);
|
148
|
+
|
149
|
+
delete [] xVertices;
|
150
|
+
delete [] yVertices;
|
151
|
+
|
152
|
+
if (zVertices) {
|
153
|
+
delete [] zVertices;
|
154
|
+
}
|
155
|
+
|
156
|
+
if (mVertices) {
|
157
|
+
delete [] mVertices;
|
158
|
+
}
|
159
|
+
|
160
|
+
if (nativeArrayOfPartStarts) {
|
161
|
+
delete [] nativeArrayOfPartStarts;
|
162
|
+
}
|
163
|
+
|
164
|
+
if (nativeArrayOfPartTypes) {
|
165
|
+
delete [] nativeArrayOfPartTypes;
|
166
|
+
}
|
167
|
+
|
168
|
+
if (object == NULL) {
|
169
|
+
SHP_FATAL("Failed to create shape object.");
|
170
|
+
return Qnil;
|
171
|
+
}
|
172
|
+
|
173
|
+
shape_object *shape = new shape_object(object);
|
174
|
+
|
175
|
+
return shape->wrapped();
|
176
|
+
}
|
177
|
+
|
178
|
+
|
179
|
+
VALUE shapefile::rewind_object(VALUE self, VALUE shapeObject) {
|
180
|
+
shapefile *file = unwrap(self);
|
181
|
+
shape_object *shape = shape_object::unwrap(shapeObject);
|
182
|
+
|
183
|
+
CHECK_VALID_HANDLE(file->value());
|
184
|
+
CHECK_VALID_HANDLE(shape->value());
|
185
|
+
|
186
|
+
if (shape == NULL) {
|
187
|
+
SHP_FATAL("You must specify a valid shape.");
|
188
|
+
return Qnil;
|
189
|
+
}
|
190
|
+
|
191
|
+
int result = SHPRewindObject(file->value(), shape->value());
|
192
|
+
|
193
|
+
return INT2FIX(result);
|
194
|
+
}
|
195
|
+
|
196
|
+
VALUE shapefile::get_info(VALUE self)
|
197
|
+
{
|
198
|
+
shapefile *file = unwrap(self);
|
199
|
+
|
200
|
+
CHECK_VALID_HANDLE(file->value());
|
201
|
+
|
202
|
+
int numberOfEntities = 0;
|
203
|
+
int shapeType = 0;
|
204
|
+
double minBounds[4];
|
205
|
+
double maxBounds[4];
|
206
|
+
|
207
|
+
SHPGetInfo(file->value(),
|
208
|
+
&numberOfEntities,
|
209
|
+
&shapeType,
|
210
|
+
minBounds,
|
211
|
+
maxBounds);
|
212
|
+
|
213
|
+
VALUE hash = rb_hash_new();
|
214
|
+
|
215
|
+
VALUE minBoundsAry = rb_ary_new();
|
216
|
+
VALUE maxBoundsAry = rb_ary_new();
|
217
|
+
|
218
|
+
rb_ary_push(minBoundsAry, rb_float_new(minBounds[0]));
|
219
|
+
rb_ary_push(minBoundsAry, rb_float_new(minBounds[1]));
|
220
|
+
rb_ary_push(minBoundsAry, rb_float_new(minBounds[2]));
|
221
|
+
rb_ary_push(minBoundsAry, rb_float_new(minBounds[3]));
|
222
|
+
|
223
|
+
rb_ary_push(maxBoundsAry, rb_float_new(maxBounds[0]));
|
224
|
+
rb_ary_push(maxBoundsAry, rb_float_new(maxBounds[1]));
|
225
|
+
rb_ary_push(maxBoundsAry, rb_float_new(maxBounds[2]));
|
226
|
+
rb_ary_push(maxBoundsAry, rb_float_new(maxBounds[3]));
|
227
|
+
|
228
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("number_of_entities")), INT2FIX(numberOfEntities));
|
229
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("shape_type")), INT2FIX(shapeType));
|
230
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("min_bounds")), minBoundsAry);
|
231
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("max_bounds")), maxBoundsAry);
|
232
|
+
|
233
|
+
return hash;
|
234
|
+
}
|
235
|
+
|
236
|
+
VALUE shapefile::read_object(VALUE self, VALUE shapeIndex)
|
237
|
+
{
|
238
|
+
CHECK_ARGUMENT_FIXNUM(shapeIndex);
|
239
|
+
|
240
|
+
shapefile *file = unwrap(self);
|
241
|
+
|
242
|
+
CHECK_VALID_HANDLE(file->value());
|
243
|
+
|
244
|
+
SHPObject *object = SHPReadObject(file->value(), FIX2INT(shapeIndex));
|
245
|
+
|
246
|
+
if (object == NULL) {
|
247
|
+
SHP_FATAL("Unable to read shape object.");
|
248
|
+
return Qnil;
|
249
|
+
}
|
250
|
+
|
251
|
+
shape_object *shape = new shape_object(object);
|
252
|
+
|
253
|
+
return shape->wrapped();
|
254
|
+
}
|
255
|
+
|
256
|
+
VALUE shapefile::write_object(VALUE self, VALUE shapeIndex, VALUE shapeObject)
|
257
|
+
{
|
258
|
+
CHECK_ARGUMENT_FIXNUM(shapeIndex);
|
259
|
+
|
260
|
+
shapefile *file = unwrap(self);
|
261
|
+
shape_object *object = shape_object::unwrap(shapeObject);
|
262
|
+
|
263
|
+
CHECK_VALID_HANDLE(file->value());
|
264
|
+
CHECK_VALID_HANDLE(object->value());
|
265
|
+
|
266
|
+
int result = SHPWriteObject(file->value(), FIX2INT(shapeIndex), object->value());
|
267
|
+
|
268
|
+
return INT2FIX(result);
|
269
|
+
}
|
270
|
+
|
271
|
+
VALUE shapefile::close(VALUE self)
|
272
|
+
{
|
273
|
+
shapefile *file = unwrap(self);
|
274
|
+
|
275
|
+
CHECK_VALID_HANDLE(file->value());
|
276
|
+
|
277
|
+
SHPClose(file->value());
|
278
|
+
|
279
|
+
file->_handle = 0;
|
280
|
+
|
281
|
+
return Qnil;
|
282
|
+
}
|
283
|
+
|
284
|
+
void shapefile::define(VALUE module)
|
285
|
+
{
|
286
|
+
shapefile::_klass = rb_define_class_under(module, "Shapefile", rb_cObject);
|
287
|
+
base::define(shapefile::_klass, false);
|
288
|
+
rb_define_singleton_method(shapefile::_klass, "create", SHP_METHOD(shapefile::create), 2);
|
289
|
+
rb_define_singleton_method(shapefile::_klass, "create_simple_object", SHP_METHOD(shapefile::create_simple_object), 5);
|
290
|
+
rb_define_singleton_method(shapefile::_klass, "create_object", SHP_METHOD(shapefile::create_simple_object), 10);
|
291
|
+
rb_define_method(shapefile::_klass, "write_object", SHP_METHOD(shapefile::write_object), 2);
|
292
|
+
rb_define_method(shapefile::_klass, "close", SHP_METHOD(shapefile::close), 0);
|
293
|
+
rb_define_method(shapefile::_klass, "get_info", SHP_METHOD(shapefile::get_info), 0);
|
294
|
+
rb_define_method(shapefile::_klass, "read_object", SHP_METHOD(shapefile::read_object), 1);
|
295
|
+
rb_define_method(shapefile::_klass, "rewind_object", SHP_METHOD(shapefile::rewind_object), 1);
|
296
|
+
}
|
297
|
+
|
298
|
+
}
|
299
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#ifndef __SHP_SHAPEFILE_HPP__
|
2
|
+
#define __SHP_SHAPEFILE_HPP__
|
3
|
+
|
4
|
+
#include "shp.hpp"
|
5
|
+
#include "base.hpp"
|
6
|
+
|
7
|
+
namespace shp {
|
8
|
+
class shapefile : public base<shapefile> {
|
9
|
+
public:
|
10
|
+
shapefile() : base<shapefile>(), _handle(0) {};
|
11
|
+
shapefile(SHPHandle handle);
|
12
|
+
static void define(VALUE module);
|
13
|
+
static VALUE create(VALUE klass, VALUE filename, VALUE shapeType);
|
14
|
+
static VALUE create_simple_object(VALUE klass, VALUE shapeType, VALUE numberOfVertices, VALUE arrayOfX, VALUE arrayOfY, VALUE arrayOfZ);
|
15
|
+
static VALUE create_object(VALUE klass, VALUE shapeType, VALUE shapeIndex, VALUE numberOfParts,
|
16
|
+
VALUE arrayOfPartStarts, VALUE arrayOfPartTypes, VALUE numberOfVertices,
|
17
|
+
VALUE arrayOfX, VALUE arrayOfY, VALUE arrayOfZ, VALUE arrayOfM);
|
18
|
+
static VALUE write_object(VALUE self, VALUE shapeIndex, VALUE shapeObject);
|
19
|
+
static VALUE close(VALUE self);
|
20
|
+
static VALUE get_info(VALUE self);
|
21
|
+
static VALUE read_object(VALUE self, VALUE shapeIndex);
|
22
|
+
static VALUE rewind_object(VALUE self, VALUE shapeObject);
|
23
|
+
|
24
|
+
virtual VALUE klass();
|
25
|
+
static VALUE _klass;
|
26
|
+
|
27
|
+
SHPHandle value() { return _handle; }
|
28
|
+
|
29
|
+
virtual ~shapefile();
|
30
|
+
private:
|
31
|
+
SHPHandle _handle;
|
32
|
+
};
|
33
|
+
}
|
34
|
+
|
35
|
+
#endif
|