@sean_kenny/coloured-bitmap-to-geojson-polygons-js
Advanced tools
Comparing version 0.1.5 to 0.2.0
import { readFile } from "fs/promises"; | ||
import { extractColourMapFromHexBmpData, extractHeaderFromHexBmpData, extractInfoHeaderFromHexBmpData } from "./bmp-file-metadata.js"; | ||
import { extractImageDataFromHexBmpData } from "./image-data/image-data.js"; | ||
import { consolidateImageDataIntoPolygons } from "./image-data-to-polygons/image-data-to-polygons.js"; | ||
import { consolidateImageDataIntoFeatures } from "./image-data-to-features/image-data-to-features.js"; | ||
export const exportColouredBitmapToGeoJSONPolygons = async (input) => { | ||
@@ -26,3 +26,3 @@ const bmpData = await readFile(input.inputFilePath); | ||
}); | ||
const { polygons } = consolidateImageDataIntoPolygons({ | ||
const { features } = consolidateImageDataIntoFeatures({ | ||
imageData, | ||
@@ -41,6 +41,6 @@ bitmapWidthPx: infoHeader.bmpWidthPx, | ||
outputGeoJSON: { | ||
type: 'GeometryCollection', | ||
geometries: polygons | ||
type: 'FeatureCollection', | ||
features | ||
} | ||
}; | ||
}; |
export type Coordinate = [number, number]; | ||
export interface Polygon<TData extends Record<string, unknown>> { | ||
type: "Polygon"; | ||
coordinates: Array<Array<Coordinate>>; | ||
export interface Feature<TData extends Record<string, unknown>> { | ||
type: "Feature"; | ||
geometry: { | ||
type: "Polygon"; | ||
coordinates: Array<Array<Coordinate>>; | ||
}; | ||
properties: { | ||
@@ -11,4 +14,4 @@ colourHexCode: string; | ||
export interface OutputGeoJSON<TData extends Record<string, unknown>> { | ||
type: "GeometryCollection"; | ||
geometries: Array<Polygon<TData>>; | ||
type: "FeatureCollection"; | ||
features: Array<Feature<TData>>; | ||
} |
{ | ||
"name": "@sean_kenny/coloured-bitmap-to-geojson-polygons-js", | ||
"version": "0.1.5", | ||
"version": "0.2.0", | ||
"description": "A library for convering colour segmented bitmaps to a GeoJSON file of polygons.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -58,13 +58,16 @@ # coloured-bitmap-to-geojson-js | ||
{ | ||
"type": "GeometryCollection", | ||
"geometries": [ | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[-180, 90], | ||
[-180, -90], | ||
... | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[-180, 90], | ||
[-180, -90], | ||
... | ||
] | ||
] | ||
], | ||
}, | ||
"properties": { | ||
@@ -76,10 +79,13 @@ "colourHexCode": "#ff0000", | ||
{ | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[-176.4, 90], | ||
[-176.4, 89.1], | ||
... | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[-176.4, 90], | ||
[-176.4, 89.1], | ||
... | ||
] | ||
] | ||
], | ||
}, | ||
"properties": { | ||
@@ -91,10 +97,13 @@ "colourHexCode": "#00ff00", | ||
{ | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[1.8000000000000114, 1.7999999999999972], | ||
[1.8000000000000114, 0], | ||
... | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[1.8000000000000114, 1.7999999999999972], | ||
[1.8000000000000114, 0], | ||
... | ||
] | ||
] | ||
], | ||
}, | ||
"properties": { | ||
@@ -101,0 +110,0 @@ "colourHexCode": "#0000ff", |
77884
44
1660
129