From ae6b3cd4c32e460baf305484f792d18a0a276de5 Mon Sep 17 00:00:00 2001 From: wemamawe Date: Wed, 21 Nov 2018 09:00:22 +0800 Subject: [PATCH 1/6] read pointz type of shp file --- shp/pointz | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 shp/pointz diff --git a/shp/pointz b/shp/pointz new file mode 100644 index 0000000..c30cc6c --- /dev/null +++ b/shp/pointz @@ -0,0 +1,4 @@ + +export default function(record) { + return {type: "PointZ", coordinates: [record.getFloat64(4, true), record.getFloat64(12, true), record.getFloat64(20, true)]}; +}; From 3c3c7be6db69b401a6a776d1ece3c20e008685c8 Mon Sep 17 00:00:00 2001 From: wemamawe Date: Wed, 21 Nov 2018 09:00:52 +0800 Subject: [PATCH 2/6] Rename pointz to pointz.js --- shp/{pointz => pointz.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename shp/{pointz => pointz.js} (100%) diff --git a/shp/pointz b/shp/pointz.js similarity index 100% rename from shp/pointz rename to shp/pointz.js From 68511ea3a5df3f875ec4f0291e9c842db5fe85d0 Mon Sep 17 00:00:00 2001 From: wemamawe Date: Wed, 21 Nov 2018 09:04:21 +0800 Subject: [PATCH 3/6] read multipointz type of shp file --- shp/multipointz.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 shp/multipointz.js diff --git a/shp/multipointz.js b/shp/multipointz.js new file mode 100644 index 0000000..60b3c5f --- /dev/null +++ b/shp/multipointz.js @@ -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}; +}; From b69be5bcb0ef8389d4e6b1bf0644794338cac2b1 Mon Sep 17 00:00:00 2001 From: wemamawe Date: Wed, 21 Nov 2018 09:08:07 +0800 Subject: [PATCH 4/6] read polygonz type of shp file --- shp/polygonz.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 shp/polygonz.js diff --git a/shp/polygonz.js b/shp/polygonz.js new file mode 100644 index 0000000..d7ae8ef --- /dev/null +++ b/shp/polygonz.js @@ -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}; + }; From 8efa06f5d764db927c8960cd66f0b25a1030376f Mon Sep 17 00:00:00 2001 From: wemamawe Date: Wed, 21 Nov 2018 09:09:02 +0800 Subject: [PATCH 5/6] read polylinez type of shp file --- shp/polylinez.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 shp/polylinez.js diff --git a/shp/polylinez.js b/shp/polylinez.js new file mode 100644 index 0000000..87bd66f --- /dev/null +++ b/shp/polylinez.js @@ -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]); })}; +}; From 87d829e550afb49cb81411d5935fa69593bf0c46 Mon Sep 17 00:00:00 2001 From: wemamawe Date: Wed, 21 Nov 2018 09:11:23 +0800 Subject: [PATCH 6/6] import 4 new parse function, and read the right type of coordinates with z --- shp/index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/shp/index.js b/shp/index.js index 8c08f64..d7879ad 100644 --- a/shp/index.js +++ b/shp/index.js @@ -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 = { @@ -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