Ciao Alexander, exactly which version of geotools are you using? Recently we have introduce a dependency in geotiff from imageio-ext tiff where we fixed a few bugs from imageio. One of this was exactly the one you mention, regardless of whether you passed over a float or double tiff imageio was lways converting to integer (32 bits).
Simone. ------------------------------------------------------- Ing. Simone Giannecchini GeoSolutions S.A.S. Owner - Software Engineer Via Carignoni 51 55041 Camaiore (LU) Italy phone: +39 0584983027 fax: +39 0584983027 mob: +39 333 8128928 http://www.geo-solutions.it http://simboss.blogspot.com/ http://www.linkedin.com/in/simonegiannecchini ------------------------------------------------------- On Sun, Jun 7, 2009 at 10:32 AM, Alexander Weidauer<[email protected]> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Dear List, > > I've a strange problem. I use to work with Geotools 2.5 and try to store > results form a triangulation patch in a GeoTiff. The patch operates on a > double matrix. But when I build the GeoTiff, I get an int32 > context. Are there mistakes in my code? > > Sorry it's a little bit long. > > 1. I use routine createDoubleGridCovarage to create the cover. I do > this in a normal way via JAI. > > 2. I use the routine sampleTriangleGeoTiff to create the sampling cover. > > 3. Main put this things together. > > 4. There is the gdalinfo output with > Band 1 Block=123x16 >>>> Type=Int32, <<< ColorInterp=Gray > > //______________________________________________________________________ > /** > * Create a GridCoverage with a double sampling model. > * <pre> > * It is important to have the height/width order here ! > * int count = 0; > * for (int h = 0; h < height; h++) { > * for (int w = 0; w < width; w++) { > * doubleBuffer[count++] = (double) ..... > * } > * } > * </pre> > * @param title title of the coverage > * @param env envelope > * @param double Buffer data content > * @param width width of the buffer > * @param height height of the buffer > * @return a GridCoverage 2D in a geo referenced context > * @todo Problem double goes in int32 comes out? > */ > public static GridCoverage2D createDoubleGridCovarage( > String title, > Envelope2D env, double[] doubleBuffer, > int width, int height) { > > //___________________________________________________________ > // The default way to create a double tiff > DataBuffer dataBuffer = new javax.media.jai.DataBufferDouble( > doubleBuffer, width * height); > > SampleModel sampleModel = > RasterFactory.createBandedSampleModel( > DataBuffer.TYPE_DOUBLE, width, height, 1); > > ColorModel colorModel = > PlanarImage.createColorModel(sampleModel); > > Raster rasterModel = > RasterFactory.createWritableRaster(sampleModel, > dataBuffer, new java.awt.Point(0, 0)); > > TiledImage img = new TiledImage(0, 0, width, height, 0, 0, > sampleModel, colorModel); > > img.setData(rasterModel); > > //_____________________________________________________________ > // The geotiff part > GridCoverageFactory fac = CoverageFactoryFinder. > getGridCoverageFactory(null); > > GridCoverage2D result = fac.create(title, img, env); > return result; > } > > > //__________________________________________________________________________ > /** > * Conversation of a triangulation set to a coverage by a given > raster width. > * @param tringleList The triangulation list > * @param inverseHeight switch the skalar field into a negative one > * @param srcEPSG Source Cooordinate reference Sytem > * @param dstEPSG Target Coordinate reference system > * @param rasterWidth Rasterwidth of the cell > * @param valueNaN Values for areas without triangles > * @return The double GeoCoverage2D > * @throws org.opengis.referencing.NoSuchAuthorityCodeException > * @throws org.opengis.referencing.FactoryException > * @throws org.opengis.geometry.MismatchedDimensionException > * @throws org.opengis.referencing.operation.TransformException > * @throws java.io.IOException > * @todo int32 comes out > * @todo exchange the raster width by using the inverse of > * the transformation set of a source cover? > */ > public static GridCoverage2D sampleTriangleGeoTiff( > TriangleList tringleList, > boolean inverseHeight, > int srcEPSG, int dstEPSG, > double rasterWidth, > double valueNaN) throws > NoSuchAuthorityCodeException, FactoryException, > MismatchedDimensionException, > TransformException, IOException { > > //_______________________________________________________________ > CoordinateReferenceSystem dstCRS = > CRS.decode("EPSG:" + dstEPSG, true); > CoordinateReferenceSystem srcCRS = > CRS.decode("EPSG:" + srcEPSG, true); > //_______________________________________________________________ > // Recalculate the triangulation into the tatrger CRS > if (srcEPSG != dstEPSG) { > tringleList.transform(srcEPSG, dstEPSG); > } > //_______________________________________________________________ > // Now Envelope in the target CRS > Envelope triEnv = tringleList.getEnvelope(); > > //_______________________________________________________________ > // Envlope 2D > Envelope2D env = new Envelope2D(dstCRS, > triEnv.getMinX(), triEnv.getMinY(), > triEnv.getWidth(), triEnv.getHeight()); > > //________________________________________________________________ > // Create a Data Buffer from the values on the single image array. > double fWidht = (double) (triEnv.getWidth() / rasterWidth); > double fHeight = (double) (triEnv.getHeight() / rasterWidth); > int width = (int)Math.round(fWidht); > int height =(int)Math.round(fHeight); > double[] doubleBuffer = new double[width * height]; > > //_______________________________________________________________ > // Create an empty coverage to get the transformation data > GridCoverage2D result = createDoubleGridCovarage( > "What Transforms", env, doubleBuffer, > width, height); > // Transformation from grid to world coordinates > MathTransform2D trfmGridToWorldCRS = > result.getGridGeometry().getGridToCRS2D(); > > // Transformation from world to grid coordinates > MathTransform2D trfmWorldToGridCRS = trfmGridToWorldCRS.inverse(); > //_______________________________________________________________ > // Resampling of triangle into the doubleBuffer > // It is important to have the height/width order here ! > int count = 0; > for (int h = 0; h < height; h++) { > for (int w = 0; w < width; w++) { > > // translate the grid coordinate into a > // point for transformation > Point2D.Double pntImage = new Point2D.Double(w, h); > Point2D.Double pntWorld = new Point2D.Double(); > trfmGridToWorldCRS.transform(pntImage, pntWorld); > > // Find matching triangles at coordinate > // @todo do that in a window > // w-rasterWidth, h-rasterWidth > // w+rasterWidth, h+rasterWidth > // to get more triangles in case of small pieces > Coordinate samplePoint = > new Coordinate(pntWorld.x, pntWorld.y); > ArrayList<Triangle> lst = > > triangelList.findTrianglesAtCoordinate(samplePoint); > > // resample the triangle set > //@todo other operators than average > double d = 0; > if (lst != null && lst.size() > 0) { > // collect the data set > for (int i = 0; i < lst.size(); i++) { > Triangle tmp = lst.get(i); > d += ConvexCombination.calcCombi( > tmp, samplePoint); > } > // create the average value > d = d / lst.size(); > } else { > d = valueNaN; > } > if (inverseHeight) { > doubleBuffer[count++] = (double) -d; > } else { > doubleBuffer[count++] = (double) d; > } > } > } > // Create the coverage > result = createDoubleGridCovarage( > "Resampled Cover", env, doubleBuffer, > width, height); > // ready > return result; > } > > > //__________________________________________________________________________ > public static void main(String[] args) { > try { > // Triangulation set made by J. Shewchuck triangle > String inFile = "data/files/0-cover-base.1"; > String outFile = inFile + ".tif"; > TriangleList list = > Triangulator.readPlainTriangulationSet(inFile); > GridCoverage2D cover = TriangleList.sampleTriangleGeoTiff( > list, true, // list, swapValues > 4326, 3035, // EPSG's > 50, 9999); // rasterWidth, NaN > File out = new File(outFile); > GeoTiffWriter geoTiffWriter = new GeoTiffWriter(out); > geoTiffWriter.write(cover, null); > } catch (Exception e) { > e.printStackTrace(); > } > > } > > //__________________________________________________________________ > ~/data/files/> gdalinfo S433846_84.bltz.3.tif > Driver: GTiff/GeoTIFF > Files: S433846_84.bltz.3.tif > Size is 123, 103 > Coordinate System is: > PROJCS["ETRS89 / ETRS-LAEA", > GEOGCS["ETRS89", > DATUM["European_Terrestrial_Reference_System_1989", > SPHEROID["GRS 1980",6378137,298.2572221010002, > AUTHORITY["EPSG","7019"]], > AUTHORITY["EPSG","6258"]], > PRIMEM["Greenwich",0], > UNIT["degree",0.0174532925199433], > AUTHORITY["EPSG","4258"]], > UNIT["metre",1, > AUTHORITY["EPSG","9001"]], > AUTHORITY["EPSG","3035"]] > Origin = (4561911.309193897061050,3481239.348060310818255) > Pixel Size = (49.819593262010656,-50.213355504722308) > Metadata: > AREA_OR_POINT=Point > TIFFTAG_XRESOLUTION=1 > TIFFTAG_YRESOLUTION=1 > TIFFTAG_RESOLUTIONUNIT=1 (unitless) > Image Structure Metadata: > INTERLEAVE=BAND > Corner Coordinates: > Upper Left ( 4561911.309, 3481239.348) > Lower Left ( 4561911.309, 3476067.372) > Upper Right ( 4568039.119, 3481239.348) > Lower Right ( 4568039.119, 3476067.372) > Center ( 4564975.214, 3478653.360) > Band 1 Block=123x16 Type=Int32, ColorInterp=Gray > > > - -- > Alexander Weidauer > __________________ _ __ ______ ______ > / _/ __/ ____/ __ \ | / / / _/ |/ / | > / // /_/ / __/ / / / | / /_____ / // /|_/ / /| | > _/ // __/ /_/ / /_/ /| |/ /_____// // / / / ___ | > /___/_/ \____/_____/ |___/ /___/_/ /_/_/ |_| > > Institut für Geodatenverarbeitung > Informationsdienste, -modelle und -applikationen > Tel.: 038333-527 > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.4-svn0 (GNU/Linux) > Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org > > iD8DBQFKK3s2MC1o6iopHygRAo6jAJ9NNZTFJoM8yF22MUWShHF6w770kwCfbdbP > K5MzBzVpduRUgrH2lAt301s= > =Qz5s > -----END PGP SIGNATURE----- > > ------------------------------------------------------------------------------ > OpenSolaris 2009.06 is a cutting edge operating system for enterprises > looking to deploy the next generation of Solaris that includes the latest > innovations from Sun and the OpenSource community. Download a copy and > enjoy capabilities such as Networking, Storage and Virtualization. > Go to: http://p.sf.net/sfu/opensolaris-get > _______________________________________________ > Geotools-devel mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/geotools-devel > ------------------------------------------------------------------------------ OpenSolaris 2009.06 is a cutting edge operating system for enterprises looking to deploy the next generation of Solaris that includes the latest innovations from Sun and the OpenSource community. Download a copy and enjoy capabilities such as Networking, Storage and Virtualization. Go to: http://p.sf.net/sfu/opensolaris-get _______________________________________________ Geotools-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-devel
