-
-
Notifications
You must be signed in to change notification settings - Fork 187
/
shp.hexpat
201 lines (177 loc) · 3.88 KB
/
shp.hexpat
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#pragma author Calcoph
#pragma description ESRI shapefile
// Spec:
// https://www.esri.com/content/dam/esrisites/sitecore-archive/Files/Pdfs/library/whitepapers/pdfs/shapefile.pdf
enum ShapeType: u32 {
Null = 0,
Point = 1,
PolyLine = 3,
Polygon = 5,
MultiPoint = 8,
PointZ = 11,
PolyLineZ = 13,
PolygonZ = 15,
MultiPointZ = 18,
PointM = 21,
PolyLineM = 23,
PolygonM = 25,
MultiPointM = 28,
MultiPatch = 32,
};
struct NullShape {
};
struct Point {
double x;
double y;
};
struct MultiPoint {
double box[4];
u32 num_points;
Point points[num_point];
};
struct PolyLine {
double box[4];
u32 num_parts;
u32 num_points;
u32 parts[num_parts];
Point points[num_points];
};
struct Polygon {
double box[4];
u32 num_parts;
u32 num_points;
u32 parts[num_parts];
Point points[num_points];
};
struct PointM {
double x;
double y;
double m;
};
struct MultiPointM {
double box[4];
u32 num_points;
Point points[num_point];
double m_range[2];
double m_array[num_points];
};
struct PolyLineM {
double box[4];
u32 num_parts;
u32 num_points;
u32 parts[num_parts];
Point points[num_points];
double m_range[2];
double m_array[num_points];
};
struct PolygonM {
double box[4];
u32 num_parts;
u32 num_points;
u32 parts[num_parts];
Point points[num_points];
double m_range[2];
double m_array[num_points];
};
struct PointZ {
double x;
double y;
double z;
double m;
};
struct MultiPointZ {
double box[4];
u32 num_points;
Point points[num_point];
double z_range[2];
double z_array[num_points];
double m_range[2];
double m_array[num_points];
};
struct PolyLineZ {
double box[4];
u32 num_parts;
u32 num_points;
u32 parts[num_parts];
Point points[num_points];
double z_range[2];
double z_array[num_points];
double m_range[2];
double m_array[num_points];
};
struct PolygonZ {
double box[4];
u32 num_parts;
u32 num_points;
u32 parts[num_parts];
Point points[num_points];
double z_range[2];
double z_array[num_points];
double m_range[2];
double m_array[num_points];
};
enum PartType: u32 {
TriangleStrip = 0,
TriangleFan = 1,
OuterRing = 2,
InnerRing = 3,
FirstRing = 4,
Ring = 5,
};
struct MultiPatch {
double box[4];
u32 num_parts;
u32 num_points;
u32 parts[num_parts];
PartType part_types[num_parts];
Point points[num_points];
double z_range[2];
double z_array[num_points];
double m_range[2];
double m_array[num_points];
};
struct Header {
be u32 magic; // 9994
padding[20]; // unused
be u32 file_length; // in 16-bit words (including header)
u32 version; // 1000
ShapeType shape_type;
// Bounding box
double bb_xmin;
double bb_ymin;
double bb_xmax;
double bb_ymax;
double bb_zmin;
double bb_zmax;
double bb_mmin;
double bb_mmax;
};
struct RecordHeader {
be u32 record_number; // starting at 1
be u32 content_length; // in 16-bit words
};
struct Record {
RecordHeader;
ShapeType shape_type;
match (shape_type) {
(ShapeType::Null): NullShape;
(ShapeType::Point): Point;
(ShapeType::PolyLine): PolyLine;
(ShapeType::Polygon): Polygon;
(ShapeType::MultiPoint): MultiPoint;
(ShapeType::PointZ): PointZ;
(ShapeType::PolyLineZ): PolyLineZ;
(ShapeType::PolygonZ): PolygonZ;
(ShapeType::MultiPointZ): MultiPointZ;
(ShapeType::PointM): PointM;
(ShapeType::PolyLineM): PolyLineM;
(ShapeType::PolygonM): PolygonM;
(ShapeType::MultiPointM): MultiPointM;
(ShapeType::MultiPatch): MultiPatch;
}
};
struct ShapeFile {
Header header;
Record records[while ($ < (header.file_length * 2))];
};
ShapeFile file @ 0x00;