@allmaps/cli
Advanced tools
Comparing version 1.0.0-beta.11 to 1.0.0-beta.12
@@ -10,8 +10,14 @@ import { Command } from 'commander'; | ||
.description(`Generate a single Georeference Annotation from input files`) | ||
.action(async (args) => { | ||
const jsonValues = await parseJsonInput(args.files); | ||
.action(async (files) => { | ||
const jsonValues = await parseJsonInput(files); | ||
const maps = parseAnnotationsValidateMaps(jsonValues); | ||
const annotation = generateAnnotation(maps); | ||
let annotation; | ||
if (maps.length === 1) { | ||
annotation = generateAnnotation(maps[0]); | ||
} | ||
else { | ||
annotation = generateAnnotation(maps); | ||
} | ||
printJson(annotation); | ||
}); | ||
} |
@@ -12,9 +12,4 @@ import { Command } from 'commander'; | ||
const maps = parseAnnotationsValidateMaps(jsonValues); | ||
if (maps.length === 1) { | ||
printJson(maps[0]); | ||
} | ||
else { | ||
printJson(maps); | ||
} | ||
printJson(maps); | ||
}); | ||
} |
import { Command } from 'commander'; | ||
import { parseJsonInput, print } from '../../lib/io.js'; | ||
import { parseAnnotationsValidateMaps } from '../../lib/parse.js'; | ||
import { createSvgString, pixelMaskToSvgPolygon } from '../../lib/svg.js'; | ||
import { createSvgString, resourceMaskToSvgPolygon } from '../../lib/svg.js'; | ||
export default function svg() { | ||
return new Command('svg') | ||
.argument('[files...]') | ||
.summary('generate SVG from pixel mask') | ||
.description('Generates SVG from pixel masks of input Georeference Annotations') | ||
.summary('generate SVG from resource mask') | ||
.description('Generates SVG from resource masks of input Georeference Annotations') | ||
.action(async (files) => { | ||
const jsonValues = await parseJsonInput(files); | ||
const maps = parseAnnotationsValidateMaps(jsonValues); | ||
const polygons = maps.map(pixelMaskToSvgPolygon); | ||
const polygons = maps.map(resourceMaskToSvgPolygon); | ||
const svg = createSvgString(polygons); | ||
@@ -15,0 +15,0 @@ print(svg); |
import { Command } from 'commander'; | ||
import svg from './transform/svg.js'; | ||
import geojson from './transform/geojson.js'; | ||
import pixelMask from './transform/pixel-mask.js'; | ||
import resourceMask from './transform/resource-mask.js'; | ||
export default function transform() { | ||
@@ -11,3 +11,3 @@ return new Command('transform') | ||
.addCommand(geojson()) | ||
.addCommand(pixelMask()); | ||
.addCommand(resourceMask()); | ||
} |
import { Command } from 'commander'; | ||
import { createTransformer } from '@allmaps/transform'; | ||
import { GCPTransformer } from '@allmaps/transform'; | ||
import { parseJsonFromFile, parseJsonInput, print } from '../../lib/io.js'; | ||
@@ -22,3 +22,3 @@ import { parseAnnotationValidateMap } from '../../lib/parse.js'; | ||
const map = Array.isArray(mapOrMaps) ? mapOrMaps[0] : mapOrMaps; | ||
const transformer = createTransformer(map.gcps); | ||
const transformer = new GCPTransformer(map.gcps, map.transformation?.type); | ||
const geoJsonGeometries = await parseJsonInput(files); | ||
@@ -25,0 +25,0 @@ const svgElements = []; |
import { Command } from 'commander'; | ||
import { createTransformer, toGeoJSONPolygon } from '@allmaps/transform'; | ||
import { GCPTransformer } from '@allmaps/transform'; | ||
import { parseJsonInput, printJson } from '../../lib/io.js'; | ||
@@ -18,4 +18,4 @@ import { parseAnnotationsValidateMaps } from '../../lib/parse.js'; | ||
if (map.gcps.length >= 3) { | ||
const transformer = createTransformer(map.gcps); | ||
const polygon = toGeoJSONPolygon(transformer, map.pixelMask, transformOptions); | ||
const transformer = new GCPTransformer(map.gcps); | ||
const polygon = transformer.toGeoJSONPolygon(map.pixelMask, transformOptions); | ||
features.push({ | ||
@@ -22,0 +22,0 @@ type: 'Feature', |
import { Command } from 'commander'; | ||
import { createTransformer } from '@allmaps/transform'; | ||
import { GCPTransformer } from '@allmaps/transform'; | ||
import { parseJsonFromFile, readInput, printJson } from '../../lib/io.js'; | ||
@@ -22,3 +22,3 @@ import { parseAnnotationValidateMap } from '../../lib/parse.js'; | ||
const map = Array.isArray(mapOrMaps) ? mapOrMaps[0] : mapOrMaps; | ||
const transformer = createTransformer(map.gcps); | ||
const transformer = new GCPTransformer(map.gcps, map.transformation?.type); | ||
const svgs = await readInput(files); | ||
@@ -25,0 +25,0 @@ const geoJsonGeometries = []; |
#!/usr/bin/env node | ||
import { Command, CommanderError } from 'commander'; | ||
import { fromZodError } from 'zod-validation-error'; | ||
import iiif from './commands/iiif.js'; | ||
@@ -30,10 +31,14 @@ import annotation from './commands/annotation.js'; | ||
if ('code' in err && err.code === 'ENOENT' && 'path' in err) { | ||
console.error(`error: file not found "${err.path}"`); | ||
console.error(`File not found "${err.path}"`); | ||
} | ||
else if (err.name === 'ZodError') { | ||
const validationError = fromZodError(err); | ||
console.error(validationError.message); | ||
} | ||
else { | ||
console.error(err.message); | ||
console.error('Error:', err.message); | ||
} | ||
} | ||
else { | ||
console.error('Unkown error', err); | ||
console.error('Unkown error:', err); | ||
} | ||
@@ -40,0 +45,0 @@ process.exit(1); |
@@ -1,4 +0,4 @@ | ||
import type { GeoJSONGeometry, GCPTransformInfo, OptionalTransformOptions } from '@allmaps/transform'; | ||
import type { GCPTransformer, GeoJSONGeometry, OptionalTransformOptions } from '@allmaps/transform'; | ||
import type { GeometryElement } from './svg.js'; | ||
export declare function transformSvgToGeoJson(transformer: GCPTransformInfo, geometry: GeometryElement, options?: OptionalTransformOptions): import("@allmaps/transform").GeoJSONPoint | import("@allmaps/transform").GeoJSONLineString | import("@allmaps/transform").GeoJSONPolygon; | ||
export declare function transformSvgToGeoJson(transformer: GCPTransformer, geometry: GeometryElement, options?: OptionalTransformOptions): import("@allmaps/transform").GeoJSONPoint | import("@allmaps/transform").GeoJSONLineString | import("@allmaps/transform").GeoJSONPolygon; | ||
export declare function createFeatureCollection(geometries: GeoJSONGeometry[]): { | ||
@@ -5,0 +5,0 @@ type: string; |
@@ -1,17 +0,16 @@ | ||
import { toGeoJSONPoint, toGeoJSONLineString, toGeoJSONPolygon } from '@allmaps/transform'; | ||
export function transformSvgToGeoJson(transformer, geometry, options) { | ||
if (geometry.type === 'circle') { | ||
return toGeoJSONPoint(transformer, geometry.coordinates); | ||
return transformer.toGeoJSONPoint(geometry.coordinates); | ||
} | ||
else if (geometry.type === 'line') { | ||
return toGeoJSONLineString(transformer, geometry.coordinates, options); | ||
return transformer.toGeoJSONLineString(geometry.coordinates, options); | ||
} | ||
else if (geometry.type === 'polyline') { | ||
return toGeoJSONLineString(transformer, geometry.coordinates, options); | ||
return transformer.toGeoJSONLineString(geometry.coordinates, options); | ||
} | ||
else if (geometry.type === 'rect') { | ||
return toGeoJSONPolygon(transformer, geometry.coordinates, options); | ||
return transformer.toGeoJSONPolygon(geometry.coordinates, options); | ||
} | ||
else if (geometry.type === 'polygon') { | ||
return toGeoJSONPolygon(transformer, geometry.coordinates, options); | ||
return transformer.toGeoJSONPolygon(geometry.coordinates, options); | ||
} | ||
@@ -18,0 +17,0 @@ else { |
@@ -33,3 +33,3 @@ import { createReadStream, readFileSync } from 'fs'; | ||
else { | ||
throw new Error('error: no input files supplied, and nothing to read from the standard input'); | ||
throw new Error('No input files supplied, and nothing to read from the standard input'); | ||
} | ||
@@ -36,0 +36,0 @@ } |
@@ -1,2 +0,3 @@ | ||
import type { GeoJSONGeometry, GCPTransformInfo, OptionalTransformOptions } from '@allmaps/transform'; | ||
import type { GCPTransformer } from '@allmaps/transform'; | ||
import type { GeoJSONGeometry, OptionalTransformOptions } from '@allmaps/transform'; | ||
import type { Map } from '@allmaps/annotation'; | ||
@@ -33,4 +34,4 @@ type Coord = [number, number]; | ||
export declare function createSvgString(elements: GeometryElement[]): string; | ||
export declare function pixelMaskToSvgPolygon(map: Map): Polygon; | ||
export declare function transformGeoJsonToSvg(transformer: GCPTransformInfo, geometry: GeoJSONGeometry, options?: OptionalTransformOptions): GeometryElement; | ||
export declare function resourceMaskToSvgPolygon(map: Map): Polygon; | ||
export declare function transformGeoJsonToSvg(transformer: GCPTransformer, geometry: GeoJSONGeometry, options?: OptionalTransformOptions): GeometryElement; | ||
export {}; |
import { parse } from 'svg-parser'; | ||
import { fromGeoJSONPoint, fromGeoJSONLineString, fromGeoJSONPolygon } from '@allmaps/transform'; | ||
function getNodeNumberProperty(node, prop) { | ||
@@ -158,9 +157,9 @@ const value = node?.properties?.[prop]; | ||
} | ||
export function pixelMaskToSvgPolygon(map) { | ||
export function resourceMaskToSvgPolygon(map) { | ||
return { | ||
type: 'polygon', | ||
attributes: { | ||
'data-image-uri': encodeURIComponent(map.image.uri) | ||
'data-image-id': encodeURIComponent(map.resource.id) | ||
}, | ||
coordinates: map.pixelMask | ||
coordinates: map.resourceMask | ||
}; | ||
@@ -172,3 +171,3 @@ } | ||
type: 'circle', | ||
coordinates: fromGeoJSONPoint(transformer, geometry) | ||
coordinates: transformer.fromGeoJSONPoint(geometry) | ||
}; | ||
@@ -179,3 +178,3 @@ } | ||
type: 'polyline', | ||
coordinates: fromGeoJSONLineString(transformer, geometry, options) | ||
coordinates: transformer.fromGeoJSONLineString(geometry, options) | ||
}; | ||
@@ -186,3 +185,3 @@ } | ||
type: 'polygon', | ||
coordinates: fromGeoJSONPolygon(transformer, geometry, options) | ||
coordinates: transformer.fromGeoJSONPolygon(geometry, options) | ||
}; | ||
@@ -189,0 +188,0 @@ } |
{ | ||
"name": "@allmaps/cli", | ||
"version": "1.0.0-beta.11", | ||
"version": "1.0.0-beta.12", | ||
"author": { | ||
@@ -16,3 +16,4 @@ "name": "Bert Spaan", | ||
".": { | ||
"import": "./dist/index.js" | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
@@ -54,8 +55,9 @@ }, | ||
"dependencies": { | ||
"@allmaps/annotation": "^1.0.0-beta.13", | ||
"@allmaps/iiif-parser": "^1.0.0-beta.24", | ||
"@allmaps/transform": "^1.0.0-beta.14", | ||
"@allmaps/annotation": "^1.0.0-beta.14", | ||
"@allmaps/iiif-parser": "^1.0.0-beta.25", | ||
"@allmaps/transform": "^1.0.0-beta.15", | ||
"commander": "^10.0.0", | ||
"stream-json": "^1.7.4", | ||
"svg-parser": "^2.0.4" | ||
"svg-parser": "^2.0.4", | ||
"zod-validation-error": "^1.5.0" | ||
}, | ||
@@ -69,2 +71,3 @@ "devDependencies": { | ||
"chai": "^4.3.6", | ||
"chai-roughly": "^1.0.0", | ||
"eslint": "^8.35.0", | ||
@@ -76,3 +79,3 @@ "mocha": "^8.4.0", | ||
}, | ||
"gitHead": "e1277b2bc286652d62751976b39b9f81e7281225" | ||
"gitHead": "45c0da2e8fa40e3d97a6a5d2f3531d6c03bd34aa" | ||
} |
@@ -40,3 +40,3 @@ # @allmaps/cli | ||
Convert the pixel mask from the input files to SVG polygons: | ||
Convert the resource mask from the input files to SVG polygons: | ||
@@ -63,12 +63,12 @@ allmaps annotation svg [files...] | ||
Transform pixel masks to GeoJSON: | ||
Transform resource masks to GeoJSON: | ||
allmaps transform pixel-mask [files...] | ||
allmaps transform resource-mask [files...] | ||
All the commands above accept the following options: | ||
| Option | Description | Default | ||
|:----------------------------------|:----------------------------------------------------------------|:-------- | ||
| `-p, --max-offset-ratio <number>` | Maximum offset ratio between original and transformed midpoints | 0 | ||
| `-d, --max-depth <number>` | Maximum recursion depth | 6 | ||
| Option | Description | Default | | ||
| :-------------------------------- | :-------------------------------------------------------------- | :------ | | ||
| `-p, --max-offset-ratio <number>` | Maximum offset ratio between original and transformed midpoints | 0 | | ||
| `-d, --max-depth <number>` | Maximum recursion depth | 6 | | ||
@@ -103,7 +103,7 @@ #### Parse and generate IIIF resources | ||
Fetch a Georeference Annotation with cURL, pipe to Allmaps CLI and transform pixel mask to GeoJSON: | ||
Fetch a Georeference Annotation with cURL, pipe to Allmaps CLI and transform resource mask to GeoJSON: | ||
```bash | ||
curl -L "https://annotations.allmaps.org/?url=https://collections.leventhalmap.org/search/commonwealth:4t64k3596/manifest" \ | ||
| allmaps transform pixel-mask | ||
| allmaps transform resource-mask | ||
``` | ||
@@ -123,3 +123,3 @@ | ||
Concatenate these two Georeference Annotations with Bash and transform pixel masks to GeoJSON: | ||
Concatenate these two Georeference Annotations with Bash and transform resource masks to GeoJSON: | ||
@@ -130,3 +130,3 @@ ```bash | ||
<(curl -L "https://annotations.allmaps.org/?url=https://collections.leventhalmap.org/search/commonwealth:6108xt43s/manifest") \ | ||
| allmaps transform pixel-mask | ||
| allmaps transform resource-mask | ||
``` | ||
@@ -133,0 +133,0 @@ |
47271
54
1086
7
12
+ Addedzod-validation-error@^1.5.0
+ Addedzod-validation-error@1.5.0(transitive)