shp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +34 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +28 -0
  6. data/README.md +30 -0
  7. data/Rakefile +23 -0
  8. data/ext/shp/base.hpp +113 -0
  9. data/ext/shp/dbf.cpp +381 -0
  10. data/ext/shp/dbf.hpp +44 -0
  11. data/ext/shp/extconf.rb +13 -0
  12. data/ext/shp/shape_object.cpp +58 -0
  13. data/ext/shp/shape_object.hpp +27 -0
  14. data/ext/shp/shapefile.cpp +299 -0
  15. data/ext/shp/shapefile.hpp +35 -0
  16. data/ext/shp/shapelib/.cvsignore +15 -0
  17. data/ext/shp/shapelib/ChangeLog +450 -0
  18. data/ext/shp/shapelib/HOWTO-RELEASE +16 -0
  19. data/ext/shp/shapelib/LICENSE.LGPL +483 -0
  20. data/ext/shp/shapelib/Makefile +113 -0
  21. data/ext/shp/shapelib/README +41 -0
  22. data/ext/shp/shapelib/README.tree +172 -0
  23. data/ext/shp/shapelib/contrib/.cvsignore +12 -0
  24. data/ext/shp/shapelib/contrib/Makefile +66 -0
  25. data/ext/shp/shapelib/contrib/ShapeFileII.pas +234 -0
  26. data/ext/shp/shapelib/contrib/Shape_PointInPoly.cpp +238 -0
  27. data/ext/shp/shapelib/contrib/Shape_PointInPoly_README.txt +59 -0
  28. data/ext/shp/shapelib/contrib/csv2shp.c +558 -0
  29. data/ext/shp/shapelib/contrib/dbfcat.c +166 -0
  30. data/ext/shp/shapelib/contrib/dbfinfo.c +106 -0
  31. data/ext/shp/shapelib/contrib/makefile.vc +34 -0
  32. data/ext/shp/shapelib/contrib/my_nan.h +46 -0
  33. data/ext/shp/shapelib/contrib/shpcat.c +100 -0
  34. data/ext/shp/shapelib/contrib/shpcentrd.c +159 -0
  35. data/ext/shp/shapelib/contrib/shpdata.c +129 -0
  36. data/ext/shp/shapelib/contrib/shpdxf.c +340 -0
  37. data/ext/shp/shapelib/contrib/shpfix.c +110 -0
  38. data/ext/shp/shapelib/contrib/shpgeo.c +1595 -0
  39. data/ext/shp/shapelib/contrib/shpgeo.h +154 -0
  40. data/ext/shp/shapelib/contrib/shpinfo.c +113 -0
  41. data/ext/shp/shapelib/contrib/shpproj.c +260 -0
  42. data/ext/shp/shapelib/contrib/shpsort.c +605 -0
  43. data/ext/shp/shapelib/contrib/shpsort.txt +44 -0
  44. data/ext/shp/shapelib/contrib/shpwkb.c +123 -0
  45. data/ext/shp/shapelib/contrib/tests/shpproj.sh +38 -0
  46. data/ext/shp/shapelib/dbfopen.c +2221 -0
  47. data/ext/shp/shapelib/makefile.vc +86 -0
  48. data/ext/shp/shapelib/makeshape.sh +21 -0
  49. data/ext/shp/shapelib/mkdist.sh +37 -0
  50. data/ext/shp/shapelib/mkinstalldirs +38 -0
  51. data/ext/shp/shapelib/mkrelease.sh +55 -0
  52. data/ext/shp/shapelib/safileio.c +286 -0
  53. data/ext/shp/shapelib/shapefil.h +647 -0
  54. data/ext/shp/shapelib/shapelib.def +46 -0
  55. data/ext/shp/shapelib/shpopen.c +2388 -0
  56. data/ext/shp/shapelib/shptree.c +1187 -0
  57. data/ext/shp/shapelib/shputils.c +1072 -0
  58. data/ext/shp/shapelib/stream1.out +1465 -0
  59. data/ext/shp/shapelib/stream1.sh +28 -0
  60. data/ext/shp/shapelib/stream2.out +530 -0
  61. data/ext/shp/shapelib/stream2.sh +11 -0
  62. data/ext/shp/shapelib/stream3.out +37 -0
  63. data/ext/shp/shapelib/web/.cvsignore +2 -0
  64. data/ext/shp/shapelib/web/codepage.html +403 -0
  65. data/ext/shp/shapelib/web/dbf_api.html +436 -0
  66. data/ext/shp/shapelib/web/index.html +235 -0
  67. data/ext/shp/shapelib/web/license.html +78 -0
  68. data/ext/shp/shapelib/web/manifest.html +87 -0
  69. data/ext/shp/shapelib/web/release.html +80 -0
  70. data/ext/shp/shapelib/web/shapelib-tools.html +352 -0
  71. data/ext/shp/shapelib/web/shp_api.html +376 -0
  72. data/ext/shp/shp.cpp +19 -0
  73. data/ext/shp/shp.hpp +47 -0
  74. data/lib/shp.rb +35 -0
  75. data/lib/shp/version.rb +3 -0
  76. data/shp.gemspec +23 -0
  77. data/spec/shp_spec.rb +127 -0
  78. metadata +176 -0
@@ -0,0 +1,376 @@
1
+ <html>
2
+ <head>
3
+ <title>.SHP File API</title>
4
+ </head>
5
+ <body>
6
+
7
+ <h1>.SHP File API</h1>
8
+
9
+ The .SHP API uses a SHPHandle to represent an open .shp/.shx file pair.
10
+ The contents of the SHPHandle are visible (see shapefile.h) but should
11
+ be ignored by the application. It is intended that all information be
12
+ accessed by the API functions. <p>
13
+
14
+ <!-------------------------------------------------------------------------->
15
+
16
+ <h2>Shape Types</h2>
17
+
18
+ Shapes have types associated with them. The following is a list of the
19
+ different shapetypes supported by Shapefiles. At this time all shapes in
20
+ a Shapefile must be of the same type (with the exception of NULL shapes). <p>
21
+
22
+ <pre>
23
+ #define SHPT_NULL 0
24
+
25
+ 2D Shape Types (pre ArcView 3.x):
26
+
27
+ #define SHPT_POINT 1 Points
28
+ #define SHPT_ARC 3 Arcs (Polylines, possible in parts)
29
+ #define SHPT_POLYGON 5 Polygons (possible in parts)
30
+ #define SHPT_MULTIPOINT 8 MultiPoint (related points)
31
+
32
+ 3D Shape Types (may include "measure" values for vertices):
33
+
34
+ #define SHPT_POINTZ 11
35
+ #define SHPT_ARCZ 13
36
+ #define SHPT_POLYGONZ 15
37
+ #define SHPT_MULTIPOINTZ 18
38
+
39
+ 2D + Measure Types:
40
+
41
+ #define SHPT_POINTM 21
42
+ #define SHPT_ARCM 23
43
+ #define SHPT_POLYGONM 25
44
+ #define SHPT_MULTIPOINTM 28
45
+
46
+ Complex (TIN-like) with Z, and Measure:
47
+
48
+ #define SHPT_MULTIPATCH 31
49
+ </pre>
50
+
51
+ <!-------------------------------------------------------------------------->
52
+
53
+ <h2>SHPObject</h2>
54
+
55
+ An individual shape is represented by the SHPObject structure. SHPObject's
56
+ created with SHPCreateObject(), SHPCreateSimpleObject(), or SHPReadObject()
57
+ should be disposed of with SHPDestroyObject().<p>
58
+
59
+ <pre>
60
+ typedef struct
61
+ {
62
+ int nSHPType; Shape Type (SHPT_* - see list above)
63
+
64
+ int nShapeId; Shape Number (-1 is unknown/unassigned)
65
+
66
+ int nParts; # of Parts (0 implies single part with no info)
67
+ int *panPartStart; Start Vertex of part
68
+ int *panPartType; Part Type (SHPP_RING if not SHPT_MULTIPATCH)
69
+
70
+ int nVertices; Vertex list
71
+ double *padfX;
72
+ double *padfY;
73
+ double *padfZ; (all zero if not provided)
74
+ double *padfM; (all zero if not provided)
75
+
76
+ double dfXMin; Bounds in X, Y, Z and M dimensions
77
+ double dfYMin;
78
+ double dfZMin;
79
+ double dfMMin;
80
+
81
+ double dfXMax;
82
+ double dfYMax;
83
+ double dfZMax;
84
+ double dfMMax;
85
+ } SHPObject;
86
+ </pre>
87
+
88
+ <!-------------------------------------------------------------------------->
89
+
90
+ <h2>SHPOpen()</h2>
91
+
92
+ <pre>
93
+ SHPHandle SHPOpen( const char * pszShapeFile, const char * pszAccess );
94
+
95
+ pszShapeFile: The name of the layer to access. This can be the
96
+ name of either the .shp or the .shx file or can
97
+ just be the path plus the basename of the pair.
98
+
99
+ pszAccess: The fopen() style access string. At this time only
100
+ "rb" (read-only binary) and "rb+" (read/write binary)
101
+ should be used.
102
+ </pre>
103
+
104
+ The SHPOpen() function should be used to establish access to the two files
105
+ for accessing vertices (.shp and .shx). Note that both files have to
106
+ be in the indicated directory, and must have the expected extensions in
107
+ lower case. The returned SHPHandle is passed to other access functions,
108
+ and SHPClose() should be invoked to recover resources, and flush changes
109
+ to disk when complete.<p>
110
+
111
+ <!-------------------------------------------------------------------------->
112
+
113
+ <h2>SHPGetInfo()</h2>
114
+
115
+ <pre>
116
+ void SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,
117
+ double * padfMinBound, double * padfMaxBound );
118
+
119
+ hSHP: The handle previously returned by SHPOpen()
120
+ or SHPCreate().
121
+
122
+ pnEntities: A pointer to an integer into which the number of
123
+ entities/structures should be placed. May be NULL.
124
+
125
+ pnShapetype: A pointer to an integer into which the shapetype
126
+ of this file should be placed. Shapefiles may contain
127
+ either SHPT_POINT, SHPT_ARC, SHPT_POLYGON or
128
+ SHPT_MULTIPOINT entities. This may be NULL.
129
+
130
+ padfMinBound: The X, Y, Z and M minimum values will be placed into
131
+ this four entry array. This may be NULL.
132
+
133
+ padfMaxBound: The X, Y, Z and M maximum values will be placed into
134
+ this four entry array. This may be NULL.
135
+ </pre>
136
+
137
+ The SHPGetInfo() function retrieves various information about shapefile
138
+ as a whole. The bounds are read from the file header, and may be
139
+ inaccurate if the file was improperly generated. <p>
140
+
141
+ <!-------------------------------------------------------------------------->
142
+
143
+ <h2>SHPReadObject()</h2>
144
+
145
+ <pre>
146
+ SHPObject *SHPReadObject( SHPHandle hSHP, int iShape );
147
+
148
+ hSHP: The handle previously returned by SHPOpen()
149
+ or SHPCreate().
150
+
151
+ iShape: The entity number of the shape to read. Entity
152
+ numbers are between 0 and nEntities-1 (as returned
153
+ by SHPGetInfo()).
154
+ </pre>
155
+
156
+ The SHPReadObject() call is used to read a single structure, or entity
157
+ from the shapefile. See the definition of the SHPObject structure for
158
+ detailed information on fields of a SHPObject. SHPObject's returned from
159
+ SHPReadObject() should be deallocated with SHPDestroyShape().
160
+ SHPReadObject() will return NULL if an illegal iShape value is requested.<p>
161
+
162
+ Note that the bounds placed into the SHPObject are those read from the
163
+ file, and may not be correct. For points the bounds are generated from
164
+ the single point since bounds aren't normally provided for point types.<p>
165
+
166
+ Generally the shapes returned will be of the type of the file as a whole.
167
+ However, any file may also contain type SHPT_NULL shapes which will have
168
+ no geometry. Generally speaking applications should skip rather than
169
+ preserve them, as they usually represented interactively deleted shapes.<p>
170
+
171
+ <!-------------------------------------------------------------------------->
172
+
173
+ <h2>SHPClose()</h2>
174
+
175
+ <pre>
176
+ void SHPClose( SHPHandle hSHP );
177
+
178
+ hSHP: The handle previously returned by SHPOpen()
179
+ or SHPCreate().
180
+ </pre>
181
+
182
+ The SHPClose() function will close the .shp and .shx files, and flush
183
+ all outstanding header information to the files. It will also recover
184
+ resources associated with the handle. After this call the hSHP handle
185
+ cannot be used again.<p>
186
+
187
+ <!-------------------------------------------------------------------------->
188
+
189
+ <h2>SHPCreate()</h2>
190
+
191
+ <pre>
192
+ SHPHandle SHPCreate( const char * pszShapeFile, int nShapeType );
193
+
194
+ pszShapeFile: The name of the layer to access. This can be the
195
+ name of either the .shp or the .shx file or can
196
+ just be the path plus the basename of the pair.
197
+
198
+ nShapeType: The type of shapes to be stored in the newly created
199
+ file. It may be either SHPT_POINT, SHPT_ARC,
200
+ SHPT_POLYGON or SHPT_MULTIPOINT.
201
+ </pre>
202
+
203
+ The SHPCreate() function will create a new .shp and .shx file of the
204
+ desired type.<p>
205
+
206
+ <!-------------------------------------------------------------------------->
207
+
208
+ <h2>SHPCreateSimpleObject()</h2>
209
+
210
+ <pre>
211
+ SHPObject *
212
+ SHPCreateSimpleObject( int nSHPType, int nVertices,
213
+ double *padfX, double * padfY, double *padfZ, );
214
+
215
+ nSHPType: The SHPT_ type of the object to be created, such
216
+ as SHPT_POINT, or SHPT_POLYGON.
217
+
218
+ nVertices: The number of vertices being passed in padfX,
219
+ padfY, and padfZ.
220
+
221
+ padfX: An array of nVertices X coordinates of the vertices
222
+ for this object.
223
+
224
+ padfY: An array of nVertices Y coordinates of the vertices
225
+ for this object.
226
+
227
+ padfZ: An array of nVertices Z coordinates of the vertices
228
+ for this object. This may be NULL in which case
229
+ they are all assumed to be zero.
230
+ </pre>
231
+
232
+ The SHPCreateSimpleObject() allows for the convenient creation of
233
+ simple objects. This is normally used so that the SHPObject can be
234
+ passed to SHPWriteObject() to write it to the file. The simple object
235
+ creation API assumes an M (measure) value of zero for each vertex. For
236
+ complex objects (such as polygons) it is assumed that there is only one
237
+ part, and that it is of the default type (SHPP_RING). <p>
238
+
239
+ Use the SHPCreateObject() function for more sophisticated objects. The
240
+ SHPDestroyObject() function should be used to free resources associated with
241
+ an object allocated with SHPCreateSimpleObject(). <p>
242
+
243
+ This function computes a bounding box for the SHPObject from the given
244
+ vertices.<p>
245
+
246
+ <!-------------------------------------------------------------------------->
247
+
248
+ <h2>SHPCreateObject()</h2>
249
+
250
+ <pre>
251
+ SHPObject *
252
+ SHPCreateObject( int nSHPType, int iShape,
253
+ int nParts, int * panPartStart, int * panPartType,
254
+ int nVertices, double *padfX, double * padfY,
255
+ double *padfZ, double *padfM );
256
+
257
+ nSHPType: The SHPT_ type of the object to be created, such
258
+ as SHPT_POINT, or SHPT_POLYGON.
259
+
260
+ iShape: The shapeid to be recorded with this shape.
261
+
262
+ nParts: The number of parts for this object. If this is
263
+ zero for ARC, or POLYGON type objects, a single
264
+ zero valued part will be created internally.
265
+
266
+ panPartStart: The list of zero based start vertices for the rings
267
+ (parts) in this object. The first should always be
268
+ zero. This may be NULL if nParts is 0.
269
+
270
+ panPartType: The type of each of the parts. This is only meaningful
271
+ for MULTIPATCH files. For all other cases this may
272
+ be NULL, and will be assumed to be SHPP_RING.
273
+
274
+ nVertices: The number of vertices being passed in padfX,
275
+ padfY, and padfZ.
276
+
277
+ padfX: An array of nVertices X coordinates of the vertices
278
+ for this object.
279
+
280
+ padfY: An array of nVertices Y coordinates of the vertices
281
+ for this object.
282
+
283
+ padfZ: An array of nVertices Z coordinates of the vertices
284
+ for this object. This may be NULL in which case
285
+ they are all assumed to be zero.
286
+
287
+ padfM: An array of nVertices M (measure values) of the
288
+ vertices for this object. This may be NULL in which
289
+ case they are all assumed to be zero.
290
+ </pre>
291
+
292
+ The SHPCreateSimpleObject() allows for the creation of objects (shapes).
293
+ This is normally used so that the SHPObject can be passed to
294
+ SHPWriteObject() to write it to the file. <p>
295
+
296
+ The SHPDestroyObject() function should be used to free resources associated
297
+ with an object allocated with SHPCreateObject(). <p>
298
+
299
+ This function computes a bounding box for the SHPObject from the given
300
+ vertices.<p>
301
+
302
+ <!-------------------------------------------------------------------------->
303
+
304
+ <h2>SHPComputeExtents()</h2>
305
+
306
+ <pre>
307
+ void SHPComputeExtents( SHPObject * psObject );
308
+
309
+ psObject: An existing shape object to be updated in place.
310
+ </pre>
311
+
312
+ This function will recompute the extents of this shape, replacing the
313
+ existing values of the dfXMin, dfYMin, dfZMin, dfMMin, dfXMax, dfYMax,
314
+ dfZMax, and dfMMax values based on the current set of vertices for the
315
+ shape. This function is automatically called by SHPCreateObject() but
316
+ if the vertices of an existing object are altered it should be called again
317
+ to fix up the extents.<p>
318
+
319
+ <!-------------------------------------------------------------------------->
320
+
321
+ <h2>SHPWriteObject()</h2>
322
+
323
+ <pre>
324
+ int SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject *psObject );
325
+
326
+ hSHP: The handle previously returned by SHPOpen("r+")
327
+ or SHPCreate().
328
+
329
+ iShape: The entity number of the shape to write. A value of
330
+ -1 should be used for new shapes.
331
+
332
+ psObject: The shape to write to the file. This should have
333
+ been created with SHPCreateObject(), or
334
+ SHPCreateSimpleObject().
335
+ </pre>
336
+
337
+ The SHPWriteObject() call is used to write a single structure, or entity
338
+ to the shapefile. See the definition of the SHPObject structure for
339
+ detailed information on fields of a SHPObject. The return value is the
340
+ entity number of the written shape. <p>
341
+
342
+ <!-------------------------------------------------------------------------->
343
+
344
+ <h2>SHPDestroyObject()</h2>
345
+
346
+ <pre>
347
+ void SHPDestroyObject( SHPObject *psObject );
348
+
349
+ psObject: The object to deallocate.
350
+ </pre>
351
+
352
+ This function should be used to deallocate the resources associated with
353
+ a SHPObject when it is no longer needed, including those created with
354
+ SHPCreateSimpleObject(), SHPCreateObject() and returned from SHPReadObject().
355
+ <p>
356
+
357
+ <!-------------------------------------------------------------------------->
358
+
359
+ <h2>SHPRewindObject()</h2>
360
+
361
+ <pre>
362
+ int SHPRewindObject( SHPHandle hSHP, SHPObject *psObject );
363
+
364
+ hSHP: The shapefile (not used at this time).
365
+ psObject: The object to deallocate.
366
+ </pre>
367
+
368
+ This function will reverse any rings necessary in order to enforce the
369
+ shapefile restrictions on the required order of inner and outer rings in
370
+ the Shapefile specification. It returns TRUE if a change is made and FALSE
371
+ if no change is made. Only polygon objects will be affected though any
372
+ object may be passed.
373
+ <p>
374
+
375
+ </body>
376
+ </html>
data/ext/shp/shp.cpp ADDED
@@ -0,0 +1,19 @@
1
+ #include "ruby.h"
2
+ #include <string>
3
+ #include <iostream>
4
+
5
+ #include "shp.hpp"
6
+ #include "shapefile.hpp"
7
+ #include "dbf.hpp"
8
+ #include "shape_object.hpp"
9
+
10
+ VALUE cSHP;
11
+
12
+ extern "C" {
13
+ void Init_shp() {
14
+ cSHP = rb_define_module("SHP");
15
+ shp::shapefile::define(cSHP);
16
+ shp::dbf::define(cSHP);
17
+ shp::shape_object::define(cSHP);
18
+ }
19
+ }
data/ext/shp/shp.hpp ADDED
@@ -0,0 +1,47 @@
1
+ #ifndef __SHP_HPP__
2
+ #define __SHP_HPP__
3
+
4
+ #include "ruby.h"
5
+ #include <string>
6
+ #include <iostream>
7
+ #include <shapefil.h>
8
+
9
+ using namespace std;
10
+
11
+ typedef VALUE (*RB_INSTANCE_METHOD)(...);
12
+
13
+ #define SHP_FATAL(msg) rb_raise(rb_eRuntimeError, msg)
14
+ #define SHP_FATAL_ARGUMENT(msg) rb_raise(rb_eArgError, msg)
15
+ #define SHP_METHOD(method) ((RB_INSTANCE_METHOD)&method)
16
+
17
+ #define CHECK_ARGUMENT_STRING(arg) \
18
+ if (TYPE(arg) != T_STRING) { \
19
+ SHP_FATAL_ARGUMENT("Argument must be a String"); \
20
+ return Qnil; \
21
+ }
22
+
23
+ #define CHECK_ARGUMENT_FIXNUM(arg) \
24
+ if (TYPE(arg) != T_FIXNUM) { \
25
+ SHP_FATAL_ARGUMENT("Argument must be a FixNum"); \
26
+ return Qnil; \
27
+ }
28
+
29
+ #define CHECK_ARGUMENT_FLOAT(arg) \
30
+ if (TYPE(arg) != T_FLOAT) { \
31
+ SHP_FATAL_ARGUMENT("Argument must be a Float"); \
32
+ return Qnil; \
33
+ }
34
+
35
+ #define CHECK_ARGUMENT_ARRAY(arg) \
36
+ if (TYPE(arg) != T_ARRAY) { \
37
+ SHP_FATAL_ARGUMENT("Argument must be an Array"); \
38
+ return Qnil; \
39
+ }
40
+
41
+ #define CHECK_VALID_HANDLE(handle) \
42
+ if (handle == NULL) { \
43
+ SHP_FATAL("Invalid object reference. Has it already been destroyed?"); \
44
+ return Qnil; \
45
+ }
46
+
47
+ #endif
data/lib/shp.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'shp/version'
2
+ require 'shp/shp'
3
+
4
+ module SHP
5
+ SHPT_NULL = 0
6
+ SHPT_POINT = 1
7
+ SHPT_ARC = 3
8
+ SHPT_POLYGON = 5
9
+ SHPT_MULTIPOINT = 8
10
+ SHPT_POINTZ = 11
11
+ SHPT_ARCZ = 13
12
+ SHPT_POLYGONZ = 15
13
+ SHPT_MULTIPOINTZ = 18
14
+ SHPT_POINTM = 21
15
+ SHPT_ARCM = 23
16
+ SHPT_POLYGONM = 25
17
+ SHPT_MULTIPOINTM = 28
18
+ SHPT_MULTIPATCH = 31
19
+
20
+ class DBF
21
+ FT_STRING = 0
22
+ FT_INTEGER = 1
23
+ FT_DOUBLE = 2
24
+ FT_LOGICAL = 3
25
+ FT_INVALID = 4
26
+
27
+ FT_NATIVE_TYPE_STRING = 'C'
28
+ FT_NATIVE_TYPE_INTEGER = 'N'
29
+ FT_NATIVE_TYPE_DOUBLE = 'N'
30
+ FT_NATIVE_TYPE_LOGICAL = 'L'
31
+ FT_NATIVE_TYPE_MEMO = 'M'
32
+ FT_NATIVE_TYPE_DATE = 'D'
33
+ FT_NATIVE_TYPE_INVALID = ''
34
+ end
35
+ end