-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSHP.bt
175 lines (160 loc) · 3.79 KB
/
SHP.bt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//------------------------------------------------
//--- 010 Editor v2.1.3 Binary Template
//
// File: SHP.bt
// Authors: A Norman
// Version: 1.3
// Purpose: Parses ESRI ShapeFiles.
// Category: GIS
// File Mask: *.shp
// ID Bytes:
// History:
// 1.3 2017-08-26 K. Grover: Combined ShapeEnums. Added Readers. Alternate record color.
// 1.2 2016-08-11 M. Nicke: Updated records for MultiPatchType
// 1.1 2016-01-29 SweetScape: Updated header for repository submission, fixed reading records to the end of the file.
// 1.0 A Norman: Initial release.
//------------------------------------------------
typedef struct {
double X;
double Y;
} POINT <read=getPOINT>;
string getPOINT(local POINT &p) {
string s;
SPrintf(s, "POINT(%f, %f)", p.X, p.Y);
return s;
}
typedef enum {
TriangleStrip = 0,
TriangleFan = 1,
OuterRing = 2,
InnerRing = 3,
FirstRing = 4,
Ring = 5
} PATCH;
string GetByteSize(int wordSize) {
string s;
SPrintf(s, "%d", 2*wordSize);
return s;
}
typedef enum {
NullShapeType,
PointType,
PolyLineType=3,
PolygonType=5,
MultiPointType=8,
PointZType=11,
PolyLineZType=13,
PolygonZType=15,
MultiPointZType=18,
PointMType=21,
PolyLineMType=23,
PolygonMType=25,
MultiPointMType=28,
MultiPatchType=31
} SHAPE;
typedef struct {
BigEndian();
int recordNumber;
int contentLength <read=GetByteSize>;
LittleEndian();
SHAPE shapeType;
if (shapeType == 1)
{
POINT location;
}
else if (shapeType == 3)
{
double box[4];
int numParts;
int numPoints;
int parts[numParts];
POINT points[numPoints];
}
else if (shapeType == 5)
{
double box[4];
int numParts;
int numPoints;
int parts[numParts];
POINT points[numPoints];
}
else if (shapeType == 31)
{
double box[4];
int numParts;
int numPoints;
int Parts[numParts];
PATCH PartTypes[numParts];
POINT points[numPoints];
double Zmin;
double Zmax;
double ZArray[numPoints];
double Mmin;
double Mmax;
double MArray[numPoints];
}
} RECORD <read=getRECORD>;
string getRECORD(local RECORD &r) {
string s;
switch (r.shapeType) {
case 1:
SPrintf(s, "%s", EnumToString(r.shapeType));
break;
case 3:
case 5:
case 31:
SPrintf(s, "%s <%d pts>", EnumToString(r.shapeType), r.numPoints);
break;
default:
SPrintf(s, "<%s>", EnumToString(r.shapeType));
}
return s;
}
typedef struct {
BigEndian();
int fileCode;
int unused[5];
int fileLength <read=GetByteSize>;
LittleEndian();
int version;
SHAPE shapeType;
double Xmin;
double Ymin;
double Xmax;
double Ymax;
double Zmin;
double Zmax;
double Mmin;
double Mmax;
} HEADER <read=getHEADER>;
string getHEADER(local HEADER &h) {
string s;
SPrintf(s, "%s", EnumToString(h.shapeType));
return s;
}
// Helper routine to set back ground color to 'even_color'
// or 'odd_color' depending upon whether 'count'
// is even or odd.
void setColorEvenOdd(int count, int even_color, int odd_color) {
local int color = (count % 2) ? odd_color : even_color;
SetBackColor(color);
}
typedef struct {
SetBackColor(cLtGreen);
HEADER header;
SetBackColor(cLtGray);
local int record_count = 0;
while( !FEof() )
{
setColorEvenOdd(record_count, cNone, cLtGray);
RECORD record;
record_count++;
}
} ESRI_SHAPE <read=getESRI_SHAPE>;
string getESRI_SHAPE(local ESRI_SHAPE &es) {
string s;
SPrintf(s, "version %d", es.header.version);
return s;
}
// Allocate data
ESRI_SHAPE esri_shape;