Package dev.avelar.mapnik
Class MemoryDatasource
java.lang.Object
dev.avelar.mapnik.Datasource
dev.avelar.mapnik.MemoryDatasource
- All Implemented Interfaces:
AutoCloseable
A datasource that holds features in memory, so you can render data that is not in a file: results
of your own queries, shapes you compute, or GeoJSON you received. Use it like any
Datasource, for example with Layer.setDatasource(dev.avelar.mapnik.Datasource).
try (MemoryDatasource ds = MemoryDatasource.create()) {
ds.add(Geometry.point(10, 20), Collections.singletonMap("name", "Depot"));
layer.setDatasource(ds);
}
Coordinates must be in the projection of the layer you attach it to. Mapnik does not inspect
in-memory features, so Datasource.fields() is empty and Datasource.geometryType() is always
Datasource.GeometryType.COLLECTION. Filters and labels still see every attribute.
-
Nested Class Summary
Nested classes/interfaces inherited from class dev.avelar.mapnik.Datasource
Datasource.Field, Datasource.FieldType, Datasource.GeometryType, Datasource.Type -
Method Summary
Modifier and TypeMethodDescriptionAdd a feature.Add a geometry with no attributes.Add a geometry with attributes.addGeoJson(String json) Add every feature of a GeoJSON FeatureCollection or Feature, read as byFeature.listFromGeoJson(String).clear()Remove every feature.static MemoryDatasourcecreate()An empty memory datasource.setEnvelope(Box2d box) Override the extentDatasource.envelope()reports, which otherwise follows the features.intsize()The number of features held.Methods inherited from class dev.avelar.mapnik.Datasource
close, create, encoding, envelope, features, features, featuresAtPoint, fields, geometryType, layerName, mbtiles, parameters, pmtiles, tilesFromUrl, type
-
Method Details
-
create
An empty memory datasource. Close it when done. -
add
Add a feature. A layer that already uses this datasource sees it on the next render. -
add
Add a geometry with attributes. It gets the next free id. -
add
Add a geometry with no attributes. -
addAll
-
addGeoJson
Add every feature of a GeoJSON FeatureCollection or Feature, read as byFeature.listFromGeoJson(String). Coordinates are used as they are; GeoJSON is normally in EPSG:4326, so attach the datasource to a layer whose projection isepsg:4326. -
size
public int size()The number of features held. -
clear
Remove every feature. -
setEnvelope
Override the extentDatasource.envelope()reports, which otherwise follows the features.
-