|
|
|
Ahmad Al-Obaidy
|
------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ Geotools-gt2-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
|||||||||||||||||
|
mbedward
|
Hi Ahmad,
I think the problem is the JAI "fileload" operation which is notorious for being unable to handle many tif formats. But also, you are doing a lot of work that GeoTools can do for you.
Here is an example... File file = ... GeoTiffReader reader = new GeoTiffReader(file); GridCoverage2D cov = (GridCoverage2D) reader.read(null);
GridEnvelope gridBounds = cov.getGridGeometry().getGridRange(); System.out.println("grid bounds: " + gridBounds); Envelope2D worldBounds = cov.getEnvelope2D();
System.out.println("world bounds: " + worldBounds); int numBands = cov.getNumSampleDimensions(); System.out.println("num bands: " + numBands);
CoordinateReferenceSystem crs = cov.getCoordinateReferenceSystem(); // get the value of the centre location as an example double[] values = new double[numBands];
double lon = worldBounds.getCenterX(); double lat = worldBounds.getCenterY(); DirectPosition dp = new DirectPosition2D(crs, lon, lat); cov.evaluate(dp, values);
System.out.println("value at " + dp + " is " + values[0]); As well as this you can still work directly with the underlying image using JAI iterators if you want to...
RenderedImage image = cov.getRenderedImage(); If you are using GeoTools 2.5.x you can convert between world coordinates and grid coordinates like this: MathTransform2D worldToGrid = cov.getGridGeometry().getCRSToGrid2D();
Point2D point = new Point2D.Double(lon, lat); Point2D gridPoint = worldToGrid.transform(point, null); If you are using GeoTools 2.6-M1 you can do this as well...
GridCoordinates2D gridCoords = cov.getGridGeometry().worldToGrid(pos); Hope this helps, Michael 2009/9/28 Ahmad Al-Obaidy <[hidden email]>
------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ Geotools-gt2-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
|
mbedward
|
PS. I forgot to include the imports for that code example...
import java.awt.geom.Point2D; import java.io.File; import org.geotools.coverage.grid.GridCoordinates2D; import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.gce.geotiff.GeoTiffReader; import org.geotools.geometry.DirectPosition2D; import org.geotools.geometry.Envelope2D; import org.geotools.swing.data.JFileDataStoreChooser;
import org.opengis.coverage.grid.GridEnvelope; import org.opengis.geometry.DirectPosition; import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.opengis.referencing.operation.MathTransform2D;
------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ Geotools-gt2-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |