Skip to content

Commit

Permalink
Bugfix, raw geometry option
Browse files Browse the repository at this point in the history
  • Loading branch information
abrman committed Oct 29, 2024
1 parent fca6160 commit 8007511
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-mails-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shp-kit": patch
---

Bugfix, raw geometry option
4 changes: 2 additions & 2 deletions src/public/shpRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const shpRead = async (
dbf?: File | Blob | ArrayBuffer | Buffer,
prj?: File | Blob | ArrayBuffer | Buffer | string
) => {
const o = { ...defaultOptions, ...(options ? { options } : {}) };
const o = { ...defaultOptions, ...(options ? options : {}) };
const shpView = await toDataView(shp);
// const prjView = prj && typeof prj !== "string" ? await toDataView(prj) : null;

Expand All @@ -48,7 +48,7 @@ const shpRead = async (

const shpNumType = shpView.getInt32(32, true) as ShapefileTypesNumber;
// const shpType = shapefileNumberTypeToStringType(shpNumType);
o;

let currByteIndex = 100;
let currFeatureIndex = 0;

Expand Down
22 changes: 22 additions & 0 deletions src/tests/shpRead.PolyLineZ.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,26 @@ describe("shpRead", () => {
expect(JSON.stringify(geojson)).toBe(targetGeoJson);
// fs.writeFile(path.join(__dirname, "output", "002-PolyLineZ.json"), JSON.stringify(geojson), () => {});
});
it("PolyLineZ.003 - Simple 3D arrow with projection and originalRawGeometry", async () => {
const targetGeoJson = fs.readFileSync(
path.join(__dirname, "test_results", "read", "PolyLineZ", "003-PolyLineZ.json"),
{
encoding: "UTF-8",
}
);

const shpBuffer = fs.readFileSync(
path.join(__dirname, "assets", "statue_of_liberty_arrow_polylineZ", "ARR-3D.shp")
);
const dbfBuffer = fs.readFileSync(
path.join(__dirname, "assets", "statue_of_liberty_arrow_polylineZ", "ARR-3D.dbf")
);
const prjBuffer = fs.readFileSync(
path.join(__dirname, "assets", "statue_of_liberty_arrow_polylineZ", "ARR-3D.prj")
);

const geojson = await shpRead(shpBuffer, { originalGeometryPropertyKey: "_raw" }, dbfBuffer, prjBuffer);
expect(JSON.stringify(geojson)).toBe(targetGeoJson);
// fs.writeFile(path.join(__dirname, "output", "002-PolyLineZ.json"), JSON.stringify(geojson), () => {});
});
});
1 change: 1 addition & 0 deletions src/tests/test_results/read/PolyLineZ/003-PolyLineZ.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"LineString","coordinates":[[-74.04629664645735,40.68824736290356,0],[-74.04557740552134,40.688697167654226,20],[-74.04569186524047,40.68880321655356,20],[-74.04532401755475,40.68876681629635,25],[-74.04535901875747,40.68849482731328,20],[-74.04546294616462,40.688591118641405,20],[-74.04618218671689,40.68814131459358,0],[-74.04629664645735,40.68824736290356,0]]},"properties":{"AREA":0,"COLOR":256,"LINETYPE":"ByLayer","LINEWEIGHT":-1,"_raw":{"type":"LineString","coordinates":[[617938.1784753243,675948.7897869407],[618136.7792900968,676113.681864586],[618104.8396947302,676152.150842319],[618206.9129463544,676139.41794235],[618197.7196544106,676040.2835171452],[618168.7188854632,676075.2128868529],[617970.1180706909,675910.3208092076],[617938.1784753243,675948.7897869407]]}}}]}

0 comments on commit 8007511

Please sign in to comment.