Java Code Examples for org.locationtech.jts.geom.Envelope#getMinY()
The following examples show how to use
org.locationtech.jts.geom.Envelope#getMinY() .
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: 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 2
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 3
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 4
Source File: GridH2SpatialIndex.java From ignite with Apache License 2.0 | 5 votes |
/** * @param row Row. * @param rowId Row id. * @return Envelope. */ private SpatialKey getEnvelope(SearchRow row, long rowId) { Value v = row.getValue(columnIds[0]); Geometry g = ((ValueGeometry) v.convertTo(Value.GEOMETRY)).getGeometry(); Envelope env = g.getEnvelopeInternal(); return new SpatialKey(rowId, (float) env.getMinX(), (float) env.getMaxX(), (float) env.getMinY(), (float) env.getMaxY()); }
Example 5
Source File: MercatorUtils.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public static Envelope convert4326To3857( Envelope envelope4326 ) { Coordinate ll4326 = new Coordinate(envelope4326.getMinX(), envelope4326.getMinY()); Coordinate ur4326 = new Coordinate(envelope4326.getMaxX(), envelope4326.getMaxY()); Coordinate ll3857 = convert4326To3857(ll4326); Coordinate ur3857 = convert4326To3857(ur4326); Envelope env3857 = new Envelope(ll3857, ur3857); return env3857; }
Example 6
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 7
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 8
Source File: GeometryUtils.java From geowave with Apache License 2.0 | 5 votes |
/** * Generate a latitude range from a JTS geometry * * @param geometry The JTS geometry * @return The y range */ public static NumericData yRangeFromGeometry(final Geometry geometry) { if ((geometry == null) || geometry.isEmpty()) { return new NumericRange(0, 0); } // Get the envelope of the geometry being held final Envelope env = geometry.getEnvelopeInternal(); // Create a NumericRange object using the y axis return new NumericRange(env.getMinY(), env.getMaxY()); }
Example 9
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 10
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 11
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 12
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 AffineTransform to use. * @param env the envelope to transform. * @return the transformed envelope. */ public static Envelope transformEnvelope( AffineTransform transformation, Envelope env ) { Point2D llFromPoint = new Point2D.Double(env.getMinX(), env.getMinY()); Point2D urFromPoint = new Point2D.Double(env.getMaxX(), env.getMaxY()); Point2D ll = new Point2D.Double(); Point2D ur = new Point2D.Double(); transformation.transform(llFromPoint, ll); transformation.transform(urFromPoint, ur); return new Envelope(ll.getX(), ur.getX(), ll.getY(), ur.getY()); }
Example 13
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 14
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 15
Source File: GeometryWrapper.java From geowave with Apache License 2.0 | 5 votes |
/** Expects Longitude before Latitude */ @Override public boolean overlaps(final NumericDimensionField[] fields, final NumericData[] rangeData) { final int latPosition = fields[0] instanceof LatitudeField ? 0 : 1; final int longPosition = fields[0] instanceof LatitudeField ? 1 : 0; if (fields.length == 1) { final Envelope env = geometry.getEnvelopeInternal(); final NumericRange r = latPosition == 0 ? new NumericRange(env.getMinY(), env.getMaxY()) : new NumericRange(env.getMinX(), env.getMaxX()); return ((rangeData[0].getMin() < r.getMax()) || DoubleMath.fuzzyEquals(rangeData[0].getMin(), r.getMax(), DOUBLE_TOLERANCE)) && ((rangeData[0].getMax() > r.getMin()) || DoubleMath.fuzzyEquals(rangeData[0].getMax(), r.getMin(), DOUBLE_TOLERANCE)); } return geometry.getFactory().createPolygon( new Coordinate[] { new Coordinate( rangeData[longPosition].getMin() - DOUBLE_TOLERANCE, rangeData[latPosition].getMin() - DOUBLE_TOLERANCE), new Coordinate( rangeData[longPosition].getMin() - DOUBLE_TOLERANCE, rangeData[latPosition].getMax() + DOUBLE_TOLERANCE), new Coordinate( rangeData[longPosition].getMax() + DOUBLE_TOLERANCE, rangeData[latPosition].getMax() + DOUBLE_TOLERANCE), new Coordinate( rangeData[longPosition].getMax() + DOUBLE_TOLERANCE, rangeData[latPosition].getMin() - DOUBLE_TOLERANCE), new Coordinate( rangeData[longPosition].getMin() - DOUBLE_TOLERANCE, rangeData[latPosition].getMin() - DOUBLE_TOLERANCE)}).intersects(geometry); }
Example 16
Source File: KMeansUtils.java From geowave with Apache License 2.0 | 4 votes |
public static ScaledTemporalRange setRunnerTimeParams( final KMeansRunner runner, final DataStorePluginOptions inputDataStore, String typeName) { if (typeName == null) { // if no id provided, locate a single // featureadapter final List<String> typeNameList = FeatureDataUtils.getFeatureTypeNames(inputDataStore); if (typeNameList.size() == 1) { typeName = typeNameList.get(0); } else if (typeNameList.isEmpty()) { LOGGER.error("No feature adapters found for use with time param"); return null; } else { LOGGER.error( "Multiple feature adapters found for use with time param. Please specify one."); return null; } } final ScaledTemporalRange scaledRange = new ScaledTemporalRange(); final String timeField = FeatureDataUtils.getTimeField(inputDataStore, typeName); if (timeField != null) { final TemporalRange timeRange = DateUtilities.getTemporalRange(inputDataStore, typeName, timeField); if (timeRange != null) { scaledRange.setTimeRange(timeRange.getStartTime(), timeRange.getEndTime()); } final String geomField = FeatureDataUtils.getGeomField(inputDataStore, typeName); final Envelope bbox = org.locationtech.geowave.adapter.vector.util.FeatureGeometryUtils.getGeoBounds( inputDataStore, typeName, geomField); if (bbox != null) { final double xRange = bbox.getMaxX() - bbox.getMinX(); final double yRange = bbox.getMaxY() - bbox.getMinY(); final double valueRange = Math.min(xRange, yRange); scaledRange.setValueRange(0.0, valueRange); } runner.setTimeParams(timeField, scaledRange); return scaledRange; } LOGGER.error("Couldn't determine field to use for time param"); return null; }
Example 17
Source File: GeopackageTableLayer.java From geopaparazzi with GNU General Public License v3.0 | 4 votes |
private long insertGeometry(ASpatialDb db, String tableName, Geometry geometry) throws Exception { int epsg = 4326; String pk = ((GPGeopackageDb) db).getPrimaryKey(tableName); long nextId = db.getLong("select max(" + pk + ") from " + tableName) + 1; 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 = "INSERT INTO " + tableName + " (" + pk + "," + gc.geometryColumnName + ") VALUES (?, ?)"; db.execOnConnection(connection -> { try (IHMPreparedStatement pStmt = connection.prepareStatement(sql)) { pStmt.setLong(1, nextId); pStmt.setBytes(2, 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 (" + nextId + "," + minX + ", " + maxX + "," + minY + ", " + maxY + ");"; db.executeInsertUpdateDeleteSql(sqlTree); } catch (Exception e) { GPLog.error(this, "ERROR on rtree", e); } return nextId; } throw new IllegalArgumentException("Geometry object is not byte array."); }
Example 18
Source File: GeometryUtils.java From geowave with Apache License 2.0 | 4 votes |
public static MultiDimensionalNumericData getBoundsFromEnvelope(final Envelope envelope) { final NumericRange[] boundsPerDimension = new NumericRange[2]; boundsPerDimension[0] = new NumericRange(envelope.getMinX(), envelope.getMaxX()); boundsPerDimension[1] = new NumericRange(envelope.getMinY(), envelope.getMaxY()); return new BasicNumericDataset(boundsPerDimension); }
Example 19
Source File: JGTProcessingRegion.java From hortonmachine with GNU General Public License v3.0 | 3 votes |
/** * Reprojects a {@link JGTProcessingRegion region}. * * @param sourceCRS * the original {@link CoordinateReferenceSystem crs} of the * region. * @param targetCRS * the target {@link CoordinateReferenceSystem crs} of the * region. * @param lenient * defines whether to apply a lenient transformation or not. * @return a new {@link JGTProcessingRegion region}. * @throws Exception * exception that may be thrown when applying the * transformation. */ public JGTProcessingRegion reproject( CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient ) throws Exception { MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, lenient); Envelope envelope = getEnvelope(); Envelope targetEnvelope = JTS.transform(envelope, transform); return new JGTProcessingRegion(targetEnvelope.getMinX(), targetEnvelope.getMaxX(), targetEnvelope.getMinY(), targetEnvelope.getMaxY(), getRows(), getCols()); }
Example 20
Source File: RegionMap.java From hortonmachine with GNU General Public License v3.0 | 3 votes |
/** * Creates a new {@link RegionMap} cropped on the new bounds and snapped on the original grid. * * <p><b>The supplied bounds are contained in the resulting region.</b></p> * * @param envelope the envelope to snap. * @return the new {@link RegionMap}. */ public RegionMap toSubRegion( Envelope envelope ) { double w = envelope.getMinX(); double s = envelope.getMinY(); double e = envelope.getMaxX(); double n = envelope.getMaxY(); return toSubRegion(n, s, w, e); }