Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[geotrellis-user] Data Missing when extracting pixel value from Raster

Hello We are trying to convert lzw compressed raster(tiff) into text format(meaning extracting each pixel centroid and band1 value.. We see that some parts of the raster is missed while conversion.. however there is a pattern in miss data (data is coming in unequal striped pattern) Please see snapshot attached .. Yellow dots shows the centroid converted while no overlap with yellow the data is missed while converting..

Code :-

    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();
                }
            });
--
Regards
Ashish Agarwal


Ph - +91- 9711163631

Attachment: strippedPattern.png
Description: PNG image


Back to the top