Class Datasource

java.lang.Object
dev.avelar.mapnik.Datasource
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
JavaDatasource, MemoryDatasource

public class Datasource extends Object implements AutoCloseable
A Mapnik datasource, such as a shapefile or a GeoJSON file. Create one with create(java.util.Map<java.lang.String, ?>) and attach it to a Layer. Needs the matching input plugin registered with Mapnik.registerDatasources(java.lang.String).
  • Method Details

    • create

      public static Datasource create(Map<String,?> params)
      Create a datasource. Mapnik memory-maps data files and caches the mapping, so do not overwrite a file in place while a process uses it: write a new file and rename it over the old one, then call Mapnik.clearCaches(). params must contain type, the plugin name (for example "geojson" or "shape"), plus that plugin's options. Values may be String, Integer/Long, Double/Float or Boolean.
    • mbtiles

      public static Datasource mbtiles(Path file, String layer)
      Vector tiles from an MBTiles file (Mapnik Vector Tile data in a SQLite database). layer is the tile layer to draw, such as "places". It is required for vector tiles: with null, Mapnik reads the file as raster tiles (PNG or JPEG images), which is right only for an MBTiles file of pictures. Use it in a layer whose projection is epsg:3857: tiles are Web Mercator. Needs Mapnik's tiles input plugin, which the prebuilt natives include.
    • pmtiles

      public static Datasource pmtiles(Path file, String layer)
    • tilesFromUrl

      public static Datasource tilesFromUrl(String url, String layer)
      Tiles fetched over HTTP: url is a TileJSON document (.json) or a template such as http://host/{z}/{x}/{y}.pbf (or .mvt; other endings are read as raster tiles). The connection is encrypted and the server's certificate is checked against the bundled list of trusted authorities (or the file named by SSL_CERT_FILE, or set with Mapnik.setTrustedCertificates(java.nio.file.Path)); an untrusted server's tiles are not drawn. layer as in mbtiles(java.nio.file.Path, java.lang.String): required for vector tiles.
    • type

      public Datasource.Type type()
    • geometryType

      public Datasource.GeometryType geometryType()
    • envelope

      public Box2d envelope()
      The extent of the data, in the datasource's own projection.
    • fields

      public List<Datasource.Field> fields()
      Attribute columns.
    • features

      public Featureset features(FeatureQuery query)
      Features matching the query. Close the result.
    • features

      public Featureset features(Box2d box)
      Features whose bounding box touches box. Close the result.
    • featuresAtPoint

      public Featureset featuresAtPoint(double x, double y, double tolerance)
      Features within tolerance of a point, in the datasource's projection. Close the result.
    • layerName

      public String layerName()
      The name the datasource gives its data, such as a table or layer name. May be empty.
    • encoding

      public String encoding()
      The text encoding of attribute data, for example utf-8.
    • parameters

      public Map<String,Object> parameters()
      The parameters the datasource holds, in key order: the ones you passed, plus any the plugin filled in. Values are String, Boolean, Long, Double or null.
    • close

      public void close()
      Release this handle. A layer that already uses the datasource keeps its own reference.
      Specified by:
      close in interface AutoCloseable