Пример #1
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));
  }
Пример #2
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);
  }
  private Projection test(String filename, String ctvName, String varName, Class projClass)
      throws IOException, InvalidRangeException {
    System.out.printf("Open= %s%n", filename);
    NetcdfDataset ncd = ucar.nc2.dataset.NetcdfDataset.openDataset(filename);

    Variable ctv = null;
    if (ctvName != null) {
      ctv = ncd.findVariable(ctvName);
      assert ctv != null;
      System.out.println(" dump of ctv = \n" + ctv);
    }

    VariableDS v = (VariableDS) ncd.findVariable(varName);
    assert v != null;

    List<CoordinateSystem> cList = v.getCoordinateSystems();
    assert cList != null;
    assert cList.size() == 1;
    CoordinateSystem csys = cList.get(0);

    List<CoordinateTransform> pList = new ArrayList<CoordinateTransform>();
    List<CoordinateTransform> tList = csys.getCoordinateTransforms();
    assert tList != null;
    for (int i = 0; i < tList.size(); i++) {
      CoordinateTransform ct = tList.get(i);
      if (ct.getTransformType() == TransformType.Projection) pList.add(ct);
    }
    assert pList.size() == 1;
    CoordinateTransform ct = pList.get(0);
    assert ct.getTransformType() == TransformType.Projection;
    assert ct instanceof ProjectionCT;

    ProjectionCT vct = (ProjectionCT) ct;
    Projection proj = vct.getProjection();
    assert proj != null;
    assert projClass.isInstance(proj) : proj.getClass().getName();

    VariableDS ctvSyn = CoordTransBuilder.makeDummyTransformVariable(ncd, ct);
    System.out.println(" dump of equivilent ctv = \n" + ctvSyn);

    if (ctv != null) {
      Formatter f = new Formatter(System.out);
      CompareNetcdf.checkContains(ctv.getAttributes(), ctvSyn.getAttributes(), f);
    }

    ncd.close();
    return proj;
  }
Пример #4
0
    public CoordinateSystemBean(CoordinateSystem cs) {
      this.coordSys = cs;

      setCoordSys(cs.getName());
      setGeoXY(cs.isGeoXY());
      setLatLon(cs.isLatLon());
      setProductSet(cs.isProductSet());
      setRegular(cs.isRegular());
      setDomainRank(cs.getDomain().size());
      setRangeRank(cs.getCoordinateAxes().size());

      coverageType = CoverageCSFactory.describe(null, cs);

      if (GridCoordSys.isGridCoordSys(parseInfo, cs, null)) {
        addDataType("grid");
      }

      if (RadialCoordSys.isRadialCoordSys(parseInfo, cs)) {
        addDataType("radial");
      }

      StringBuilder buff = new StringBuilder();
      List ctList = cs.getCoordinateTransforms();
      for (int i = 0; i < ctList.size(); i++) {
        CoordinateTransform ct = (CoordinateTransform) ctList.get(i);
        if (i > 0) buff.append(" ");
        buff.append(ct.getTransformType());
        if (ct instanceof VerticalCT)
          buff.append("(").append(((VerticalCT) ct).getVerticalTransformType()).append(")");
        if (ct instanceof ProjectionCT) {
          ProjectionCT pct = (ProjectionCT) ct;
          if (pct.getProjection() != null) {
            buff.append("(").append(pct.getProjection().getClassName()).append(")");
          }
        }
      }
      setCoordTransforms(buff.toString());
    }