Ejemplo n.º 1
0
  private void setupConfig(final Job job, final MrsImageDataProvider provider)
      throws DataProviderException {
    try {
      Configuration conf = job.getConfiguration();
      DataProviderFactory.saveProviderPropertiesToConfig(provider.getProviderProperties(), conf);
      context.save(conf);
      // Add the input pyramid metadata to the job configuration
      for (final String input : context.getInputs()) {
        MrsImagePyramid pyramid;
        try {
          pyramid = MrsImagePyramid.open(input, context.getProviderProperties());
        } catch (IOException e) {
          throw new DataProviderException("Failure opening input image pyramid: " + input, e);
        }
        final MrsImagePyramidMetadata metadata = pyramid.getMetadata();
        log.debug(
            "In HadoopUtils.setupMrsPyramidInputFormat, loading pyramid for "
                + input
                + " pyramid instance is "
                + pyramid
                + " metadata instance is "
                + metadata);

        String image = metadata.getName(context.getZoomLevel());
        // if we don't have this zoom level, use the max, then we'll decimate/subsample that one
        if (image == null) {
          log.error(
              "Could not get image in setupMrsPyramidInputFormat at zoom level "
                  + context.getZoomLevel()
                  + " for "
                  + pyramid);
          image = metadata.getName(metadata.getMaxZoomLevel());
        }

        HadoopUtils.setMetadata(conf, metadata);
      }
    } catch (IOException e) {
      throw new DataProviderException(
          "Failure configuring map/reduce job " + context.toString(), e);
    }
  }
Ejemplo n.º 2
0
  protected static Document mrsPyramidMetadataToTileMapXml(
      final String raster, final String url, final MrsImagePyramidMetadata mpm)
      throws ParserConfigurationException {
    /*
     * String tileMap = "<?xml version='1.0' encoding='UTF-8' ?>" +
     * "<TileMap version='1.0.0' tilemapservice='http://localhost/mrgeo-services/api/tms/1.0.0'>" +
     * "  <Title>AfPk Elevation V2</Title>" + "  <Abstract>A test of V2 MrsImagePyramid.</Abstract>"
     * + "  <SRS>EPSG:4326</SRS>" + "  <BoundingBox minx='68' miny='33' maxx='72' maxy='35' />" +
     * "  <Origin x='68' y='33' />" +
     * "  <TileFormat width='512' height='512' mime-type='image/tiff' extension='tif' />" +
     * "  <TileSets profile='global-geodetic'>" +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/1' units-per-pixel='0.3515625' order='1' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/2' units-per-pixel='0.17578125' order='2' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/3' units-per-pixel='0.08789063' order='3' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/4' units-per-pixel='0.08789063' order='4' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/5' units-per-pixel='0.08789063' order='5' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/6' units-per-pixel='0.08789063' order='6' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/7' units-per-pixel='0.08789063' order='7' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/8' units-per-pixel='0.08789063' order='8' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/9' units-per-pixel='0.08789063' order='9' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/10' units-per-pixel='0.08789063' order='10' />"
     * + "  </TileSets>" + "</TileMap>";
     */

    final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

    // root elements
    final Document doc = docBuilder.newDocument();
    final Element rootElement = doc.createElement("TileMap");
    doc.appendChild(rootElement);
    final Attr v = doc.createAttribute("version");
    v.setValue(VERSION);
    rootElement.setAttributeNode(v);
    final Attr tilemapservice = doc.createAttribute("tilemapservice");
    tilemapservice.setValue(normalizeUrl(normalizeUrl(url).replace(raster, "")));
    rootElement.setAttributeNode(tilemapservice);

    // child elements
    final Element title = doc.createElement("Title");
    title.setTextContent(raster);
    rootElement.appendChild(title);

    final Element abst = doc.createElement("Abstract");
    abst.setTextContent("");
    rootElement.appendChild(abst);

    final Element srs = doc.createElement("SRS");
    srs.setTextContent(SRS);
    rootElement.appendChild(srs);

    final Element bbox = doc.createElement("BoundingBox");
    rootElement.appendChild(bbox);
    final Attr minx = doc.createAttribute("minx");
    minx.setValue(String.valueOf(mpm.getBounds().getMinX()));
    bbox.setAttributeNode(minx);
    final Attr miny = doc.createAttribute("miny");
    miny.setValue(String.valueOf(mpm.getBounds().getMinY()));
    bbox.setAttributeNode(miny);
    final Attr maxx = doc.createAttribute("maxx");
    maxx.setValue(String.valueOf(mpm.getBounds().getMaxX()));
    bbox.setAttributeNode(maxx);
    final Attr maxy = doc.createAttribute("maxy");
    maxy.setValue(String.valueOf(mpm.getBounds().getMaxY()));
    bbox.setAttributeNode(maxy);

    final Element origin = doc.createElement("Origin");
    rootElement.appendChild(origin);
    final Attr x = doc.createAttribute("x");
    x.setValue(String.valueOf(mpm.getBounds().getMinX()));
    origin.setAttributeNode(x);
    final Attr y = doc.createAttribute("y");
    y.setValue(String.valueOf(mpm.getBounds().getMinY()));
    origin.setAttributeNode(y);

    final Element tileformat = doc.createElement("TileFormat");
    rootElement.appendChild(tileformat);
    final Attr w = doc.createAttribute("width");
    w.setValue(String.valueOf(mpm.getTilesize()));
    tileformat.setAttributeNode(w);
    final Attr h = doc.createAttribute("height");
    h.setValue(String.valueOf(mpm.getTilesize()));
    tileformat.setAttributeNode(h);
    final Attr mt = doc.createAttribute("mime-type");
    mt.setValue("image/tiff");
    tileformat.setAttributeNode(mt);
    final Attr ext = doc.createAttribute("extension");
    ext.setValue("tif");
    tileformat.setAttributeNode(ext);

    final Element tilesets = doc.createElement("TileSets");
    rootElement.appendChild(tilesets);
    final Attr profile = doc.createAttribute("profile");
    profile.setValue("global-geodetic");
    tilesets.setAttributeNode(profile);

    for (int i = 0; i <= mpm.getMaxZoomLevel(); i++) {
      final Element tileset = doc.createElement("TileSet");
      tilesets.appendChild(tileset);
      final Attr href = doc.createAttribute("href");
      href.setValue(normalizeUrl(normalizeUrl(url)) + "/" + i);
      tileset.setAttributeNode(href);
      final Attr upp = doc.createAttribute("units-per-pixel");
      upp.setValue(String.valueOf(180d / 256d / Math.pow(2, i)));
      tileset.setAttributeNode(upp);
      final Attr order = doc.createAttribute("order");
      order.setValue(String.valueOf(i));
      tileset.setAttributeNode(order);
    }

    return doc;
  }