Hello,

I am back with my problem... I am always trying to put some information into
my raster, but it seems that my MathTransform does not give me the good
tranformation...
I am doing this :

int rasterSizeY = gc2d.getRenderedImage().getHeight();
int rasterSizeX = gc2d.getRenderedImage().getWidth();

WritableRaster oldLOSGrid =
RasterFactory.createBandedRaster(DataBuffer.TYPE_BYTE,

rasterSizeX, rasterSizeY, 1, null);

 Envelope2D env = gc2d.getEnvelope2D();
 DirectPosition2D leftup = new
DirectPosition2D(env.getMinX(),env.getMaxY());
 DirectPosition2D rightdown = new
DirectPosition2D(env.getMaxX(),env.getMinY());
 DirectPosition2D center = new
DirectPosition2D((env.getMaxX()-env.getMinX())/2,
(env.getMaxY()-env.getMinY())/2);

 List<MappedPosition> list = new ArrayList<MappedPosition>(2);

 MappedPosition mp1 = new MappedPosition(leftup, new DirectPosition2D(0,0));
 MappedPosition mp2 = new MappedPosition(rightdown, new
DirectPosition2D(rasterSizeX,rasterSizeY));
 MappedPosition mp3 = new MappedPosition(center, new
DirectPosition2D(rasterSizeX/2,rasterSizeY/2));

 list.add(mp1);
 list.add(mp2);
 list.add(mp3);

 //MathTransformBuilder mtb = new SimilarTransformBuilder(list);
 MathTransformBuilder mtb = new AffineTransformBuilder(list);
 MathTransform mt = null;
 DirectPosition result = null;
 try {
     mt = mtb.getMathTransform();
} catch (FactoryException ex) {
     Logger.getLogger(Site.class.getName()).log(Level.SEVERE, null, ex);
}

Indeed, the origin of a WritableRaster is the left up corner.

Then, I write my datas in the raster like this :

result = mt.transform(new
DirectPosition2D(oldPath.get(i)[1],oldPath.get(i)[0]), result); // [1] & [0]
are respectively longitude and latitude of my point
int x1 = (int)result.getCoordinates()[0];
int y1 = (int)result.getCoordinates()[1];
try{
       oldLOSGrid.setSample(x1, y1, 0, 200);
}catch(ArrayIndexOutOfBoundsException aioe){
       System.out.println("ERROR 1");
}

Finally, I put the WritableRaster into a GridCoverage and write it in a
geotiff file...
But when i open this geotiff with Quantum or udig, the points are not well
georeferenced...!
Is there something wrong in my code ?

Thanks !!
Thomas

2008/5/7 Anaxa Gore <[EMAIL PROTECTED]>:

> Hi Jan !
>
> Thanks for resources on MathTransformBuilder !
> It will be helpful !
>
> Thomas
>
> 2008/5/7 Jan Jezek <[EMAIL PROTECTED]>:
>
> Hi Thomas,
> >
> > >
> > >PS : Is there any documentation explaining more in detail than the
> > javadoc
> > >the use of different MathTransforms ?...
> > >
> >
> > If you mean code examples etc.. then you can take a look in unit tests
> > of MathTransformaBuilder.
> >
> >
> > http://svn.geotools.org/geotools/trunk/gt/modules/library/referencing/src/test/java/org/geotools/referencing/operation/builder/MathTransformBuilderTest.java
> >
> > there is no other documentation than javadoc about what you want yet (my
> > bad).
> >
> > If you mean the theory of LSM and 2D  transformations (Similar, Affine,
> > Projective) then there are many resources on the internet  (wikipedia), but
> > actually I don't know about documentation focused just on this topic a
> > describing it all together.
> >
> > I'm just working on command line utility for generating worldfile from
> > set of GCPs with control of used transformation method and errors
> > statistics.I'll have to write some documentation about that as well (but
> > maybe just in Czech language). I'll inform about that when I'll finish it.
> >
> >
> > Bests,
> > Jan.
> >
> >
> >
> > >2008/5/6 Anaxa Gore <[EMAIL PROTECTED]>:
> > >
> > >> Hi,
> > >>
> > >> I want to write some georeferenced informations into a
> > GridCoverage2D.
> > To
> > >> do this, I create a Writable Raster, like this :
> > >>
> > >> final int width  = 5000;
> > >> final int height = 5000;
> > >> WritableRaster raster =
> > >> RasterFactory.createBandedRaster(DataBuffer.TYPE_FLOAT,width, height,
> > 1,
> > >> null);
> > >>
> > >> I perform some calculation on my datas and then want to write some
> > points
> > >> into the raster, just created. So I suppose I need a MathTransform,
> > from my
> > >> Envelope2D, describing my geograhic area, to my raster
> > coordinates...?
> > >> I am doing something like this :
> > >>
> > >> DirectPosition2D leftdown = new DirectPosition2D(102.0,23.0);
> > >> DirectPosition2D rightup = new DirectPosition2D(103.0,24.0);
> > >> DirectPosition2D inter = new DirectPosition2D(102.5,23.5);
> > >> Envelope2D env = new Envelope2D(leftdown, rightup);
> > >>
> > >> List<MappedPosition> list = new ArrayList<MappedPosition>(2);
> > >>
> > >> MappedPosition mp1 = new MappedPosition(new DirectPosition2D(0,0),
> > >> leftdown);
> > >> MappedPosition mp2 = new MappedPosition(new
> > >> DirectPosition2D(width,height),rightup);
> > >> MappedPosition mp3 = new MappedPosition(new
> > >> DirectPosition2D(width/2,height/2), inter);
> > >>
> > >> list.add(mp1);
> > >> list.add(mp2);
> > >> list.add(mp3);
> > >>
> > >> AffineTransformBuilder mtb = new AffineTransformBuilder(list);
> > >> MathTransform mt = null;
> > >>
> > >> try {
> > >>         mt = mtb.getMathTransform();
> > >> } catch (FactoryException ex) {
> > >>
> > Logger.getLogger(_2_WriteRaster.class.getName()).log(Level.SEVERE,
> > >> null, ex);
> > >> }
> > >>
> > >> But I always get this error, when trying to get the MathTransform :
> > >>
> > >> Exception in thread "main" javax.vecmath.SingularMatrixException:
> > cannot
> > >> invert matrix
> > >>         at javax.vecmath.GMatrix.invertGeneral(GMatrix.java:1711)
> > >>         at javax.vecmath.GMatrix.invert(GMatrix.java:397)
> > >>         at
> > >>
> >
> > org.geotools.referencing.operation.builder.ProjectiveTransformBuilder.calculateLSM(ProjectiveTransformBuilder.java:243)
> > >>         at
> > >>
> >
> > org.geotools.referencing.operation.builder.AffineTransformBuilder.getProjectiveMatrix(AffineTransformBuilder.java:99)
> > >>         at
> > >>
> >
> > org.geotools.referencing.operation.builder.ProjectiveTransformBuilder.computeMathTransform(ProjectiveTransformBuilder.java:280)
> > >>         at
> > >>
> >
> > org.geotools.referencing.operation.builder.MathTransformBuilder.getMathTransform(MathTransformBuilder.java:687)
> > >>         at
> > >>
> >
> > org.geotools.referencing.operation.builder.MathTransformBuilder.getErrorStatistics(MathTransformBuilder.java:645)
> > >>         at
> > >>
> >
> > org.geotools.referencing.operation.builder.MathTransformBuilder.getTransformation(MathTransformBuilder.java:733)
> > >>         at
> > >> geotools_tests.rasters._2_WriteRaster.main(_2_WriteRaster.java:117)
> > >>
> > >> Is there something wrong in my code ?
> > >> Thomas
> > >>
> > >
> >
> > >-------------------------------------------------------------------------
> > >This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> > >Don't miss this year's exciting event. There's still time to save $100.
> > >Use priority code J8TL2D2.
> > >
> > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> > >_______________________________________________
> > >Geotools-gt2-users mailing list
> > >[email protected]
> > >https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
> > >
> > >
> >
> >
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to