npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dra2020/topojson-server

v3.0.103

Published

Convert GeoJSON to TopoJSON for smaller files and the power of topology!

Downloads

96

Readme

TopoJSON Server

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.

Installing

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.

API Reference

# 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.

Command-Line Reference

geo2topo

# geo2topo [options…] [name=]file<>

Converts one or more GeoJSON objects to an output topology. For example, to convert a GeoJSON FeatureCollection in the input file us-states.json to a TopologyJSON topology in the output file us.json:

geo2topo states=us-states.json > us.json

The resulting topology has a “states” object which corresponds to the input geometry. For convenience, you can omit the object name and specify only the output file name; the object name will then 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

Accept newline-delimited JSON, with one feature per line.

# geo2topo -o file # geo2topo --out file

Specify the output TopoJSON file name. Defaults to “-” for stdout.

# geo2topo -q count # geo2topo --quantization count

Specify a pre-quantization paramter. 0 disables quantization. See topojson.topology for a description of quantization.