shp 0.0.1

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.
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,113 @@
1
+
2
+ PREFIX = /usr/local
3
+ CFLAGS = -g -Wall -fPIC
4
+ #CFLAGS = -g -DUSE_CPL
5
+ #CC = g++
6
+
7
+ LIBOBJ = shpopen.o dbfopen.o safileio.o shptree.o
8
+ SHPBIN = shpcreate shpadd shpdump shprewind dbfcreate dbfadd dbfdump \
9
+ shptreedump
10
+
11
+ default: all
12
+
13
+ all: $(SHPBIN) shptest lib
14
+
15
+ shpopen.o: shpopen.c shapefil.h
16
+ $(CC) $(CFLAGS) -c shpopen.c
17
+
18
+ shptree.o: shptree.c shapefil.h
19
+ $(CC) $(CFLAGS) -c shptree.c
20
+
21
+ dbfopen.o: dbfopen.c shapefil.h
22
+ $(CC) $(CFLAGS) -c dbfopen.c
23
+
24
+ safileio.o: safileio.c shapefil.h
25
+ $(CC) $(CFLAGS) -c safileio.c
26
+
27
+ shpcreate: shpcreate.c shpopen.o safileio.o
28
+ $(CC) $(CFLAGS) shpcreate.c shpopen.o safileio.o $(LINKOPT) -o shpcreate
29
+
30
+ shpadd: shpadd.c shpopen.o safileio.o
31
+ $(CC) $(CFLAGS) shpadd.c shpopen.o safileio.o $(LINKOPT) -o shpadd
32
+
33
+ shpdump: shpdump.c shpopen.o safileio.o
34
+ $(CC) $(CFLAGS) shpdump.c shpopen.o safileio.o $(LINKOPT) -o shpdump
35
+
36
+ shprewind: shprewind.c shpopen.o safileio.o
37
+ $(CC) $(CFLAGS) shprewind.c shpopen.o safileio.o $(LINKOPT) -o shprewind
38
+
39
+ dbfcreate: dbfcreate.c dbfopen.o safileio.o
40
+ $(CC) $(CFLAGS) dbfcreate.c dbfopen.o safileio.o $(LINKOPT) -o dbfcreate
41
+
42
+ dbfadd: dbfadd.c dbfopen.o safileio.o
43
+ $(CC) $(CFLAGS) dbfadd.c dbfopen.o safileio.o $(LINKOPT) -o dbfadd
44
+
45
+ dbfdump: dbfdump.c dbfopen.o safileio.o
46
+ $(CC) $(CFLAGS) dbfdump.c dbfopen.o safileio.o $(LINKOPT) -o dbfdump
47
+
48
+ shptest: shptest.c shpopen.o safileio.o
49
+ $(CC) $(CFLAGS) shptest.c shpopen.o safileio.o $(LINKOPT) -o shptest
50
+
51
+ shputils: shputils.c shpopen.o safileio.o dbfopen.o
52
+ $(CC) $(CFLAGS) shputils.c shpopen.o safileio.o dbfopen.o $(LINKOPT) -o shputils
53
+
54
+ shptreedump: shptreedump.c shptree.o shpopen.o safileio.o
55
+ $(CC) $(CFLAGS) shptreedump.c shptree.o shpopen.o safileio.o $(LINKOPT) \
56
+ -o shptreedump
57
+
58
+ clean:
59
+ rm -f *.o shptest $(SHPBIN) libshp.a
60
+
61
+ test: test2 test3
62
+
63
+ #
64
+ # Note this stream only works if example data is accessable.
65
+ # Fetch ftp://gdal.velocet.ca/pub/outgoing/shape_eg_data.zip
66
+ #
67
+ test1:
68
+ @./stream1.sh > s1.out
69
+ @if test "`diff s1.out stream1.out`" = '' ; then \
70
+ echo "******* Stream 1 Succeeded *********"; \
71
+ rm s1.out; \
72
+ else \
73
+ echo "******* Stream 1 Failed *********"; \
74
+ diff s1.out stream1.out; \
75
+ fi
76
+
77
+ test2:
78
+ @./stream2.sh > s2.out
79
+ @if test "`diff s2.out stream2.out`" = '' ; then \
80
+ echo "******* Stream 2 Succeeded *********"; \
81
+ rm s2.out; \
82
+ rm test*.s??; \
83
+ else \
84
+ echo "******* Stream 2 Failed *********"; \
85
+ diff s2.out stream2.out; \
86
+ fi
87
+
88
+ test3:
89
+ @./makeshape.sh > s3.out
90
+ @if test "`diff s3.out stream3.out`" = '' ; then \
91
+ echo "******* Stream 3 Succeeded *********"; \
92
+ rm s3.out; \
93
+ rm test.*; \
94
+ else \
95
+ echo "******* Stream 3 Failed *********"; \
96
+ diff s3.out stream3.out; \
97
+ fi
98
+
99
+
100
+ lib: libshp.a
101
+
102
+ libshp.a: $(LIBOBJ)
103
+ ar r libshp.a $(LIBOBJ)
104
+
105
+ lib_install: libshp.a
106
+ cp libshp.a $(PREFIX)/lib
107
+ cp shapefil.h $(PREFIX)/include
108
+
109
+ bin_install: $(SHPBIN)
110
+ cp $(SHPBIN) $(PREFIX)/bin
111
+
112
+ install: lib_install bin_install
113
+
@@ -0,0 +1,41 @@
1
+
2
+ Please read shapelib.html.
3
+
4
+ Building on Unix
5
+ ----------------
6
+
7
+ 1) Edit Makefile, and set CFLAGS, and CC macros as required for the
8
+ target system. Often the defaults will work fine.
9
+
10
+ 2) type "make"
11
+
12
+ The result should be:
13
+
14
+ Core shapelib support.
15
+ shpopen.o
16
+ dbfopen.o
17
+ safileio.o
18
+ shptree.o
19
+ libshp.a
20
+
21
+ Utility/demonstration programs:
22
+ shpcreate, shpdump, shpadd, dbfcreate, dbfdump, dbfadd, shptreedump
23
+
24
+ 3) To test type:
25
+ make test
26
+
27
+ 4) To libshp.a and the test binaries in /usr/local:
28
+ make install
29
+
30
+
31
+ Building on Windows
32
+ -------------------
33
+
34
+ If you have run the VC++ VCVARS32.BAT, you should be able to type the
35
+ following in a command window to build the code and executables:
36
+
37
+ C:> nmake /f makefile.vc
38
+
39
+ Otherwise create your own VC++ project. There aren't many files to deal with
40
+ here!
41
+
@@ -0,0 +1,172 @@
1
+ Venkat,
2
+
3
+ I have completed the planned Shapefile quadtree mechanism. The additions
4
+ to the traditional Shapelib are found in shptree.c (functions supporting
5
+ quad tree searching and query). There are also some new prototypes for
6
+ the tree stuff in shapefil.h ... including some prototypes for functions
7
+ you don't require and hence that I haven't implemented at this time.
8
+
9
+ I have also prepared a demonstration program using the API. That is
10
+ the ``shpdumptree'' program, with the source code in shpdumptree.c. The
11
+ shpdumptree program has two functions. One is to dump an ASCII rendering
12
+ of the internal quadtree, and the other is example use of a quad tree
13
+ searching function.
14
+
15
+ Dumping the Tree
16
+ ----------------
17
+
18
+ The tree dumping is done as shown below. The "-maxdepth" commandline
19
+ switch can be used to control the maximum depth, otherwise it internally
20
+ computes a ``reasonable depth'' to use based on the number of structures
21
+ in the shapefile.
22
+
23
+ warmerda@gdal[207]% shptreedump -maxdepth 6 eg_data/polygon.shp
24
+ ( SHPTreeNode
25
+ Min = (471127.19,4751545.00)
26
+ Max = (489292.31,4765610.50)
27
+ Shapes(0):
28
+ ( SHPTreeNode
29
+ Min = (471127.19,4751545.00)
30
+ Max = (481118.01,4765610.50)
31
+ Shapes(0):
32
+ ( SHPTreeNode
33
+ Min = (471127.19,4751545.00)
34
+ Max = (481118.01,4759281.03)
35
+ Shapes(0):
36
+ ( SHPTreeNode
37
+ Min = (471127.19,4751545.00)
38
+ Max = (476622.14,4759281.03)
39
+ Shapes(0):
40
+ ( SHPTreeNode
41
+ Min = (471127.19,4751545.00)
42
+ Max = (476622.14,4755799.81)
43
+ Shapes(0):
44
+ ( SHPTreeNode
45
+ Min = (471127.19,4751545.00)
46
+ Max = (474149.41,4755799.81)
47
+ Shapes(6): 395 397 402 404 405 422
48
+ )
49
+ ( SHPTreeNode
50
+ Min = (473599.92,4751545.00)
51
+ Max = (476622.14,4755799.81)
52
+ Shapes(10): 392 394 403 413 414 417 426 433 434 447
53
+ )
54
+ )
55
+ ...
56
+
57
+ A structure like the following represents one node in the tree. In
58
+ this case it cover the region of 473599.92 < X < 476622.14,and
59
+ 4751545.0 < Y < 4755799.81. There are ten shapes within this region
60
+ who's shapeids are 392, 394 ... 447. This node has no children nodes.
61
+
62
+ ( SHPTreeNode
63
+ Min = (473599.92,4751545.00)
64
+ Max = (476622.14,4755799.81)
65
+ Shapes(10): 392 394 403 413 414 417 426 433 434 447
66
+ )
67
+
68
+ The heirarchy of indentation is intended to show the parent, child
69
+ relationship between nodes, with the tree being deeper the further to the
70
+ right you go.
71
+
72
+ The `-v' flag to the program can be used to expand the report to include
73
+ the full information about shapes, not just their shapeid. This can result
74
+ in a report looking more like this:
75
+
76
+ ...
77
+ ( SHPTreeNode
78
+ Min = (478095.78,4751545.00)
79
+ Max = (481118.01,4755799.81)
80
+ Shapes(3):
81
+ ( Shape
82
+ ShapeId = 448
83
+ Min = (479988.09,4753300.00)
84
+ Max = (480705.59,4754236.50)
85
+ Vertex[0] = (480136.59,4754174.50)
86
+ Vertex[1] = (480229.97,4754182.00)
87
+ Vertex[2] = (480370.09,4754200.50)
88
+ Vertex[3] = (480695.12,4754236.50)
89
+ Vertex[4] = (480687.97,4754129.50)
90
+ Vertex[5] = (480650.47,4754075.50)
91
+ Vertex[6] = (480520.62,4753948.00)
92
+ Vertex[7] = (480490.00,4753900.00)
93
+ Vertex[8] = (480499.78,4753840.50)
94
+ Vertex[9] = (480500.97,4753820.50)
95
+ Vertex[10] = (480534.75,4753660.50)
96
+ Vertex[11] = (480560.00,4753565.00)
97
+ Vertex[12] = (480574.91,4753550.50)
98
+ ...
99
+
100
+ While it is possible to part the output of the shptreedump program, and
101
+ insert it into your database, my intention was that the shptreedump program
102
+ would serve as an example of how to pre-order traversal of the quad tree,
103
+ and collect the information you will need to insert into your database.
104
+ I would then expect you to write a new program based on shptreedump that
105
+ calls a C API for your database to insert objects instead of printing them
106
+ out. Alternatively there may be an ASCII format for loading tables that
107
+ you could modify the program to output.
108
+
109
+ Searching
110
+ ---------
111
+
112
+ The other thing that you can do with the shptreedump program is to
113
+ perform a search on the quadtree. For instance the following shows
114
+ searching on a small region.
115
+
116
+ % shptreedump -search 471127 4751545 476622 4759281 eg_data/polygon.shp
117
+ Shape 17: not in area of interest, but fetched.
118
+ Shape 31: not in area of interest, but fetched.
119
+ Shape 52: not in area of interest, but fetched.
120
+ Shape 76: not in area of interest, but fetched.
121
+ Shape 82: not in area of interest, but fetched.
122
+ Shape 104: not in area of interest, but fetched.
123
+ Shape 124: not in area of interest, but fetched.
124
+ Shape 134: not in area of interest, but fetched.
125
+ Shape 139: not in area of interest, but fetched.
126
+ Shape 154: not in area of interest, but fetched.
127
+ Shape 175: not in area of interest, but fetched.
128
+ Shape 177: not in area of interest, but fetched.
129
+ Shape 185: not in area of interest, but fetched.
130
+ Shape 192: not in area of interest, but fetched.
131
+ Shape 196: appears to be in area of interest.
132
+ ....
133
+
134
+
135
+ I have included this capability (and the SHPTreeFindLikelyShapes() function)
136
+ so that you can see a working example of how to search this quad tree.
137
+ Note that searching is a multi-stage affair.
138
+
139
+ First a pass is made over the quadtree, collecting the shapeids of all
140
+ shapes contained in a quadtree node for which the bounding rectangle overlaps
141
+ the search rectangle. This is all accomplished by SHPTreeFindLikelyShapes()
142
+ in shptree.c.
143
+
144
+ The second phase is to fetch the actual shapes, and verify if their bounding
145
+ box falls within the area of interest. This is necessary because the shape
146
+ will tend to have a significantly smaller bounding rectangle than the tree
147
+ node in which it is found. This can result ``false positives'' on the first
148
+ phase search, as indicated by teh ``not in area of interest, but fetched''
149
+ messages above. This stage is done in the SHPTreeNodeSearchAndDump()
150
+ function in shptreedump.c.
151
+
152
+ A possible third phase is to verify that the actualy line segments in the
153
+ shape actually cross the area of interest. I don't both with this as it
154
+ is complicated, and assuming that the drawing engine takes care of clipping
155
+ it is quite a bit easier to let it fall through.
156
+
157
+ Building
158
+ --------
159
+
160
+ I have added a makefile.vc to the shapelib distribution. After you have
161
+ unpacked the shapefile you should have a shapelib subdirectory. If you
162
+ cd to that directory, and enter ``nmake -f makefile.vc'' in a DOS window
163
+ you should be able to build everything with VC++ (assuming it is properly
164
+ installed and in your path).
165
+
166
+ You can also create a project in VC just including the files
167
+ shpopen.c, shptree.c and shptreedump.c, building as a Win32 console
168
+ application.
169
+
170
+ For your convenience I am including prebuild .obj files, and .exe files
171
+ in the distribution.
172
+
@@ -0,0 +1,12 @@
1
+ shpdxf
2
+ dbfinfo
3
+ shpcentrd
4
+ shpdata
5
+ shpwkb
6
+ dbfcat
7
+ shpinfo
8
+ shpfix
9
+ shpcat
10
+ Shape_PointInPoly
11
+ shpproj
12
+ shpsort
@@ -0,0 +1,66 @@
1
+
2
+ #LINKOPT = /usr/local/lib/libdbmalloc.a
3
+ #CFLAGS = -g
4
+
5
+ # Endian: define either _LITTLE_ENDIAN or _BIG_ENDIAN
6
+ ENDIAN = -D_LITTLE_ENDIAN
7
+
8
+ CFLAGS = -g -I.. -I$(HOME)/bld/include -DPROJ4 $(ENDIAN) -DDEBUG -DDEBUG2
9
+
10
+ SHPOBJ = ../shpopen.o ../dbfopen.o ../safileio.o
11
+
12
+ SHPGOBJ = ../shpopen.o ../dbfopen.o ../safileio.o shpgeo.o
13
+
14
+ GEOOBJ = ./shpgeo.o -lm -L$(HOME)/bld/lib -lproj
15
+
16
+ default: all
17
+
18
+ all: shpdxf shpproj dbfinfo shpcentrd shpdata shpwkb dbfinfo dbfcat shpinfo shpfix shpcat Shape_PointInPoly shpsort
19
+
20
+ clean:
21
+ rm -f shpdxf shpproj dbfinfo shpcentrd shpdata shpwkb dbfcat dbfinfo shpinfo shpfix shpcat *.o
22
+
23
+ shpgeo.o: shpgeo.c shpgeo.h
24
+ $(CC) $(CFLAGS) -c shpgeo.c
25
+
26
+ shpdxf: shpdxf.c $(SHPOBJ)
27
+ $(CC) $(CFLAGS) shpdxf.c ${SHPOBJ} $(LINKOPT) -o shpdxf
28
+
29
+ shpcentrd: shpcentrd.c $(SHPGOBJ)
30
+ $(CC) $(CFLAGS) shpcentrd.c ${SHPOBJ} $(LINKOPT) $(GEOOBJ) -o shpcentrd
31
+
32
+ shpdata: shpdata.c $(SHPGOBJ)
33
+ $(CC) $(CFLAGS) shpdata.c ${SHPOBJ} $(LINKOPT) $(GEOOBJ) -o shpdata
34
+
35
+ shpinfo: shpinfo.c $(SHPOBJ)
36
+ $(CC) $(CFLAGS) shpinfo.c ${SHPOBJ} $(LINKOPT) $(GEOOBJ) -o shpinfo
37
+
38
+ shpfix: shpfix.c $(SHPOBJ)
39
+ $(CC) $(CFLAGS) shpfix.c ${SHPOBJ} $(LINKOPT) -o shpfix
40
+
41
+ shpcat: shpcat.c $(SHPOBJ)
42
+ $(CC) $(CFLAGS) shpcat.c ${SHPOBJ} $(LINKOPT) -o shpcat
43
+
44
+ shpwkb: shpwkb.c $(SHPGOBJ)
45
+ $(CC) $(CFLAGS) shpwkb.c ${SHPOBJ} $(LINKOPT) $(GEOOBJ) -o shpwkb
46
+
47
+ shpproj: shpproj.c $(SHPGOBJ)
48
+ $(CC) $(CFLAGS) shpproj.c $(SHPOBJ) $(GEOOBJ) -lm -lproj $(LINKOPT) -o shpproj
49
+
50
+ shpsort: shpsort.c $(SHPOBJ)
51
+ $(CC) $(CFLAGS) shpsort.c ${SHPOBJ} $(LINKOPT) -lm -o shpsort
52
+
53
+ dbfinfo: dbfinfo.c $(SHPOBJ)
54
+ $(CC) $(CFLAGS) dbfinfo.c $(SHPOBJ) $(LINKOPT) -o dbfinfo
55
+
56
+ dbfcat: dbfcat.c $(SHPOBJ)
57
+ $(CC) $(CFLAGS) dbfcat.c $(SHPOBJ) $(LINKOPT) -o dbfcat
58
+
59
+ Shape_PointInPoly: Shape_PointInPoly.cpp $(SHPOBJ)
60
+ $(CXX) $(CFLAGS) Shape_PointInPoly.cpp $(SHPOBJ) $(LINKOPT) \
61
+ -o Shape_PointInPoly
62
+
63
+ check: testproj
64
+
65
+ testproj:
66
+ tests/shpproj.sh
@@ -0,0 +1,234 @@
1
+ {
2
+ /******************************************************************************
3
+ * $Id: ShapeFileII.pas,v 1.3 2003-05-14 20:04:51 warmerda Exp $
4
+ *
5
+ * Project: Shapelib
6
+ * Purpose: Delphi Pascal interface to Shapelib.
7
+ * Author: Kevin Meyer (Kevin@CyberTracker.co.za)
8
+ *
9
+ ******************************************************************************
10
+ * Copyright (c) 2002, Keven Meyer (Kevin@CyberTracker.co.za)
11
+ *
12
+ * This software is available under the following "MIT Style" license,
13
+ * or at the option of the licensee under the LGPL (see LICENSE.LGPL). This
14
+ * option is discussed in more detail in shapelib.html.
15
+ *
16
+ * --
17
+ *
18
+ * Permission is hereby granted, free of charge, to any person obtaining a
19
+ * copy of this software and associated documentation files (the "Software"),
20
+ * to deal in the Software without restriction, including without limitation
21
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
22
+ * and/or sell copies of the Software, and to permit persons to whom the
23
+ * Software is furnished to do so, subject to the following conditions:
24
+ *
25
+ * The above copyright notice and this permission notice shall be included
26
+ * in all copies or substantial portions of the Software.
27
+ *
28
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
29
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
31
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
34
+ * DEALINGS IN THE SOFTWARE.
35
+ ******************************************************************************
36
+ *
37
+ * $Log: ShapeFileII.pas,v $
38
+ * Revision 1.3 2003-05-14 20:04:51 warmerda
39
+ * Changed fpSHP and fpSHX to integer at suggestion of Ivan Lucena.
40
+ *
41
+ * Revision 1.2 2002/01/21 14:09:26 warmerda
42
+ * Fixed name.
43
+ *
44
+ * Revision 1.1 2002/01/17 14:30:37 warmerda
45
+ * New
46
+ *
47
+ */
48
+ }
49
+ unit ShapeFileII;
50
+
51
+ interface
52
+ //uses { uses clause }
53
+ // ;
54
+ { Set compiler to pack on byte boundaries only }
55
+ {$ALIGN OFF}
56
+ {$OVERFLOWCHECKS OFF}
57
+ {$J-}
58
+ const
59
+ SHPT_NULL = 0;
60
+ SHPT_POINT = 1;
61
+ SHPT_ARC = 3;
62
+ SHPT_POLYGON = 5;
63
+ SHPT_MULTIPOINT = 8;
64
+ SHPT_POINTZ = 11;
65
+ SHPT_ARCZ = 13;
66
+ SHPT_POLYGONZ = 15;
67
+ SHPT_MULTIPOINTZ = 18;
68
+ SHPT_POINTM = 21;
69
+ SHPT_ARCM = 23;
70
+ SHPT_POLYGONM = 25;
71
+ SHPT_MULTIPOINTM = 28;
72
+ SHPT_MULTIPATCH = 31;
73
+ XBASE_FLDHDR_SZ = 32;
74
+ szAccessBRW = 'rb+';
75
+
76
+ // *********************** SHP support ************************
77
+
78
+ type
79
+ SHPObject = record
80
+ nSHPType,
81
+ nShapeId,
82
+ nParts : LongWord;
83
+ panPartStart,
84
+ panPartType : array of LongWord;
85
+ nVertices : LongWord;
86
+ padfX, padfY, padfZ, padfM : array of double;
87
+ dfXMin, dfYMin, dfZMin, dfMMin : double;
88
+ dfXMax, dfYMax, dfZMax, dfMMax : double;
89
+ end;
90
+ SHPObjectHandle = ^SHPObject;
91
+
92
+ SHPBoundsArr = double;
93
+
94
+ SHPInfo = record
95
+ fpSHP,
96
+ fpSHX : integer;
97
+
98
+ nShapeType,
99
+ nFileSize,
100
+ nRecords,
101
+ nMaxRecords : LongWord;
102
+ panRecOffset,
103
+ panRecSize : array of LongWord;
104
+ adBoundsMin, adBoundsMax : SHPBoundsArr;
105
+ bUpdated : LongWord;
106
+ end;
107
+ SHPHandle = ^SHPInfo;
108
+
109
+ // *********************** DBF support ************************
110
+
111
+ DBFInfo = record
112
+ fp : FILE;
113
+ nRecords,
114
+ nRecordLength,
115
+ nHeaderLength,
116
+ nFields : LongWord;
117
+
118
+ panFieldOffset,
119
+ panFieldSize,
120
+ panFieldDecimals : array of LongWord;
121
+
122
+ pachFieldType : LongWord;
123
+ pszHeader : PChar;
124
+ nCurrentRecord,
125
+ bCurrentRecordModified : LongWord;
126
+ pszCurrentRecord : PChar;
127
+
128
+ bNoHeader,
129
+ bUpdated : LongWord;
130
+ end;
131
+ DBFHandle = ^DBFInfo;
132
+
133
+ DBFFieldType = (DBFTString, DBFTInteger, DBFTDouble, DBFTInvalid) ;
134
+
135
+ // *********************** SHP func declarations ************************
136
+
137
+ {$ALIGN ON}
138
+
139
+ function SHPOpen(pszShapeFile, pszAccess : PChar) : SHPHandle;cdecl;
140
+ procedure SHPGetInfo(hSHP : SHPHandle; var pnEntities, pnShapeType : LongWord; var padfMinBoud, padfMaxBound : SHPBoundsArr);cdecl;
141
+ procedure SHPClose(hSHP : SHPHandle);cdecl;
142
+ function SHPReadObject(hSHP : SHPHandle; iShape : LongWord): SHPObjectHandle;cdecl;
143
+ function SHPCreate(pszShapeFile : PChar; nShapeType : LongWord):SHPHandle;cdecl;
144
+ function SHPWriteObject(hSHP : SHPHandle; iShape : LongWord; psObject : SHPObjectHandle): LongWord;cdecl;
145
+ function SHPCreateSimpleObject(nSHPType, nVertices : LongWord; var padfX, padfY, padfZ : double):SHPObjectHandle;cdecl;
146
+ procedure SHPDestroy(psObject : SHPObjectHandle);cdecl;
147
+
148
+ procedure SHPComputeExtents(psObject : SHPObjectHandle);cdecl;
149
+ function SHPCreateObject(nSHPType, iShape, nParts : LongWord; var panPartStart, panPartType : LongWord; nVertices : LongWord; var padfX, padfY, padfZ, padfM : SHPBoundsArr): SHPObjectHandle;cdecl;
150
+
151
+ function SHPTypeStr(pnShapeType : LongWord): string;
152
+
153
+ // *********************** DBF func declarations ************************
154
+
155
+ function DBFOpen(pszDBFFile, pszAccess : PChar): DBFHandle;cdecl;
156
+ function DBFCreate(pszDBFFile : PChar): DBFHandle ;cdecl;
157
+ function DBFGetFieldCount(hDBF : DBFHandle) : LongWord ;cdecl;
158
+ function DBFGetRecordCount(hDBF : DBFHandle) : LongWord;cdecl;
159
+ function DBFGetFieldIndex(hDBF: DBFHandle; pszFieldName : PChar): LongWord;cdecl;
160
+ function DBFGetFieldInfo(hDBF : DBFHandle; iField : LongWord; pszFieldName : PChar;
161
+ var pnWidth, pnDecimals : LongWord): DBFFieldType;cdecl;
162
+ function DBFAddField(hDBF : DBFHandle; pszFieldName : PChar;
163
+ eType : DBFFieldType; nWidth, nDecimals : LongWord): LongWord;cdecl;
164
+
165
+ function DBFReadIntegerAttribute(hDBF : DBFHandle;iShape, iField : LongWord ): LongWord;cdecl;
166
+ function DBFReadDoubleAttribute(hDBF : DBFHandle; iShape, iField : LongWord ):double;cdecl;
167
+ function DBFReadStringAttribute(hDBF : DBFHandle; iShape, iField : LongWord ) : pchar;cdecl;
168
+ function DBFIsAttributeNULL(hDBF : DBFHandle; iShape, iField : LongWord ): LongWord;cdecl;
169
+ function DBFWriteIntegerAttribute(hDBF : DBFHandle;iShape, iField, nFieldValue : LongWord): LongWord;cdecl;
170
+ function DBFWriteDoubleAttribute(hDBF : DBFHandle;iShape, iField : LongWord;
171
+ dFieldValue : double): LongWord ;cdecl;
172
+ function DBFWriteStringAttribute(hDBF : DBFHandle;iShape, iField : LongWord;
173
+ pszFieldValue : PChar): LongWord ;cdecl;
174
+ function DBFWriteNULLAttribute(hDBF : DBFHandle; iShape, iField : LongWord ) : LongWord;cdecl;
175
+ procedure DBFClose(hDBF : DBFHandle);cdecl;
176
+ function DBFGetNativeFieldType(hDBF : DBFHandle; iField : LongWord) : Char;cdecl;
177
+
178
+ // *********************** SHP implementation ************************
179
+ implementation
180
+ // *****************************************************************************
181
+ function SHPCreateSimpleObject(nSHPType, nVertices : LongWord; var padfX, padfY, padfZ : double):SHPObjectHandle;external 'shapelib.dll' name 'SHPCreateSimpleObject';
182
+ function SHPOpen(pszShapeFile, pszAccess : PChar) : SHPHandle; external 'shapelib.dll' name 'SHPOpen';
183
+ procedure SHPGetInfo(hSHP : SHPHandle; var pnEntities, pnShapeType : LongWord; var padfMinBoud, padfMaxBound : SHPBoundsArr);external 'shapelib.dll' name 'SHPGetInfo';
184
+ procedure SHPClose(hSHP : SHPHandle);external 'shapelib.dll' name 'SHPClose';
185
+ function SHPReadObject(hSHP : SHPHandle; iShape : LongWord) : SHPObjectHandle;external 'shapelib.dll' name 'SHPReadObject';
186
+ function SHPCreate(pszShapeFile : PChar; nShapeType : LongWord):SHPHandle;external 'shapelib.dll' name 'SHPCreate';
187
+ function SHPWriteObject(hSHP : SHPHandle; iShape : LongWord; psObject : SHPObjectHandle): LongWord;cdecl;external 'shapelib.dll' name 'SHPWriteObject';
188
+ procedure SHPDestroy(psObject : SHPObjectHandle);external 'shapelib.dll' name 'SHPDestroyObject';
189
+ procedure SHPComputeExtents(psObject : SHPObjectHandle);external 'shapelib.dll' name 'SHPComputeExtents';
190
+ function SHPCreateObject(nSHPType, iShape, nParts : LongWord; var panPartStart, panPartType : LongWord; nVertices : LongWord; var padfX, padfY, padfZ, padfM : SHPBoundsArr): SHPObjectHandle;external 'shapelib.dll' name 'SHPCreateObject';
191
+ // *****************************************************************************
192
+ function SHPTypeStr(pnShapeType : LongWord): string;
193
+ begin
194
+ case pnShapeType of
195
+ SHPT_NULL : result := 'NULL';
196
+ SHPT_POINT : result := 'POINT';
197
+ SHPT_ARC : result := 'ARC';
198
+ SHPT_POLYGON : result := 'POLYGON';
199
+ SHPT_MULTIPOINT : result := 'MULTIPOINT';
200
+ SHPT_POINTZ : result := 'POINTZ';
201
+ SHPT_ARCZ : result := 'ARCZ';
202
+ SHPT_POLYGONZ : result := 'POLYGONZ';
203
+ SHPT_MULTIPOINTZ : result := 'MULTIPOINTZ';
204
+ SHPT_POINTM : result := 'POINTM';
205
+ SHPT_ARCM : result := 'ARCM';
206
+ SHPT_POLYGONM : result := 'POLYGONM';
207
+ SHPT_MULTIPOINTM : result := 'MULTIPOINTM';
208
+ SHPT_MULTIPATCH : result := 'MULTIPATCH';
209
+ else
210
+ result := '--unknown--';
211
+ end;
212
+ end;
213
+ // *****************************************************************************
214
+ // *****************************************************************************
215
+ function DBFOpen(pszDBFFile, pszAccess : PChar): DBFHandle;external 'shapelib.dll';
216
+ function DBFCreate(pszDBFFile : PChar): DBFHandle ;external 'shapelib.dll';
217
+ function DBFGetFieldCount(hDBF : DBFHandle) : LongWord ;external 'shapelib.dll';
218
+ function DBFGetRecordCount(hDBF : DBFHandle) : LongWord;external 'shapelib.dll';
219
+ function DBFGetFieldIndex(hDBF: DBFHandle; pszFieldName : PChar): LongWord;external 'shapelib.dll';
220
+ function DBFGetFieldInfo(hDBF : DBFHandle; iField : LongWord; pszFieldName : PChar; var pnWidth, pnDecimals : LongWord): DBFFieldType;external 'shapelib.dll';
221
+ function DBFAddField(hDBF : DBFHandle; pszFieldName : PChar; eType : DBFFieldType; nWidth, nDecimals : LongWord): LongWord;external 'shapelib.dll';
222
+ function DBFReadIntegerAttribute(hDBF : DBFHandle;iShape, iField : LongWord ): LongWord;external 'shapelib.dll';
223
+ function DBFReadDoubleAttribute(hDBF : DBFHandle; iShape, iField : LongWord ):double;external 'shapelib.dll';
224
+ function DBFReadStringAttribute(hDBF : DBFHandle; iShape, iField : LongWord ) : pchar;external 'shapelib.dll';
225
+ function DBFIsAttributeNULL(hDBF : DBFHandle; iShape, iField : LongWord ): LongWord;external 'shapelib.dll';
226
+ function DBFWriteIntegerAttribute(hDBF : DBFHandle;iShape, iField, nFieldValue : LongWord): LongWord;external 'shapelib.dll';
227
+ function DBFWriteDoubleAttribute(hDBF : DBFHandle;iShape, iField : LongWord; dFieldValue : double): LongWord ;external 'shapelib.dll';
228
+ function DBFWriteStringAttribute(hDBF : DBFHandle;iShape, iField : LongWord; pszFieldValue : PChar): LongWord ;external 'shapelib.dll';
229
+ function DBFWriteNULLAttribute(hDBF : DBFHandle; iShape, iField : LongWord ) : LongWord;external 'shapelib.dll';
230
+ procedure DBFClose(hDBF : DBFHandle);external 'shapelib.dll';
231
+ function DBFGetNativeFieldType(hDBF : DBFHandle; iField : LongWord) : Char;external 'shapelib.dll';
232
+ // *****************************************************************************
233
+
234
+ end.