From: Mwhei <yan...@16...> - 2007-11-11 07:53:19
|
Hello dear everyone, Excuse me to ask a question.I make some codes as follows.There is a geotiff raster map.The function of those codes is to let the values of ever= y pix be multified by 2.Then output a new geotiff raster map.But when I click the map I make, it cannot be previewed under Windows.And it can be opened i= n QGIS,can not be opened in Udig.Who can give me some suggestions?Thank you very much! = =20 Sincerely yours, = =20 Yang import java.awt.image.BufferedImage; import java.awt.image.DataBuffer; import java.awt.image.Raster; import java.awt.image.WritableRaster; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.media.jai.RasterFactory; import org.geotools.coverage.FactoryFinder; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.GridCoverageFactory; import org.geotools.gce.geotiff.GeoTiffWriter; import org.geotools.geometry.GeneralEnvelope; import org.geotools.referencing.CRS; import org.opengis.referencing.FactoryException; import org.opengis.referencing.NoSuchAuthorityCodeException; import org.opengis.referencing.crs.CoordinateReferenceSystem; public class GetoolsReadGeotiff { =09public static void main (String args[]) =09{ =09=09File f1 =3D new File("data/geotiff.tiff"); =09=09 =20 =09 BufferedImage bufferedImage =3D null; =09=09 =09=09 GeneralEnvelope dataEnvelope=3Dnull; =09=09=20 =09=09try { =09=09=09 =09=09=09bufferedImage =3D ImageIO.read(f1); =09=09 =09=09} catch (IOException e) { =09=09=09// TODO Auto-generated catch block =09=09=09e.printStackTrace(); =09=09}=20 =09 //=E8=8E=B7=E5=8F=96=E6=95=B0=E6=8D=AE=E6=B5=81 =09=09DataBuffer db =3D bufferedImage.getData().getDataBuffer();=20 =09 =09//=E8=8E=B7=E5=8F=96=E6=A0=85=E6=A0=BC=09 =09=09 Raster sourceraster=3DbufferedImage.getData(); =09=09 =09=09 =09=09=20 =09=09// =E5=8F=96=E5=87=BA=E6=AF=8F=E4=B8=AA=E8=B1=A1=E7=B4=A0=E5=80=BC=E8= =BE=93=E5=87=BA=E5=88=B0=E6=96=87=E4=BB=B6=20 =09/* try{ =20 FileWriter letters =3D new =20 FileWriter("data/output.txt",true); =20 BufferedWriter buff =3D new BufferedWriter(letters); = =20 for(int i=3D0;i<db.getSize();i++) {=20 =09 buff.write(" "+db.getElem(i)); =20 =09 if(i!=3D0&&i%(sourceraster.getWidth()-1)=3D=3D0) buff.write= ("\n");=20 } =20 buff.newLine(); =20 buff.close(); =20 =20 System.out.println("=E8=BE=93=E5=87=BA=E5=AE=8C=E6=AF=95=EF=BC= =81"); =20 }catch(IOException e){ =20 System.out.println("Error-- "+e.toString()); =20 } */=20 =09=09final int width =3D sourceraster.getWidth(); =20 =09=09final int height =3D sourceraster.getHeight(); =20 =09=09WritableRaster raster =3D RasterFactory.createBandedRaster(DataBuffer.TYPE_FLOAT, width, height, 1, null); for (int y=3D0; y<height; y++) { for (int x=3D0; x<width; x++) { raster.setSample(x, y, 0, 2*sourceraster.getSample(x, y, 0)); } } =20 CoordinateReferenceSystem crs=3Dnull; =09=09try { =09=09=09crs =3D CRS.decode("EPSG:4326"); =09=09} catch (NoSuchAuthorityCodeException e1) { =09=09 e1.printStackTrace(); =09=09} catch (FactoryException e1) { =09=09 e1.printStackTrace(); =09=09} =20 GeneralEnvelope envelope=3D dataEnvelope; =20 envelope.setCoordinateReferenceSystem(crs); =20 GridCoverageFactory factory =3D FactoryFinder.getGridCoverageFactory(null); =20 =20 GridCoverage2D gc =3D factory.create("My grayscale coverage", rast= er, envelope); =09=09 =20 =20 =20 File f2 =3D new File("data/geotiff1.tiff"); =20 GeoTiffWriter gtw; =09=09 try { =09=09=09 gtw =3D new GeoTiffWriter(f2); =09=09=09 =09=09=09 gtw.write( gc, null); =09=09=09 =09=09=09// GeoTiffReader gr =3D new GeoTiffReader(f2, null); =09=09 =20 =09=09=09// GridCoverage gc2 =3D gr.read(null); =09=09=09=20 =09=09=09 System.out.println("=E8=BE=93=E5=87=BA=E5=AE=8C=E6=AF=95=EF=BC=81= "); =20 =09=09 } catch (IOException e) { =09=09=09=20 =09=09=09e.printStackTrace(); =09=09}=20 =09 =09} } =20 --=20 View this message in context: http://www.nabble.com/Hello-dear-sir%2Cwhy-th= e-geotiff-raster-map-I-make-out--is-Abnormal--tf4785062.html#a13689225 Sent from the geotools-gt2-users mailing list archive at Nabble.com. |
From: Jody G. <jga...@re...> - 2007-11-19 15:10:45
|
Mwhei wrote: > Hello dear everyone, > Excuse me to ask a question.I make some codes as follows.There is a > geotiff raster map.The function of those codes is to let the values of every > pix be multified by 2.Then output a new geotiff raster map.But when I click > the map I make, it cannot be previewed under Windows.And it can be opened in > QGIS,can not be opened in Udig.Who can give me some suggestions?Thank you > very much! > Our uDig stuff has lagged behind by several geotools releases; there is a "Tech Preview" somewhere which Jesse will anounce that can be used to demo improved raster support (basically the results of the FOSS4G code sprint). Jody |