org.opentripplanner.ext.vectortiles.LayerBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.ext.vectortiles;
import com.wdtinc.mapbox_vector_tile.VectorTile;
import com.wdtinc.mapbox_vector_tile.adapt.jts.JtsAdapter;
import com.wdtinc.mapbox_vector_tile.adapt.jts.TileGeomResult;
import com.wdtinc.mapbox_vector_tile.build.MvtLayerBuild;
import com.wdtinc.mapbox_vector_tile.build.MvtLayerParams;
import com.wdtinc.mapbox_vector_tile.build.MvtLayerProps;
import java.util.List;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.opentripplanner.ext.vectortiles.VectorTilesResource.LayerParameters;
import org.opentripplanner.util.geometry.GeometryUtils;
public abstract class LayerBuilder {
private static final GeometryFactory GEOMETRY_FACTORY = GeometryUtils.getGeometryFactory();
private final MvtLayerProps layerProps = new MvtLayerProps();
private final VectorTile.Tile.Layer.Builder layerBuilder;
private final PropertyMapper mapper;
public LayerBuilder(String layerName, PropertyMapper mapper) {
this.mapper = mapper;
this.layerBuilder = MvtLayerBuild.newLayerBuilder(layerName, MvtLayerParams.DEFAULT);
}
/**
* Get a list of geometries in this layer inside the query envelope. The geometries should include
* an object of type T as their userData.
*/
protected abstract List getGeometries(Envelope query);
VectorTile.Tile.Layer build(Envelope envelope, LayerParameters params) {
Envelope query = new Envelope(envelope);
query.expandBy(
envelope.getWidth() * params.expansionFactor(),
envelope.getHeight() * params.expansionFactor()
);
TileGeomResult tileGeom = JtsAdapter.createTileGeom(
getGeometries(query),
envelope,
query,
GEOMETRY_FACTORY,
MvtLayerParams.DEFAULT,
g -> true
);
List features = JtsAdapter.toFeatures(
tileGeom.mvtGeoms,
layerProps,
this.mapper
);
layerBuilder.addAllFeatures(features);
MvtLayerBuild.writeProps(layerBuilder, layerProps);
return layerBuilder.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy