当前位置: 首页>>代码示例>>Java>>正文


Java Band.WriteRaster方法代码示例

本文整理汇总了Java中org.gdal.gdal.Band.WriteRaster方法的典型用法代码示例。如果您正苦于以下问题:Java Band.WriteRaster方法的具体用法?Java Band.WriteRaster怎么用?Java Band.WriteRaster使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.gdal.gdal.Band的用法示例。


在下文中一共展示了Band.WriteRaster方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: copyToDataset

import org.gdal.gdal.Band; //导入方法依赖的package包/类
public void copyToDataset(Dataset ds, int dsWidth, int dsHeight, Bounds fullBounds, Bounds bounds,
    int tilesize, int zoomlevel, int gdaltype) throws IOException
{
  Pixel ulPixelTile = TMSUtils
      .latLonToPixelsUL(bounds.n, bounds.w, zoomlevel, tilesize);
  Pixel ulPixelDS = TMSUtils
      .latLonToPixelsUL(fullBounds.n, fullBounds.w, zoomlevel, tilesize);
  Pixel lrPixelTile = TMSUtils
      .latLonToPixelsUL(bounds.s, bounds.e, zoomlevel, tilesize);
  Pixel lrPixelDS = TMSUtils
      .latLonToPixelsUL(fullBounds.s, fullBounds.e, zoomlevel, tilesize);

  long leftPixel = Math.max(ulPixelDS.px, ulPixelTile.px);
  long rightPixel = Math.min(lrPixelDS.px, lrPixelTile.px);
  long topPixel = Math.max(ulPixelDS.py, ulPixelTile.py);
  long bottomPixel = Math.min(lrPixelDS.py, lrPixelTile.py);
  int xoffset = (ulPixelTile.px < leftPixel) ? (int) (leftPixel - ulPixelTile.px) : 0;
  int yoffset = (ulPixelTile.py < topPixel) ? (int) (topPixel - ulPixelTile.py) : 0;
  int xoffsetWrite = (int)(leftPixel - ulPixelDS.px);
  int yoffsetWrite = (int)(topPixel - ulPixelDS.py);
  int outWidth = (int) (rightPixel - leftPixel);
  int outHeight = (int) (bottomPixel - topPixel);

  byte[] rowdata = new byte[bytesPerPixel() * outWidth];
  for (int b = 0; b < ds.GetRasterCount(); b++) {
    for (int y = 0; y < outHeight; y++) {
      Band band = ds.GetRasterBand(b + 1); // gdal bands are 1's based
      System.arraycopy(data, calculateByteOffset(xoffset, y + yoffset, b), rowdata, 0, rowdata.length);
      int success = band.WriteRaster(xoffsetWrite, y + yoffsetWrite, outWidth, 1, outWidth, 1, gdaltype, rowdata);
      if (success != gdalconstConstants.CE_None) {
        throw new IOException("Failed writing raster. gdal error: " + success);
      }
    }
  }
}
 
开发者ID:ngageoint,项目名称:mrgeo,代码行数:36,代码来源:MrGeoRaster.java

示例2: toDataset

import org.gdal.gdal.Band; //导入方法依赖的package包/类
private Dataset toDataset(Dataset ds, int gdaltype, Bounds bounds,
    int xoffset, int yoffset,
    int outWidth, int outHeight,
    double[] nodatas)
{
  double[] xform = new double[6];
  if (bounds != null)
  {

    xform[0] = bounds.w;
    xform[1] = bounds.width() / outWidth;
    xform[2] = 0;
    xform[3] = bounds.n;
    xform[4] = 0;
    xform[5] = -bounds.height() / outHeight;

    ds.SetProjection(GDALUtils.EPSG4326());
  }
  else
  {
    xform[0] = 0;
    xform[1] = outWidth;
    xform[2] = 0;
    xform[3] = 0;
    xform[4] = 0;
    xform[5] = -outHeight;
  }
  ds.SetGeoTransform(xform);

  byte[] rowdata = new byte[bytesPerPixel() * outWidth];

  for (int b = 0; b < bands; b++)
  {
    Band band = ds.GetRasterBand(b + 1); // gdal bands are 1's based
    if (nodatas != null)
    {
      if (b < nodatas.length)
      {
        band.SetNoDataValue(nodatas[b]);
      }
      else
      {
        band.SetNoDataValue(nodatas[nodatas.length - 1]);
      }
    }
    for (int y=0; y < outHeight; y++) {
      System.arraycopy(data, calculateByteOffset(xoffset, y + yoffset, b), rowdata, 0, rowdata.length);
      int success = band.WriteRaster(0, y, outWidth, 1, outWidth, 1, gdaltype, rowdata);
      if (success != gdalconstConstants.CE_None)
      {
        System.out.println("Failed writing raster. gdal error: " + success);
        break;
      }
    }
  }

  return ds;
}
 
开发者ID:ngageoint,项目名称:mrgeo,代码行数:59,代码来源:MrGeoRaster.java


注:本文中的org.gdal.gdal.Band.WriteRaster方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。