@konfirm/geojson 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +16 -0
- package/.github/workflows/release.yml +21 -0
- package/.github/workflows/tests.yml +56 -0
- package/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +260 -0
- package/dist/Domain/Constants.d.ts +5 -0
- package/dist/Domain/GeoJSON/Concept/Altitude.d.ts +3 -0
- package/dist/Domain/GeoJSON/Concept/BoundingBox.d.ts +6 -0
- package/dist/Domain/GeoJSON/Concept/ExteriorRing.d.ts +4 -0
- package/dist/Domain/GeoJSON/Concept/GeoJSONObject.d.ts +11 -0
- package/dist/Domain/GeoJSON/Concept/InteriorRing.d.ts +4 -0
- package/dist/Domain/GeoJSON/Concept/Latitude.d.ts +3 -0
- package/dist/Domain/GeoJSON/Concept/LinearRing.d.ts +4 -0
- package/dist/Domain/GeoJSON/Concept/Longitude.d.ts +3 -0
- package/dist/Domain/GeoJSON/Concept/Position.d.ts +7 -0
- package/dist/Domain/GeoJSON/Feature.d.ts +12 -0
- package/dist/Domain/GeoJSON/FeatureCollection.d.ts +8 -0
- package/dist/Domain/GeoJSON/GeoJSON.d.ts +7 -0
- package/dist/Domain/GeoJSON/Geometry/LineString.d.ts +11 -0
- package/dist/Domain/GeoJSON/Geometry/MultiLineString.d.ts +7 -0
- package/dist/Domain/GeoJSON/Geometry/MultiPoint.d.ts +8 -0
- package/dist/Domain/GeoJSON/Geometry/MultiPolygon.d.ts +7 -0
- package/dist/Domain/GeoJSON/Geometry/Point.d.ts +11 -0
- package/dist/Domain/GeoJSON/Geometry/Polygon.d.ts +11 -0
- package/dist/Domain/GeoJSON/Geometry.d.ts +9 -0
- package/dist/Domain/GeoJSON/GeometryCollection.d.ts +8 -0
- package/dist/Domain/GeoJSON/GeometryObject.d.ts +12 -0
- package/dist/Domain/Guards/Number.d.ts +3 -0
- package/dist/Domain/Guards/Tuple.d.ts +3 -0
- package/dist/Domain/Iterator/IterablePair.d.ts +32 -0
- package/dist/Domain/Iterator/SimpleGeometry.d.ts +90 -0
- package/dist/Domain/Utility/Calculate.d.ts +9 -0
- package/dist/Domain/Utility/Distance.d.ts +3 -0
- package/dist/Domain/Utility/Intersect.d.ts +2 -0
- package/dist/Domain/Utility/Segments.d.ts +2 -0
- package/dist/Domain/Utility/Winding.d.ts +3 -0
- package/dist/geojson.cjs.js +655 -0
- package/dist/geojson.cjs.min.js +1 -0
- package/dist/geojson.d.ts +198 -0
- package/dist/geojson.es.js +627 -0
- package/dist/geojson.es.min.js +1 -0
- package/dist/geojson.js +660 -0
- package/dist/geojson.min.js +1 -0
- package/dist/main.d.ts +15 -0
- package/package.json +63 -0
- package/rollup.config.mjs +43 -0
- package/source/Domain/Constants.ts +5 -0
- package/source/Domain/GeoJSON/Concept/Altitude.ts +9 -0
- package/source/Domain/GeoJSON/Concept/BoundingBox.ts +31 -0
- package/source/Domain/GeoJSON/Concept/ExteriorRing.ts +12 -0
- package/source/Domain/GeoJSON/Concept/GeoJSONObject.ts +23 -0
- package/source/Domain/GeoJSON/Concept/InteriorRing.ts +12 -0
- package/source/Domain/GeoJSON/Concept/Latitude.ts +7 -0
- package/source/Domain/GeoJSON/Concept/LinearRing.ts +14 -0
- package/source/Domain/GeoJSON/Concept/Longitude.ts +7 -0
- package/source/Domain/GeoJSON/Concept/Position.ts +18 -0
- package/source/Domain/GeoJSON/Feature.ts +24 -0
- package/source/Domain/GeoJSON/FeatureCollection.ts +16 -0
- package/source/Domain/GeoJSON/GeoJSON.ts +9 -0
- package/source/Domain/GeoJSON/Geometry/LineString.ts +12 -0
- package/source/Domain/GeoJSON/Geometry/MultiLineString.ts +9 -0
- package/source/Domain/GeoJSON/Geometry/MultiPoint.ts +10 -0
- package/source/Domain/GeoJSON/Geometry/MultiPolygon.ts +9 -0
- package/source/Domain/GeoJSON/Geometry/Point.ts +12 -0
- package/source/Domain/GeoJSON/Geometry/Polygon.ts +20 -0
- package/source/Domain/GeoJSON/Geometry.ts +11 -0
- package/source/Domain/GeoJSON/GeometryCollection.ts +23 -0
- package/source/Domain/GeoJSON/GeometryObject.ts +20 -0
- package/source/Domain/Guards/Number.ts +13 -0
- package/source/Domain/Guards/Tuple.ts +6 -0
- package/source/Domain/Guards/Utility.ts +1 -0
- package/source/Domain/Iterator/IterablePair.ts +47 -0
- package/source/Domain/Iterator/SimpleGeometry.ts +137 -0
- package/source/Domain/Utility/Calculate.ts +143 -0
- package/source/Domain/Utility/Distance.ts +56 -0
- package/source/Domain/Utility/Intersect.ts +42 -0
- package/source/Domain/Utility/Numeric.ts +8 -0
- package/source/Domain/Utility/Segments.ts +5 -0
- package/source/Domain/Utility/Winding.ts +19 -0
- package/source/main.ts +20 -0
- package/test/Domain/GeoJSON/Concept/Altitude.ts +58 -0
- package/test/Domain/GeoJSON/Concept/BoundingBox.ts +77 -0
- package/test/Domain/GeoJSON/Concept/ExteriorRing.ts +65 -0
- package/test/Domain/GeoJSON/Concept/GeoJSONObject.ts +56 -0
- package/test/Domain/GeoJSON/Concept/InteriorRing.ts +65 -0
- package/test/Domain/GeoJSON/Concept/Latitude.ts +56 -0
- package/test/Domain/GeoJSON/Concept/LinearRing.ts +63 -0
- package/test/Domain/GeoJSON/Concept/Longitude.ts +56 -0
- package/test/Domain/GeoJSON/Concept/Position.ts +56 -0
- package/test/Domain/GeoJSON/Feature.ts +9 -0
- package/test/Domain/GeoJSON/FeatureCollection.ts +9 -0
- package/test/Domain/GeoJSON/GeoJSON.ts +21 -0
- package/test/Domain/GeoJSON/Geometry/LineString.ts +11 -0
- package/test/Domain/GeoJSON/Geometry/MultiLineString.ts +11 -0
- package/test/Domain/GeoJSON/Geometry/MultiPoint.ts +11 -0
- package/test/Domain/GeoJSON/Geometry/MultiPolygon.ts +11 -0
- package/test/Domain/GeoJSON/Geometry/Point.ts +11 -0
- package/test/Domain/GeoJSON/Geometry/Polygon.ts +11 -0
- package/test/Domain/GeoJSON/Geometry.ts +9 -0
- package/test/Domain/GeoJSON/GeometryCollection.ts +9 -0
- package/test/Domain/GeoJSON/GeometryObject.ts +4 -0
- package/test/Domain/Guards/Number.ts +49 -0
- package/test/Domain/Guards/Tuple.ts +27 -0
- package/test/Domain/Iterator/IterablePair.ts +203 -0
- package/test/Domain/Iterator/SimpleGeometry.ts +195 -0
- package/test/Domain/Utility/Calculate.ts +178 -0
- package/test/Domain/Utility/Distance.ts +19 -0
- package/test/Domain/Utility/Intersect.ts +54 -0
- package/test/Domain/Utility/Numeric.ts +30 -0
- package/test/Domain/Utility/Winding.ts +52 -0
- package/test/README.ts +123 -0
- package/test/data/Distance.ts +51 -0
- package/test/data/HolySee.ts +74 -0
- package/test/data/Intersect.ts +300 -0
- package/test/data/Italy.ts +2883 -0
- package/test/data/SanMarino.ts +83 -0
- package/test/data/Shapes.ts +107 -0
- package/test/helper/geometry.ts +76 -0
- package/test/helper/malform.ts +82 -0
- package/test/main.ts +4 -0
- package/tsconfig.json +12 -0
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { intersect } from './Domain/Utility/Intersect';
|
|
2
|
+
export { distance } from './Domain/Utility/Distance';
|
|
3
|
+
export { SimpleGeometryIterator } from './Domain/Iterator/SimpleGeometry';
|
|
4
|
+
export { Position, isPosition, isStrictPosition } from './Domain/GeoJSON/Concept/Position';
|
|
5
|
+
export { Point, isPoint, isStrictPoint } from './Domain/GeoJSON/Geometry/Point';
|
|
6
|
+
export { MultiPoint, isMultiPoint, isStrictMultiPoint } from './Domain/GeoJSON/Geometry/MultiPoint';
|
|
7
|
+
export { LineString, isLineString, isStrictLineString } from './Domain/GeoJSON/Geometry/LineString';
|
|
8
|
+
export { MultiLineString, isMultiLineString, isStrictMultiLineString } from './Domain/GeoJSON/Geometry/MultiLineString';
|
|
9
|
+
export { Polygon, isPolygon, isStrictPolygon } from './Domain/GeoJSON/Geometry/Polygon';
|
|
10
|
+
export { MultiPolygon, isMultiPolygon, isStrictMultiPolygon } from './Domain/GeoJSON/Geometry/MultiPolygon';
|
|
11
|
+
export { GeometryCollection, isGeometryCollection, isStrictGeometryCollection } from './Domain/GeoJSON/GeometryCollection';
|
|
12
|
+
export { Geometry, isGeometry, isStrictGeometry } from './Domain/GeoJSON/Geometry';
|
|
13
|
+
export { Feature, isFeature, isStrictFeature } from './Domain/GeoJSON/Feature';
|
|
14
|
+
export { FeatureCollection, isFeatureCollection, isStrictFeatureCollection } from './Domain/GeoJSON/FeatureCollection';
|
|
15
|
+
export { GeoJSON, isGeoJSON, isStrictGeoJSON } from './Domain/GeoJSON/GeoJSON';
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@konfirm/geojson",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "GeoJSON implementation",
|
|
5
|
+
"iife": "dist/geojson.js",
|
|
6
|
+
"main": "dist/geojson.cjs.js",
|
|
7
|
+
"module": "dist/geojson.es.js",
|
|
8
|
+
"types": "dist/geojson.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./source/main.ts",
|
|
12
|
+
"import": "./dist/geojson.es.js",
|
|
13
|
+
"require": "./dist/geojson.cjs.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/konfirm/geojson.git"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/konfirm/geojson/issues"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"test": "run-script-os",
|
|
25
|
+
"test:nix": "ts-node node_modules/tape/bin/tape 'test/**/*.ts'",
|
|
26
|
+
"test:win32": "ts-node node_modules/tape/bin/tape test/**/*.ts",
|
|
27
|
+
"test:coverage": "run-script-os",
|
|
28
|
+
"test:coverage:nix": "nyc --reporter=html --require ts-node/register tape 'test/**/*.ts' | tap-arc",
|
|
29
|
+
"test:coverage:win32": "nyc --reporter=html --require ts-node/register tape test/**/*.ts | tap-arc",
|
|
30
|
+
"test:pretty": "run-script-os",
|
|
31
|
+
"test:pretty:nix": "nyc --require ts-node/register tape 'test/**/*.ts' | tap-arc",
|
|
32
|
+
"test:pretty:win32": "nyc --require ts-node/register tape test/**/*.ts | tap-arc",
|
|
33
|
+
"prebuild": "tsc --declarationDir temp --declaration true --emitDeclarationOnly true",
|
|
34
|
+
"build": "rollup -c rollup.config.mjs",
|
|
35
|
+
"postbuild": "rm -rf temp",
|
|
36
|
+
"prepublish": "npm run build"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"geojson"
|
|
40
|
+
],
|
|
41
|
+
"author": "Rogier Spieker <rogier+npm@konfirm.eu>",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@rollup/plugin-commonjs": "^24.0.1",
|
|
45
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
46
|
+
"@rollup/plugin-terser": "^0.4.0",
|
|
47
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
48
|
+
"@types/tape": "^4.13.2",
|
|
49
|
+
"nyc": "^15.1.0",
|
|
50
|
+
"rollup": "^3.14.0",
|
|
51
|
+
"rollup-plugin-dts": "^5.1.1",
|
|
52
|
+
"run-script-os": "^1.1.6",
|
|
53
|
+
"tap-arc": "^0.3.5",
|
|
54
|
+
"tape": "^5.6.3",
|
|
55
|
+
"template-literal-each": "^3.0.0",
|
|
56
|
+
"ts-node": "^10.9.1",
|
|
57
|
+
"tslib": "^2.5.0",
|
|
58
|
+
"typescript": "^4.9.5"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@konfirm/guard": "^2.0.0"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import typescript from '@rollup/plugin-typescript';
|
|
3
|
+
import { nodeResolve as resolve } from '@rollup/plugin-node-resolve';
|
|
4
|
+
import common from '@rollup/plugin-commonjs';
|
|
5
|
+
import { default as terser } from '@rollup/plugin-terser';
|
|
6
|
+
import declaration from 'rollup-plugin-dts'
|
|
7
|
+
|
|
8
|
+
const { main, iife, module, types } = JSON.parse(readFileSync('./package.json'));
|
|
9
|
+
|
|
10
|
+
const defaults = {
|
|
11
|
+
name: 'GeoJSON',
|
|
12
|
+
sourcemap: false,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function configure(...args) {
|
|
16
|
+
return args.reduce((carry, options) => {
|
|
17
|
+
const basic = { ...defaults, ...options };
|
|
18
|
+
const min = {
|
|
19
|
+
...basic,
|
|
20
|
+
file: basic.file.replace(/(\.[a-z]+)$/, '.min$1'),
|
|
21
|
+
plugins: [terser({ format: { comments: false } })],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return carry.concat(basic, min);
|
|
25
|
+
}, []);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default [
|
|
29
|
+
{
|
|
30
|
+
input: 'source/main.ts',
|
|
31
|
+
output: configure(
|
|
32
|
+
{ file: main, format: 'cjs' },
|
|
33
|
+
{ file: iife, format: 'iife' },
|
|
34
|
+
{ file: module, format: 'es' },
|
|
35
|
+
),
|
|
36
|
+
plugins: [resolve(), common(), typescript(), common()],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
input: 'temp/main.d.ts',
|
|
40
|
+
output: { file: types, format: 'es' },
|
|
41
|
+
plugins: [declaration()],
|
|
42
|
+
}
|
|
43
|
+
];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const EARTH_RADIUS = 6_371_008.7714; // mean radius
|
|
2
|
+
export const EARTH_RADIUS_MAJOR = 6_378_137; // equatorial radius
|
|
3
|
+
export const EARTH_RADIUS_MINOR = 6_356_752.314_245; // semiminor axis
|
|
4
|
+
export const EARTH_FLATTENING = 298.257_223_563;
|
|
5
|
+
export const GPS_SATELLITE_ORBIT = 20_180_000;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EARTH_RADIUS, GPS_SATELLITE_ORBIT } from "../../Constants";
|
|
2
|
+
import { isNumberBetween, isNumberValue } from "../../Guards/Number";
|
|
3
|
+
|
|
4
|
+
export type Altitude = number;
|
|
5
|
+
export function isAltitude(value: any): value is Altitude {
|
|
6
|
+
return isNumberValue(value);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const isStrictAltitude = isNumberBetween<Altitude>(-EARTH_RADIUS, GPS_SATELLITE_ORBIT);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { all, any } from "@konfirm/guard";
|
|
2
|
+
import { isTuple } from "../../Guards/Tuple";
|
|
3
|
+
import { isLongitude, Longitude, isStrictLongitude } from "./Longitude";
|
|
4
|
+
import { isLatitude, Latitude, isStrictLatitude } from "./Latitude";
|
|
5
|
+
import { Altitude, isAltitude, isStrictAltitude } from "./Altitude";
|
|
6
|
+
|
|
7
|
+
export type BoundingBox
|
|
8
|
+
= [Longitude, Latitude, Altitude, Longitude, Latitude, Altitude]
|
|
9
|
+
| [Longitude, Latitude, Longitude, Latitude];
|
|
10
|
+
const isBoundingBoxWithAltitude = all(
|
|
11
|
+
isTuple(isLongitude, isLatitude, isAltitude, isLongitude, isLatitude, isAltitude),
|
|
12
|
+
([, s, , , n]) => s <= n
|
|
13
|
+
)
|
|
14
|
+
const isBoundingBoxWithoutAltitude = all(
|
|
15
|
+
isTuple(isLongitude, isLatitude, isLongitude, isLatitude),
|
|
16
|
+
([, s, , n]) => s <= n
|
|
17
|
+
)
|
|
18
|
+
export const isBoundingBox = any<BoundingBox>(
|
|
19
|
+
isBoundingBoxWithAltitude,
|
|
20
|
+
isBoundingBoxWithoutAltitude
|
|
21
|
+
);
|
|
22
|
+
export const isStrictBoundingBox = any<BoundingBox>(
|
|
23
|
+
all(
|
|
24
|
+
isTuple(isStrictLongitude, isStrictLatitude, isStrictAltitude, isStrictLongitude, isStrictLatitude, isStrictAltitude),
|
|
25
|
+
isBoundingBoxWithAltitude
|
|
26
|
+
),
|
|
27
|
+
all(
|
|
28
|
+
isTuple(isStrictLongitude, isStrictLatitude, isStrictLongitude, isStrictLatitude),
|
|
29
|
+
isBoundingBoxWithoutAltitude
|
|
30
|
+
),
|
|
31
|
+
);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { all } from "@konfirm/guard";
|
|
2
|
+
import { isCounterClockwiseWinding } from "../../Utility/Winding";
|
|
3
|
+
import { isLinearRing, isStrictLinearRing, LinearRing } from "./LinearRing";
|
|
4
|
+
|
|
5
|
+
export type ExteriorRing = LinearRing;
|
|
6
|
+
export const isExteriorRing = all<ExteriorRing>(
|
|
7
|
+
isLinearRing,
|
|
8
|
+
);
|
|
9
|
+
export const isStrictExteriorRing = all<ExteriorRing>(
|
|
10
|
+
isStrictLinearRing,
|
|
11
|
+
isCounterClockwiseWinding
|
|
12
|
+
);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { all, Guard, isString, isStructure } from "@konfirm/guard";
|
|
2
|
+
import { BoundingBox, isBoundingBox, isStrictBoundingBox } from "./BoundingBox";
|
|
3
|
+
|
|
4
|
+
type GeoJSONBase = {
|
|
5
|
+
type: string;
|
|
6
|
+
bbox?: BoundingBox;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
export type GeoJSONObject<T extends GeoJSONBase = GeoJSONBase>
|
|
10
|
+
= GeoJSONBase
|
|
11
|
+
& T;
|
|
12
|
+
export function isGeoJSONObject<T extends GeoJSONBase>(type: string): Guard<T> {
|
|
13
|
+
return isStructure<T>({
|
|
14
|
+
type: all(isString, (value: any) => value === type),
|
|
15
|
+
bbox: isBoundingBox,
|
|
16
|
+
}, 'bbox');
|
|
17
|
+
}
|
|
18
|
+
export function isStrictGeoJSONObject<T extends GeoJSONBase>(type: string): Guard<T> {
|
|
19
|
+
return isStructure<T>({
|
|
20
|
+
type: all(isString, (value: any) => value === type),
|
|
21
|
+
bbox: isStrictBoundingBox,
|
|
22
|
+
}, 'bbox');
|
|
23
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { all } from "@konfirm/guard";
|
|
2
|
+
import { isClockwiseWinding } from "../../Utility/Winding";
|
|
3
|
+
import { isLinearRing, isStrictLinearRing, LinearRing } from "./LinearRing";
|
|
4
|
+
|
|
5
|
+
export type InteriorRing = LinearRing;
|
|
6
|
+
export const isInteriorRing = all<InteriorRing>(
|
|
7
|
+
isLinearRing,
|
|
8
|
+
);
|
|
9
|
+
export const isStrictInteriorRing = all<InteriorRing>(
|
|
10
|
+
isStrictLinearRing,
|
|
11
|
+
isClockwiseWinding
|
|
12
|
+
);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { isNumberBetween, isNumberValue } from "../../Guards/Number";
|
|
2
|
+
|
|
3
|
+
export type Latitude = number;
|
|
4
|
+
export function isLatitude(value: any): value is Latitude {
|
|
5
|
+
return isNumberValue(value);
|
|
6
|
+
}
|
|
7
|
+
export const isStrictLatitude = isNumberBetween<Latitude>(-90, 90);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { all, isArrayOfSize, isArrayOfType } from "@konfirm/guard";
|
|
2
|
+
import { isPosition, isStrictPosition, Position } from "./Position";
|
|
3
|
+
|
|
4
|
+
export type LinearRing = Array<Position>;
|
|
5
|
+
export const isLinearRing = all<LinearRing>(
|
|
6
|
+
isArrayOfType(isPosition),
|
|
7
|
+
isArrayOfSize(4),
|
|
8
|
+
(value: Array<Position>) => value[value.length - 1].every((v, i) => v === value[0][i])
|
|
9
|
+
);
|
|
10
|
+
export const isStrictLinearRing = all<LinearRing>(
|
|
11
|
+
isArrayOfType(isStrictPosition),
|
|
12
|
+
isArrayOfSize(4),
|
|
13
|
+
(value: Array<Position>) => value[value.length - 1].every((v, i) => v === value[0][i])
|
|
14
|
+
);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { isNumberBetween, isNumberValue } from "../../Guards/Number";
|
|
2
|
+
|
|
3
|
+
export type Longitude = number;
|
|
4
|
+
export function isLongitude(value: any): value is Longitude {
|
|
5
|
+
return isNumberValue(value);
|
|
6
|
+
}
|
|
7
|
+
export const isStrictLongitude = isNumberBetween<Longitude>(-180, 180);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { any } from "@konfirm/guard";
|
|
2
|
+
import { isTuple } from "../../Guards/Tuple";
|
|
3
|
+
import { Altitude, isAltitude, isStrictAltitude } from "./Altitude";
|
|
4
|
+
import { isLatitude, isStrictLatitude, Latitude } from "./Latitude";
|
|
5
|
+
import { isLongitude, isStrictLongitude, Longitude } from "./Longitude";
|
|
6
|
+
|
|
7
|
+
export type Position = [Longitude, Latitude, Altitude?];
|
|
8
|
+
export const isPosition = any<Position>(
|
|
9
|
+
isTuple(isLongitude, isLatitude),
|
|
10
|
+
isTuple(isLongitude, isLatitude, isAltitude)
|
|
11
|
+
);
|
|
12
|
+
export const isStrictPosition = any<Position>(
|
|
13
|
+
isTuple(isStrictLongitude, isStrictLatitude),
|
|
14
|
+
isTuple(isStrictLongitude, isStrictLatitude, isStrictAltitude),
|
|
15
|
+
);
|
|
16
|
+
export function isEquivalentPosition(one: any, two: any): boolean {
|
|
17
|
+
return isPosition(one) && isPosition(two) && one.length === two.length && one.every((v, i) => v === two[i]);
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { all, any, isNULL, isObject, isStructure } from "@konfirm/guard";
|
|
2
|
+
import { GeoJSONObject, isGeoJSONObject } from "./Concept/GeoJSONObject";
|
|
3
|
+
import { Geometry, isGeometry, isStrictGeometry } from "./Geometry";
|
|
4
|
+
import { GeometryCollection, isGeometryCollection, isStrictGeometryCollection } from "./GeometryCollection";
|
|
5
|
+
|
|
6
|
+
export type Feature = GeoJSONObject<{
|
|
7
|
+
type: 'Feature';
|
|
8
|
+
geometry: Geometry | GeometryCollection;
|
|
9
|
+
properties: { [key: string]: unknown } | null;
|
|
10
|
+
}>
|
|
11
|
+
export const isFeature = all<Feature>(
|
|
12
|
+
isGeoJSONObject('Feature'),
|
|
13
|
+
isStructure({
|
|
14
|
+
geometry: any(isGeometry, isGeometryCollection),
|
|
15
|
+
properties: any(isNULL, isObject)
|
|
16
|
+
})
|
|
17
|
+
);
|
|
18
|
+
export const isStrictFeature = all<Feature>(
|
|
19
|
+
isGeoJSONObject('Feature'),
|
|
20
|
+
isStructure({
|
|
21
|
+
geometry: any(isStrictGeometry, isStrictGeometryCollection),
|
|
22
|
+
properties: any(isNULL, isObject)
|
|
23
|
+
})
|
|
24
|
+
);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { all, isArrayOfType, isKeyOfType } from "@konfirm/guard";
|
|
2
|
+
import { Feature, isFeature, isStrictFeature } from "./Feature";
|
|
3
|
+
import { GeoJSONObject, isGeoJSONObject } from "./Concept/GeoJSONObject";
|
|
4
|
+
|
|
5
|
+
export type FeatureCollection = GeoJSONObject<{
|
|
6
|
+
type: 'FeatureCollection';
|
|
7
|
+
features: Array<Feature>;
|
|
8
|
+
}>
|
|
9
|
+
export const isFeatureCollection = all<FeatureCollection>(
|
|
10
|
+
isGeoJSONObject('FeatureCollection'),
|
|
11
|
+
isKeyOfType('features', isArrayOfType(isFeature))
|
|
12
|
+
);
|
|
13
|
+
export const isStrictFeatureCollection = all<FeatureCollection>(
|
|
14
|
+
isGeoJSONObject('FeatureCollection'),
|
|
15
|
+
isKeyOfType('features', isArrayOfType(isStrictFeature))
|
|
16
|
+
);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { any } from "@konfirm/guard";
|
|
2
|
+
import { Feature, isFeature, isStrictFeature } from "./Feature";
|
|
3
|
+
import { FeatureCollection, isFeatureCollection, isStrictFeatureCollection } from "./FeatureCollection";
|
|
4
|
+
import { GeometryCollection, isGeometryCollection, isStrictGeometryCollection } from "./GeometryCollection";
|
|
5
|
+
import { Geometry, isGeometry, isStrictGeometry } from "./Geometry";
|
|
6
|
+
|
|
7
|
+
export type GeoJSON = Geometry | GeometryCollection | Feature | FeatureCollection;
|
|
8
|
+
export const isGeoJSON = any<GeoJSON>(isGeometry, isGeometryCollection, isFeature, isFeatureCollection);
|
|
9
|
+
export const isStrictGeoJSON = any<GeoJSON>(isStrictGeometry, isStrictGeometryCollection, isStrictFeature, isStrictFeatureCollection);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Guard } from "../../Guards/Utility";
|
|
2
|
+
import { GeometryObject, isGeometryObject } from "../GeometryObject";
|
|
3
|
+
import { isMultiPointCoordinates, isStrictMultiPointCoordinates, MultiPoint } from "./MultiPoint";
|
|
4
|
+
|
|
5
|
+
export type LineString = GeometryObject<{
|
|
6
|
+
type: 'LineString';
|
|
7
|
+
coordinates: MultiPoint['coordinates'];
|
|
8
|
+
}>
|
|
9
|
+
export const isLineStringCoordinates = isMultiPointCoordinates;
|
|
10
|
+
export const isLineString: Guard<LineString> = isGeometryObject<LineString>('LineString', isLineStringCoordinates);
|
|
11
|
+
export const isStrictLineStringCoordinates = isStrictMultiPointCoordinates;
|
|
12
|
+
export const isStrictLineString: Guard<LineString> = isGeometryObject<LineString>('LineString', isStrictLineStringCoordinates);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { isArrayOfType } from "@konfirm/guard";
|
|
2
|
+
import { isGeometryObject, MultiGeometryObject } from "../GeometryObject";
|
|
3
|
+
import { isLineStringCoordinates, isStrictLineStringCoordinates, LineString } from "./LineString";
|
|
4
|
+
|
|
5
|
+
export type MultiLineString = MultiGeometryObject<LineString>;
|
|
6
|
+
export const isMultiLineStringCoordinates = isArrayOfType(isLineStringCoordinates);
|
|
7
|
+
export const isMultiLineString = isGeometryObject<MultiLineString>('MultiLineString', isMultiLineStringCoordinates);
|
|
8
|
+
export const isStrictMultiLineStringCoordinates = isArrayOfType(isStrictLineStringCoordinates);
|
|
9
|
+
export const isStrictMultiLineString = isGeometryObject<MultiLineString>('MultiLineString', isStrictMultiLineStringCoordinates);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isArrayOfType } from "@konfirm/guard";
|
|
2
|
+
import { Guard } from "../../Guards/Utility";
|
|
3
|
+
import { isGeometryObject, MultiGeometryObject } from "../GeometryObject";
|
|
4
|
+
import { isPointCoordinates, isStrictPointCoordinates, Point } from "./Point";
|
|
5
|
+
|
|
6
|
+
export type MultiPoint = MultiGeometryObject<Point>
|
|
7
|
+
export const isMultiPointCoordinates: Guard<MultiPoint['coordinates']> = isArrayOfType(isPointCoordinates)
|
|
8
|
+
export const isMultiPoint = isGeometryObject<MultiPoint>('MultiPoint', isMultiPointCoordinates);
|
|
9
|
+
export const isStrictMultiPointCoordinates: Guard<MultiPoint['coordinates']> = isArrayOfType(isStrictPointCoordinates)
|
|
10
|
+
export const isStrictMultiPoint = isGeometryObject<MultiPoint>('MultiPoint', isStrictMultiPointCoordinates);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { isArrayOfType } from "@konfirm/guard";
|
|
2
|
+
import { isGeometryObject, MultiGeometryObject } from "../GeometryObject";
|
|
3
|
+
import { isPolygonCoordinates, isStrictPolygonCoordinates, Polygon } from "./Polygon";
|
|
4
|
+
|
|
5
|
+
export type MultiPolygon = MultiGeometryObject<Polygon>
|
|
6
|
+
export const isMultiPolygonCoordinates = isArrayOfType(isPolygonCoordinates);
|
|
7
|
+
export const isMultiPolygon = isGeometryObject<MultiPolygon>('MultiPolygon', isMultiPolygonCoordinates);
|
|
8
|
+
export const isStrictMultiPolygonCoordinates = isArrayOfType(isStrictPolygonCoordinates);
|
|
9
|
+
export const isStrictMultiPolygon = isGeometryObject<MultiPolygon>('MultiPolygon', isStrictMultiPolygonCoordinates);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GeometryObject, isGeometryObject } from "../GeometryObject";
|
|
2
|
+
import { isPosition, isStrictPosition, Position } from "../Concept/Position";
|
|
3
|
+
import { Guard } from "../../Guards/Utility";
|
|
4
|
+
|
|
5
|
+
export type Point = GeometryObject<{
|
|
6
|
+
type: 'Point';
|
|
7
|
+
coordinates: Position;
|
|
8
|
+
}>
|
|
9
|
+
export const isPointCoordinates: Guard<Point['coordinates']> = isPosition;
|
|
10
|
+
export const isPoint: Guard<Point> = isGeometryObject<Point>('Point', isPointCoordinates);
|
|
11
|
+
export const isStrictPointCoordinates: Guard<Point['coordinates']> = isStrictPosition;
|
|
12
|
+
export const isStrictPoint: Guard<Point> = isGeometryObject<Point>('Point', isStrictPointCoordinates);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { all, isArrayOfType } from "@konfirm/guard";
|
|
2
|
+
import { GeometryObject, isGeometryObject } from "../GeometryObject";
|
|
3
|
+
import { ExteriorRing, isExteriorRing } from "../Concept/ExteriorRing";
|
|
4
|
+
import { InteriorRing, isInteriorRing } from "../Concept/InteriorRing";
|
|
5
|
+
import { isLinearRing, isStrictLinearRing } from "../Concept/LinearRing";
|
|
6
|
+
|
|
7
|
+
export type Polygon = GeometryObject<{
|
|
8
|
+
type: 'Polygon';
|
|
9
|
+
coordinates: [ExteriorRing, ...Array<InteriorRing>];
|
|
10
|
+
}>
|
|
11
|
+
export const isPolygonCoordinates = all(
|
|
12
|
+
isArrayOfType(isLinearRing)
|
|
13
|
+
);
|
|
14
|
+
export const isPolygon = isGeometryObject<Polygon>('Polygon', isPolygonCoordinates);
|
|
15
|
+
export const isStrictPolygonCoordinates = all(
|
|
16
|
+
isArrayOfType(isStrictLinearRing),
|
|
17
|
+
(value: any) => isExteriorRing(value[0]),
|
|
18
|
+
(value: any) => value.slice(1).every(isInteriorRing)
|
|
19
|
+
);
|
|
20
|
+
export const isStrictPolygon = isGeometryObject<Polygon>('Polygon', isStrictPolygonCoordinates);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { any } from "@konfirm/guard";
|
|
2
|
+
import { isLineString, isStrictLineString, LineString } from "./Geometry/LineString";
|
|
3
|
+
import { isMultiLineString, isStrictMultiLineString, MultiLineString } from "./Geometry/MultiLineString";
|
|
4
|
+
import { isMultiPoint, isStrictMultiPoint, MultiPoint } from "./Geometry/MultiPoint";
|
|
5
|
+
import { isMultiPolygon, isStrictMultiPolygon, MultiPolygon } from "./Geometry/MultiPolygon";
|
|
6
|
+
import { isPoint, isStrictPoint, Point } from "./Geometry/Point";
|
|
7
|
+
import { isPolygon, isStrictPolygon, Polygon } from "./Geometry/Polygon";
|
|
8
|
+
|
|
9
|
+
export type Geometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;
|
|
10
|
+
export const isGeometry = any<Geometry>(isPoint, isMultiPoint, isLineString, isMultiLineString, isPolygon, isMultiPolygon);
|
|
11
|
+
export const isStrictGeometry = any<Geometry>(isStrictPoint, isStrictMultiPoint, isStrictLineString, isStrictMultiLineString, isStrictPolygon, isStrictMultiPolygon);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { all, any, isArrayOfType, isKeyOfType } from "@konfirm/guard";
|
|
2
|
+
import { GeoJSONObject, isGeoJSONObject } from "./Concept/GeoJSONObject";
|
|
3
|
+
import { Geometry, isGeometry, isStrictGeometry } from "./Geometry";
|
|
4
|
+
|
|
5
|
+
export type GeometryCollection = GeoJSONObject<{
|
|
6
|
+
type: 'GeometryCollection';
|
|
7
|
+
geometries: Array<Geometry | GeometryCollection>;
|
|
8
|
+
}>;
|
|
9
|
+
|
|
10
|
+
const isGeometryCollectionObject = all<GeometryCollection>(
|
|
11
|
+
isGeoJSONObject('GeometryCollection'),
|
|
12
|
+
isKeyOfType('geometries', isArrayOfType(any(isGeometry, isGeometryCollection)))
|
|
13
|
+
);
|
|
14
|
+
const isStrictGeometryCollectionObject = all<GeometryCollection>(
|
|
15
|
+
isGeoJSONObject('GeometryCollection'),
|
|
16
|
+
isKeyOfType('geometries', isArrayOfType(any(isStrictGeometry, isStrictGeometryCollection)))
|
|
17
|
+
);
|
|
18
|
+
export function isGeometryCollection(value: any): value is GeometryCollection {
|
|
19
|
+
return isGeometryCollectionObject(value)
|
|
20
|
+
}
|
|
21
|
+
export function isStrictGeometryCollection(value: any): value is GeometryCollection {
|
|
22
|
+
return isStrictGeometryCollectionObject(value)
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { all, Guard, isKeyOfType, Validator } from "@konfirm/guard";
|
|
2
|
+
import { GeoJSONObject, isGeoJSONObject } from "./Concept/GeoJSONObject";
|
|
3
|
+
|
|
4
|
+
type GeometryBase = GeoJSONObject & {
|
|
5
|
+
coordinates: Array<unknown>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type GeometryObject<T extends GeometryBase>
|
|
9
|
+
= Omit<GeometryBase, 'coordinates'>
|
|
10
|
+
& T;
|
|
11
|
+
export type MultiGeometryObject<T extends GeometryBase> = GeometryObject<{
|
|
12
|
+
type: `Multi${T['type']}`;
|
|
13
|
+
coordinates: Array<T['coordinates']>;
|
|
14
|
+
}>;
|
|
15
|
+
export function isGeometryObject<T extends GeometryBase>(type: string, isCoordinates: Validator): Guard<T> {
|
|
16
|
+
return all<T>(
|
|
17
|
+
isGeoJSONObject(type),
|
|
18
|
+
isKeyOfType('coordinates', isCoordinates)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isNumber } from '@konfirm/guard';
|
|
2
|
+
import { Guard } from './Utility';
|
|
3
|
+
|
|
4
|
+
export function isNumberValue<T extends number>(value: any): value is T {
|
|
5
|
+
return isNumber(value) && Number.isFinite(value);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function isNumberBetween<T extends number>(a: number, b: number = Infinity): Guard<T> {
|
|
9
|
+
const min = Math.min(a, b);
|
|
10
|
+
const max = Math.max(a, b);
|
|
11
|
+
|
|
12
|
+
return (value: any): value is T => isNumberValue(value) && value >= min && value <= max;
|
|
13
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { isArray, Validator } from "@konfirm/guard";
|
|
2
|
+
import { Guard } from './Utility';
|
|
3
|
+
|
|
4
|
+
export function isTuple<T extends Array<unknown>>(...rules: Array<Validator>): Guard<T> {
|
|
5
|
+
return (value: any): value is T => isArray(value) && value.length === rules.length && rules.every((rule, index) => rule(value[index]));
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Guard<T> = (value: any) => value is T;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterator class which traverses all value pairs of two or more Iterable instances
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @class IterablePairIterator
|
|
6
|
+
* @template T
|
|
7
|
+
*/
|
|
8
|
+
export class IterablePairIterator<T = unknown> {
|
|
9
|
+
private readonly iterators: Array<Iterable<T>> = [];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Constructs a new instance of IterablePairIterator
|
|
13
|
+
*
|
|
14
|
+
* @param iterators
|
|
15
|
+
*/
|
|
16
|
+
constructor(...iterators: [Iterable<T>, Iterable<T>, ...Array<Iterable<T>>]) {
|
|
17
|
+
this.iterators = iterators;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Generator yielding all value pairs from the provided iterators
|
|
22
|
+
*
|
|
23
|
+
* @return {*} {Iterator<[T, T]>}
|
|
24
|
+
* @memberof IterablePairIterator
|
|
25
|
+
*/
|
|
26
|
+
*[Symbol.iterator](): Iterator<[T, T]> {
|
|
27
|
+
for (const [a, b] of this.pairs(this.iterators)) {
|
|
28
|
+
for (const one of a) {
|
|
29
|
+
for (const two of b) {
|
|
30
|
+
yield [one, two];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create unique Iterator<T> combinations to traverse over
|
|
38
|
+
*
|
|
39
|
+
* @private
|
|
40
|
+
* @param {Array<Iterable<T>>} source
|
|
41
|
+
* @return {*} {Array<[Iterable<T>, Iterable<T>]>}
|
|
42
|
+
* @memberof IterablePairIterator
|
|
43
|
+
*/
|
|
44
|
+
private pairs(source: Array<Iterable<T>>): Array<[Iterable<T>, Iterable<T>]> {
|
|
45
|
+
return source.map((a, i) => source.slice(i + 1).map((b) => [a, b])).flat() as Array<[Iterable<T>, Iterable<T>]>;
|
|
46
|
+
}
|
|
47
|
+
}
|