提取每个像素值时丢失像素

时间:2019-03-27 11:50:00

标签: raster geotrellis

enter image description here我们正在尝试将lzw压缩栅格(tiff)转换为文本格式(意味着提取每个像素质心和band1值。。我们看到转换时会丢失栅格的某些部分。错过数据中的一种模式(数据以不等条纹的形式出现)。请查看快照..黄点表示已转换的质心,而与黄色没有重叠,则转换时会丢失数据。

我们尝试了图块大小128和256,但两种情况下的输出均不同

List<String> tiffExtensions = new ArrayList<>();
tiffExtensions.add(".tif");
tiffExtensions.add(".TIF");
tiffExtensions.add(".tiff");
tiffExtensions.add(".TIFF");

final scala.Option<CRS> crsNone = scala.Option.apply(null);
final scala.Option<Object> objectNone = scala.Option.apply(null);
final scala.Option<Object> numPartitionsObject = scala.Option.apply(new Integer(10));
final scala.Option<Object> tileSize = scala.Option.apply(Integer.parseInt("256"));
final scala.Option<Object> partitionBytes = scala.Option.apply(128l * 1024 * 1024);
HadoopGeoTiffRDD.Options options = new HadoopGeoTiffRDD.Options$().apply(
        JavaConverters.asScalaIteratorConverter(tiffExtensions.iterator()).asScala().toSeq(), crsNone,
        HadoopGeoTiffRDD.GEOTIFF_TIME_TAG_DEFAULT(), HadoopGeoTiffRDD.GEOTIFF_TIME_FORMAT_DEFAULT(), tileSize,
        numPartitionsObject, partitionBytes, objectNone);
RDD<Tuple2<ProjectedExtent, Tile>> rasterImageRdd = HadoopGeoTiffRDD.spatial(new Path(rastedImageDir), options,
        javaSparkContext.sc());
JavaRDD<Tuple2<ProjectedExtent, Tile>> rasterImageJavaRdd = rasterImageRdd.toJavaRDD();
JavaRDD<String> pixelRdd = rasterImageJavaRdd
        .flatMap(new FlatMapFunction<Tuple2<ProjectedExtent, Tile>, String>() {
            private static final long serialVersionUID = -6395159549445351446L;

            public Iterator<String> call(Tuple2<ProjectedExtent, Tile> v1) throws Exception {
                ArrayList<String> list = new ArrayList<String>();
                Tile t = v1._2;
                ProjectedExtent projectedExtent = v1._1;
                ProjectedRaster<CellGrid> r = new ProjectedRaster<CellGrid>(
                        new Raster<CellGrid>(t, projectedExtent.extent()), projectedExtent.crs());
                GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4283);
                WKTWriter wktWriter = new WKTWriter();
                for (int i = 0; i < t.rows(); i++) {
                    for (int j = 0; j < t.cols(); j++) {
                        StringBuilder sb = new StringBuilder();
                        if (!Double.isNaN(t.getDouble(j, i))) {
                            Double elevation = t.getDouble(j, i);
                            Tuple2<Object, Object> longLatTupel = r.raster().rasterExtent().gridToMap(j, i);
                            if (longLatTupel._2() != null && longLatTupel._1() != null) {
                                Double latitude = Double.parseDouble(longLatTupel._2() + "");
                                Double longitude = Double.parseDouble(longLatTupel._1() + "");
                                Point point = geometryFactory.createPoint(new Coordinate(longitude, latitude));
                                sb.append(elevation).append(TAB_SEP);
                                sb.append(point);
                                list.add(sb.toString());
                            }
                        }
                    }
                }
                return list.iterator();
            }
        });

_

0 个答案:

没有答案