Example #1
0
  private boolean checkTransform(
      String csName, double lon, double lat, double expectedX, double expectedY, double tolerance) {
    CoordinateTransformFactory ctFactory = new CoordinateTransformFactory();
    CRSFactory csFactory = new CRSFactory();
    /*
     * Create {@link CoordinateReferenceSystem} & CoordinateTransformation.
     * Normally this would be carried out once and reused for all transformations
     */
    CoordinateReferenceSystem crs = csFactory.createFromName(csName);

    final String WGS84_PARAM =
        "+title=long/lat:WGS84 +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees";
    CoordinateReferenceSystem WGS84 = csFactory.createFromParameters("WGS84", WGS84_PARAM);

    CoordinateTransform trans = ctFactory.createTransform(WGS84, crs);

    /*
     * Create input and output points.
     * These can be constructed once per thread and reused.
     */
    ProjCoordinate p = new ProjCoordinate();
    ProjCoordinate p2 = new ProjCoordinate();
    p.x = lon;
    p.y = lat;

    /*
     * Transform point
     */
    trans.transform(p, p2);

    return isInTolerance(p2, expectedX, expectedY, tolerance);
  }
Example #2
0
  public void testExplicitTransform() {
    String csName1 = "EPSG:32636";
    String csName2 = "EPSG:4326";

    CoordinateTransformFactory ctFactory = new CoordinateTransformFactory();
    CRSFactory csFactory = new CRSFactory();
    /*
     * Create {@link CoordinateReferenceSystem} & CoordinateTransformation.
     * Normally this would be carried out once and reused for all transformations
     */
    CoordinateReferenceSystem crs1 = csFactory.createFromName(csName1);
    CoordinateReferenceSystem crs2 = csFactory.createFromName(csName2);

    CoordinateTransform trans = ctFactory.createTransform(crs1, crs2);

    /*
     * Create input and output points.
     * These can be constructed once per thread and reused.
     */
    ProjCoordinate p1 = new ProjCoordinate();
    ProjCoordinate p2 = new ProjCoordinate();
    p1.x = 500000;
    p1.y = 4649776.22482;

    /*
     * Transform point
     */
    trans.transform(p1, p2);

    assertTrue(isInTolerance(p2, 33, 42, 0.000001));
  }
Example #3
0
  /** test transforming all geometries contained within a FeatureCollection */
  public void testTransformFeatureCollection() {
    try {
      URL url = new URL(Configuration.getGMLBaseDir(), Configuration.GML_COMPLEX_EXAMPLE);
      GMLFeatureCollectionDocument doc = new GMLFeatureCollectionDocument();
      doc.load(url);
      FeatureCollection fc = doc.parse();
      CoordinateSystem crs = CRSFactory.create("epsg:31467");
      GeoTransformer gt = new GeoTransformer(crs);
      gt.transform(fc);
      for (int i = 0; i < fc.size(); i++) {
        assertEquals(true, isTargetCRS(fc.getFeature(i), crs));
      }

      // GMLFeatureAdapter ada = new GMLFeatureAdapter();
      // ada.export( fc ).prettyPrint( System.out );

    } catch (Exception e) {
      LOG.logError(e.getLocalizedMessage(), e);
      assertEquals(true, false);
    }
  }