Пример #1
0
  /** ********************************************************************* */
  static boolean GDALInfoReportCorner(Dataset hDataset, String corner_name, double x, double y) {

    double dfGeoX, dfGeoY;
    String pszProjection;
    double[] adfGeoTransform = new double[6];
    CoordinateTransformation hTransform = null;

    System.out.print(corner_name + " ");

    /* -------------------------------------------------------------------- */
    /*      Transform the point into georeferenced coordinates.             */
    /* -------------------------------------------------------------------- */
    hDataset.GetGeoTransform(adfGeoTransform);
    {
      pszProjection = hDataset.GetProjectionRef();

      dfGeoX = adfGeoTransform[0] + adfGeoTransform[1] * x + adfGeoTransform[2] * y;
      dfGeoY = adfGeoTransform[3] + adfGeoTransform[4] * x + adfGeoTransform[5] * y;
    }

    if (adfGeoTransform[0] == 0
        && adfGeoTransform[1] == 0
        && adfGeoTransform[2] == 0
        && adfGeoTransform[3] == 0
        && adfGeoTransform[4] == 0
        && adfGeoTransform[5] == 0) {
      System.out.println("(" + x + "," + y + ")");
      return false;
    }

    /* -------------------------------------------------------------------- */
    /*      Report the georeferenced coordinates.                           */
    /* -------------------------------------------------------------------- */
    System.out.print("(" + dfGeoX + "," + dfGeoY + ") ");

    /* -------------------------------------------------------------------- */
    /*      Setup transformation to lat/long.                               */
    /* -------------------------------------------------------------------- */
    if (pszProjection != null && pszProjection.length() > 0) {
      SpatialReference hProj, hLatLong = null;

      hProj = new SpatialReference(pszProjection);
      if (hProj != null) hLatLong = hProj.CloneGeogCS();

      if (hLatLong != null) {
        gdal.PushErrorHandler("CPLQuietErrorHandler");
        hTransform = new CoordinateTransformation(hProj, hLatLong);
        gdal.PopErrorHandler();
        hLatLong.delete();
        if (gdal.GetLastErrorMsg().indexOf("Unable to load PROJ.4 library") != -1)
          hTransform = null;
      }

      if (hProj != null) hProj.delete();
    }

    /* -------------------------------------------------------------------- */
    /*      Transform to latlong and report.                                */
    /* -------------------------------------------------------------------- */
    if (hTransform != null) {
      double[] transPoint = new double[3];
      hTransform.TransformPoint(transPoint, dfGeoX, dfGeoY, 0);
      System.out.print("(" + gdal.DecToDMS(transPoint[0], "Long", 2));
      System.out.print("," + gdal.DecToDMS(transPoint[1], "Lat", 2) + ")");
    }

    if (hTransform != null) hTransform.delete();

    System.out.println("");

    return true;
  }