Convert Figma logo to code with AI

mbloch logomapshaper

Tools for editing Shapefile, GeoJSON, TopoJSON and CSV files

3,719
532
3,719
133

Top Related Projects

An extension of GeoJSON that encodes topology! 🌐

41,217

πŸƒ JavaScript library for mobile-friendly interactive maps πŸ‡ΊπŸ‡¦

1,021

Geographic projections, spherical shapes and spherical trigonometry.

9,199

A modular geospatial engine written in JavaScript and TypeScript

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL

10,476

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)

Quick Overview

Mapshaper is a powerful command-line tool and web application for editing and processing geospatial data. It supports various formats including Shapefile, GeoJSON, TopoJSON, and CSV, allowing users to simplify, edit, and convert between these formats. Mapshaper is particularly useful for cartographers and GIS professionals working with complex geographic datasets.

Pros

  • Supports multiple geospatial data formats
  • Offers both command-line and web-based interfaces
  • Provides advanced simplification algorithms for reducing file sizes
  • Includes a wide range of editing and processing tools

Cons

  • Learning curve for advanced features and command-line usage
  • Web interface may have limitations for very large datasets
  • Some operations can be computationally intensive
  • Documentation could be more comprehensive for certain features

Code Examples

  1. Simplifying a shapefile:
mapshaper input.shp -simplify dp 10% -o output.shp

This command simplifies the input shapefile using the Douglas-Peucker algorithm, reducing the number of points to 10% of the original, and saves the result as output.shp.

  1. Converting GeoJSON to TopoJSON:
mapshaper input.geojson -o output.topojson format=topojson

This example converts a GeoJSON file to TopoJSON format.

  1. Merging multiple shapefiles:
mapshaper file1.shp file2.shp file3.shp combine-files -merge-layers -o merged.shp

This command combines three shapefiles into a single merged shapefile.

Getting Started

To get started with Mapshaper:

  1. Install Node.js if not already installed.
  2. Install Mapshaper globally using npm:
npm install -g mapshaper
  1. Use the command-line interface:
mapshaper -h

This will display the help menu with available commands and options.

  1. For the web interface, navigate to https://mapshaper.org in your browser.

  2. To use Mapshaper as a Node.js library in your project:

npm install mapshaper

Then, in your JavaScript code:

const mapshaper = require('mapshaper');

// Use mapshaper API functions
mapshaper.runCommands('input.shp -simplify dp 10% -o output.shp', function(error) {
  if (error) console.error(error);
  console.log('Processing complete');
});

This example demonstrates how to use Mapshaper's API to run commands programmatically within a Node.js application.

Competitor Comparisons

An extension of GeoJSON that encodes topology! 🌐

Pros of TopoJSON

  • Specialized in topological encoding, resulting in smaller file sizes for geographic data
  • Supports topology preservation, maintaining shared boundaries between features
  • Widely adopted in the geospatial community, with extensive documentation and examples

Cons of TopoJSON

  • Limited to working with JSON-based geographic data formats
  • Fewer general-purpose GIS operations compared to Mapshaper
  • Steeper learning curve for users not familiar with topological concepts

Code Comparison

TopoJSON:

var topology = topojson.topology({
  foo: {type: "LineString", coordinates: [[0, 0], [1, 1]]},
  bar: {type: "LineString", coordinates: [[1, 1], [2, 2]]}
});

Mapshaper:

mapshaper.runCommands('-i input.shp -simplify dp 20% -o output.geojson');

Key Differences

  • TopoJSON focuses on topological encoding and manipulation of geographic data
  • Mapshaper offers a broader range of GIS operations and supports various file formats
  • TopoJSON is more specialized for web-based mapping applications
  • Mapshaper provides a command-line interface for batch processing and scripting

Both tools are valuable in the geospatial ecosystem, with TopoJSON excelling in efficient data representation for web mapping, while Mapshaper offers more versatile GIS functionality and format support.

41,217

πŸƒ JavaScript library for mobile-friendly interactive maps πŸ‡ΊπŸ‡¦

Pros of Leaflet

  • Widely adopted, feature-rich interactive mapping library
  • Extensive plugin ecosystem for additional functionality
  • Optimized for mobile devices and responsive design

Cons of Leaflet

  • Focused on web-based mapping, not data processing or simplification
  • Steeper learning curve for complex map visualizations
  • Larger file size compared to minimal mapping libraries

Code Comparison

Leaflet (creating a map):

var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: 'Β© OpenStreetMap contributors'
}).addTo(map);

Mapshaper (simplifying geometry):

mapshaper -i input.shp -simplify dp 10% -o output.shp

Summary

Leaflet is a comprehensive web mapping library, ideal for interactive maps and visualizations. Mapshaper, on the other hand, is a powerful tool for processing and simplifying geographic data. While Leaflet excels in displaying maps, Mapshaper is better suited for data preparation and manipulation tasks. The choice between the two depends on whether you need to create interactive web maps (Leaflet) or process and simplify geographic data (Mapshaper).

1,021

Geographic projections, spherical shapes and spherical trigonometry.

Pros of d3-geo

  • Part of the larger D3 ecosystem, offering seamless integration with other D3 modules
  • Provides a wide range of geographic projections and transformations
  • Highly customizable and flexible for creating complex geographic visualizations

Cons of d3-geo

  • Steeper learning curve, especially for those not familiar with D3
  • Requires more code to achieve basic map rendering compared to Mapshaper
  • Limited built-in simplification and editing features for geographic data

Code Comparison

d3-geo:

const projection = d3.geoMercator();
const path = d3.geoPath().projection(projection);
svg.selectAll("path")
   .data(geojson.features)
   .enter().append("path")
   .attr("d", path);

Mapshaper:

mapshaper.runCommands('-i input.shp -simplify dp 20% -o output.geojson');

Summary

d3-geo excels in creating custom, interactive geographic visualizations within the D3 ecosystem, offering extensive projection options. Mapshaper, on the other hand, provides a more straightforward approach to geographic data processing and simplification. While d3-geo requires more code for basic map rendering, it offers greater flexibility for complex visualizations. Mapshaper's strength lies in its simplicity and efficient command-line operations for data manipulation.

9,199

A modular geospatial engine written in JavaScript and TypeScript

Pros of Turf

  • Extensive collection of geospatial analysis functions
  • Designed for use in both browser and Node.js environments
  • Active community and regular updates

Cons of Turf

  • Can be slower for large datasets compared to Mapshaper
  • Lacks some advanced simplification and editing features

Code Comparison

Mapshaper (simplifying a GeoJSON feature):

mapshaper.simplify(geojson, {
  method: 'visvalingam',
  percentage: 10
});

Turf (simplifying a GeoJSON feature):

var simplified = turf.simplify(geojson, {
  tolerance: 0.01,
  highQuality: true
});

Key Differences

  • Mapshaper focuses on processing and editing geographic datasets, with a command-line interface and web-based GUI
  • Turf is a JavaScript library for geospatial analysis, offering a wide range of functions for various operations
  • Mapshaper excels at file format conversions and advanced simplification techniques
  • Turf provides more comprehensive spatial analysis capabilities, such as buffering, interpolation, and clustering

Both tools have their strengths and are often used in combination for different aspects of geospatial data processing and analysis.

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL

Pros of Mapbox GL JS

  • Advanced rendering capabilities for interactive, customizable maps
  • Extensive documentation and community support
  • Seamless integration with other Mapbox services

Cons of Mapbox GL JS

  • Requires an API key and potentially incurs usage costs
  • Steeper learning curve for complex implementations
  • Larger file size and potentially higher resource usage

Code Comparison

Mapshaper (simplifying GeoJSON):

mapshaper.runCommands('-i input.geojson -simplify dp 10% -o output.geojson');

Mapbox GL JS (creating a map):

mapboxgl.accessToken = 'YOUR_ACCESS_TOKEN';
const map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/streets-v11',
    center: [-74.5, 40],
    zoom: 9
});

Key Differences

  • Mapshaper focuses on processing and simplifying geographic data
  • Mapbox GL JS specializes in rendering interactive web maps
  • Mapshaper is open-source and free to use, while Mapbox GL JS requires an API key
  • Mapbox GL JS offers more advanced styling and interactivity options
  • Mapshaper is generally easier to use for basic data processing tasks
10,476

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)

Pros of QGIS

  • Comprehensive GIS functionality with advanced spatial analysis tools
  • Extensive plugin ecosystem for additional features and integrations
  • Robust support for various data formats and coordinate systems

Cons of QGIS

  • Steeper learning curve due to its complex interface and extensive features
  • Requires installation and may have higher system requirements
  • Can be slower for simple map editing tasks compared to lightweight tools

Code Comparison

QGIS (Python):

layer = QgsVectorLayer("path/to/shapefile.shp", "layer_name", "ogr")
if not layer.isValid():
    print("Layer failed to load!")
QgsProject.instance().addMapLayer(layer)

Mapshaper (JavaScript):

mapshaper -i input.shp -simplify dp 20% -o output.geojson

Summary

QGIS is a powerful, full-featured GIS software with extensive capabilities, while Mapshaper is a lightweight, command-line tool focused on map simplification and conversion. QGIS offers more comprehensive analysis but may be overkill for simple tasks. Mapshaper excels in quick, efficient map processing but lacks advanced GIS functionality. Choose based on your project's complexity and requirements.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Mapshaper

Introduction

Mapshaper is software for editing Shapefile, GeoJSON, TopoJSON, CSV and several other data formats, written in JavaScript.

Mapshaper supports essential map making tasks like simplifying shapes, editing attribute data, clipping, erasing, dissolving, filtering and more.

See the project wiki for documentation on how to use mapshaper.

To suggest improvements, add an issue.

Command line tools

Mapshaper includes several command line programs, which can be run under Mac OS X, Linux and Windows.

  • mapshaper Runs mapshaper commands.
  • mapshaper-xl Works the same as mapshaper, but runs with more RAM to support larger files.
  • mapshaper-gui Runs the mapshaper Web interface locally.

The project wiki has an introduction to using the command line tool that includes many simple examples.

For a detailed reference, see the Command Reference.

Interactive web interface

Visit the public website at www.mapshaper.org or use the web UI locally via the mapshaper-gui script.

All processing is done in the browser, so your data stays private, even when using the public website.

The web UI works in recent desktop versions of Chrome, Firefox, Safari and Internet Explorer. Safari before v10.1 and IE before v10 are not supported.

User-contributed resources

rmapshaper is an R package written by Andy Teucher that gives R users access to many of mapshaper's editing commands.

Here are resources for using mapshaper with Docker, provided by Christian Weiss.

You can find a number of mapshaper tutorials online, including a two part guide to command line cartography by Dylan Moriarty and this introduction by Jack Dougherty.

Large file support

Web interface

Firefox is able to load Shapefiles and GeoJSON files larger than 1GB. Chrome has improved in recent versions, but is still prone to out-of-memory errors when importing files larger than several hundred megabytes.

Command line interface

There are hard limits for reading and writing most file types. The maximum output size of a single file of any type is 2GB. Some file types (GeoJSON, CSV, .shp, .dbf) are read incrementally, so much larger files can be imported.

When working with very large files, mapshaper may become unresponsive or crash with the message "JavaScript heap out of memory."

You can use mapshaper-xl as a replacement for the standard mapshaper program to allocate more heap memory (8GB by default). You can allocate even more memory like this: mapshaper-xl 20gb [commands].

Another option is to run Node directly with the --max-old-space-size option. The following example (Mac or Linux) allocates 16GB of heap memory:

$ node  --max-old-space-size=16000 `which mapshaper` <mapshaper commands>

Installation

Mapshaper requires Node.js.

With Node installed, you can install the latest release version of mapshaper using npm. Install with the "-g" flag to make the executable scripts available systemwide.

npm install -g mapshaper

To install and run the latest development code from github:

git clone git@github.com:mbloch/mapshaper.git
cd mapshaper
npm install       # install dependencies
npm run build     # bundle source code files
npm link          # (optional) add global symlinks so scripts are available systemwide

Building and testing

From the project directory, run npm run build to build both the cli and web UI modules.

Run npm test to run mapshaper's tests.

License

This software is licensed under MPL 2.0.

According to Mozilla's FAQ, "The MPL's Γ’Β€Β˜file-levelҀ™ copyleft is designed to encourage contributors to share modifications they make to your code, while still allowing them to combine your code with code under other licenses (open or proprietary) with minimal restrictions."

Acknowledgements

My colleagues at The New York Times, for countless suggestions, bug reports and general helpfulness.

Mark Harrower, for collaborating on the original "MapShaper" program at the University of Wisconsin–Madison.

NPM DownloadsLast 30 Days