Zh-hans:Mapnik
Mapnik | |
---|---|
执照: | GNU Lesser General Public License |
平台: | Windows、 macOS和 Linux |
版本: | 3.1.0 (2021-01-08) |
语言: | 英语 |
网站: | https://mapnik.org |
源代码: | https://github.com/mapnik/mapnik |
编程语言: | C++和Python |
Mapnik is an open-source toolkit for rendering maps. Among other things, it is used to render the four main Slippy Map layers on the OpenStreetMap website. It supports a variety of geospatial data formats and provides flexible styling options for designing many different kinds of maps.
Mapnik is written in C++ and can be scripted using binding languages such as JavaScript (Node.js), Python, Ruby, and Java. It uses the AGG rendering library and offers anti-aliasing rendering with subpixel accuracy. It can read ESRI shapefiles, PostGIS, TIFF rasters, .osm files, any GDAL or OGR supported formats, CSV files, and more.
You can learn more about using Mapnik at the Mapnik Wiki GitHub and by joining the #mapnik channel on freenode
Note that Mapnik is a map rendering toolkit and should not be confused with any of the common map stylesheets that may use Mapnik as a foundation. One of these, OpenStreetMap Carto is used as the main map on the OSM website.
专业用语
For a long time, the term Mapnik was used for both the library rendering geospatial data as images and the map style written in the Mapnik XML styling language used for rendering the main map on www.openstreetmap.org (the style is sometimes called OSM Mapnik). Since December 2012, the map at www.openstreetmap.org is rendered using a CartoCSS port of that style called OpenStreetMap Carto. Be aware of that confusion of names if you read older guides in this wiki or discussions on the mailing list or the forum.
Use Mapnik if you refer to the rendering engine, use the correct name of the map style if you refer to the styling rules.
安装
Refer to the Mapnik Installation Wiki GitHub. Many Linux distributions provide packages.
概览
Mapnik can output map images to a variety of graphics formats - PNG, JPEG, SVG, and PDF. OpenStreetMap's primary use of Mapnik involves rendering many millions of map tiles which are displayed in a JavaScript Slippy Map interface.
Map files
Mapnik maps are configured using its own XML format (sometimes called Mapnik XML). A map file contains:
- a list of layers (a layer applies a specific style to a specific data source)
- the definition of the styles that may be used by the layers
Mapnik风格
Mapnik allows for customization of all the cartographic aspect of a map - data features, icons, fonts, colors, patterns, and even certain effects such as pseudo-3d buildings and drop-shadows. This is all controlled by defining data sources and style rules, most commonly in an XML language specific to Mapnik.
The Mapnik style rules used for the OSM Standard tile layer are open-source and can be used as the basis for custom renderings of OSM data. Other styles are available as well, such as Humanitarian map style.
There are a number of external tools that can assist in the creation of Mapnik styles. They offer styling languages that are more compact and easier to read and write than Mapnik's built-in XML language. TileMill and Kosmtik are devolpment environments using CartoCSS as a style preprocessor (to convert the CSS-like CartoCSS into a Mapnix XML style), MagnaCarto uses the CartoCSS language as well but comes with its own converter which is able to produce Mapserver map files as well.
Former tools for that purpose whose development was discontinued are Quantumnik, a QGIS plugin, Spreadnik and Cascadenik.
数据源
Mapnik can use data from different sources: it can directly process OSM data, PostGIS databases, shapefiles, and more.
- PostGIS is the most common approach for rendering OSM data with Mapnik. OSM can be loaded by a tool such as Osmosis, osm2pgsql or Imposm and accessed via SQL queries and GIS functions defined in a Mapnik style. This approach can be used for more advanced renderings and is the main data source used by the Standard OpenStreetMap layer.
- Shapefiles are a common storage and exchange format for geographic data. In addition to PostGIS, the Standard OpenStreetMap style uses several shapefiles to render the map. For example, land masses are drawn using shapefiles generated from the natural=coastline ways by the Coastline Error Checker. See Coastline#Rendering.
- OGR: Mapnik can read from vector sources supported by the GDAL/OGR library.
- GeoTIFF: Mapnik can render GeoTIFF files as raster images. This is commonly used for relief maps. Hillshade GeoTIFF files can be generated using tools like GDAL based on digital terrain data such as SRTM.
- Raster images: In a similar way to GeoTIFF, Mapnik can also render bitmap images which contain no geocoding information. The bounding box for these images has to be specified through separate parameters.
查看更多
- Old XML format Mapnik stylesheets for OpenStreetMap "standard" style - to increase confusion these were often called "Mapnik"
- switch2osm.org for guides how to set up a tile server using Mapnik
- Renderd, Tirex as tile servers with Mapnik
- Shaded relief maps using mapnik
- Keep the PostgreSQL database in sync with changes made on the OpenStreetMap server: Minutely Mapnik
- Nik4 is a mapnik-to-image exporting script.
- Gopnik GitHub is a tile server and a render for slippy map based on mapnik library
- Artem Pavlenko - The Secrets of Mapnik (video from SotM US 2013)