Skip to content

Commit 218553d

Browse files
authored
Merge pull request #8 from vojtatom/dev
Adding types to Records
2 parents 51ba46d + 10ee156 commit 218553d

File tree

14 files changed

+68
-4
lines changed

14 files changed

+68
-4
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v3
1414
- name: 'Setup Node.js'
15-
uses: 'actions/setup-node@v1'
15+
uses: 'actions/setup-node@v3'
1616
with:
1717
node-version: 18
1818
- name: Install dependencies

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "shpts",
33
"private": false,
4-
"version": "1.0.5",
4+
"version": "1.0.6",
55
"type": "module",
66
"repository": {
77
"type": "git",

shpts/geometry/base.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export abstract class BaseRecord {
2121
return 4;
2222
}
2323

24+
abstract get type(): string;
25+
2426
protected static readBbox(stream: MemoryStream): BoundingBox {
2527
const xMin = stream.readDouble(true);
2628
const yMin = stream.readDouble(true);

shpts/geometry/multipatch.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export class MultiPatchRecord extends BaseRingedRecord {
1616
super(coordType);
1717
}
1818

19+
get type() {
20+
if (this.coords.length === 1) return 'Polygon';
21+
return 'MultiPolygon';
22+
}
23+
1924
static fromPresetReader(reader: ShapeReader, header: GeomHeader) {
2025
const hasZ = reader.hasZ;
2126
const hasM = reader.hasM;

shpts/geometry/multipoint.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export class MultiPointRecord extends BaseRecord {
1111
super(coordType);
1212
}
1313

14+
get type() {
15+
return 'MultiPoint';
16+
}
17+
1418
static fromPresetReader(reader: ShapeReader, header: GeomHeader) {
1519
const hasZ = reader.hasZ;
1620
const hasM = reader.hasM;

shpts/geometry/null.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export class ShpNullGeom extends BaseRecord {
77
super(CoordType.NULL);
88
}
99

10+
get type() {
11+
return 'Null';
12+
}
13+
1014
public toGeoJson(): GeoJsonGeom {
1115
throw new Error('Method cannot be implemented.');
1216
}

shpts/geometry/point.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export class PointRecord extends BaseRecord {
1010
super(coordType);
1111
}
1212

13+
get type() {
14+
return 'Point';
15+
}
16+
1317
static fromPresetReader(reader: ShapeReader, header: GeomHeader) {
1418
const hasZ = reader.hasZ;
1519
const hasM = reader.hasM;

shpts/geometry/polygon.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export class PolygonRecord extends BaseRingedRecord {
1616
super(coordType);
1717
}
1818

19+
get type() {
20+
if (this.coords.length === 1) return 'Polygon';
21+
return 'MultiPolygon';
22+
}
23+
1924
static fromPresetReader(reader: ShapeReader, header: GeomHeader) {
2025
const hasZ = reader.hasZ;
2126
const hasM = reader.hasM;

shpts/geometry/polyline.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ import { BaseRingedRecord } from './base';
44
import { GeoJsonCoord, GeoJsonLineString, GeoJsonMultiLineString } from '@shpts/types/geojson';
55
import { GeomUtil } from '@shpts/utils/geometry';
66
import { GeomHeader } from '@shpts/types/data';
7-
import { MemoryStream } from '@shpts/utils/stream';
87

98
export class PolyLineRecord extends BaseRingedRecord {
109
constructor(public coords: PolyLineCoord, coordType: CoordType) {
1110
super(coordType);
1211
}
1312

13+
get type() {
14+
if (this.coords.length === 1) return 'LineString';
15+
return 'MultiLineString';
16+
}
17+
1418
static fromPresetReader(reader: ShapeReader, header: GeomHeader) {
1519
const hasZ = reader.hasZ;
1620
const hasM = reader.hasM;

test/multipatch.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ test('Reading MultiPatchRecord with Z', async () => {
1010

1111
expect(reader.recordCount).toEqual(1);
1212
let geom = expectGeometry(reader, 0, CoordType.XYZM, MultiPatchRecord);
13+
expect(geom.type).toEqual('MultiPolygon');
1314
expect(geom.coords.length).toEqual(12);
1415
let polygon = geom.coords[0];
1516
expectRing(polygon[0], [
@@ -116,6 +117,7 @@ test('Reading MultiPatchRecord with Outer/Inner Rings', async () => {
116117
expect(reader.recordCount).toEqual(1);
117118

118119
let geom = expectGeometry(reader, 0, CoordType.XYZM, MultiPatchRecord);
120+
expect(geom.type).toEqual('Polygon');
119121
expect(geom.coords.length).toBe(1);
120122
let polygon = geom.coords[0];
121123
expect(polygon.length).toBe(3);
@@ -150,6 +152,7 @@ test('Reading MultiPatchRecord with First Ring and Rings', async () => {
150152
expect(reader.recordCount).toEqual(1);
151153

152154
let geom = expectGeometry(reader, 0, CoordType.XYZM, MultiPatchRecord);
155+
expect(geom.type).toEqual('Polygon');
153156
expect(geom.coords.length).toBe(1);
154157
let polygon = geom.coords[0];
155158
expect(polygon.length).toBe(3);
@@ -184,6 +187,7 @@ test('Reading MultiPatchRecord with First Ring and Rings', async () => {
184187
expect(reader.recordCount).toEqual(1);
185188

186189
let geom = expectGeometry(reader, 0, CoordType.XYZM, MultiPatchRecord);
190+
expect(geom.type).toEqual('MultiPolygon');
187191
expect(geom.coords.length).toBe(3);
188192
let polygon = geom.coords[0];
189193
expect(polygon.length).toBe(1);

0 commit comments

Comments
 (0)