use of com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer in project geoprism-registry by terraframe.
the class VectorTileBuilder method writeVectorLayers.
@Override
public List<Layer> writeVectorLayers(Envelope envelope, Envelope bounds) {
try (ResultSet resultSet = this.getResultSet()) {
List<Layer> layers = new LinkedList<Layer>();
layers.add(this.writeVectorLayer("context", bounds, resultSet));
return layers;
} catch (JSONException | IOException | SQLException e) {
throw new ProgrammingErrorException(e);
}
}
use of com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer in project geoprism-registry by terraframe.
the class VectorTileBuilder method writeVectorTiles.
protected byte[] writeVectorTiles(String layerName, Envelope envelope, ValueQuery query) throws IOException {
OIterator<ValueObject> iterator = query.getIterator();
try {
List<Geometry> geometries = new LinkedList<Geometry>();
while (iterator.hasNext()) {
ValueObject object = iterator.next();
AttributeGeometryIF attributeIF = (AttributeGeometryIF) object.getAttributeIF(GeoserverFacade.GEOM_COLUMN);
Geometry geometry = attributeIF.getGeometry();
geometry.setUserData(this.getUserData(object));
geometries.add(geometry);
}
GeometryFactory geomFactory = new GeometryFactory();
IGeometryFilter acceptAllGeomFilter = geometry -> true;
MvtLayerParams layerParams = new MvtLayerParams();
TileGeomResult tileGeom = JtsAdapter.createTileGeom(geometries, envelope, geomFactory, layerParams, acceptAllGeomFilter);
final VectorTile.Tile.Builder tileBuilder = VectorTile.Tile.newBuilder();
// Create MVT layer
final MvtLayerProps layerProps = new MvtLayerProps();
final IUserDataConverter ignoreUserData = new UserDataConverter();
// MVT tile geometry to MVT features
final List<VectorTile.Tile.Feature> features = JtsAdapter.toFeatures(tileGeom.mvtGeoms, layerProps, ignoreUserData);
final VectorTile.Tile.Layer.Builder layerBuilder = MvtLayerBuild.newLayerBuilder(layerName, layerParams);
layerBuilder.addAllFeatures(features);
MvtLayerBuild.writeProps(layerBuilder, layerProps);
// Build MVT layer
final VectorTile.Tile.Layer layer = layerBuilder.build();
// Add built layer to MVT
tileBuilder.addLayers(layer);
// / Build MVT
Tile mvt = tileBuilder.build();
return mvt.toByteArray();
} finally {
iterator.close();
}
}
use of com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer in project geoprism-registry by terraframe.
the class VectorTileBuilder method writeVectorTiles.
public byte[] writeVectorTiles(Envelope envelope, Envelope bounds) {
// Add built layer to MVT
final VectorTile.Tile.Builder builder = VectorTile.Tile.newBuilder();
List<Layer> layers = this.writeVectorLayers(envelope, bounds);
for (Layer layer : layers) {
builder.addLayers(layer);
}
// / Build MVT
Tile mvt = builder.build();
return mvt.toByteArray();
}
use of com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer in project geoprism-registry by terraframe.
the class VectorTileBuilder method writeVectorLayer.
public VectorTile.Tile.Layer writeVectorLayer(String layerName, Envelope bounds, ResultSet resultSet) throws IOException {
try {
List<Geometry> geometries = new LinkedList<Geometry>();
while (resultSet.next()) {
String label = resultSet.getString("default_locale");
Map<String, String> data = new TreeMap<String, String>();
data.put(GeoEntity.OID, resultSet.getString("oid"));
data.put(DefaultAttribute.CODE.getName(), resultSet.getString("code"));
data.put(DefaultAttribute.UID.getName(), resultSet.getString("uid"));
data.put(GeoEntity.DISPLAYLABEL, label);
for (Locale locale : locales) {
try {
data.put(GeoEntity.DISPLAYLABEL + "_" + locale.toString().toLowerCase(), resultSet.getString(locale.toString()));
} catch (PSQLException e) {
// Ignore: The column doesn't exist because the list was created
// before the locale was installed
}
}
JtsGeometry geom = (JtsGeometry) resultSet.getObject(GeoserverFacade.GEOM_COLUMN);
if (geom != null) {
Geometry geometry = geom.getGeometry();
geometry.setUserData(data);
geometries.add(geometry);
}
}
GeometryFactory geomFactory = new GeometryFactory();
IGeometryFilter acceptAllGeomFilter = geometry -> true;
MvtLayerParams layerParams = new MvtLayerParams();
TileGeomResult tileGeom = JtsAdapter.createTileGeom(geometries, bounds, geomFactory, layerParams, acceptAllGeomFilter);
// Create MVT layer
final MvtLayerProps layerProps = new MvtLayerProps();
final IUserDataConverter ignoreUserData = new UserDataConverter();
// MVT tile geometry to MVT features
final List<VectorTile.Tile.Feature> features = JtsAdapter.toFeatures(tileGeom.mvtGeoms, layerProps, ignoreUserData);
final VectorTile.Tile.Layer.Builder layerBuilder = MvtLayerBuild.newLayerBuilder(layerName, layerParams);
layerBuilder.addAllFeatures(features);
MvtLayerBuild.writeProps(layerBuilder, layerProps);
// Build MVT layer
return layerBuilder.build();
} catch (SQLException e) {
throw new ProgrammingErrorException(e);
}
}
Aggregations