94#if defined(SG_WINDOWS)
95 const auto ws = aPath.wstr();
96 gzFile file = gzopen_w(ws.c_str(),
"rb");
98 const auto s = aPath.utf8Str();
99 gzFile file = gzopen(s.c_str(),
"rb");
102 throw sg_io_exception(
"couldn't open file:", aPath);
106 int header, fileLength, fileVersion, shapeType;
107 sgReadIntBE(file, header);
109 throw sg_io_exception(
"bad SHP header value", aPath);
113 for (
int i=0;
i<6; ++
i) {
114 sgReadIntBE(file, fileLength);
117 sgReadIntLE(file, fileVersion);
118 sgReadIntLE(file, shapeType);
121 throw sg_io_exception(
"bad SHP file version", aPath);
125 throw sg_io_exception(
"SHP file does not contain Polygon data", aPath);
129 throw sg_io_exception(
"SHP file does not contain PolyLine data", aPath);
134 for (
int i=0;
i<8; ++
i) {
135 sgReadDouble(file, &range);
138 int readLength = 100;
139 while (readLength < fileLength) {
140 int recordNumber, contentLengthWords;
141 readSHPRecordHeader(file, recordNumber, contentLengthWords);
144 sgReadIntLE(file, recordShapeType);
149 if (recordShapeType != shapeType) {
151 throw sg_io_exception(
"SHP file shape-type mismatch", aPath);
155 for (
int i=0;
i<4; ++
i) {
156 sgReadDouble(file, &box[
i]);
159 int numParts, numPoints;
160 sgReadInt(file, &numParts);
161 sgReadInt(file, &numPoints);
163 std::vector<int> parts;
164 parts.resize(numParts);
165 sgReadInt(file, numParts, parts.data());
168 parseSHPPoints2D(file, numPoints, points);
170 for (
int part=0; part<numParts; ++part) {
172 unsigned int startIndex = parts[part];
173 unsigned int endIndex = ((part + 1) == numParts) ? numPoints : parts[part + 1];
174 partPoints.insert(partPoints.begin(), points.begin() + startIndex, points.begin() + endIndex);
180 aResult.insert(aResult.end(), lines.begin(), lines.end());
185 readLength += (contentLengthWords + 4);
189 }
catch (sg_exception& e) {