コード例 #1
0
    public ImageFormatter serviceRequest(IMapRequest req) throws IOException, WMSServiceException {
      ImageFormatter formatter = null;
      try {
        Sector reqExtent =
            (SingleFileLayer.this.isElevation)
                ? req.getExtentForElevationRequest()
                : req.getExtent();

        if (null == this.intersects(reqExtent, SingleFileLayer.this.getBBox())) {
          String msg =
              Logging.getMessage(
                  "WMS.Layer.OutOfCoverage",
                  reqExtent.toString(),
                  SingleFileLayer.this.getBBox().toString());
          Logging.logger().severe(msg);
          throw new WMSServiceException(msg);
        }

        if (req.getHeight() <= 0 || req.getWidth() <= 0) {
          String msg =
              Logging.getMessage("generic.InvalidImageSize", req.getWidth(), req.getHeight());
          Logging.logger().severe(msg);
          throw new WMSServiceException(msg);
        }

        DataRaster[] rasters = SingleFileLayer.this.rasters;
        if (null == rasters || 0 == rasters.length) {
          String msg = Logging.getMessage("nullValue.RasterIsNull");
          Logging.logger().severe(msg);
          throw new WMSServiceException(msg);
        }

        double missingDataReplacement = (double) SingleFileLayer.this.nodataReplacement;
        try {
          String s = req.getBGColor();
          if (null != s) {
            missingDataReplacement = Double.parseDouble(s);
          }
        } catch (Exception e) {
          missingDataReplacement = (double) SingleFileLayer.this.nodataReplacement;
        }

        DataRaster raster = rasters[0];
        if (raster instanceof BufferedImageRaster) {
          BufferedImageRaster reqRaster =
              new BufferedImageRaster(
                  req.getWidth(), req.getHeight(), Transparency.TRANSLUCENT, reqExtent);

          raster.drawOnTo(reqRaster);

          BufferedImage img = reqRaster.getBufferedImage();
          this.makeNoDataTransparent(
              img, SingleFileLayer.this.nodataSignal, (short) missingDataReplacement);

          formatter = new BufferedImageFormatter(img);
        } else if (raster instanceof ByteBufferRaster) {
          AVList reqParams = new AVListImpl();

          reqParams.setValue(AVKey.WIDTH, req.getWidth());
          reqParams.setValue(AVKey.HEIGHT, req.getHeight());
          reqParams.setValue(AVKey.SECTOR, reqExtent);
          reqParams.setValue(
              AVKey.BYTE_ORDER, AVKey.LITTLE_ENDIAN); // by default BIL is LITTLE ENDIAN
          reqParams.setValue(AVKey.PIXEL_FORMAT, AVKey.ELEVATION);

          String reqFormat = req.getFormat();
          if (null != reqFormat && reqFormat.endsWith("32")) {
            reqParams.setValue(AVKey.DATA_TYPE, AVKey.FLOAT32);
          } else {
            reqParams.setValue(AVKey.DATA_TYPE, AVKey.INT16);
          }
          reqParams.setValue(AVKey.MISSING_DATA_REPLACEMENT, missingDataReplacement);

          ByteBufferRaster reqRaster =
              new ByteBufferRaster(req.getWidth(), req.getHeight(), reqExtent, reqParams);

          raster.drawOnTo(reqRaster);

          if (SingleFileLayer.this.convertFeetToMeters) {
            this.convertFeetToMeters(reqRaster);
          }

          formatter = new DataRasterFormatter(reqRaster);
        } else {
          String msg =
              Logging.getMessage(
                  "generic.UnrecognizedImageSourceType", raster.getClass().getName());
          Logging.logger().severe(msg);
          throw new WMSServiceException(msg);
        }
      } catch (WMSServiceException wmsse) {
        throw wmsse;
      } catch (Exception ex) {
        Logging.logger()
            .log(
                java.util.logging.Level.SEVERE,
                SingleFileLayer.this.getThreadId() + ex.getMessage(),
                ex);
        // throw new WMSServiceException( s );
      } finally {
      }

      return formatter;
    }
コード例 #2
0
 protected double calcPixelSizeOfRequestArea(IMapRequest req) {
   Sector reqSector = req.getExtent();
   double reqHeight = (double) ((req.getHeight() > 0) ? req.getHeight() : 512);
   return (reqSector.getDeltaLatDegrees() / reqHeight);
 }