コード例 #1
0
ファイル: Hdf5ProductWriter.java プロジェクト: maduhu/beam
 private void writeGeoCoding(final MapGeoCoding geoCoding) throws IOException {
   final MapInfo mapInfo = geoCoding.getMapInfo();
   final MapProjection mapProjection = mapInfo.getMapProjection();
   final int groupID = createH5G(_fileID, "geo_coding");
   try {
     createScalarAttribute(groupID, "java_class_name", MapGeoCoding.class.getName());
     createScalarAttribute(groupID, "easting", mapInfo.getEasting());
     createScalarAttribute(groupID, "northing", mapInfo.getNorthing());
     createScalarAttribute(groupID, "pixel_x", mapInfo.getPixelX());
     createScalarAttribute(groupID, "pixel_y", mapInfo.getPixelY());
     createScalarAttribute(groupID, "pixel_size_x", mapInfo.getPixelSizeX());
     createScalarAttribute(groupID, "pixel_size_y", mapInfo.getPixelSizeY());
     createScalarAttribute(groupID, "datum", mapInfo.getDatum().getName());
     createScalarAttribute(groupID, "unit", mapProjection.getMapUnit());
     createScalarAttribute(groupID, "projection", mapProjection.getName());
     final int paramsID = createH5G(groupID, "projection_params");
     try {
       final MapTransform mapTransform = mapProjection.getMapTransform();
       final MapTransformDescriptor mapTransformDescriptor = mapTransform.getDescriptor();
       final Parameter[] parameters = mapTransformDescriptor.getParameters();
       for (int i = 0; i < parameters.length; i++) {
         createScalarAttribute(
             paramsID, parameters[i].getName(), mapTransform.getParameterValues()[i]);
       }
     } finally {
       closeH5G(paramsID);
     }
   } finally {
     closeH5G(groupID);
   }
 }
コード例 #2
0
ファイル: EnviHeader.java プロジェクト: pmar/nest
  /**
   * Writes the systems byte order to the out stream. In java only high byte first.
   *
   * @param out the stream to write to
   * @param rasterDataNode
   */
  private static void writeMapProjectionInfo(PrintWriter out, RasterDataNode rasterDataNode) {
    Product product = rasterDataNode.getProduct();
    if (product == null) {
      return;
    }

    String mapProjectionName = "Arbitrary";
    String mapUnits = "Meters";
    double referencePixelX = 0, referencePixelY = 0;
    double easting = 0, northing = 0;
    double pixelSizeX = 0, pixelSizeY = 0;
    String datumName = "";
    int utmZone = -1;
    String utmHemisphere = "";
    MapProjection mapProjection = null;

    if (product.getGeoCoding() instanceof CrsGeoCoding) {
      final CrsGeoCoding crsGeoCoding = (CrsGeoCoding) product.getGeoCoding();
      final CoordinateReferenceSystem crs = crsGeoCoding.getMapCRS();

      final ImageGeometry imgGeom =
          ImageGeometry.createTargetGeometry(
              product, crs, null, null, null, null, null, null, null, null, null);

      final String crsName = crs.getName().toString().toUpperCase();
      if (crsName.equals("WGS84(DD)")) {
        mapProjectionName = "Geographic Lat/Lon";
        mapUnits = "Degrees";
      } else if (crsName.contains("UTM")) {
        mapProjectionName = "UTM";
        String zoneStr = crsName.substring(crsName.indexOf("ZONE") + 5, crsName.length()).trim();
        int i = 0;
        String zoneNumStr = "";
        while (Character.isDigit(zoneStr.charAt(i))) {
          zoneNumStr += zoneStr.charAt(i++);
        }
        utmZone = Integer.parseInt(zoneNumStr);

        GeoPos centrePos =
            crsGeoCoding.getGeoPos(
                new PixelPos(product.getSceneRasterWidth() / 2, product.getSceneRasterHeight() / 2),
                null);
        utmHemisphere = centrePos.getLat() > 0 ? "North" : "South";
      }
      referencePixelX = imgGeom.getReferencePixelX();
      referencePixelY = imgGeom.getReferencePixelY();
      easting = imgGeom.getEasting();
      northing = imgGeom.getNorthing();
      pixelSizeX = imgGeom.getPixelSizeX();
      pixelSizeY = imgGeom.getPixelSizeY();
      datumName = crsGeoCoding.getDatum().getName();

    } else if (product.getGeoCoding() instanceof MapGeoCoding) {
      final MapGeoCoding mapGeoCoding = (MapGeoCoding) product.getGeoCoding();

      final MapInfo info = mapGeoCoding.getMapInfo();
      if (info == null) {
        return;
      }
      mapProjection = info.getMapProjection();

      if (mapProjection instanceof UTMProjection) {
        mapProjectionName = "UTM";
        final UTMProjection utmProjection = (UTMProjection) mapProjection;
        utmZone = utmProjection.getZone();
        utmHemisphere = utmProjection.isNorth() ? "North" : "South";
      } else if (mapProjection.isPreDefined()) {
        mapProjectionName = mapProjection.getName();
      }

      if ("meter".equals(mapProjection.getMapUnit())) {
        mapUnits = "Meters";
      } else if ("degree".equals(mapProjection.getMapUnit())) {
        mapUnits = "Degrees";
      } else {
        mapUnits = mapProjection.getMapUnit();
      }

      datumName = mapGeoCoding.getDatum().getName();
    } else {
      return;
    }

    out.print(_enviMapInfo);
    out.print(" = {");
    out.print(mapProjectionName);
    out.print(",");
    out.print(referencePixelX + 1.0f);
    out.print(",");
    out.print(referencePixelY + 1.0f);
    out.print(",");
    out.print(easting);
    out.print(",");
    out.print(northing);
    out.print(",");
    out.print(pixelSizeX);
    out.print(",");
    out.print(pixelSizeY);
    out.print(",");
    if (utmZone != -1) {
      out.print(utmZone);
      out.print(",");
      out.print(utmHemisphere);
      out.print(",");
    }
    out.print(datumName);
    out.print(",");
    out.print("units=" + mapUnits);
    out.print("}");
    out.println();

    if (mapProjection != null && !mapProjection.isPreDefined()) {
      final MapTransform mapTransform = mapProjection.getMapTransform();
      final double[] parameterValues = mapTransform.getParameterValues();
      final String transformName = mapTransform.getDescriptor().getName();
      out.print(_enviProjectionInfo);
      out.print(" = {");
      if (transformName.equals(TransverseMercatorDescriptor.NAME)) {
        out.print(3);
        out.print(",");
        out.print(parameterValues[0]); // semi_major (meters)
        out.print(",");
        out.print(parameterValues[1]); // semi_minor (meters)
        out.print(",");
        out.print(parameterValues[2]); // latitude_of_origin (degree)
        out.print(",");
        out.print(parameterValues[3]); // central_meridian (degree)
        out.print(",");
        out.print(parameterValues[5]); // false_easting (meters)
        out.print(",");
        out.print(parameterValues[6]); // false_northing (meters)
        out.print(",");
        out.print(parameterValues[4]); //  scaling_factor (no unit)
        out.print(",");
      } else if (transformName.equals(LambertConformalConicDescriptor.NAME)) {
        out.print(4);
        out.print(",");
        out.print(parameterValues[0]); // semi_major (meters)
        out.print(",");
        out.print(parameterValues[1]); // semi_minor (meters)
        out.print(",");
        out.print(parameterValues[2]); // latitude_of_origin (degree)
        out.print(",");
        out.print(parameterValues[3]); // central_meridian (degree)
        out.print(",");
        out.print(0.0); // false_easting (meters)
        out.print(",");
        out.print(0.0); // false_northing (meters)
        out.print(",");
        out.print(parameterValues[4]); // latitude_of_intersection_1 (meters)
        out.print(",");
        out.print(parameterValues[5]); // latitude_of_intersection_2 (meters)
        out.print(",");
      }
      out.print(mapProjectionName);
      out.print(",");
      out.print("units=" + mapUnits);
      out.print("}");
      out.println();
    }
  }