@atlas-composer/cli
v0.2.0
Published
Command that writes the territories of an Atlas Composer atlas and the composed geometries of a composite projection as GeoJSON
Maintainers
Readme
@atlas-composer/cli
Command that writes the territories of an Atlas Composer atlas as GeoJSON, for GIS and tile tools.
The atlas-composer command reads the atlases and the presets of @atlas-composer/preset-library and the countries of Natural Earth from world-atlas.
Installation
npm install @atlas-composer/cliTerritories of an atlas
npx atlas-composer territories france > france.geojsonterritories <atlas> writes to the standard output a GeoJSON FeatureCollection with one feature per territory of the atlas, in longitudes and latitudes. Each feature has the id, the code, the name and the iso of its territory in properties. The rings follow RFC 7946: exterior rings counterclockwise, and a ring that crosses the antimeridian cut in two. At 50m, GEOS reads each geometry as valid; at 10m and 110m, some rings of Natural Earth cross themselves and GEOS reads their geometries as invalid: ogr2ogr -makevalid repairs them.
--resolution 10m|50m|110mchooses the Natural Earth resolution,50mby default. The extraction rules of the atlases count the polygons of a country in the50mtopology: at10mand110m, each polygon goes to the territory of the50mpolygon that contains it or is nearest, and a polygon that Natural Earth draws at this resolution only, farther than 50 km and outside the bounds of its territory, is left out.--data <file>reads the geometries from a JSON file of GeoJSON features, each with the code of a territory of the atlas inproperties.code, in place of Natural Earth.
Territories placed in a composite projection
npx atlas-composer compose france-standard --out france-standard.geojsoncompose <preset> places each territory as the composite-custom preset draws it, with the overseas territories next to the mainland, and writes two files:
france-standard.geojson, a GeoJSONFeatureCollectionof the placed territories;france-standard.geojson.json, with thecanvasDimensionsand thereferenceScaleof the composition, the codes of the territories that the preset leaves out inskippedCodes, and the codes of the territories that their frame clips entirely inemptyCodes.
compose <file.json> reads a configuration exported from the Atlas Composer app, for the atlas that its metadata.atlasId names. --data <file> reads the geometries as for territories; without it, compose reads Natural Earth at the resolution of --resolution, 50m by default.
Coordinates of the composed file
The coordinates of the composed file are longitudes and latitudes that draw the composition in Web Mercator: display the file in EPSG:3857, or reproject it from EPSG:4326 to EPSG:3857. The longer side of the canvas spans the 360° of longitude, and the center of the canvas is at longitude 0 and latitude 0. A longitude of the file is a position in the composition, unrelated to the longitude of the territory on the globe.
The file is for GIS and tile tools, such as QGIS, GDAL, tippecanoe or MapLibre. d3-geo joins two vertices by a great-circle arc and reads the orientation of RFC 7946 as an inverted territory: with d3, load the preset with @atlas-composer/projection-loader.
One territory per code
compose projects each territory through the sub-projection of its code, clipped to its frame and to the canvas, as the editor of the Atlas Composer app draws it. A territory that the preset leaves out has no sub-projection, and is missing from the composed file: US-ALEU, US-VI and US-MP in usa-pseudo-d3cp. The editor draws such a territory once it is checked, with default parameters. A territory whose geometry falls in the frame of another one is drawn once, in its own frame: FR-MF and FR-BL in france-proportional.
PROJ pipelines of a composite projection
npx atlas-composer describe france-standard > france-standard.proj.jsondescribe <preset> writes to the standard output, as JSON, the PROJ pipeline of each territory of the composite-custom preset, from longitudes and latitudes in degrees to the pixels of the canvas, and the ring of its frame in clip. describe <file.json> reads a configuration exported from the Atlas Composer app. The command reads no geometry. The README of @atlas-composer/projection-loader describes the form of the pipelines, their use with cct, pyproj and GDAL, and their limits.
API
import { composeTerritories, naturalEarthSource } from '@atlas-composer/cli'
import { buildTerritories, getPreset } from '@atlas-composer/preset-library'
import atlas from '@atlas-composer/preset-library/atlases/france' with { type: 'json' }
import { ProjectionLoader } from '@atlas-composer/projection-loader'
import { d3ProjectionFactories } from '@atlas-composer/projection-loader/helpers'
const loader = new ProjectionLoader()
loader.registerAll(d3ProjectionFactories)
const { collection: territories } = buildTerritories(atlas, naturalEarthSource('50m'))
const config = await getPreset('france-standard')
if (!config) {
throw new Error('Unknown preset')
}
const { collection, skippedCodes, emptyCodes } = composeTerritories(loader, config, territories)naturalEarthSource(resolution) reads the countries of world-atlas as a source of buildTerritories. composeTerritories(loader, config, territories) returns the composed collection with canvasDimensions, referenceScale, skippedCodes and emptyCodes.
License
MIT
