Hi Jiri,
I can confirm the error with your image file. I'll leave it to Simone,
Andrea and others who know the GeoTools coverage-related code well to
diagnose the problem.
In the meantime, here is a possible work-around is to use JAI to read
your image directly and then use the JAITools Vectorize image
operation to create polygons...
ParameterBlockJAI pb = new ParameterBlockJAI("ImageRead");
pb.setParameter("input", "/Users/michael/coding/geotools/data/test.tif");
RenderedOp op = JAI.create("ImageRead", pb);
pb = new ParameterBlockJAI("Vectorize");
pb.setSource("source0", op);
RenderedOp vop = JAI.create("Vectorize", pb);
Collection<Polygon> polys = (Collection<Polygon>)
vop.getProperty(VectorizeDescriptor.VECTOR_PROPERTY_NAME);
The javadocs for the Vectorize operation are here:
http://jaitools.org/docs/jaitools/stable/apidocs/org/jaitools/media/jai/vectorize/VectorizeDescriptor.html
I've just tested this with your image and it seems to work.
Note that this will give you polygons with vertices expressed in image
coordinates. You can then use an AffineTransform or similar to convert
these into world coordinates, after which you can create a
SimpleFeatureCollection from them.
Hope this helps.
Michael
On 25 July 2011 07:09, Jiří Novák <[email protected]> wrote:
> Hi everybody,
>
> I'am a newbie in using Geotools and I have the following problem:
>
> I need to "vectorize" polygons from black & white raster in 'test.tif'
> format.
>
> I was trying to follow those documentations:
> - http://docs.geotools.org/latest/userguide/library/coverage/grid.html
> - http://docs.geotools.org/latest/javadocs/
>
> When I open my tif in qgis, it says that the projection is:
>
> +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
>
> Nevertheless with:
> final File file = new
> File("/home/jirka/hibernate-spatial/event-tutorial/test.tif");
> AbstractGridFormat format = GridFormatFinder.findFormat(file);
> AbstractGridCoverage2DReader reader = format.getReader(file);
>
> I just get:
> Exception in thread "main" java.lang.UnsupportedOperationException: Trying
> to get a reader from
> an unknown format.
> at
> org.geotools.coverage.grid.io.UnknownFormat.getReader(UnknownFormat.java:62)
> at event.App.main(App.java:42)
>
> When following the tests
> (http://svn.osgeo.org/geotools/trunk/modules/plugin/geotiff/src/test/java/org/geotools/gce/geotiff/GeoTiffReaderTest.java)
> and trying:
> final File file = new
> File("/home/jirka/hibernate-spatial/event-tutorial/test.tif");
>
> // hint for CRS
> CoordinateReferenceSystem crs = CRS.decode("EPSG:4326", true);
> final Hints hint = new Hints();
> hint.put(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, crs);
>
> // getting a reader
> GeoTiffReader reader = new GeoTiffReader(file, hint);
> I get:
> Exception in thread "main" org.geotools.data.DataSourceException: Raster to
> Model
> Transformation is not available
> at org.geotools.gce.geotiff.GeoTiffReader.<init>(GeoTiffReader.java:228)
> at event.App.main(App.java:37)
>
> Caused by: org.geotools.data.DataSourceException: Raster to Model
> Transformation is not
> available
> at org.geotools.gce.geotiff.GeoTiffReader.getHRInfo(GeoTiffReader.java:385)
> at org.geotools.gce.geotiff.GeoTiffReader.<init>(GeoTiffReader.java:215)
> ... 1 more
>
> My maven dependencies settings are:
> <dependency>
> <groupId>org.geotools</groupId>
> <artifactId>gt-process</artifactId>
> <version>8.0-M1</version>
> </dependency>
>
> <dependency>
> <groupId>org.geotools</groupId>
> <artifactId>gt-geotiff</artifactId>
> <version>8.0-M1</version>
> </dependency>
>
> <dependency>
> <groupId>org.geotools</groupId>
> <artifactId>gt-image</artifactId>
> <version>8.0-M1</version>
> </dependency>
>
> <dependency>
> <groupId>org.geotools</groupId>
> <artifactId>gt-coverage</artifactId>
> <version>8.0-M1</version>
> </dependency>
>
> <dependency>
> <groupId>org.geotools</groupId>
> <artifactId>gt-epsg-hsql</artifactId>
> <version>8.0-M1</version>
> </dependency>
>
> Could anybody give me some hint (workaround) how to get this tif (probably
> with not properly set metadata information) vectorized?
>
> Thank you very much, for any piece of information,
>
> Jiri Novak
>
> ------------------------------------------------------------------------------
> Magic Quadrant for Content-Aware Data Loss Prevention
> Research study explores the data loss prevention market. Includes in-depth
> analysis on the changes within the DLP market, and the criteria used to
> evaluate the strengths and weaknesses of these DLP solutions.
> http://www.accelacomm.com/jaw/sfnl/114/51385063/
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>
------------------------------------------------------------------------------
Storage Efficiency Calculator
This modeling tool is based on patent-pending intellectual property that
has been used successfully in hundreds of IBM storage optimization engage-
ments, worldwide. Store less, Store more with what you own, Move data to
the right place. Try It Now! http://www.accelacomm.com/jaw/sfnl/114/51427378/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users