Java Code Examples for org.locationtech.jts.geom.Envelope#getMinX()
The following examples show how to use
org.locationtech.jts.geom.Envelope#getMinX() .
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: LasIndexer.java From hortonmachine with GNU General Public License v3.0 | 7 votes |
public static Polygon envelopeToPolygon( Envelope envelope ) { double w = envelope.getMinX(); double e = envelope.getMaxX(); double s = envelope.getMinY(); double n = envelope.getMaxY(); Coordinate[] coords = new Coordinate[5]; coords[0] = new Coordinate(w, n); coords[1] = new Coordinate(e, n); coords[2] = new Coordinate(e, s); coords[3] = new Coordinate(w, s); coords[4] = new Coordinate(w, n); GeometryFactory gf = GeometryUtilities.gf(); LinearRing linearRing = gf.createLinearRing(coords); Polygon polygon = gf.createPolygon(linearRing, null); return polygon; }
Example 2
Source File: TestUtils.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
@Test public void testTiles() throws Exception { int tx = 0; int ty = 0; int tz = 0; Envelope env4326 = MercatorUtils.tileBounds4326(tx, ty, tz); Envelope env3857 = MercatorUtils.tileBounds3857(tx, ty, tz); Coordinate ll3857 = new Coordinate(env3857.getMinX(), env3857.getMinY()); Coordinate ur3857 = new Coordinate(env3857.getMaxX(), env3857.getMaxY()); Coordinate ll4326transf = MercatorUtils.convert3857To4326(ll3857); Coordinate ur4326transf = MercatorUtils.convert3857To4326(ur3857); Coordinate ll4326 = new Coordinate(env4326.getMinX(), env4326.getMinY()); Coordinate ur4326 = new Coordinate(env4326.getMaxX(), env4326.getMaxY()); double tolerance = 0.0000001; assertTrue(ll4326transf.equals2D(ll4326, tolerance)); assertTrue(ur4326transf.equals2D(ur4326, tolerance)); }
Example 3
Source File: MercatorUtils.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Get the tiles that fit into a given tile at lower zoomlevel. * * @param origTx the original tile x. * @param origTy the original tile y. * @param origZoom the original tile zoom. * @param higherZoom the requested zoom. * @param tileSize the used tile size. * @return the ordered list of tiles. */ public static List<int[]> getTilesAtHigherZoom( int origTx, int origTy, int origZoom, int higherZoom, int tileSize ) { Envelope boundsLL = tileBounds4326(origTx, origTy, origZoom); int delta = higherZoom - origZoom; int splits = (int) Math.pow(2, delta); double intervalX = boundsLL.getWidth() / splits; double intervalY = boundsLL.getHeight() / splits; List<int[]> tilesList = new ArrayList<>(); for( double y = boundsLL.getMaxY() - intervalY / 2.0; y > boundsLL.getMinY(); y = y - intervalY ) { for( double x = boundsLL.getMinX() + intervalX / 2.0; x < boundsLL.getMaxX(); x = x + intervalX ) { int[] tileNumber = getTileNumber(y, x, higherZoom); tilesList.add(tileNumber); } } return tilesList; }
Example 4
Source File: ASpatialDb.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Reproject an envelope. * * @param fromEnvelope the original envelope. * @param fromSrid the original srid. * @param toSrid the destination srid. * @return the reprojected Envelope. * @throws Exception */ public Envelope reproject( Envelope fromEnvelope, int fromSrid, int toSrid ) throws Exception { double w = fromEnvelope.getMinX(); double e = fromEnvelope.getMaxX(); double s = fromEnvelope.getMinY(); double n = fromEnvelope.getMaxY(); String sql = "select ST_Transform( ST_PointFromText('POINT( " + w + " " + s + ")', " + fromSrid + ") , " + toSrid + "), ST_Transform( ST_PointFromText('POINT( " + e + " " + n + ")', " + fromSrid + ") , " + toSrid + ")"; return execOnConnection(connection -> { IGeometryParser gp = getType().getGeometryParser(); try (IHMStatement stmt = connection.createStatement(); IHMResultSet rs = stmt.executeQuery(sql)) { if (rs.next()) { Geometry llPoint = gp.fromResultSet(rs, 1); Geometry urPoint = gp.fromResultSet(rs, 2); if (llPoint instanceof Point) { Point ll = (Point) llPoint; Point ur = (Point) urPoint; Envelope newEnv = new Envelope(ll.getX(), ur.getX(), ll.getY(), ur.getY()); return newEnv; } } return null; } }); }
Example 5
Source File: DatabaseLasDataManager.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
@Override public synchronized List<Geometry> getEnvelopesInGeometry( Geometry checkGeom, boolean doOnlyEnvelope, double[] minMaxZ ) throws Exception { checkOpen(); List<LasCell> lasCells = LasCellsTable.getLasCells(spatialDb, checkGeom, true, false, false, false, false); double minZ = Double.POSITIVE_INFINITY; double maxZ = Double.NEGATIVE_INFINITY; Envelope env = new Envelope(); for( LasCell lasCell : lasCells ) { minZ = Math.min(minZ, lasCell.minElev); maxZ = Math.max(maxZ, lasCell.maxElev); env.expandToInclude(lasCell.polygon.getEnvelopeInternal()); } ReferencedEnvelope3D dataEnvelope = new ReferencedEnvelope3D(env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY(), minZ, maxZ, crs); Polygon envelopePolygon = LasIndexer.envelopeToPolygon(dataEnvelope); ArrayList<Geometry> envelopeList = new ArrayList<Geometry>(); envelopeList.add(envelopePolygon); return envelopeList; }
Example 6
Source File: FeatureUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Create a {@link Polygon} from an {@link Envelope}. * * @param envelope the envelope to convert. * @return the created polygon. */ public static Polygon envelopeToPolygon( Envelope envelope ) { double w = envelope.getMinX(); double e = envelope.getMaxX(); double s = envelope.getMinY(); double n = envelope.getMaxY(); Coordinate[] coords = new Coordinate[5]; coords[0] = new Coordinate(w, n); coords[1] = new Coordinate(e, n); coords[2] = new Coordinate(e, s); coords[3] = new Coordinate(w, s); coords[4] = new Coordinate(w, n); GeometryFactory gf = GeometryUtilities.gf(); LinearRing linearRing = gf.createLinearRing(coords); Polygon polygon = gf.createPolygon(linearRing, null); return polygon; }
Example 7
Source File: SpatialiteCommonMethods.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
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 8
Source File: PagesRTreeIndex.java From presto with Apache License 2.0 | 5 votes |
private boolean testReferencePoint(Envelope probeEnvelope, OGCGeometry buildGeometry, int partition) { Envelope buildEnvelope = getEnvelope(buildGeometry); Envelope intersection = buildEnvelope.intersection(probeEnvelope); if (intersection.isNull()) { return false; } Rectangle extent = partitions.get(partition); double x = intersection.getMinX(); double y = intersection.getMinY(); return x >= extent.getXMin() && x < extent.getXMax() && y >= extent.getYMin() && y < extent.getYMax(); }
Example 9
Source File: MercatorUtils.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public static Envelope convert3857To4326( Envelope envelope3857 ) { Coordinate ll3857 = new Coordinate(envelope3857.getMinX(), envelope3857.getMinY()); Coordinate ur3857 = new Coordinate(envelope3857.getMaxX(), envelope3857.getMaxY()); Coordinate ll4326 = convert3857To4326(ll3857); Coordinate ur4326 = convert3857To4326(ur3857); Envelope env4326 = new Envelope(ll4326, ur4326); return env4326; }
Example 10
Source File: OmsRasterReader.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private void readGrass( File mapFile ) throws Exception { JGrassMapEnvironment mapEnvironment = new JGrassMapEnvironment(new File(file)); CoordinateReferenceSystem crs = mapEnvironment.getCoordinateReferenceSystem(); JGrassRegion readRegion = mapEnvironment.getFileRegion(); double n = readRegion.getNorth(); double s = readRegion.getSouth(); double w = readRegion.getWest(); double e = readRegion.getEast(); Envelope env = readRegion.getEnvelope(); originalEnvelope = new GeneralEnvelope( new ReferencedEnvelope(env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY(), crs)); // if bounds supplied, use them as region if (pBounds != null) { // n, s, w, e n = pBounds[0]; s = pBounds[1]; w = pBounds[2]; e = pBounds[3]; } if (pRes != null) { readRegion = new JGrassRegion(w, e, s, n, pRes[0], pRes[1]); } if (pRowcol != null) { readRegion = new JGrassRegion(w, e, s, n, pRowcol[0], pRowcol[1]); } if (!doEnvelope) { if (generalParameter == null) { generalParameter = createGridGeometryGeneralParameter(readRegion.getCols(), readRegion.getRows(), readRegion.getNorth(), readRegion.getSouth(), readRegion.getEast(), readRegion.getWest(), crs); } GrassCoverageFormat format = new GrassCoverageFormatFactory().createFormat(); GrassCoverageReader reader = format.getReader(mapEnvironment.getCELL()); outRaster = (GridCoverage2D) reader.read(generalParameter); checkNovalues(); } }
Example 11
Source File: DbsUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Create a polygon using an envelope. * * @param env the envelope to use. * @return the created geomerty. */ public static Polygon createPolygonFromEnvelope( Envelope env ) { double minX = env.getMinX(); double minY = env.getMinY(); double maxY = env.getMaxY(); double maxX = env.getMaxX(); Coordinate[] c = new Coordinate[]{new Coordinate(minX, minY), new Coordinate(minX, maxY), new Coordinate(maxX, maxY), new Coordinate(maxX, minY), new Coordinate(minX, minY)}; return gf().createPolygon(c); }
Example 12
Source File: GeometryUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public static Polygon createPolygonFromEnvelope( Envelope env ) { double minX = env.getMinX(); double minY = env.getMinY(); double maxY = env.getMaxY(); double maxX = env.getMaxX(); Coordinate[] c = new Coordinate[]{new Coordinate(minX, minY), new Coordinate(minX, maxY), new Coordinate(maxX, maxY), new Coordinate(maxX, minY), new Coordinate(minX, minY)}; return gf().createPolygon(c); }
Example 13
Source File: TestSpatialDbsMain.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
@Test public void testReprojectFromDb() throws Exception { double w = 11.143413001499738; double e = 11.147502220729288; double s = 46.62897848892326; double n = 46.62981208577648; Envelope env = new Envelope(w, e, s, n); Envelope reprojected = db.reproject(env, 4326, 32632); double rw = reprojected.getMinX(); double re = reprojected.getMaxX(); double rs = reprojected.getMinY(); double rn = reprojected.getMaxY(); assertEquals(664076.6777860201, rw, 0.001); assertEquals(664387.1714802807, re, 0.001); assertEquals(5166166.626361137, rs, 0.001); assertEquals(5166267.775614383, rn, 0.001); WKTReader reader = new WKTReader(); Geometry point = reader.read("POINT (11.143413001499738 46.62897848892326)"); Geometry reprojectedGeom = db.reproject(point, 4326, 32632); Geometry expected = reader.read("POINT (664076.6777860201 5166166.626361137)"); double distance = reprojectedGeom.distance(expected); assertEquals(0.0, distance, 0.00001); }
Example 14
Source File: TransformationUtils.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Given a transformation, transform an envelope by it. * * @param transformation the AffineTransformation to use. * @param env the envelope to transform. * @return the transformed envelope. */ public static Envelope transformEnvelope( AffineTransformation transformation, Envelope env ) { Coordinate llFromPoint = new Coordinate(env.getMinX(), env.getMinY()); Coordinate urFromPoint = new Coordinate(env.getMaxX(), env.getMaxY()); Coordinate ll = new Coordinate(); Coordinate ur = new Coordinate(); transformation.transform(llFromPoint, ll); transformation.transform(urFromPoint, ur); return new Envelope(ll.getX(), ur.getX(), ll.getY(), ur.getY()); }
Example 15
Source File: GeopackageTableLayer.java From geopaparazzi with GNU General Public License v3.0 | 5 votes |
private void updateGeometry(ASpatialDb db, String tableName, long id, Geometry geometry) throws Exception { int epsg = 4326; String pk = ((GPGeopackageDb) db).getPrimaryKey(tableName); IGeometryParser gp = db.getType().getGeometryParser(); geometry.setSRID(epsg); Object obj = gp.toSqlObject(geometry); if (obj instanceof byte[]) { byte[] objBytes = (byte[]) obj; GeometryColumn gc = db.getGeometryColumnsForTable(tableName); String sql = "update " + tableName + " set " + gc.geometryColumnName + "=? where " + pk + "=" + id; db.execOnConnection(connection -> { try (IHMPreparedStatement pStmt = connection.prepareStatement(sql)) { pStmt.setBytes(1, objBytes); pStmt.executeUpdate(); } return null; }); Envelope env = geometry.getEnvelopeInternal(); double minX = env.getMinX(); double maxX = env.getMaxX(); double minY = env.getMinY(); double maxY = env.getMaxY(); try { // also update rtree index, since it is not supported String sqlTree = "INSERT OR REPLACE INTO rtree_" + tableName + "_" + gc.geometryColumnName + " VALUES (" + id + "," + minX + ", " + maxX + "," + minY + ", " + maxY + ");"; db.executeInsertUpdateDeleteSql(sqlTree); } catch (Exception e) { GPLog.error(this, "ERROR on rtree", e); } } else { throw new IllegalArgumentException("Geometry object is not byte array."); } }
Example 16
Source File: TransformationUtils.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Scale an envelope to have a given width. * * @param original the envelope. * @param newWidth the new width to use. * @return the scaled envelope placed in the original lower left corner position. */ public static Envelope scaleToWidth( Envelope original, double newWidth ) { double width = original.getWidth(); double factor = newWidth / width; double newHeight = original.getHeight() * factor; return new Envelope(original.getMinX(), original.getMinX() + newWidth, original.getMinY(), original.getMinY() + newHeight); }
Example 17
Source File: TransformationUtils.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Get the affine transform that brings from the world envelope to the rectangle. * * @param worldEnvelope the envelope. * @param pixelRectangle the destination rectangle. * @return the transform. */ public static AffineTransformation getWorldToRectangle( Envelope worldEnvelope, Rectangle pixelRectangle ) { int cols = (int) pixelRectangle.getWidth(); int rows = (int) pixelRectangle.getHeight(); double worldWidth = worldEnvelope.getWidth(); double worldHeight = worldEnvelope.getHeight(); double x = -worldEnvelope.getMinX(); double y = -worldEnvelope.getMinY(); AffineTransformation translate = AffineTransformation.translationInstance(x, y); double xScale = cols / worldWidth; double yScale = rows / worldHeight; AffineTransformation scale = AffineTransformation.scaleInstance(xScale, yScale); int m00 = 1; int m10 = 0; int m01 = 0; int m11 = -1; int m02 = 0; int m12 = rows; AffineTransformation mirror_y = new AffineTransformation(m00, m01, m02, m10, m11, m12); AffineTransformation world2pixel = new AffineTransformation(translate); world2pixel.compose(scale); world2pixel.compose(mirror_y); return world2pixel; }
Example 18
Source File: LasCellsTable.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
/** * Query the las cell table. * * @param db the db to use. * @param envelope an optional {@link Envelope} to query spatially. * @param exactGeometry an optional exact geometry. If available it is used instead of the envelope. * @param doPosition if <code>true</code> position info is extracted. * @param doIntensity if <code>true</code> intensity and classification info is extracted. * @param doReturns if <code>true</code> return info is extracted. * @param doTime if <code>true</code> time info is extracted. * @param doColor if <code>true</code> color info is extracted. * @param limitTo limit the cells to a value if != -1 * @return the list of extracted points * @throws Exception */ public static List<LasCell> getLasCells( ASpatialDb db, Envelope envelope, Geometry exactGeometry, boolean doPosition, boolean doIntensity, boolean doReturns, boolean doTime, boolean doColor, int limitTo ) throws Exception { List<LasCell> lasCells = new ArrayList<>(); String sql = "SELECT " + COLUMN_GEOM + "," + COLUMN_ID + "," + COLUMN_SOURCE_ID + "," + COLUMN_POINTS_COUNT; if (doPosition) sql += "," + COLUMN_AVG_ELEV + "," + // COLUMN_MIN_ELEV + "," + // COLUMN_MAX_ELEV + "," + // COLUMN_POSITION_BLOB;// if (doIntensity) sql += "," + COLUMN_AVG_INTENSITY + "," + // COLUMN_MIN_INTENSITY + "," + // COLUMN_MAX_INTENSITY + "," + // COLUMN_INTENS_CLASS_BLOB;// if (doReturns) sql += "," + COLUMN_RETURNS_BLOB; if (doTime) sql += "," + COLUMN_MIN_GPSTIME + "," + // COLUMN_MAX_GPSTIME + "," + // COLUMN_GPSTIME_BLOB; if (doColor) sql += "," + COLUMN_COLORS_BLOB; sql += " FROM " + TABLENAME; if (exactGeometry != null) { sql += " WHERE " + db.getSpatialindexGeometryWherePiece(TABLENAME, null, exactGeometry); } else if (envelope != null) { double x1 = envelope.getMinX(); double y1 = envelope.getMinY(); double x2 = envelope.getMaxX(); double y2 = envelope.getMaxY(); sql += " WHERE " + db.getSpatialindexBBoxWherePiece(TABLENAME, null, x1, y1, x2, y2); } if (limitTo > 0) { sql += " LIMIT " + limitTo; } String _sql = sql; IGeometryParser gp = db.getType().getGeometryParser(); return db.execOnConnection(conn -> { try (IHMStatement stmt = conn.createStatement(); IHMResultSet rs = stmt.executeQuery(_sql)) { while( rs.next() ) { LasCell lasCell = resultSetToCell(db, gp, doPosition, doIntensity, doReturns, doTime, doColor, rs); lasCells.add(lasCell); } return lasCells; } }); }
Example 19
Source File: LasLevelsTable.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
/** * Query the las level table. * * @param db the db to use. * @param levelNum the level to query. * @param envelope an optional {@link Envelope} to query spatially. * @return the list of extracted level cells. * @throws Exception */ public static List<LasLevel> getLasLevels( ASpatialDb db, int levelNum, Envelope envelope ) throws Exception { String tableName = TABLENAME + levelNum; List<LasLevel> lasLevels = new ArrayList<>(); String sql = "SELECT " + COLUMN_GEOM + "," + // COLUMN_ID + "," + COLUMN_SOURCE_ID + "," + COLUMN_AVG_ELEV + "," + // COLUMN_MIN_ELEV + "," + // COLUMN_MAX_ELEV + "," + // COLUMN_AVG_INTENSITY + "," + // COLUMN_MIN_INTENSITY + "," + // COLUMN_MAX_INTENSITY; sql += " FROM " + tableName; if (envelope != null) { double x1 = envelope.getMinX(); double y1 = envelope.getMinY(); double x2 = envelope.getMaxX(); double y2 = envelope.getMaxY(); sql += " WHERE " + db.getSpatialindexBBoxWherePiece(tableName, null, x1, y1, x2, y2); } String _sql = sql; IGeometryParser gp = db.getType().getGeometryParser(); return db.execOnConnection(conn -> { try (IHMStatement stmt = conn.createStatement(); IHMResultSet rs = stmt.executeQuery(_sql)) { while( rs.next() ) { LasLevel lasLevel = new LasLevel(); lasLevel.level = levelNum; int i = 1; Geometry geometry = gp.fromResultSet(rs, i++); if (geometry instanceof Polygon) { Polygon polygon = (Polygon) geometry; lasLevel.polygon = polygon; lasLevel.id = rs.getLong(i++); lasLevel.sourceId = rs.getLong(i++); lasLevel.avgElev = rs.getDouble(i++); lasLevel.minElev = rs.getDouble(i++); lasLevel.maxElev = rs.getDouble(i++); lasLevel.avgIntensity = rs.getShort(i++); lasLevel.minIntensity = rs.getShort(i++); lasLevel.maxIntensity = rs.getShort(i++); lasLevels.add(lasLevel); } } return lasLevels; } }); }
Example 20
Source File: ASpatialDb.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
/** * Get the geometries of a table inside a given envelope. * * @param tableName * the table name. * @param envelope * the envelope to check. * @param prePostWhere an optional set of 3 parameters. The parameters are: a * prefix wrapper for geom, a postfix for the same and a where string * to apply. They all need to be existing if the parameter is passed. * @return The list of geometries intersecting the envelope. * @throws Exception */ public List<Geometry> getGeometriesIn( String tableName, Envelope envelope, String... prePostWhere ) throws Exception { List<String> wheres = new ArrayList<>(); String pre = ""; String post = ""; String where = ""; if (prePostWhere != null && prePostWhere.length == 3) { if (prePostWhere[0] != null) pre = prePostWhere[0]; if (prePostWhere[1] != null) post = prePostWhere[1]; if (prePostWhere[2] != null) { where = prePostWhere[2]; wheres.add(where); } } GeometryColumn gCol = getGeometryColumnsForTable(tableName); String sql = "SELECT " + pre + gCol.geometryColumnName + post + " FROM " + DbsUtilities.fixTableName(tableName); if (envelope != null && supportsSpatialIndex) { double x1 = envelope.getMinX(); double y1 = envelope.getMinY(); double x2 = envelope.getMaxX(); double y2 = envelope.getMaxY(); String spatialindexBBoxWherePiece = getSpatialindexBBoxWherePiece(tableName, null, x1, y1, x2, y2); if (spatialindexBBoxWherePiece != null) wheres.add(spatialindexBBoxWherePiece); } if (wheres.size() > 0) { sql += " WHERE " + DbsUtilities.joinBySeparator(wheres, " AND "); } String _sql = sql; IGeometryParser geometryParser = getType().getGeometryParser(); return execOnConnection(connection -> { List<Geometry> geoms = new ArrayList<Geometry>(); try (IHMStatement stmt = connection.createStatement(); IHMResultSet rs = stmt.executeQuery(_sql)) { while( rs.next() ) { Geometry geometry = geometryParser.fromResultSet(rs, 1); if (!supportsSpatialIndex && envelope != null) { // need to check manually if (!geometry.getEnvelopeInternal().intersects(envelope)) { continue; } } geoms.add(geometry); } } return geoms; }); }