Java Code Examples for org.locationtech.jts.geom.Geometry#toText()

The following examples show how to use org.locationtech.jts.geom.Geometry#toText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PostgisDb.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getSpatialindexGeometryWherePiece( String tableName, String alias, Geometry geometry ) throws Exception {
    GeometryColumn gCol = getGeometryColumnsForTable(tableName);
    if (alias == null) {
        alias = "";
    } else {
        alias = alias + ".";
    }
    int srid = geometry.getSRID();
    Envelope envelopeInternal = geometry.getEnvelopeInternal();
    Polygon bounds = DbsUtilities.createPolygonFromEnvelope(envelopeInternal);
    String sql = alias + gCol.geometryColumnName + " && ST_GeomFromText('" + bounds.toText() + "'," + srid
            + ") AND ST_Intersects(" + alias + gCol.geometryColumnName + ",ST_GeomFromText('" + geometry.toText() + "',"
            + srid + "))";
    return sql;
}
 
Example 2
Source File: Rasterlite2Coverage.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Extract an image from the database.
 * 
 * @param geom the image bounding box geometry.
 * @param width the pixel width of the expected image.
 * @param height the pixel height of the expected image.
 * @return the image bytes.
 * @throws Exception
 */
public byte[] getRL2Image( Geometry geom, String geomEpsg, int width, int height ) throws Exception {
    String sql;
    String rasterName = getName();
    if (geomEpsg != null) {
        sql = "select GetMapImageFromRaster('" + rasterName + "', ST_Transform(ST_GeomFromText('" + geom.toText() + "', "
                + geomEpsg + "), " + srid + ") , " + width + " , " + height
                + ", 'default', 'image/png', '#ffffff', 0, 80, 1 )";
    } else {
        sql = "select GetMapImageFromRaster('" + rasterName + "', ST_GeomFromText('" + geom.toText() + "') , " + width + " , "
                + height + ", 'default', 'image/png', '#ffffff', 0, 80, 1 )";
    }

    return database.execOnConnection(mConn -> {
        try (IHMStatement stmt = mConn.createStatement()) {
            IHMResultSet resultSet = stmt.executeQuery(sql);
            if (resultSet.next()) {
                byte[] bytes = resultSet.getBytes(1);
                return bytes;
            }
        }
        return null;
    });
}
 
Example 3
Source File: ASpatialDb.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Reproject an geometry.
 * 
 * @param fromGeometry the original geometry.
 * @param fromSrid the original srid.
 * @param toSrid the destination srid.
 * @return the reprojected Geometry.
 * @throws Exception
 */
public Geometry reproject( Geometry fromGeometry, int fromSrid, int toSrid ) throws Exception {
    String sql = "select ST_Transform( ST_GeomFromText('" + fromGeometry.toText() + "', " + fromSrid + ") , " + toSrid + ")";
    return execOnConnection(connection -> {
        IGeometryParser gp = getType().getGeometryParser();
        try (IHMStatement stmt = connection.createStatement(); IHMResultSet rs = stmt.executeQuery(sql)) {
            if (rs.next()) {
                Geometry repGeom = gp.fromResultSet(rs, 1);
                return repGeom;
            }
            return null;
        }
    });
}
 
Example 4
Source File: SpatialiteCommonMethods.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public static String getSpatialindexGeometryWherePiece( ASpatialDb db, String tableName, String alias, Geometry geometry )
        throws Exception {
    String rowid = "";
    if (alias == null) {
        alias = "";
        rowid = tableName + ".ROWID";
    } else {
        rowid = alias + ".ROWID";
        alias = alias + ".";
    }

    Envelope envelope = geometry.getEnvelopeInternal();
    double x1 = envelope.getMinX();
    double x2 = envelope.getMaxX();
    double y1 = envelope.getMinY();
    double y2 = envelope.getMaxY();
    GeometryColumn gCol = db.getGeometryColumnsForTable(tableName);
    if (tableName.indexOf('.') != -1) {
        // if the tablename contains a dot, then it comes from an attached
        // database
        tableName = "DB=" + tableName;
    }
    String sql = "ST_Intersects(" + alias + gCol.geometryColumnName + ", " + "ST_GeomFromText('" + geometry.toText() + "')"
            + ") = 1 AND " + rowid + " IN ( SELECT ROWID FROM SpatialIndex WHERE "//
            + "f_table_name = '" + tableName + "' AND " //
            + "search_frame = BuildMbr(" + x1 + ", " + y1 + ", " + x2 + ", " + y2 + "))";
    return sql;
}
 
Example 5
Source File: H2GisDb.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getSpatialindexGeometryWherePiece( String tableName, String alias, Geometry geometry ) throws Exception {
    GeometryColumn gCol = getGeometryColumnsForTable(tableName);
    if (alias == null) {
        alias = "";
    } else {
        alias = alias + ".";
    }

    Envelope envelopeInternal = geometry.getEnvelopeInternal();
    Polygon bounds = DbsUtilities.createPolygonFromEnvelope(envelopeInternal);
    String sql = alias + gCol.geometryColumnName + " && ST_GeomFromText('" + bounds.toText() + "') AND ST_Intersects(" + alias
            + gCol.geometryColumnName + ",ST_GeomFromText('" + geometry.toText() + "'))";
    return sql;
}
 
Example 6
Source File: PrintUtilities.java    From hortonmachine with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Print the envelope as WKT.
 * 
 * @param env
 *            the {@link org.locationtech.jts.geom.Envelope}.
 * @return the WKT string.
 */
public static String envelope2WKT( org.locationtech.jts.geom.Envelope env ) {
    GeometryFactory gf = GeometryUtilities.gf();
    Geometry geometry = gf.toGeometry(env);
    return geometry.toText();
}