Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Oct 8, 2024
1 parent 3ee0c2c commit 0ad2c61
Show file tree
Hide file tree
Showing 34 changed files with 141 additions and 111 deletions.
4 changes: 2 additions & 2 deletions modules/geopackage/src/lib/parse-geopackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
GeoJSONTable,
Feature
} from '@loaders.gl/schema';
import {convertWKBToGeoJSON, transformGeoJsonCoords} from '@loaders.gl/gis';
import {convertWKBToGeometry, transformGeoJsonCoords} from '@loaders.gl/gis';
import {Proj4Projection} from '@math.gl/proj4';
import initSqlJs, {SqlJsStatic, Database, Statement} from 'sql.js';

Expand Down Expand Up @@ -399,7 +399,7 @@ function parseGeometry(arrayBuffer: ArrayBuffer): Geometry | null {
const wkbOffset = 8 + envelopeLength;

const wkbBytes = arrayBuffer.slice(wkbOffset);
return convertWKBToGeoJSON(wkbBytes);
return convertWKBToGeometry(wkbBytes);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions modules/gis/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ export type {WKBHeader} from './lib/geometry-converters/wkt/helpers/parse-wkb-he
export {WKT_MAGIC_STRINGS} from './lib/geometry-converters/wkt/convert-wkt-to-geojson';

// GEOMETRY CONVERSION
export {convertBinaryGeometryToGeoJSON} from './lib/geometry-converters/convert-binary-geometry-to-geojson';
export {convertBinaryGeometryToGeometry} from './lib/geometry-converters/convert-binary-geometry-to-geojson';

export {convertWKTToGeoJSON} from './lib/geometry-converters/wkt/convert-wkt-to-geojson';
export {convertWKBToGeoJSON} from './lib/geometry-converters/wkt/convert-wkb-to-geojson';
export {convertTWKBToGeoJSON} from './lib/geometry-converters/wkt/convert-twkb-to-geojson';
export {convertWKTToGeometry} from './lib/geometry-converters/wkt/convert-wkt-to-geojson';
export {convertWKBToGeometry} from './lib/geometry-converters/wkt/convert-wkb-to-geojson';
export {convertWKBToBinaryGeometry} from './lib/geometry-converters/wkt/convert-wkb-to-binary-geometry';
export {convertTWKBToGeometry} from './lib/geometry-converters/wkt/convert-twkb-to-geojson';

export {convertGeoJSONToWKT} from './lib/geometry-converters/wkt/convert-geojson-to-wkt';
export {convertGeoJSONToWKB} from './lib/geometry-converters/wkt/convert-geojson-to-wkb';
export {convertGeoJSONToTWKB} from './lib/geometry-converters/wkt/convert-geojson-to-twkb';
export {convertGeometryToWKT} from './lib/geometry-converters/wkt/convert-geojson-to-wkt';
export {convertGeometryToWKB} from './lib/geometry-converters/wkt/convert-geojson-to-wkb';
export {convertGeometryToTWKB} from './lib/geometry-converters/wkt/convert-geojson-to-twkb';

// CRS
export type {WKTCRS, ParseWKTCRSOptions} from './lib//wkt-crs/parse-wkt-crs';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import type {
Feature,
GeoJsonProperties
} from '@loaders.gl/schema';
import {convertBinaryGeometryToGeoJSON} from '../geometry-converters/convert-binary-geometry-to-geojson';
import {convertBinaryGeometryToGeometry} from '../geometry-converters/convert-binary-geometry-to-geojson';

// Note:L We do not handle GeometryCollection, define a limited Geometry type that always has coordinates.
// Note: We do not handle GeometryCollection, define a limited Geometry type that always has coordinates.
// type FeatureGeometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;

type BinaryToGeoJsonOptions = {
Expand Down Expand Up @@ -131,7 +131,7 @@ function parseFeatureCollection(dataArray: BinaryFeature[]): Feature[] {

/** Parse input binary data and return a single GeoJSON Feature */
function parseFeature(data: BinaryFeature, startIndex?: number, endIndex?: number): Feature {
const geometry = convertBinaryGeometryToGeoJSON(data, startIndex, endIndex);
const geometry = convertBinaryGeometryToGeometry(data, startIndex, endIndex);
const properties = parseProperties(data, startIndex, endIndex);
const fields = parseFields(data, startIndex, endIndex);
return {type: 'Feature', geometry, properties, ...fields};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
} from '@loaders.gl/schema';

/** Parse input binary data and return a valid GeoJSON geometry object */
export function convertBinaryGeometryToGeoJSON(
export function convertBinaryGeometryToGeometry(
data: BinaryGeometry,
startIndex?: number,
endIndex?: number
Expand Down Expand Up @@ -106,8 +106,8 @@ function lineStringToGeoJson(
/** Parse binary data of type Point */
function pointToGeoJson(
data: BinaryPointGeometry,
startIndex: number,
endIndex: number
startIndex?: number,
endIndex?: number
): Point | MultiPoint {
const {positions} = data;
const coordinates = ringToGeoJson(positions, startIndex, endIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import type {
Geometry,
GeoArrowEncoding
} from '@loaders.gl/schema';
import {convertWKBToGeoJSON} from './wkt/convert-wkb-to-geojson';
import {convertWKTToGeoJSON} from './wkt/convert-wkt-to-geojson';
import {convertWKBToGeometry} from './wkt/convert-wkb-to-geojson';
import {convertWKTToGeometry} from './wkt/convert-wkt-to-geojson';

/**
* parse geometry from arrow data that is returned from processArrowData()
Expand Down Expand Up @@ -65,12 +65,12 @@ function arrowWKBToGeometry(arrowCellValue: any): Geometry | null {
arrowCellValue.byteOffset,
arrowCellValue.byteOffset + arrowCellValue.byteLength
);
return convertWKBToGeoJSON(arrayBuffer);
return convertWKBToGeometry(arrayBuffer);
}

function arrowWKTToGeometry(arrowCellValue: any): Geometry | null {
const string: string = arrowCellValue;
return convertWKTToGeoJSON(string);
return convertWKTToGeometry(string);
}

/**
Expand Down
20 changes: 10 additions & 10 deletions modules/gis/src/lib/geometry-converters/convert-to-geojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

import type {Geometry, BinaryGeometry} from '@loaders.gl/schema';

import {convertGeoJSONToWKB} from './wkt/convert-geojson-to-wkb';
import {convertGeoJSONToWKT} from './wkt/convert-geojson-to-wkt';
import {convertGeometryToWKB} from './wkt/convert-geojson-to-wkb';
import {convertGeometryToWKT} from './wkt/convert-geojson-to-wkt';
import {convertWKBToBinaryGeometry} from './wkt/convert-wkb-to-binary-geometry';
import {convertWKTToGeoJSON} from './wkt/convert-wkt-to-geojson';
import {convertWKTToGeometry} from './wkt/convert-wkt-to-geojson';

import {convertBinaryGeometryToGeoJSON} from './convert-binary-geometry-to-geojson';
import {convertBinaryGeometryToGeometry} from './convert-binary-geometry-to-geojson';

export function convertToGeoJSON(geometry: ArrayBuffer | string): Geometry {
if (geometry instanceof ArrayBuffer) {
const binaryGeometry = convertWKBToBinaryGeometry(geometry);
return convertBinaryGeometryToGeoJSON(binaryGeometry);
return convertBinaryGeometryToGeometry(binaryGeometry);
}

// Assume string encoded WKT
if (typeof geometry === 'string') {
return convertWKTToGeoJSON(geometry)!;
return convertWKTToGeometry(geometry)!;
}

throw new Error('Geo conversion not implemented');
Expand All @@ -32,21 +32,21 @@ export function convertToBinaryGeometry(geometry: ArrayBuffer | string | Geometr

// Assume string encoded WKT
if (typeof geometry === 'string') {
// const geometry = convertWKTToGeoJSON(geometry);
// const geometry = convertWKTToGeometry(geometry);
// return convertGeometryToBinaryGeometry(geometry);
}

throw new Error('Geo conversion not implemented');
}

export function convertToWKT(geometry: Geometry): string {
return convertGeoJSONToWKT(geometry);
return convertGeometryToWKT(geometry);
}

export function convertToWKB(geometry: Geometry): ArrayBuffer {
return convertGeoJSONToWKB(geometry);
return convertGeometryToWKB(geometry);
}

// export function convertToTWKB(geometry: Geometry): ArrayBuffer {
// return convertGeoJSONToTWKB(geometry);
// return convertGeometryToTWKB(geometry);
// }
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type TWKBEncoderContext = TWKBPrecision & {
hasM?: boolean;
};

export function convertGeoJSONToTWKB(
export function convertGeometryToTWKB(
geometry: Geometry,
options?: {hasZ?: boolean; hasM?: boolean}
): ArrayBuffer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type WKBOptions = {
* @param geojson A GeoJSON Feature or Geometry
* @returns string
*/
export function convertGeoJSONToWKB(
export function convertGeometryToWKB(
geometry: Geometry | Feature,
options: WKBOptions = {}
): ArrayBuffer {
Expand Down Expand Up @@ -186,7 +186,7 @@ function encodePolygon(coordinates: Polygon['coordinates'], options: WKBOptions)
writer.writeInt8(1);

writeWkbType(writer, WKB.Polygon, options);
const [exteriorRing, ...interiorRings] = coordinates;
const [exteriorRing = [], ...interiorRings] = coordinates;

if (exteriorRing.length > 0) {
writer.writeUInt32LE(1 + interiorRings.length);
Expand All @@ -213,7 +213,7 @@ function encodePolygon(coordinates: Polygon['coordinates'], options: WKBOptions)
/** Get encoded size of Polygon geometry */
function getPolygonSize(coordinates: Polygon['coordinates'], options: WKBOptions): number {
const coordinateSize = getCoordinateSize(options);
const [exteriorRing, ...interiorRings] = coordinates;
const [exteriorRing = [], ...interiorRings] = coordinates;

let size = 1 + 4 + 4;

Expand Down Expand Up @@ -330,7 +330,7 @@ function encodeGeometryCollection(

for (const geometry of collection.geometries) {
// TODO: handle srid? {srid: collection.srid}
const arrayBuffer = convertGeoJSONToWKB(geometry, options);
const arrayBuffer = convertGeometryToWKB(geometry, options);
writer.writeBuffer(arrayBuffer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {Geometry} from '@loaders.gl/schema';
* @param geojson
* @returns string
*/
export function convertGeoJSONToWKT(geometry: Geometry): string {
export function convertGeometryToWKT(geometry: Geometry): string {
switch (geometry.type) {
case 'Point':
return `POINT ${wrapParens(pairWKT(geometry.coordinates))}`;
Expand All @@ -25,10 +25,10 @@ export function convertGeoJSONToWKT(geometry: Geometry): string {
case 'MultiLineString':
return `MULTILINESTRING ${wrapParens(ringsWKT(geometry.coordinates))}`;
case 'GeometryCollection':
return `GEOMETRYCOLLECTION ${wrapParens(geometry.geometries.map(convertGeoJSONToWKT).join(', '))}`;
return `GEOMETRYCOLLECTION ${wrapParens(geometry.geometries.map(convertGeometryToWKT).join(', '))}`;
default:
throw new Error(
'convertGeoJSONToWKT requires a valid GeoJSON Geometry (not Feature) as input'
'convertGeometryToWKT requires a valid GeoJSON Geometry (not Feature) as input'
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type TWKBHeader = {
};

/** Converts a TWKB encoded buffer to a GeoJSON Geometry */
export function convertTWKBToGeoJSON(arrayBuffer: ArrayBuffer): Geometry {
export function convertTWKBToGeometry(arrayBuffer: ArrayBuffer): Geometry {
const binaryReader = new BinaryReader(arrayBuffer);

const context = parseTWKBHeader(binaryReader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
// Copyright (c) vis.gl contributors

import type {Geometry} from '@loaders.gl/schema';
import {convertBinaryGeometryToGeoJSON} from '../convert-binary-geometry-to-geojson';
import {convertBinaryGeometryToGeometry} from '../convert-binary-geometry-to-geojson';
import {convertWKBToBinaryGeometry} from './convert-wkb-to-binary-geometry';

export function convertWKBToGeoJSON(arrayBuffer: ArrayBuffer): Geometry {
export type convertWKBOptions = {
/** Does the GeoJSON input have Z values? */
hasZ?: boolean;

/** Does the GeoJSON input have M values? */
hasM?: boolean;

/** Spatial reference for input GeoJSON */
srid?: any;
};

export function convertWKBToGeometry(arrayBuffer: ArrayBuffer): Geometry {
const binaryGeometry = convertWKBToBinaryGeometry(arrayBuffer);
return convertBinaryGeometryToGeoJSON(binaryGeometry);
return convertBinaryGeometryToGeometry(binaryGeometry);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type ParseWKTState = {
*
* @note We only support the "geojson" subset of the OGC simple features standard
**/
export function convertWKTToGeoJSON(input: string, options?: ParseWKTOptions): Geometry | null {
export function convertWKTToGeometry(input: string, options?: ParseWKTOptions): Geometry | null {
const parts = input.split(';');
let _ = parts.pop();
const srid = (parts.shift() || '').split('=').pop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type {
import {getTableLength, getTableRowAsObject} from '@loaders.gl/schema-utils';

import {GeoColumnMetadata, getGeoMetadata} from '../geoarrow/geoparquet-metadata';
import {convertWKBToGeoJSON} from '../geometry-converters/wkt/convert-wkb-to-geojson';
import {convertWKTToGeoJSON} from '../geometry-converters/wkt/convert-wkt-to-geojson';
import {convertWKBToGeometry} from '../geometry-converters/wkt/convert-wkb-to-geojson';
import {convertWKTToGeometry} from '../geometry-converters/wkt/convert-wkt-to-geojson';

/** TODO - move to loaders.gl/gis? */
export function convertWKBTableToGeoJSON(
Expand Down Expand Up @@ -45,12 +45,12 @@ export function convertWKBTableToGeoJSON(
function parseGeometry(geometry: unknown, columnMetadata: GeoColumnMetadata): Geometry | null {
switch (columnMetadata.encoding) {
case 'wkt':
return convertWKTToGeoJSON(geometry as string) || null;
return convertWKTToGeometry(geometry as string) || null;
case 'wkb':
default:
const arrayBuffer = ArrayBuffer.isView(geometry)
? geometry.buffer.slice(geometry.byteOffset, geometry.byteOffset + geometry.byteLength)
: (geometry as ArrayBuffer);
return convertWKBToGeoJSON(arrayBuffer);
return convertWKBToGeometry(arrayBuffer);
}
}
4 changes: 2 additions & 2 deletions modules/gis/test/binary-features/binary-to-geojson.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import test from 'tape-promise/tape';
import type {BinaryFeatureCollection, FeatureCollection} from '@loaders.gl/schema';
import {fetchFile} from '@loaders.gl/core';
import {binaryToGeojson, convertBinaryGeometryToGeoJSON} from '@loaders.gl/gis';
import {binaryToGeojson, convertBinaryGeometryToGeometry} from '@loaders.gl/gis';

import {GEOMETRY_TEST_CASES} from '@loaders.gl/gis/test/data/binary-features/geometry-test-cases';
import {EMPTY_BINARY_DATA} from '@loaders.gl/gis/test/data/binary-features/empty_binary';
Expand Down Expand Up @@ -36,7 +36,7 @@ test('binary-to-geojson feature collections', async (t) => {
test('binary-to-geojson geometries', (t) => {
for (const testCase of GEOMETRY_TEST_CASES) {
const binaryData = testCase.binary;
t.deepEqual(convertBinaryGeometryToGeoJSON(binaryData), testCase.geoJSON);
t.deepEqual(convertBinaryGeometryToGeometry(binaryData), testCase.geoJSON);
// t.deepEqual(binaryToGeoJson(binaryData, binaryData.type, 'geometry'), testCase.geoJSON);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/gis/test/data/wkt/wkb-testdataZ.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"wkbXdr": "00000003eb00000000",
"ewkbXdr": "00a0000003000010e600000000",
"twkb": "a31801",
"geoJSON": {"type": "Polygon", "coordinates": [[[]]]},
"geoJSON": {"type": "Polygon", "coordinates": []},
"ewkbNoSrid": "010300008000000000",
"ewkbXdrNoSrid": "008000000300000000",
"binary": {
Expand Down
Loading

0 comments on commit 0ad2c61

Please sign in to comment.