Skip to content

Commit

Permalink
geotiff is done
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr Martian committed Sep 28, 2024
1 parent 1888446 commit 7baa4cf
Show file tree
Hide file tree
Showing 161 changed files with 97,335 additions and 3,869 deletions.
17 changes: 15 additions & 2 deletions benchmarks/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import tmp from 'tmp';
tmp.setGracefulCleanup();

const dir = tmp.dirSync({ prefix: 'store_benchmarks' });
const TEST_SIZE = 1_000_000;
// const TEST_SIZE = 1_000_000;
const TEST_SIZE = 100_000;

const mmapStore = new S2MMapStore<{ a: number }>(`${dir.name}/mmap`, false, false);
// const fileStore = new S2FileStore<{ a: number }>(`${dir.name}/file`, false, false);
Expand Down Expand Up @@ -59,11 +60,23 @@ console.info('mmap total time: ', mmapAddSeconds + mmapSortSeconds + mmapQuerySe

// const myDB = open({ path: `${dir.name}/lmdb` });
// const lmdbAddStart = Bun.nanoseconds();
// for (let i = 0; i < 10_000; i++) await myDB.put(String(i), { a: i });
// for (let i = 0; i < TEST_SIZE; i++) {
// const rand = getRandomInt(0, TEST_SIZE);
// await myDB.put(String(rand), { a: rand });
// }
// const lmdbAddEnd = Bun.nanoseconds();
// const lmdbAddSeconds = (lmdbAddEnd - lmdbAddStart) / 1_000_000_000;
// console.info('lmdb Add time: ', lmdbAddSeconds);

// // Let's perform a simple lookup to simulate a query
// const lmdbQueryStart = Bun.nanoseconds();
// await myDB.get('22');
// const lmdbQueryEnd = Bun.nanoseconds();
// const lmdbQuerySeconds = (lmdbQueryEnd - lmdbQueryStart) / 1_000_000_000;
// console.info('lmdb Query time: ', lmdbQuerySeconds);

// console.info('lmdb total time: ', lmdbAddSeconds + lmdbQuerySeconds);

// await myDB.close();

/// ----------------------------------------------
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2,804 changes: 2,804 additions & 0 deletions deno.lock

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,33 @@ export default tseslint.config(
},
},
},
jsdoc.configs['flat/recommended-typescript-error'],
jsdoc.configs['flat/recommended-typescript'],
{
rules: {
// ensure explicit comparisons
eqeqeq: ['error', 'always'],
'no-implicit-coercion': ['error', { boolean: false }],
'no-implicit-coercion': ['error', { boolean: false, number: true, string: true }],
'@typescript-eslint/strict-boolean-expressions': [
'error',
{
allowString: false,
allowNumber: false,
allowNullableObject: false,
allowNullableBoolean: false,
allowNullableString: false,
allowNullableNumber: false,
allowAny: false,
},
],
'no-extra-boolean-cast': 'error',
'no-constant-condition': ['error', { checkLoops: false }],
'no-unused-expressions': ['error', { allowTernary: true, allowShortCircuit: true }],
// manage promises correctly
'@typescript-eslint/no-misused-promises': 'error',
'no-async-promise-executor': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/prefer-promise-reject-errors': 'error',
'@typescript-eslint/promise-function-async': 'error',
'require-await': 'error',
// console logs
'no-console': ['error', { allow: ['info', 'warn', 'error'] }],
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"package-check": "package-check",
"test:dev": "bun test --watch --coverage",
"test": "bun test",
"test:fast": "FAST_TESTS_ONLY=true bun test",
"test:coverage": "bun run test --coverage",
"test:cov": "bun run tools/buildCoverage.ts",
"docs": "typedoc"
Expand All @@ -70,6 +71,7 @@
"eslint-plugin-jsdoc": "^50.2.3",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-tsdoc": "^0.3.0",
"geotiff": "^2.1.3",
"lmdb": "^3.1.2",
"nextafter": "^1.0.0",
"prettier": "^3.3.3",
Expand All @@ -82,6 +84,7 @@
},
"dependencies": {
"earclip": "^1.1.0",
"latest": "^0.2.0",
"open-vector-tile": "^1.3.0",
"s2-tilejson": "^1.6.0",
"s2json-spec": "^1.5.5",
Expand Down
4 changes: 2 additions & 2 deletions src/converters/toJSON/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function toJSON(

await writer.appendString('\n\t],');
await writer.appendString(`\n\t"faces": ${JSON.stringify([...faces])}`);
if (bbox) await writer.appendString(`,\n\t"bbox": ${JSON.stringify(bbox)}`);
if (bbox !== undefined) await writer.appendString(`,\n\t"bbox": ${JSON.stringify(bbox)}`);
await writer.appendString('\n}');
}

Expand Down Expand Up @@ -89,7 +89,7 @@ export async function toJSONLD(
for (const convertedFeature of convertedFeatures) {
const userFeature = onFeature(convertedFeature);
if (userFeature === undefined) continue;
writer.appendString(JSON.stringify(userFeature) + '\n');
await writer.appendString(JSON.stringify(userFeature) + '\n');
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/converters/toTiles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export interface BuildGuide {
* Build vector tiles give a guide on what sources to parse data from and how to store it
* @param buildGuide - the user defined guide on building the vector tiles
*/
export function toVectorTiles(buildGuide: BuildGuide): void {
export async function toTiles(buildGuide: BuildGuide): Promise<void> {
const { tileWriter } = buildGuide;

// first setup our metadata builder
Expand All @@ -81,7 +81,7 @@ export function toVectorTiles(buildGuide: BuildGuide): void {

// FINISH:
const metadata = metaBuilder.commit();
tileWriter.commit(metadata);
await tileWriter.commit(metadata);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/dataStore/externalSort/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface SortChunk {
* @param event - the sort chunk message
*/
self.onmessage = (event: Bun.MessageEvent<SortChunk>): void => {
sortChunk(event.data).then((outFile): void => {
void sortChunk(event.data).then((outFile): void => {
postMessage(outFile);
});
};
2 changes: 1 addition & 1 deletion src/dataStore/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class S2FileStore<V = Stringifiable> {
readSync(this.#valueFd, valueBuf, 0, valueLength, valueOffset);
res.push(JSON.parse(valueBuf.toString()) as V);
}
if (max && res.length >= max) break;
if (max !== undefined && res.length >= max) break;
lowerIndex++;
if (lowerIndex >= this.#size) break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dataStore/kv/file.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { closeSync, openSync, readSync, writeSync } from 'fs';
import { closeSync, openSync, writeSync } from 'fs';

import type { KVStore } from '.';
import type { Key, Stringifiable } from '..';
Expand Down
7 changes: 3 additions & 4 deletions src/dataStore/mmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class S2MMapStore<V = Stringifiable> {
* @returns the value if the map contains values for the key
*/
get(key: Key, max?: number, bigint = false): V[] | undefined {
this.switchToReadState();
if (!this.#sorted) throw new Error('Not sorted, please call "switchToReadState" first');
let lowerIndex = this.#lowerBound(key);
if (lowerIndex >= this.#size) return undefined;
const { low: lowID, high: highID } = this.#getLowHigh(key);
Expand All @@ -116,7 +116,7 @@ export class S2MMapStore<V = Stringifiable> {
const valueBuf = Buffer.from(valSlice);
res.push(JSON.parse(valueBuf.toString()) as V);
}
if (max && res.length >= max) break;
if (max !== undefined && res.length >= max) break;
lowerIndex++;
if (lowerIndex >= this.#size) break;
}
Expand All @@ -131,7 +131,7 @@ export class S2MMapStore<V = Stringifiable> {
* @returns true if the map contains value(s) for the key
*/
has(key: Key): boolean {
this.switchToReadState();
if (!this.#sorted) throw new Error('Not sorted, please call "switchToReadState" first');
const lowerIndex = this.#lowerBound(key);
if (lowerIndex >= this.#size) return false;
const { low: lowID, high: highID } = this.#getLowHigh(key);
Expand Down Expand Up @@ -166,7 +166,6 @@ export class S2MMapStore<V = Stringifiable> {
*/
#lowerBound(id: Key): number {
const loHiID = this.#getLowHigh(id);
this.#sort();
// lower bound search
let lo: number = 0;
let hi: number = this.#size;
Expand Down
2 changes: 1 addition & 1 deletion src/dataStructures/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class Cache<K, V> extends Map<K, V> {
*/
delete(key: K): boolean {
const value = super.get(key);
if (value !== undefined && this.onDelete) this.onDelete(key, value);
if (value !== undefined && this.onDelete !== undefined) this.onDelete(key, value);
return super.delete(key);
}
}
2 changes: 1 addition & 1 deletion src/dataStructures/tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class Tile {
const { metadata = {} } = feature;

const layerName = (metadata.layer as string) ?? layer ?? 'default';
if (!this.layers[layerName]) {
if (this.layers[layerName] === undefined) {
this.layers[layerName] = new Layer(layerName, []);
}
this.layers[layerName].features.push(feature);
Expand Down
6 changes: 4 additions & 2 deletions src/geometry/clip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ function _clipLine(
const { x: bx, y: by, z: bz, m: bm } = geom[i + 1];
const a = axis === 0 ? ax : ay;
const b = axis === 0 ? bx : by;
const z = az && bz ? (az + bz) / 2 : az ? az : bz ? bz : undefined;
const azNU = az !== undefined;
const bzNU = bz !== undefined;
const z = azNU && bzNU ? (az + bz) / 2 : azNU ? az : bzNU ? bz : undefined;
let entered = false;
let exited = false;
let intP: VectorPoint | undefined;
Expand All @@ -401,7 +403,7 @@ function _clipLine(
}

// Update the intersection point and offset if the intP exists
if (intP) {
if (intP !== undefined) {
// our first enter will change the offset for the line
if (entered && !firstEnter) {
curOffset = accOffset + distance(prevP, intP);
Expand Down
62 changes: 36 additions & 26 deletions src/geometry/geometry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,24 +213,24 @@ export interface VectorPoint<M extends MValue = MValue> {
t?: number;
}
/** Definition of a Vector MultiPoint */
export type VectorMultiPoint = VectorPoint[];
export type VectorMultiPoint<M extends MValue = MValue> = VectorPoint<M>[];
/** Definition of a Vector LineString */
export type VectorLineString = VectorPoint[];
export type VectorLineString<M extends MValue = MValue> = VectorPoint<M>[];
/** Definition of a Vector MultiLineString */
export type VectorMultiLineString = VectorLineString[];
export type VectorMultiLineString<M extends MValue = MValue> = VectorLineString<M>[];
/** Definition of a Vector Polygon */
export type VectorPolygon = VectorLineString[];
export type VectorPolygon<M extends MValue = MValue> = VectorLineString<M>[];
/** Definition of a Vector MultiPolygon */
export type VectorMultiPolygon = VectorPolygon[];
export type VectorMultiPolygon<M extends MValue = MValue> = VectorPolygon<M>[];

/** All possible geometry coordinates */
export type VectorCoordinates =
| VectorPoint
| VectorMultiPoint
| VectorLineString
| VectorMultiLineString
| VectorPolygon
| VectorMultiPolygon;
export type VectorCoordinates<M extends MValue = MValue> =
| VectorPoint<M>
| VectorMultiPoint<M>
| VectorLineString<M>
| VectorMultiLineString<M>
| VectorPolygon<M>
| VectorMultiPolygon<M>;

/** All possible geometry types */
export type VectorGeometryType =
Expand All @@ -241,9 +241,9 @@ export type VectorGeometryType =
| 'Polygon'
| 'MultiPolygon';
/** All possible geometry shapes */
export type VectorGeometry =
| VectorPointGeometry
| VectorMultiPointGeometry
export type VectorGeometry<M extends MValue = MValue> =
| VectorPointGeometry<M>
| VectorMultiPointGeometry<M>
| VectorLineStringGeometry
| VectorMultiLineStringGeometry
| VectorPolygonGeometry
Expand Down Expand Up @@ -284,37 +284,47 @@ export type VectorPolygonOffset = VectorLineOffset[];
export type VectorMultiPolygonOffset = VectorPolygonOffset[];

/** PointGeometry is a point */
export type VectorPointGeometry = VectorBaseGeometry<'Point', VectorPoint, undefined, BBOX>;
export type VectorPointGeometry<M extends MValue = MValue> = VectorBaseGeometry<
'Point',
VectorPoint<M>,
undefined,
BBOX
>;
/** MultiPointGeometry contains multiple points */
export type VectorMultiPointGeometry = VectorBaseGeometry<
export type VectorMultiPointGeometry<M extends MValue = MValue> = VectorBaseGeometry<
'MultiPoint',
VectorMultiPoint,
VectorMultiPoint<M>,
undefined,
BBOX
>;
/** LineStringGeometry is a line */
export type VectorLineStringGeometry = VectorBaseGeometry<
export type VectorLineStringGeometry<M extends MValue = MValue> = VectorBaseGeometry<
'LineString',
VectorLineString,
VectorLineString<M>,
VectorLineOffset,
BBOX
>;
/** MultiLineStringGeometry contians multiple lines */
export type VectorMultiLineStringGeometry = VectorBaseGeometry<
export type VectorMultiLineStringGeometry<M extends MValue = MValue> = VectorBaseGeometry<
'MultiLineString',
VectorMultiLineString,
VectorMultiLineString<M>,
VectorMultiLineOffset,
BBOX
>;
/** PolygonGeometry is a polygon with potential holes */
export interface VectorPolygonGeometry
extends VectorBaseGeometry<'Polygon', VectorPolygon, VectorPolygonOffset, BBOX> {
export interface VectorPolygonGeometry<M extends MValue = MValue>
extends VectorBaseGeometry<'Polygon', VectorPolygon<M>, VectorPolygonOffset, BBOX> {
indices?: number[];
tesselation?: number[];
}
/** MultiPolygonGeometry is a polygon with multiple polygons with their own potential holes */
export interface VectorMultiPolygonGeometry
extends VectorBaseGeometry<'MultiPolygon', VectorMultiPolygon, VectorMultiPolygonOffset, BBOX> {
export interface VectorMultiPolygonGeometry<M extends MValue = MValue>
extends VectorBaseGeometry<
'MultiPolygon',
VectorMultiPolygon<M>,
VectorMultiPolygonOffset,
BBOX
> {
indices?: number[];
tesselation?: number[];
}
Loading

0 comments on commit 7baa4cf

Please sign in to comment.