|
|
@@ -1,6 +1,6 @@ |
|
|
|
import yargs from 'yargs'; |
|
|
|
import { hideBin } from 'yargs/helpers'; |
|
|
|
import { project, Bounds } from '@theoryofnekomata/orbis-core'; |
|
|
|
import { project, ProjectBounds } from '@theoryofnekomata/orbis-core'; |
|
|
|
import { writeFile } from 'fs/promises'; |
|
|
|
import { basename, dirname, resolve } from 'path'; |
|
|
|
|
|
|
@@ -8,10 +8,11 @@ type ProjectArgs = { |
|
|
|
input: string, |
|
|
|
projection: string, |
|
|
|
output?: string, |
|
|
|
bounds: Bounds, |
|
|
|
bounds: ProjectBounds, |
|
|
|
width?: number, |
|
|
|
height?: number, |
|
|
|
padding: [number, number], |
|
|
|
country?: string, |
|
|
|
}; |
|
|
|
|
|
|
|
const coerceNumber = (n?: string) => { |
|
|
@@ -36,21 +37,62 @@ const coercePadding = (n?: string) => { |
|
|
|
]; |
|
|
|
}; |
|
|
|
|
|
|
|
const coerceBounds = (n?: string): Bounds => { |
|
|
|
const coerceBounds = (n?: string): ProjectBounds => { |
|
|
|
if (typeof n !== 'string') { |
|
|
|
return [ |
|
|
|
[-180, 90], |
|
|
|
[180, -90], |
|
|
|
] as Bounds; |
|
|
|
return { |
|
|
|
type: 'geojson', |
|
|
|
value: { |
|
|
|
type: 'Sphere', |
|
|
|
}, |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
return n |
|
|
|
.split(';') |
|
|
|
.map((p) => ( |
|
|
|
p |
|
|
|
.split(',') |
|
|
|
.map((c: string) => Number(c)) |
|
|
|
)) as Bounds; |
|
|
|
const [boundsType, etcBounds] = n.split(':'); |
|
|
|
|
|
|
|
if (boundsType === 'geojson') { |
|
|
|
const [geometryType, etcArgs] = etcBounds.split(';'); |
|
|
|
|
|
|
|
if (geometryType === 'Sphere') { |
|
|
|
return { |
|
|
|
type: boundsType, |
|
|
|
value: { |
|
|
|
type: geometryType, |
|
|
|
}, |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
if (geometryType === 'Polygon' || geometryType === 'MultiPolygon') { |
|
|
|
return { |
|
|
|
type: boundsType, |
|
|
|
value: { |
|
|
|
type: geometryType, |
|
|
|
coordinates: JSON.parse(etcArgs), |
|
|
|
}, |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
type: 'geojson', |
|
|
|
value: { |
|
|
|
type: 'Sphere', |
|
|
|
}, |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
if (boundsType === 'country') { |
|
|
|
const [country] = etcBounds.split(';'); |
|
|
|
return { |
|
|
|
type: boundsType, |
|
|
|
value: country, |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
type: 'geojson', |
|
|
|
value: { |
|
|
|
type: 'Sphere', |
|
|
|
}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
const main = async (argv: string | readonly string[]) => { |
|
|
@@ -85,12 +127,15 @@ const main = async (argv: string | readonly string[]) => { |
|
|
|
.coerce('height', coerceNumber) |
|
|
|
.option('padding', { |
|
|
|
alias: 'p', |
|
|
|
default: [0, 0], |
|
|
|
default: '0;0', |
|
|
|
}) |
|
|
|
.coerce('padding', coercePadding) |
|
|
|
.option('bounds', { |
|
|
|
alias: 'b', |
|
|
|
default: [[-180, 90], [180, -90]], |
|
|
|
default: 'geojson:Sphere', |
|
|
|
}) |
|
|
|
.option('country', { |
|
|
|
alias: 'c', |
|
|
|
}) |
|
|
|
.coerce('bounds', coerceBounds), |
|
|
|
handler: async (projectArgvRaw) => { |
|
|
|