Skip to content

Commit 019cbe2

Browse files
committed
fix: fixed support for loading only geometry
1 parent fd66e17 commit 019cbe2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

shpts/reader/featureReader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class FeatureReader {
2020
}
2121

2222
private constructor(shapeFile: ShapeReader, dbfReader?: DbfReader) {
23-
if (shapeFile.recordCount !== dbfReader?.recordCount) {
23+
if (dbfReader && shapeFile.recordCount !== dbfReader?.recordCount) {
2424
throw new Error(
2525
`Record count mismatch: SHP-file has ${shapeFile.recordCount} records, DBF has ${dbfReader?.recordCount}`
2626
);

test/features.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ test('Read feature collection', async () => {
5353
});
5454
});
5555

56+
test('Read feature collection only with geometry', async () => {
57+
const shp = openFileAsArray('testdata/featureclass.shp');
58+
const shx = openFileAsArray('testdata/featureclass.shx');
59+
const reader = await FeatureReader.fromArrayBuffers(shp, shx);
60+
const collection = reader.readFeatureCollection();
61+
expect(collection.features.length).toEqual(7);
62+
expect(reader.fields?.length).toEqual(undefined);
63+
64+
collection.features.forEach((feature) => {
65+
expect(feature.geom).not.toBeNull();
66+
expect(feature.properties).not.toBeNull();
67+
expect(Object.keys(feature.properties).length).toEqual(0);
68+
expect(feature.geom instanceof PolyLineRecord).toBeTruthy();
69+
});
70+
});
71+
5672
test('SHP and DBF count mismatch', async () => {
5773
const shp = openFileAsArray('testdata/polyline.shp');
5874
const shx = openFileAsArray('testdata/polyline.shx');

0 commit comments

Comments
 (0)