Search in sources :

Example 1 with Layer

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);
    }
}
Also used : PSQLException(org.postgresql.util.PSQLException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) JSONException(org.json.JSONException) IOException(java.io.IOException) Layer(com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer) LinkedList(java.util.LinkedList) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 2 with Layer

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();
    }
}
Also used : VectorLayerPublisherIF(net.geoprism.ontology.VectorLayerPublisherIF) TableEntity(net.geoprism.registry.TableEntity) IUserDataConverter(com.wdtinc.mapbox_vector_tile.adapt.jts.IUserDataConverter) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) IGeometryFilter(com.wdtinc.mapbox_vector_tile.adapt.jts.IGeometryFilter) JtsAdapter(com.wdtinc.mapbox_vector_tile.adapt.jts.JtsAdapter) ValueObject(com.runwaysdk.dataaccess.ValueObject) VectorTile(com.wdtinc.mapbox_vector_tile.VectorTile) MvtLayerBuild(com.wdtinc.mapbox_vector_tile.build.MvtLayerBuild) MvtLayerParams(com.wdtinc.mapbox_vector_tile.build.MvtLayerParams) PSQLException(org.postgresql.util.PSQLException) ValueQuery(com.runwaysdk.query.ValueQuery) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) SQLException(java.sql.SQLException) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) JSONException(org.json.JSONException) LocalizationFacade(com.runwaysdk.localization.LocalizationFacade) GeoEntity(com.runwaysdk.system.gis.geo.GeoEntity) ResultSet(java.sql.ResultSet) Locale(java.util.Locale) Map(java.util.Map) AttributeGeometryIF(com.runwaysdk.gis.dataaccess.AttributeGeometryIF) Tile(com.wdtinc.mapbox_vector_tile.VectorTile.Tile) Geometry(com.vividsolutions.jts.geom.Geometry) LinkedList(java.util.LinkedList) AttributeIF(com.runwaysdk.dataaccess.AttributeIF) Database(com.runwaysdk.dataaccess.database.Database) MasterListVersion(net.geoprism.registry.MasterListVersion) JtsGeometry(org.postgis.jts.JtsGeometry) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) Envelope(com.vividsolutions.jts.geom.Envelope) GeoserverFacade(com.runwaysdk.system.gis.mapping.GeoserverFacade) Collection(java.util.Collection) IOException(java.io.IOException) Layer(com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer) RegistryConstants(net.geoprism.registry.RegistryConstants) TileGeomResult(com.wdtinc.mapbox_vector_tile.adapt.jts.TileGeomResult) UserDataConverter(net.geoprism.ontology.UserDataConverter) OIterator(com.runwaysdk.query.OIterator) List(java.util.List) TreeMap(java.util.TreeMap) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) MvtLayerProps(com.wdtinc.mapbox_vector_tile.build.MvtLayerProps) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) IUserDataConverter(com.wdtinc.mapbox_vector_tile.adapt.jts.IUserDataConverter) IUserDataConverter(com.wdtinc.mapbox_vector_tile.adapt.jts.IUserDataConverter) UserDataConverter(net.geoprism.ontology.UserDataConverter) VectorTile(com.wdtinc.mapbox_vector_tile.VectorTile) Tile(com.wdtinc.mapbox_vector_tile.VectorTile.Tile) TileGeomResult(com.wdtinc.mapbox_vector_tile.adapt.jts.TileGeomResult) Layer(com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer) LinkedList(java.util.LinkedList) AttributeGeometryIF(com.runwaysdk.gis.dataaccess.AttributeGeometryIF) Geometry(com.vividsolutions.jts.geom.Geometry) JtsGeometry(org.postgis.jts.JtsGeometry) Layer(com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer) MvtLayerProps(com.wdtinc.mapbox_vector_tile.build.MvtLayerProps) VectorTile(com.wdtinc.mapbox_vector_tile.VectorTile) ValueObject(com.runwaysdk.dataaccess.ValueObject) MvtLayerParams(com.wdtinc.mapbox_vector_tile.build.MvtLayerParams) IGeometryFilter(com.wdtinc.mapbox_vector_tile.adapt.jts.IGeometryFilter)

Example 3 with Layer

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();
}
Also used : VectorTile(com.wdtinc.mapbox_vector_tile.VectorTile) Tile(com.wdtinc.mapbox_vector_tile.VectorTile.Tile) Layer(com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer)

Example 4 with Layer

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);
    }
}
Also used : Locale(java.util.Locale) VectorLayerPublisherIF(net.geoprism.ontology.VectorLayerPublisherIF) TableEntity(net.geoprism.registry.TableEntity) IUserDataConverter(com.wdtinc.mapbox_vector_tile.adapt.jts.IUserDataConverter) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) IGeometryFilter(com.wdtinc.mapbox_vector_tile.adapt.jts.IGeometryFilter) JtsAdapter(com.wdtinc.mapbox_vector_tile.adapt.jts.JtsAdapter) ValueObject(com.runwaysdk.dataaccess.ValueObject) VectorTile(com.wdtinc.mapbox_vector_tile.VectorTile) MvtLayerBuild(com.wdtinc.mapbox_vector_tile.build.MvtLayerBuild) MvtLayerParams(com.wdtinc.mapbox_vector_tile.build.MvtLayerParams) PSQLException(org.postgresql.util.PSQLException) ValueQuery(com.runwaysdk.query.ValueQuery) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) SQLException(java.sql.SQLException) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) JSONException(org.json.JSONException) LocalizationFacade(com.runwaysdk.localization.LocalizationFacade) GeoEntity(com.runwaysdk.system.gis.geo.GeoEntity) ResultSet(java.sql.ResultSet) Locale(java.util.Locale) Map(java.util.Map) AttributeGeometryIF(com.runwaysdk.gis.dataaccess.AttributeGeometryIF) Tile(com.wdtinc.mapbox_vector_tile.VectorTile.Tile) Geometry(com.vividsolutions.jts.geom.Geometry) LinkedList(java.util.LinkedList) AttributeIF(com.runwaysdk.dataaccess.AttributeIF) Database(com.runwaysdk.dataaccess.database.Database) MasterListVersion(net.geoprism.registry.MasterListVersion) JtsGeometry(org.postgis.jts.JtsGeometry) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) Envelope(com.vividsolutions.jts.geom.Envelope) GeoserverFacade(com.runwaysdk.system.gis.mapping.GeoserverFacade) Collection(java.util.Collection) IOException(java.io.IOException) Layer(com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer) RegistryConstants(net.geoprism.registry.RegistryConstants) TileGeomResult(com.wdtinc.mapbox_vector_tile.adapt.jts.TileGeomResult) UserDataConverter(net.geoprism.ontology.UserDataConverter) OIterator(com.runwaysdk.query.OIterator) List(java.util.List) TreeMap(java.util.TreeMap) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) MvtLayerProps(com.wdtinc.mapbox_vector_tile.build.MvtLayerProps) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) IUserDataConverter(com.wdtinc.mapbox_vector_tile.adapt.jts.IUserDataConverter) PSQLException(org.postgresql.util.PSQLException) SQLException(java.sql.SQLException) IUserDataConverter(com.wdtinc.mapbox_vector_tile.adapt.jts.IUserDataConverter) UserDataConverter(net.geoprism.ontology.UserDataConverter) PSQLException(org.postgresql.util.PSQLException) TreeMap(java.util.TreeMap) TileGeomResult(com.wdtinc.mapbox_vector_tile.adapt.jts.TileGeomResult) Layer(com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer) LinkedList(java.util.LinkedList) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Geometry(com.vividsolutions.jts.geom.Geometry) JtsGeometry(org.postgis.jts.JtsGeometry) JtsGeometry(org.postgis.jts.JtsGeometry) MvtLayerProps(com.wdtinc.mapbox_vector_tile.build.MvtLayerProps) VectorTile(com.wdtinc.mapbox_vector_tile.VectorTile) MvtLayerParams(com.wdtinc.mapbox_vector_tile.build.MvtLayerParams) IGeometryFilter(com.wdtinc.mapbox_vector_tile.adapt.jts.IGeometryFilter)

Aggregations

Layer (com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer)4 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)3 VectorTile (com.wdtinc.mapbox_vector_tile.VectorTile)3 Tile (com.wdtinc.mapbox_vector_tile.VectorTile.Tile)3 IOException (java.io.IOException)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 LinkedList (java.util.LinkedList)3 AttributeIF (com.runwaysdk.dataaccess.AttributeIF)2 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)2 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)2 ValueObject (com.runwaysdk.dataaccess.ValueObject)2 Database (com.runwaysdk.dataaccess.database.Database)2 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)2 AttributeGeometryIF (com.runwaysdk.gis.dataaccess.AttributeGeometryIF)2 LocalizationFacade (com.runwaysdk.localization.LocalizationFacade)2 OIterator (com.runwaysdk.query.OIterator)2 ValueQuery (com.runwaysdk.query.ValueQuery)2 GeoEntity (com.runwaysdk.system.gis.geo.GeoEntity)2 GeoserverFacade (com.runwaysdk.system.gis.mapping.GeoserverFacade)2