Java Code Examples for org.locationtech.jts.geom.Envelope#getMaxX()

The following examples show how to use org.locationtech.jts.geom.Envelope#getMaxX() . 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: GeometryUtils.java    From geowave with Apache License 2.0 6 votes vote down vote up
/**
 * This utility method will convert a JTS envelope to contraints that can be used in a GeoWave
 * query.
 *
 * @return Constraints as a mapping of NumericData objects representing ranges for a latitude
 *         dimension and a longitude dimension
 */
public static ConstraintSet basicConstraintSetFromEnvelope(final Envelope env) {
  // Create a NumericRange object using the x axis
  final NumericRange rangeLongitude = new NumericRange(env.getMinX(), env.getMaxX());

  // Create a NumericRange object using the y axis
  final NumericRange rangeLatitude = new NumericRange(env.getMinY(), env.getMaxY());

  final Map<Class<? extends NumericDimensionDefinition>, ConstraintData> constraintsPerDimension =
      new HashMap<>();
  // Create and return a new IndexRange array with an x and y axis
  // range

  final ConstraintData xRange = new ConstraintData(rangeLongitude, false);
  final ConstraintData yRange = new ConstraintData(rangeLatitude, false);
  constraintsPerDimension.put(CustomCRSUnboundedSpatialDimensionX.class, xRange);
  constraintsPerDimension.put(CustomCRSUnboundedSpatialDimensionY.class, yRange);
  constraintsPerDimension.put(CustomCRSBoundedSpatialDimensionX.class, xRange);
  constraintsPerDimension.put(CustomCRSBoundedSpatialDimensionY.class, yRange);
  constraintsPerDimension.put(LongitudeDefinition.class, xRange);
  constraintsPerDimension.put(LatitudeDefinition.class, yRange);

  return new ConstraintSet(constraintsPerDimension);
}
 
Example 2
Source File: MercatorUtils.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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: ASpatialDb.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 4
Source File: RL2NwwLayer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public RL2NwwLayer( Rasterlite2Coverage rasterCoverage, Integer tileSize ) throws Exception {
    super(makeLevels(rasterCoverage, tileSize));
    this.layerName = rasterCoverage.getName();

    Envelope bounds = rasterCoverage.getBounds();
    double w = bounds.getMinX();
    double s = bounds.getMinY();
    double e = bounds.getMaxX();
    double n = bounds.getMaxY();

    double centerX = w + (e - w) / 2.0;
    double centerY = s + (n - s) / 2.0;
    Coordinate centerCoordinate = new Coordinate(centerX, centerY);

    CoordinateReferenceSystem targetCRS = DefaultGeographicCRS.WGS84;
    CoordinateReferenceSystem sourceCRS = CrsUtilities.getCrsFromSrid(rasterCoverage.getSrid());

    MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
    centerCoordinateLL = JTS.transform(centerCoordinate, null, transform);

    this.setUseTransparentTextures(true);

}
 
Example 5
Source File: DatabaseLasDataManager.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
@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: 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 7
Source File: GridH2SpatialIndex.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @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 8
Source File: MercatorUtils.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns bounds of the given tile in EPSG:3857 coordinates
 *
 * @param tx       tile x.
 * @param ty       tile y.
 * @param zoom     zoomlevel.
 * @return the Envelope.
 */
public static Envelope tileBounds3857( final int x, final int y, final int zoom ) {
    Envelope env4326 = tileBounds4326(x, y, zoom);
    Coordinate ll4326 = new Coordinate(env4326.getMinX(), env4326.getMinY());
    Coordinate ur4326 = new Coordinate(env4326.getMaxX(), env4326.getMaxY());

    Coordinate ll3857transf = MercatorUtils.convert4326To3857(ll4326);
    Coordinate ur3857transf = MercatorUtils.convert4326To3857(ur4326);

    return new Envelope(ll3857transf, ur3857transf);
}
 
Example 9
Source File: MercatorUtils.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
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 vote down vote up
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: GeometryUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
/**
 * Generate a longitude range from a JTS geometry
 *
 * @param geometry The JTS geometry
 * @return The x range
 */
public static NumericData xRangeFromGeometry(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 x axis
  return new NumericRange(env.getMinX(), env.getMaxX());
}
 
Example 12
Source File: TransformationUtils.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 13
Source File: TransformationUtils.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 14
Source File: LasLevelsTable.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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 15
Source File: LasCellsTable.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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 16
Source File: ASpatialDb.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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;
    });
}
 
Example 17
Source File: GeometryUtils.java    From geowave with Apache License 2.0 4 votes vote down vote up
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 18
Source File: KMeansUtils.java    From geowave with Apache License 2.0 4 votes vote down vote up
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 19
Source File: JGTProcessingRegion.java    From hortonmachine with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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 vote down vote up
/**
 * 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);
}