Java Code Examples for org.geotools.referencing.crs.DefaultGeographicCRS#WGS84

The following examples show how to use org.geotools.referencing.crs.DefaultGeographicCRS#WGS84 . 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: MBTilesHelper.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Read the image of a tile from a generic geotools coverage reader.
 * 
 * @param reader the reader, expected to be in CRS 3857.
 * @param x the tile x.
 * @param y the tile y.
 * @param zoom the zoomlevel.
 * @return the image.
 * @throws IOException 
 */
public static BufferedImage readGridcoverageImageForTile( AbstractGridCoverage2DReader reader, int x, int y, int zoom,
        CoordinateReferenceSystem resampleCrs ) throws IOException {
    double north = tile2lat(y, zoom);
    double south = tile2lat(y + 1, zoom);
    double west = tile2lon(x, zoom);
    double east = tile2lon(x + 1, zoom);

    Coordinate ll = new Coordinate(west, south);
    Coordinate ur = new Coordinate(east, north);

    try {
        CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84;

        MathTransform transform = CRS.findMathTransform(sourceCRS, resampleCrs);
        ll = JTS.transform(ll, null, transform);
        ur = JTS.transform(ur, null, transform);
    } catch (Exception e) {
        e.printStackTrace();
    }

    BufferedImage image = ImageUtilities.imageFromReader(reader, TILESIZE, TILESIZE, ll.x, ur.x, ll.y, ur.y, resampleCrs);
    return image;
}
 
Example 2
Source File: DaoImages.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get the current data envelope.
 * 
 * @param connection the db connection.
 * @return the envelope.
 * @throws Exception
 */
public static ReferencedEnvelope getEnvelope( IHMConnection connection ) throws Exception {
    String query = "SELECT min(" + //
            ImageTableFields.COLUMN_LON.getFieldName() + "), max(" + //
            ImageTableFields.COLUMN_LON.getFieldName() + "), min(" + //
            ImageTableFields.COLUMN_LAT.getFieldName() + "), max(" + //
            ImageTableFields.COLUMN_LAT.getFieldName() + ") " + //
            " FROM " + TABLE_IMAGES;
    try (IHMStatement statement = connection.createStatement(); IHMResultSet rs = statement.executeQuery(query);) {
        if (rs.next()) {
            double minX = rs.getDouble(1);
            double maxX = rs.getDouble(2);
            double minY = rs.getDouble(3);
            double maxY = rs.getDouble(4);

            ReferencedEnvelope env = new ReferencedEnvelope(minX, maxX, minY, maxY, DefaultGeographicCRS.WGS84);
            return env;
        }
    }

    return null;
}
 
Example 3
Source File: DaoGpsLog.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get the current data envelope.
 * 
 * @param connection the db connection.
 * @return the envelope.
 * @throws Exception
 */
public static ReferencedEnvelope getEnvelope( IHMConnection connection ) throws Exception {
    String query = "SELECT min(" + //
            GpsLogsDataTableFields.COLUMN_DATA_LON.getFieldName() + "), max(" + //
            GpsLogsDataTableFields.COLUMN_DATA_LON.getFieldName() + "), min(" + //
            GpsLogsDataTableFields.COLUMN_DATA_LAT.getFieldName() + "), max(" + //
            GpsLogsDataTableFields.COLUMN_DATA_LAT.getFieldName() + ") " + //
            " FROM " + TABLE_GPSLOG_DATA;
    try (IHMStatement statement = connection.createStatement(); IHMResultSet rs = statement.executeQuery(query);) {
        if (rs.next()) {
            double minX = rs.getDouble(1);
            double maxX = rs.getDouble(2);
            double minY = rs.getDouble(3);
            double maxY = rs.getDouble(4);

            ReferencedEnvelope env = new ReferencedEnvelope(minX, maxX, minY, maxY, DefaultGeographicCRS.WGS84);
            return env;
        }
    }

    return null;
}
 
Example 4
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testTouches() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    ReferencedEnvelope bbox =
            new ReferencedEnvelope(-1.0, 1.0, -1.9, 1.0, DefaultGeographicCRS.WGS84);
    Filter filter = ff2.touches(ff.property("the_geom"), ff.literal(bbox));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 5
Source File: GeoHashGridProcessTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testScaled() {
    ReferencedEnvelope envelope = new ReferencedEnvelope(-180,180,-90,90,DefaultGeographicCRS.WGS84);
    int width = 16;
    int height = 8;
    int pixelsPerCell = 1;
    String strategy = "Basic";
    Float scaleMin = 0f;

    GridCoverage2D coverage = process.execute(features, pixelsPerCell, strategy, null, null, scaleMin, null, false, envelope, width, height, null);
    checkInternal(coverage, fineDelta);
    checkEdge(coverage, envelope, fineDelta);
}
 
Example 6
Source File: GeoHashGridProcessTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBasic() {
    ReferencedEnvelope envelope = new ReferencedEnvelope(-180,180,-90,90,DefaultGeographicCRS.WGS84);
    int width = 8;
    int height = 4;
    int pixelsPerCell = 1;
    String strategy = "Basic";
    Float scaleMin = 0f;

    GridCoverage2D coverage = process.execute(features, pixelsPerCell, strategy, null, null, scaleMin, null, false, envelope, width, height, null);
    checkInternal(coverage, fineDelta);
    checkEdge(coverage, envelope, fineDelta);
}
 
Example 7
Source File: DaoNotes.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the current data envelope.
 * 
 * @param connection the db connection.
 * @param noteTypeName if <code>null</code>, simple notes are handled. Else this 
 *          is taken as name for the note type.
 * @return the envelope.
 * @throws Exception
 */
public static ReferencedEnvelope getEnvelope( IHMConnection connection, String noteTypeName ) throws Exception {
    String query = "SELECT min(" + //
            NotesTableFields.COLUMN_LON.getFieldName() + "), max(" + //
            NotesTableFields.COLUMN_LON.getFieldName() + "), min(" + //
            NotesTableFields.COLUMN_LAT.getFieldName() + "), max(" + //
            NotesTableFields.COLUMN_LAT.getFieldName() + ") " + //
            " FROM " + TABLE_NOTES;

    if (noteTypeName != null) {
        query += " where " + NotesTableFields.COLUMN_TEXT.getFieldName() + "='" + noteTypeName + "'";
    } else {
        String formFN = NotesTableFields.COLUMN_FORM.getFieldName();
        query += " where " + formFN + " is null OR " + formFN + "=''";
    }

    try (IHMStatement statement = connection.createStatement(); IHMResultSet rs = statement.executeQuery(query);) {
        if (rs.next()) {
            double minX = rs.getDouble(1);
            double maxX = rs.getDouble(2);
            double minY = rs.getDouble(3);
            double maxY = rs.getDouble(4);

            ReferencedEnvelope env = new ReferencedEnvelope(minX, maxX, minY, maxY, DefaultGeographicCRS.WGS84);
            return env;
        }
    } catch (Exception e) {
        // print trace but return null
        e.printStackTrace();
    }

    return null;
}
 
Example 8
Source File: FeatureFigureEditorApp.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private SimpleFeatureType createSimpleFeatureType(String typeName, Class<?> geometryType, SimpleFeatureType defaults) {
    SimpleFeatureTypeBuilder sftb = new SimpleFeatureTypeBuilder();
    if (defaults != null) {
        //sftb.init(defaults);
    }
    DefaultGeographicCRS crs = DefaultGeographicCRS.WGS84;
    sftb.setCRS(crs);
    sftb.setName(typeName);
    sftb.add("geom", geometryType);
    sftb.add("style", String.class);
    sftb.setDefaultGeometry("geom");
    return sftb.buildFeatureType();
}
 
Example 9
Source File: CrsUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts meters to degrees, based on a given coordinate in 90 degrees direction.
 * 
 * @param meters the meters to convert.
 * @param c the position to consider.
 * @return the converted degrees.
 */
public static double getMetersAsWGS84( double meters, Coordinate c ) {
    GeodeticCalculator gc = new GeodeticCalculator(DefaultGeographicCRS.WGS84);
    gc.setStartingGeographicPoint(c.x, c.y);
    gc.setDirection(90, meters);
    Point2D destinationGeographicPoint = gc.getDestinationGeographicPoint();
    double degrees = Math.abs(destinationGeographicPoint.getX() - c.x);
    return degrees;
}
 
Example 10
Source File: AbstractImportVectorDataNodeAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private CoordinateReferenceSystem promptForFeatureCrs(Product product) {
    final FeatureCrsDialog dialog = new FeatureCrsDialog(product, "Import " + getVectorDataType() + " Data");

    featureCrsDialogResult = dialog.show();
    if (featureCrsDialogResult == ModalDialog.ID_OK) {
        return dialog.getFeatureCrs();
    }

    return DefaultGeographicCRS.WGS84;
}
 
Example 11
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBeyond() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    ReferencedEnvelope bbox =
            new ReferencedEnvelope(-1.0, 1.0, -1.9, 1.0, DefaultGeographicCRS.WGS84);
    Filter filter = ff2.beyond(ff.property("the_geom"), ff.literal(bbox), 10.0, "km");
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 12
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDWithin() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    ReferencedEnvelope bbox =
            new ReferencedEnvelope(-1.0, 1.0, -1.9, 1.0, DefaultGeographicCRS.WGS84);
    Filter filter = ff2.dwithin(ff.property("the_geom"), ff.literal(bbox), 10.0, "km");
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 13
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDisjoint() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    ReferencedEnvelope bbox =
            new ReferencedEnvelope(-1.0, 1.0, -1.9, 1.0, DefaultGeographicCRS.WGS84);
    Filter filter = ff2.disjoint(ff.property("the_geom"), ff.literal(bbox));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 14
Source File: GeoHashGridProcessTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testInvertQuery() {
    Filter filter = ff.bbox("geom", 0, 0, 0, 0, "EPSG:4326");
    ReferencedEnvelope env = new ReferencedEnvelope(0,1,2,3,DefaultGeographicCRS.WGS84);
    Query query = new Query();
    query.setFilter(filter);
    Query queryOut = process.invertQuery(env, query, null);
    assertEquals(ff.bbox("geom", 0, 2, 1, 3, "EPSG:4326"), queryOut.getFilter());
}
 
Example 15
Source File: PinPositionTest.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setup() throws TransformException, FactoryException {
    final AffineTransform i2m = new AffineTransform();
    i2m.scale(2.0, 2.0);
    final GeoCoding geoCoding = new CrsGeoCoding(DefaultGeographicCRS.WGS84, new Rectangle(0, 0, 10, 10), i2m);

    final Product product = new Product("P", "T", 10, 10);
    product.setSceneGeoCoding(geoCoding);

    placemark = Placemark.createPointPlacemark(PinDescriptor.getInstance(), "P1", "L", "", new PixelPos(1.0f, 1.0f), null, product.getSceneGeoCoding());
    product.getPinGroup().add(placemark);
}
 
Example 16
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBBox() {
    TestFilterPanelv2Dialog testPanel = new TestFilterPanelv2Dialog(null);
    testPanel.configure("test", String.class, false);

    ReferencedEnvelope bbox =
            new ReferencedEnvelope(-1.0, 1.0, -1.9, 1.0, DefaultGeographicCRS.WGS84);
    Filter filter = ff2.bbox(ff.property("the_geom"), bbox);
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example 17
Source File: SingletonResultSet.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public CoordinateReferenceSystem getCRS() {
  return DefaultGeographicCRS.WGS84;
}
 
Example 18
Source File: WGS84CrsProvider.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public CoordinateReferenceSystem getCRS(final GeoPos referencePos, ParameterValueGroup parameter,
                                        GeodeticDatum datum) throws FactoryException {
    return DefaultGeographicCRS.WGS84;
}
 
Example 19
Source File: WorldMapImageLoader.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Object getCoordinateReferenceSystem() {
    return DefaultGeographicCRS.WGS84;
}
 
Example 20
Source File: OmsInsolation.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void process() throws Exception { // transform the
    checkNull(inElev, tStartDate, tEndDate);
    // extract some attributes of the map
    HashMap<String, Double> attribute = CoverageUtilities.getRegionParamsFromGridCoverage(inElev);
    double dx = attribute.get(CoverageUtilities.XRES);

    /*
     * The models use only one value of the latitude. So I have decided to
     * set it to the center of the raster. Extract the CRS of the
     * GridCoverage and transform the value of a WGS84 latitude.
     */
    CoordinateReferenceSystem sourceCRS = inElev.getCoordinateReferenceSystem2D();
    CoordinateReferenceSystem targetCRS = DefaultGeographicCRS.WGS84;

    double srcPts[] = new double[]{attribute.get(CoverageUtilities.EAST), attribute.get(CoverageUtilities.SOUTH)};

    Coordinate source = new Coordinate(srcPts[0], srcPts[1]);
    Point[] so = new Point[]{GeometryUtilities.gf().createPoint(source)};
    CrsUtilities.reproject(sourceCRS, targetCRS, so);
    // the latitude value
    lambda = Math.toRadians(so[0].getY());

    /*
     * transform the start and end date in an int value (the day in the
     * year, from 1 to 365)
     */
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd").withZone(DateTimeZone.UTC);
    DateTime currentDatetime = formatter.parseDateTime(tStartDate);
    int startDay = currentDatetime.getDayOfYear();
    currentDatetime = formatter.parseDateTime(tEndDate);
    int endDay = currentDatetime.getDayOfYear();
    CoverageUtilities.getRegionParamsFromGridCoverage(inElev);
    RenderedImage pitTmpRI = inElev.getRenderedImage();
    int width = pitTmpRI.getWidth();
    int height = pitTmpRI.getHeight();
    WritableRaster pitWR = CoverageUtilities.replaceNovalue(pitTmpRI, -9999.0);
    pitTmpRI = null;

    WritableRaster insolationWR = CoverageUtilities.createWritableRaster(width, height, null, pitWR.getSampleModel(),
            0.0);
    WritableRandomIter insolationIterator = RandomIterFactory.createWritable(insolationWR, null);

    WritableRaster gradientWR = normalVector(pitWR, dx);

    pm.beginTask(msg.message("insolation.calculating"), endDay - startDay);

    for( int i = startDay; i <= endDay; i++ ) {
        calcInsolation(lambda, pitWR, gradientWR, insolationWR, i, dx);
        pm.worked(i - startDay);
    }
    pm.done();
    for( int y = 2; y < height - 2; y++ ) {
        for( int x = 2; x < width - 2; x++ ) {
            if (HMConstants.isNovalue(pitWR.getSampleDouble(x, y, 0))) {
                insolationIterator.setSample(x, y, 0, HMConstants.doubleNovalue);

            }
        }
    }

    outIns = CoverageUtilities.buildCoverage("insolation", insolationWR, attribute, inElev.getCoordinateReferenceSystem());
}