Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 4 function to read shp file with Z value #53

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions shp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import slice from "slice-source";
import view from "../view";
import shp_cancel from "./cancel";
import parseMultiPoint from "./multipoint";
import parseMultiPointZ from "./multipointz";
import parseNull from "./null";
import parsePoint from "./point";
import parsePolygon from "./polygon";
import parsePolyLine from "./polyline";
import parsePointZ from "./pointz";
import parsePolygonZ from "./polygonz";
import parsePolyLineZ from "./polylinez";
import shp_read from "./read";

var parsers = {
Expand All @@ -14,10 +18,10 @@ var parsers = {
3: parsePolyLine,
5: parsePolygon,
8: parseMultiPoint,
11: parsePoint, // PointZ
13: parsePolyLine, // PolyLineZ
15: parsePolygon, // PolygonZ
18: parseMultiPoint, // MultiPointZ
11: parsePointZ, // PointZ
13: parsePolyLineZ, // PolyLineZ
15: parsePolygonZ, // PolygonZ
18: parseMultiPointZ, // MultiPointZ
21: parsePoint, // PointM
23: parsePolyLine, // PolyLineM
25: parsePolygon, // PolygonM
Expand Down
5 changes: 5 additions & 0 deletions shp/multipointz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function(record) {
var i = 40, j, n = record.getInt32(36, true), coordinates = new Array(n);
for (j = 0; j < n; ++j, i += 24) coordinates[j] = [record.getFloat64(i, true), record.getFloat64(i + 8, true),record.getFloat64(i + 16, true)];
return {type: "MultiPoint", coordinates: coordinates};
};
4 changes: 4 additions & 0 deletions shp/pointz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export default function(record) {
return {type: "PointZ", coordinates: [record.getFloat64(4, true), record.getFloat64(12, true), record.getFloat64(20, true)]};
};
26 changes: 26 additions & 0 deletions shp/polygonz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

export default function(record) {
var z=0,i = 44, j, n = record.getInt32(36, true), m = record.getInt32(40, true), parts = new Array(n), points = new Array(m), polygons = [], holes = [];
for (j = 0; j < n; ++j, i += 4) parts[j] = record.getInt32(i, true);
z = i + 16*m + 16
for (j = 0; j < m; ++j, i += 16,z+=8) points[j] = [record.getFloat64(i, true), record.getFloat64(i + 8, true),record.getFloat64(z, true)];

parts.forEach(function(i, j) {
var ring = points.slice(i, parts[j + 1]);
if (ringClockwise(ring)) polygons.push([ring]);
else holes.push(ring);
});

holes.forEach(function(hole) {
polygons.some(function(polygon) {
if (ringContainsSome(polygon[0], hole)) {
polygon.push(hole);
return true;
}
}) || polygons.push([hole]);
});

return polygons.length === 1
? {type: "PolygonZ", coordinates: polygons[0]}
: {type: "MultiPolygonZ", coordinates: polygons};
};
13 changes: 13 additions & 0 deletions shp/polylinez.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function(record) {
var z=0,i = 44, j, n = record.getInt32(36, true), m = record.getInt32(40, true), parts = new Array(n), points = new Array(m);
for (j = 0; j < n; ++j, i += 4) parts[j] = record.getInt32(i, true);
z = i + 16*m + 16
for (j = 0; j < m; ++j, i += 16,z +=8){
points[j] = [record.getFloat64(i, true), record.getFloat64(i + 8, true), record.getFloat64(z, true)];
//console.log([record.getFloat64(i, true), record.getFloat64(i + 8, true), record.getFloat64(z, true)]);
}

return n === 1
? {type: "LineString", coordinates: points}
: {type: "MultiLineString", coordinates: parts.map(function(i, j) { return points.slice(i, parts[j + 1]); })};
};