|
@@ -1,6 +1,6 @@ |
|
|
import yargs from 'yargs'; |
|
|
import yargs from 'yargs'; |
|
|
import { hideBin } from 'yargs/helpers'; |
|
|
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 { writeFile } from 'fs/promises'; |
|
|
import { basename, dirname, resolve } from 'path'; |
|
|
import { basename, dirname, resolve } from 'path'; |
|
|
|
|
|
|
|
@@ -8,10 +8,11 @@ type ProjectArgs = { |
|
|
input: string, |
|
|
input: string, |
|
|
projection: string, |
|
|
projection: string, |
|
|
output?: string, |
|
|
output?: string, |
|
|
bounds: Bounds, |
|
|
|
|
|
|
|
|
bounds: ProjectBounds, |
|
|
width?: number, |
|
|
width?: number, |
|
|
height?: number, |
|
|
height?: number, |
|
|
padding: [number, number], |
|
|
padding: [number, number], |
|
|
|
|
|
country?: string, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const coerceNumber = (n?: 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') { |
|
|
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[]) => { |
|
|
const main = async (argv: string | readonly string[]) => { |
|
@@ -85,12 +127,15 @@ const main = async (argv: string | readonly string[]) => { |
|
|
.coerce('height', coerceNumber) |
|
|
.coerce('height', coerceNumber) |
|
|
.option('padding', { |
|
|
.option('padding', { |
|
|
alias: 'p', |
|
|
alias: 'p', |
|
|
default: [0, 0], |
|
|
|
|
|
|
|
|
default: '0;0', |
|
|
}) |
|
|
}) |
|
|
.coerce('padding', coercePadding) |
|
|
.coerce('padding', coercePadding) |
|
|
.option('bounds', { |
|
|
.option('bounds', { |
|
|
alias: 'b', |
|
|
alias: 'b', |
|
|
default: [[-180, 90], [180, -90]], |
|
|
|
|
|
|
|
|
default: 'geojson:Sphere', |
|
|
|
|
|
}) |
|
|
|
|
|
.option('country', { |
|
|
|
|
|
alias: 'c', |
|
|
}) |
|
|
}) |
|
|
.coerce('bounds', coerceBounds), |
|
|
.coerce('bounds', coerceBounds), |
|
|
handler: async (projectArgvRaw) => { |
|
|
handler: async (projectArgvRaw) => { |
|
|