org.geotools.referencing.crs.DefaultGeographicCRS Java Examples

The following examples show how to use org.geotools.referencing.crs.DefaultGeographicCRS. 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: AbstractImportVectorDataNodeAction.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public CoordinateReferenceSystem getFeatureCrs(final Product product) {
    if (product.getSceneCRS() == Product.DEFAULT_IMAGE_CRS) {
        return Product.DEFAULT_IMAGE_CRS;
    }

    final CoordinateReferenceSystem[] featureCrsBuffer = new CoordinateReferenceSystem[1];
    Runnable runnable = () -> featureCrsBuffer[0] = promptForFeatureCrs(product);
    if (!SwingUtilities.isEventDispatchThread()) {
        try {
            SwingUtilities.invokeAndWait(runnable);
        } catch (InterruptedException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    } else {
        runnable.run();
    }
    CoordinateReferenceSystem featureCrs = featureCrsBuffer[0];
    return featureCrs != null ? featureCrs : DefaultGeographicCRS.WGS84;
}
 
Example #2
Source File: GeometryUtils.java    From geowave with Apache License 2.0 6 votes vote down vote up
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings()
public static CoordinateReferenceSystem getDefaultCRS() {
  if (defaultCrsSingleton == null) { // avoid sync penalty if we can
    synchronized (MUTEX_DEFAULT_CRS) {
      // have to do this inside the sync to avoid double init
      if (defaultCrsSingleton == null) {
        try {
          initClassLoader();
          defaultCrsSingleton = CRS.decode(DEFAULT_CRS_STR, true);
        } catch (final Exception e) {
          LOGGER.error("Unable to decode " + DEFAULT_CRS_STR + " CRS", e);
          defaultCrsSingleton = DefaultGeographicCRS.WGS84;
        }
      }
    }
  }
  return defaultCrsSingleton;
}
 
Example #3
Source File: FeatureLayer.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public FeatureLayer(LayerType layerType, final FeatureCollection<SimpleFeatureType, SimpleFeature> fc,
                    PropertySet configuration) {
    super(layerType, configuration);
    crs = fc.getSchema().getGeometryDescriptor().getCoordinateReferenceSystem();
    if (crs == null) {
        // todo - check me! Why can this happen??? (nf)
        crs = DefaultGeographicCRS.WGS84;
    }
    final ReferencedEnvelope envelope = new ReferencedEnvelope(fc.getBounds(), crs);
    modelBounds = new Rectangle2D.Double(envelope.getMinX(), envelope.getMinY(),
                                         envelope.getWidth(), envelope.getHeight());
    mapContext = new DefaultMapContext(crs);
    final Style style = (Style) configuration.getValue(FeatureLayerType.PROPERTY_NAME_SLD_STYLE);
    mapContext.addLayer(fc, style);
    renderer = new StreamingRenderer();
    workaroundLabelCacheBug();
    style.accept(new RetrievingStyleVisitor());
    renderer.setContext(mapContext);

}
 
Example #4
Source File: RenderPanelImpl.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Calculate bounds.
 *
 * @return the referenced envelope
 */
private ReferencedEnvelope calculateBounds() {
    ReferencedEnvelope bounds = null;

    try {
        bounds = featureList.getBounds();

        if (bounds == null) {
            // It could be that the above call was too costly!
            bounds = featureList.getFeatures().getBounds();
        }

        if (bounds.getCoordinateReferenceSystem() == null) {
            // We need a coordinate reference system set otherwise
            // transformations fail to render
            bounds = ReferencedEnvelope.create(bounds, DefaultGeographicCRS.WGS84);
        }

        if (bounds != null) {
            expandEnvelope(bounds);
        }
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    return bounds;
}
 
Example #5
Source File: GeoHashGridTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGeoHashGrid_scaled() throws Exception {
    features = TestUtil.createAggregationFeatures(ImmutableList.of(
            ImmutableMap.of("_aggregation", mapper.writeValueAsBytes(ImmutableMap.of("key",GeoHash.encodeHash(new LatLong(-89.9,-179.9),1),"doc_count",20))),
            ImmutableMap.of("_aggregation", mapper.writeValueAsBytes(ImmutableMap.of("key",GeoHash.encodeHash(new LatLong(89.9,179.9),1),"doc_count",30)))
            ));
    ReferencedEnvelope envelope = new ReferencedEnvelope(-180,180,-90,90,DefaultGeographicCRS.WGS84);
    geohashGrid.setScale(new RasterScale(5f, 10f));
    geohashGrid.initalize(envelope, features);
    assertEquals(GeoHash.widthDegrees(1), geohashGrid.getCellWidth(), 1e-10);
    assertEquals(GeoHash.heightDegrees(1), geohashGrid.getCellHeight(), 1e-10);
    assertEquals(new Envelope(-180+GeoHash.widthDegrees(1)/2.,180-GeoHash.widthDegrees(1)/2.,-90+GeoHash.heightDegrees(1)/2.,90-GeoHash.heightDegrees(1)/2.), geohashGrid.getEnvelope());
    int ny = (int) Math.round(180/geohashGrid.getCellHeight());
    int nx = (int) Math.round(360/GeoHash.widthDegrees(1));
    assertEquals(ny, geohashGrid.getGrid().length);
    assertEquals(nx, geohashGrid.getGrid()[0].length);
    float[][] expected = new float[ny][nx];
    expected[0][7] = 10;
    expected[ny-1][0] = 5;
    IntStream.range(0, ny).forEach(i-> assertArrayEquals(geohashGrid.getGrid()[i], expected[i], 0.0f));
}
 
Example #6
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 #7
Source File: CoverageUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a useless {@link GridCoverage2D} that might be usefull as placeholder.
 * 
 * @return the dummy grod coverage.
 */
public static GridCoverage2D buildDummyCoverage() {
    HashMap<String, Double> envelopeParams = new HashMap<String, Double>();
    envelopeParams.put(NORTH, 1.0);
    envelopeParams.put(SOUTH, 0.0);
    envelopeParams.put(WEST, 0.0);
    envelopeParams.put(EAST, 1.0);
    envelopeParams.put(XRES, 1.0);
    envelopeParams.put(YRES, 1.0);
    envelopeParams.put(ROWS, 1.0);
    envelopeParams.put(COLS, 1.0);
    double[][] dataMatrix = new double[1][1];
    dataMatrix[0][0] = 0;
    WritableRaster writableRaster = createWritableRasterFromMatrix(dataMatrix, true);
    return buildCoverage("dummy", writableRaster, envelopeParams, DefaultGeographicCRS.WGS84); //$NON-NLS-1$
}
 
Example #8
Source File: OmsNmeaFeatureReader.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public static SimpleFeatureBuilder getNmeaFeatureBuilder() {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("nmea");
    b.setCRS(DefaultGeographicCRS.WGS84);
    b.add("the_geom", Point.class);
    b.add(NmeaGpsPoint.strSpeed, Double.class);
    b.add(NmeaGpsPoint.strAltitude, Double.class);
    b.add(NmeaGpsPoint.strQuality, Double.class);
    b.add(NmeaGpsPoint.strSat, Integer.class);
    b.add(NmeaGpsPoint.strHdop, Double.class);
    b.add(NmeaGpsPoint.strMsl, Double.class);
    b.add(NmeaGpsPoint.strUtctime, String.class);
    b.add(NmeaGpsPoint.strMag_var, Double.class);
    b.add(NmeaGpsPoint.strAngle, Double.class);
    final SimpleFeatureType featureType = b.buildFeatureType();
    SimpleFeatureBuilder nmeaSimpleFeatureBuilder = new SimpleFeatureBuilder(featureType);
    return nmeaSimpleFeatureBuilder;
}
 
Example #9
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 #10
Source File: ImportTrackActionTest.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testReadTrack() throws Exception {

    CrsGeoCoding geoCoding = new CrsGeoCoding(DefaultGeographicCRS.WGS84, new Rectangle(360, 180), new AffineTransform());
    InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("TrackData.csv"));

    FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = ImportTrackAction.readTrack(reader, geoCoding);
    assertNotNull(featureCollection);
    assertEquals(23, featureCollection.size());

    // test ordering
    SimpleFeature[] simpleFeatures = featureCollection.toArray(new SimpleFeature[0]);
    assertEquals(23, simpleFeatures.length);
    assertEquals("ID00000000", simpleFeatures[0].getID());
    assertEquals("ID00000011", simpleFeatures[11].getID());
    assertEquals("ID00000022", simpleFeatures[22].getID());
}
 
Example #11
Source File: TestFeatureUtils.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("nls")
public void testFeatureUtils() throws Exception {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("typename");
    b.setCRS(DefaultGeographicCRS.WGS84);
    b.add("the_geom", Point.class);
    b.add("AttrName", String.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    Object[] values = new Object[]{GeometryUtilities.gf().createPoint(new Coordinate(0, 0)), "test"};
    builder.addAll(values);
    SimpleFeature feature = builder.buildFeature(type.getTypeName());

    Object attr = FeatureUtilities.getAttributeCaseChecked(feature, "attrname");
    assertEquals("test", attr.toString());
    attr = FeatureUtilities.getAttributeCaseChecked(feature, "attrnam");
    assertNull(attr);
}
 
Example #12
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 #13
Source File: ImageMosaicNwwLayer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public ImageMosaicNwwLayer( File imageMosaicShpFile, Integer tileSize, GeneralParameterValue[] gp,
        boolean removeSameColorImages ) throws Exception {
    super(makeLevels(imageMosaicShpFile, getRenderer(imageMosaicShpFile, gp), tileSize, removeSameColorImages));
    this.layerName = FileUtilities.getNameWithoutExtention(imageMosaicShpFile);

    ReferencedEnvelope envelope = OmsVectorReader.readEnvelope(imageMosaicShpFile.getAbsolutePath());
    ReferencedEnvelope envelopeLL = envelope.transform(DefaultGeographicCRS.WGS84, true);

    double w = envelopeLL.getMinX();
    double s = envelopeLL.getMinY();
    double e = envelopeLL.getMaxX();
    double n = envelopeLL.getMaxY();

    double centerX = w + (e - w) / 2.0;
    double centerY = s + (n - s) / 2.0;

    centerCoordinate = new Coordinate(centerX, centerY);

    this.setUseTransparentTextures(true);

}
 
Example #14
Source File: RasterizedSpatialiteLasLayer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public RasterizedSpatialiteLasLayer( String title, ASpatialDb db, Integer tileSize, boolean transparentBackground,
        boolean doIntensity ) throws Exception {
    super(makeLevels(title, tileSize, transparentBackground, db, doIntensity));
    String plus = doIntensity ? INTENSITY : ELEVATION;
    this.layerName = title + " " + plus;
    this.setUseTransparentTextures(true);

    try {
        Envelope tableBounds = db.getTableBounds(LasSourcesTable.TABLENAME);
        GeometryColumn spatialiteGeometryColumns = db.getGeometryColumnsForTable(LasCellsTable.TABLENAME);
        CoordinateReferenceSystem dataCrs = CRS.decode("EPSG:" + spatialiteGeometryColumns.srid);
        CoordinateReferenceSystem targetCRS = DefaultGeographicCRS.WGS84;
        ReferencedEnvelope env = new ReferencedEnvelope(tableBounds, dataCrs);
        ReferencedEnvelope envLL = env.transform(targetCRS, true);

        centre = envLL.centre();
    } catch (Exception e) {
        e.printStackTrace();
        centre = CrsUtilities.WORLD.centre();
    }
}
 
Example #15
Source File: NwwPanel.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public ReferencedEnvelope getViewportBounds() {
    View view = wwd.getView();
    Position posUL = view.computePositionFromScreenPoint(0, 0);
    Position posLR = view.computePositionFromScreenPoint(getWidth(), getHeight());

    if (posLR != null && posUL != null) {
        double west = posUL.longitude.degrees;
        double north = posUL.latitude.degrees;
        double east = posLR.longitude.degrees;
        double south = posLR.latitude.degrees;

        ReferencedEnvelope env = new ReferencedEnvelope(west, east, south, north, DefaultGeographicCRS.WGS84);
        return env;
    } else {
        return null;// new ReferencedEnvelope(-180, 180, -90, 90,
                    // DefaultGeographicCRS.WGS84);
    }
}
 
Example #16
Source File: ExportGeometryActionTest.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testWritingShapeFile_Geometry() throws Exception {
    SimpleFeatureType sft = createPlainFeatureType("Polygon", Geometry.class, DefaultGeographicCRS.WGS84);

    GeometryFactory gf = new GeometryFactory();
    Polygon polygon = gf.createPolygon(gf.createLinearRing(new Coordinate[]{
            new Coordinate(0, 0),
            new Coordinate(1, 0),
            new Coordinate(0, 1),
            new Coordinate(0, 0),
    }), null);
    SimpleFeature polygonFeature = createPlainFeature(sft, "_1", polygon, "");


    ArrayList<SimpleFeature> features = new ArrayList<>();
    features.add(polygonFeature);
    Class<Polygon> geomType = Polygon.class;
    doExportImport(features, geomType);
}
 
Example #17
Source File: SimpleFeatureShapeFigureTest.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testMixedGeometries_2() {

    SimpleFeatureType sft = createPlainFeatureType("Geometry", Geometry.class, DefaultGeographicCRS.WGS84);

    Geometry geometry;
    SimpleFeature feature;
    SimpleFeatureShapeFigure figure;

    geometry = createPoint();
    feature = createPlainFeature(sft, "_4", geometry, "");
    figure = new SimpleFeatureShapeFigure(feature, sceneTransformProvider, new DefaultFigureStyle());
    Assert.assertEquals(geometry, figure.getGeometry());
    Assert.assertNotNull(figure.getShape());
    Assert.assertEquals(Figure.Rank.POINT, figure.getRank());

    geometry = createGeometryCollection();
    feature = createPlainFeature(sft, "_5", geometry, "");
    figure = new SimpleFeatureShapeFigure(feature, sceneTransformProvider, new DefaultFigureStyle());
    Assert.assertEquals(geometry, figure.getGeometry());
    Assert.assertNotNull(figure.getShape());
    Assert.assertEquals(Figure.Rank.NOT_SPECIFIED, figure.getRank());
}
 
Example #18
Source File: ImportTrackAction.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private static SimpleFeatureType createTrackFeatureType(GeoCoding geoCoding) {
    SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
    ftb.setName("org.esa.snap.TrackPoint");
    /*0*/
    ftb.add("pixelPos", Point.class, geoCoding.getImageCRS());
    /*1*/
    ftb.add("geoPos", Point.class, DefaultGeographicCRS.WGS84);
    /*2*/
    ftb.add("data", Double.class);
    ftb.setDefaultGeometry(geoCoding instanceof CrsGeoCoding ? "geoPos" : "pixelPos");
    // GeoTools Bug: this doesn't work
    // ftb.userData("trackPoints", "true");
    final SimpleFeatureType ft = ftb.buildFeatureType();
    ft.getUserData().put("trackPoints", "true");
    return ft;
}
 
Example #19
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 #20
Source File: TestENU.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public void testWithGeotools() throws MatrixException {
    Coordinate c1 = new Coordinate(11, 46, 0);
    Coordinate c2 = new Coordinate(11.001, 46.001, 0);

    GeodeticCalculator gc = new GeodeticCalculator(DefaultGeographicCRS.WGS84);
    gc.setStartingGeographicPoint(c1.x, c1.y);
    gc.setDestinationGeographicPoint(c2.x, c2.y);
    double orthodromicDistance = gc.getOrthodromicDistance();

    ENU enu = new ENU(c1);
    Coordinate ce1 = enu.wgs84ToEnu(c1);
    Coordinate ce2 = enu.wgs84ToEnu(c2);

    double distance = ce1.distance(ce2);
    assertTrue(isDeltaOk(orthodromicDistance, distance));
    
    Coordinate c1Back = enu.enuToWgs84(ce1);
    Coordinate c2Back = enu.enuToWgs84(ce2);
    
    assertEquals(0, c1.distance(c1Back), 0.000001);
    assertEquals(0, c2.distance(c2Back), 0.000001);
    
}
 
Example #21
Source File: ShapefileTool.java    From geowave with Apache License 2.0 5 votes vote down vote up
private static SimpleFeatureType createFeatureType(final String typeName, final boolean isPoint) {

    final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setName(typeName);
    builder.setCRS(DefaultGeographicCRS.WGS84); // <- Coordinate reference
    // system

    // add attributes in order
    builder.add("the_geom", isPoint ? Point.class : Polygon.class);
    builder.length(15).add("Name", String.class); // <- 15 chars width for name field

    // build the type

    return builder.buildFeatureType();
  }
 
Example #22
Source File: TestLineSmootherMcMaster.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void testVectorReader() throws Exception {

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("test");
        b.setCRS(DefaultGeographicCRS.WGS84);
        b.add("the_geom", LineString.class);
        b.add("id", Integer.class);

        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        SimpleFeatureType type = b.buildFeatureType();

        Geometry line = new WKTReader().read("LINESTRING (0 0, 1 1, 2 2, 3 3, 4 4, 5 3, 6 2, 7 1, 8 0)");
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Object[] values = new Object[]{line, 0};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0");
        newCollection.add(feature);

        OmsLineSmootherMcMaster smoother = new OmsLineSmootherMcMaster();
        smoother.inVector = newCollection;
        smoother.pLookahead = 3;
        smoother.pSlide = 0.9;
        smoother.pDensify = 0.9;
        smoother.process();
        SimpleFeatureCollection outFeatures = smoother.outVector;

        List<Geometry> geomList = FeatureUtilities.featureCollectionToGeometriesList(outFeatures, false, null);
        Geometry geometry = geomList.get(0);

        int newLength = geometry.getCoordinates().length;

        Geometry densifiedline = new WKTReader()
                .read("LINESTRING (0 0, 0.5 0.5, 1 1, 1.5 1.5, 2 2, 2.5 2.5, 3 3, 3.5 3.5, 4 4, 4.5 3.5, 5 3, 5.5 2.5, 6 2, 6.5 1.5, 7 1, 7.5 0.5, 8 0)");
        int expectedLength = densifiedline.getCoordinates().length;

        assertEquals(expectedLength, newLength);

    }
 
Example #23
Source File: TestLasIO.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void testLasWriter() throws Exception {
    URL lasUrl = this.getClass().getClassLoader().getResource(lasWriteFileName);
    File lasFile = new File(lasUrl.toURI());

    LasReaderBuffered lasReader = new LasReaderBuffered(lasFile, null);
    lasReader.open();
    ILasHeader lasHeader = lasReader.getHeader();

    /*
     * write tmp files
     */
    File lasTmp = File.createTempFile("lasreader", ".las");

    ALasWriter lasWriter = ALasWriter.getWriter(lasTmp, DefaultGeographicCRS.WGS84);
    lasWriter.setBounds(lasHeader);
    lasWriter.open();
    while( lasReader.hasNextPoint() ) {
        lasWriter.addPoint(lasReader.getNextPoint());
    }
    lasWriter.close();

    LasReaderBuffered tmpLasReader = new LasReaderBuffered(lasTmp, null);
    tmpLasReader.open();
    ILasHeader tmpLasHeader = tmpLasReader.getHeader();
    checkHeader(lasHeader, tmpLasHeader);
    LasRecord tmpLasDot = tmpLasReader.getPointAt(0);
    LasRecord lasDot = lasReader.getPointAt(0);
    assertTrue(LasUtils.lasRecordEqual(tmpLasDot, lasDot));
    tmpLasReader.close();
    lasReader.close();

    lasTmp.deleteOnExit();
}
 
Example #24
Source File: TestVectorTableJoiner.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void testVectorTableJoiner() throws Exception {

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("test");
        b.setCRS(DefaultGeographicCRS.WGS84);
        b.add("the_geom", Point.class);
        b.add("id", Integer.class);

        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Point point = GeometryUtilities.gf().createPoint(new Coordinate(0, 0));
        Object[] values = new Object[]{point, 1};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0");
        newCollection.add(feature);

        HashMap<String, List<Object>> tabledata = new HashMap<String, List<Object>>();
        List<Object> id = Arrays.asList(new Object[]{1});
        tabledata.put("id", id);
        List<Object> area = Arrays.asList(new Object[]{123.45});
        tabledata.put("area", area);
        List<Object> area2 = Arrays.asList(new Object[]{67.89});
        tabledata.put("area2", area2);

        OmsVectorTableJoiner joiner = new OmsVectorTableJoiner();
        joiner.inVector = newCollection;
        joiner.tabledata = tabledata;
        joiner.fCommon = "id";
        joiner.pFields = "area";
        joiner.process();
        SimpleFeatureCollection outFeatures = joiner.outVector;

        SimpleFeature f = FeatureUtilities.featureCollectionToList(outFeatures).get(0);
        String areaStr = f.getAttribute("area").toString();

        assertTrue(areaStr.equals("123.45"));
    }
 
Example #25
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 #26
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 #27
Source File: TestGeopackage.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("nls")
public void testMultiVectorGeopackageIO() throws Exception {
    String polygonTable = "polygontest";
    String lineTable = "linetest";

    SimpleFeatureCollection polygonFC = HMTestMaps.getTestLeftFC();
    LineString line = GeometryUtilities.createDummyLine();
    SimpleFeatureCollection lineFc = FeatureUtilities.featureCollectionFromGeometry(DefaultGeographicCRS.WGS84, line);

    File tmpGpkg = File.createTempFile("hm_test_multi_vector_", "." + HMConstants.GPKG);
    OmsVectorWriter.writeVector(tmpGpkg.getAbsolutePath() + HMConstants.DB_TABLE_PATH_SEPARATOR + polygonTable, polygonFC);
    OmsVectorWriter.writeVector(tmpGpkg.getAbsolutePath() + HMConstants.DB_TABLE_PATH_SEPARATOR + lineTable, lineFc);

    SimpleFeatureCollection readPolygonFC = OmsVectorReader
            .readVector(tmpGpkg.getAbsolutePath() + HMConstants.DB_TABLE_PATH_SEPARATOR + polygonTable);
    int srid = CrsUtilities.getSrid(readPolygonFC.getSchema().getCoordinateReferenceSystem());
    assertEquals(32632, srid);
    List<SimpleFeature> features = FeatureUtilities.featureCollectionToList(readPolygonFC);
    assertEquals(1, features.size());

    SimpleFeatureCollection readLinesFC = OmsVectorReader
            .readVector(tmpGpkg.getAbsolutePath() + HMConstants.DB_TABLE_PATH_SEPARATOR + lineTable);
    srid = CrsUtilities.getSrid(readLinesFC.getSchema().getCoordinateReferenceSystem());
    assertEquals(4326, srid);
    features = FeatureUtilities.featureCollectionToList(readLinesFC);
    assertEquals(1, features.size());

}
 
Example #28
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 #29
Source File: TestFilterPanelv2.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCrosses() {
    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.crosses(ff.property("the_geom"), ff.literal(bbox));
    String expected = filter.toString();
    testPanel.filterDialog(String.class, filter);

    String actual = testPanel.getFilterString();

    assertEquals(expected, actual);
}
 
Example #30
Source File: TestVectorFieldRounder.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void testVectorFieldRounder() throws Exception {

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("test");
        b.setCRS(DefaultGeographicCRS.WGS84);
        b.add("the_geom", Point.class);
        b.add("area", Double.class);

        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Point point = GeometryUtilities.gf().createPoint(new Coordinate(0, 0));
        Object[] values = new Object[]{point, 123.456789};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0");
        newCollection.add(feature);

        OmsVectorFieldRounder rounder = new OmsVectorFieldRounder();
        rounder.inVector = newCollection;
        rounder.fRound = "area";
        rounder.pPattern = ".##";
        rounder.process();
        SimpleFeatureCollection outFeatures = rounder.outVector;

        SimpleFeature f = FeatureUtilities.featureCollectionToList(outFeatures).get(0);
        String areaStr = f.getAttribute("area").toString();

        assertTrue(areaStr.equals("123.46"));
    }