Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
topojson-server
Advanced tools
Convert GeoJSON to TopoJSON for smaller files and the power of topology!
The topojson-server npm package is used to convert GeoJSON objects to TopoJSON. TopoJSON is an extension of GeoJSON that encodes topology, which can significantly reduce the size of the data and improve the efficiency of spatial operations.
Convert GeoJSON to TopoJSON
This feature allows you to convert a GeoJSON object into a TopoJSON object. The code sample demonstrates how to use the `topology` function to achieve this conversion.
const topojson = require('topojson-server');
const geojson = { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [0, 0], [0, 1], [1, 1], [1, 0], [0, 0] ] ] } } ] };
const topology = topojson.topology({ myGeo: geojson });
console.log(JSON.stringify(topology));
Simplify TopoJSON
This feature allows you to simplify a TopoJSON object, which can be useful for reducing the complexity of the data. The code sample demonstrates how to use the `simplify` function to simplify a TopoJSON object.
const topojson = require('topojson-server');
const geojson = { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [0, 0], [0, 1], [1, 1], [1, 0], [0, 0] ] ] } } ] };
const topology = topojson.topology({ myGeo: geojson });
const simplified = topojson.simplify(topology, 0.01);
console.log(JSON.stringify(simplified));
Quantize TopoJSON
This feature allows you to quantize a TopoJSON object, which can help in reducing the file size by limiting the precision of the coordinates. The code sample demonstrates how to use the `quantize` function to quantize a TopoJSON object.
const topojson = require('topojson-server');
const geojson = { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [0, 0], [0, 1], [1, 1], [1, 0], [0, 0] ] ] } } ] };
const topology = topojson.topology({ myGeo: geojson });
const quantized = topojson.quantize(topology, 1e4);
console.log(JSON.stringify(quantized));
The geojson package provides utilities for working with GeoJSON data. While it does not support TopoJSON, it offers a range of functions for manipulating GeoJSON objects, such as validation, bounding box calculation, and more.
Mapshaper is a tool for editing Shapefile, GeoJSON, TopoJSON, and other map formats. It offers a command-line interface and a web-based interface for simplifying, filtering, and converting map data. Compared to topojson-server, Mapshaper provides a broader range of data manipulation features.
The shapefile package is used for reading and writing Shapefiles, which are a popular format for geographic data. While it does not directly support TopoJSON, it can be used in conjunction with other tools to convert Shapefiles to GeoJSON and then to TopoJSON.
The topojson-server module provides tools for converting GeoJSON to TopoJSON. See How to Infer Topology for details on how the topology is constructed.
See shapefile for converting ESRI shapefiles to GeoJSON, ndjson-cli for manipulating newline-delimited JSON streams, d3-geo-projection for manipulating GeoJSON, and topojson-client for manipulating TopoJSON and converting it back to GeoJSON. See also us-atlas and world-atlas for pre-built TopoJSON.
If you use NPM, npm install topojson-server
. Otherwise, download the latest release. You can also load directly from unpkg. AMD, CommonJS, and vanilla environments are supported. In vanilla, a topojson
global is exported:
<script src="https://unpkg.com/topojson-server@3"></script>
<script>
var topology = topojson.topology({foo: geojson});
</script>
Try topojson-server in your browser.
# topojson.topology(objects[, quantization]) <>
Returns a TopoJSON topology for the specified GeoJSON objects. The returned topology makes a shallow copy of the input objects: the identifier, bounding box, properties and coordinates of input objects may be shared with the output topology.
If a quantization parameter is specified, the input geometry is quantized prior to computing the topology, the returned topology is quantized, and its arcs are delta-encoded. Quantization is recommended to improve the quality of the topology if the input geometry is messy (i.e., small floating point error means that adjacent boundaries do not have identical values); typical values are powers of ten, such as 1e4, 1e5 or 1e6. See also topojson.quantize to quantize a topology after it has been constructed, without altering the topological relationships.
# geo2topo [options…] [name=]file… <>
Converts one or more GeoJSON objects to an output topology. For example, to convert the us-states.json GeoJSON FeatureCollection to a TopologyJSON topology with the “states” object in us.json:
geo2topo states=us-states.json > us.json
For convenience, you can omit the object name and specify only the output file name; the object name will be the basename of the file, with the directory and extension removed. For example, to convert the states.json GeoJSON FeatureCollection to a TopologyJSON topology with the “states” object in us.json:
geo2topo states.json > us.json
Any properties and identifiers of input feature objects are propagated to the output. If you want to transform or filter properties, try ndjson-cli as demonstrated in Command-Line Cartography.
See also topo2geo.
# geo2topo -h
# geo2topo --help
Output usage information.
# geo2topo -V
# geo2topo --version
Output the version number.
# geo2topo -n
# geo2topo --newline-delimited
Output newline-delimited JSON, with one feature per line.
# geo2topo -i file
# geo2topo --in file
Specify the input TopoJSON file name. Defaults to “-” for stdin.
# geo2topo -l
# geo2topo --list
List the names of the objects in the input topology, and then exit. For example, this:
geo2topo -l < us.json
Will output this:
counties
states
nation
FAQs
Convert GeoJSON to TopoJSON for smaller files and the power of topology!
The npm package topojson-server receives a total of 0 weekly downloads. As such, topojson-server popularity was classified as not popular.
We found that topojson-server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.