0

在此处输入图像描述我们正在尝试将 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();
            }
        });

_

4

0 回答 0