Ciao Gabriella,
I understand you are trying to create a GridCoverage2D from a
worldimage whose raster is a jpeg image.

If this guess is correct then the code you are using is incorrect.

A correct snippet of code to cope with your needs would be as follows:

// get a reader
final WorldImageReader wiReader = new WorldImageReader(new
File("data/nz2_2.jpg"));

// get the coverage
final GridCoverage2D gc = (GridCoverage2D) wiReader.read(null);


A couple of remarks:

You need to let the WorldImageReader point to a valid world file which
means, a raster (like your jpeg, let' say coverage.jpeg), a world file
(the jgw or better rename it as wld) like coverage.wld) and a prj file
that contains the wkt representation of the coordinate reference
ssytem for the raster (coverage.prj). Attention, if no prj is provided
the actual behaviour is to assume EPSG:4326 but I am planning on
adding the capability to provide to specify the CRS via a Read
Parameters in order to let you specifiy the crs on the fly if no PRJ
is availaible. In case you need it, here is the WKT that you have to
put in your_coverage_name.prj file for your crs:

PROJCS["NZGD49 / New Zealand Map Grid",
  GEOGCS["NZGD49",
    DATUM["New_Zealand_Geodetic_Datum_1949",
      SPHEROID["International 1924", 6378388.0, 297.0,
AUTHORITY["EPSG","7022"]],
      TOWGS84[59.47, -5.04, 187.44, 0.47, -0.1, 1.024, -4.5993],
      AUTHORITY["EPSG","6272"]],
    PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]],
    UNIT["degree", 0.017453292519943295],
    AXIS["Lon", EAST],
    AXIS["Lat", NORTH],
    AUTHORITY["EPSG","4272"]],
  PROJECTION["New_Zealand_Map_Grid"],
  PARAMETER["latitude_of_origin", -41.0],
  PARAMETER["central_meridian", 173.0],
  PARAMETER["false_easting", 2510000.0],
  PARAMETER["false_northing", 6023150.0],
  UNIT["m", 1.0],
  AXIS["x", EAST],
  AXIS["y", NORTH],
  AUTHORITY["EPSG","27200"]]

In order to get everything working you might have to add some more
dependencies to your classpath and probably to start up your up with
some good -D properties.
I would do as follows. Create a prj file next to your raster and try
the code I gave you. Then we will be on the same line and I will be
able to track down possible issues (anyway a bit more info about what
you are doing will be needed).


Let me point out that your input as a user is highly appreciated,
hence feel free to mail me and the list with your
problems/concerns/doubts anytime you want.



Regards,
Simone.



On 10/10/06, Gabriella Turek <[EMAIL PROTECTED]> wrote:
> I've tried to recompile my 2.2 code to 2.3_M0 and it does not (not
> unexpected), so I've been trying to modify my code to make it work, but
> I've had no success.
>
> With 2.2 I was able to plot georeferenced images, shape files and
> features in a CSV table even though, strangely enough, I get
> the error:
>
> SEVERE: Data source and map context coordinate system differ, yet it was
> not possible to get a projected bounds estimate...
> org.opengis.referencing.operation.OperationNotFoundException: Bursa wolf
> parameters required
>
> even though everything seems to plot correctly.
>
> For 2.3_MO I am not having any luck. What is no longer working is the
> plotting of the georeferenced images, which in 2.2 I did via
>
> URL imgURL = (new File("data/nz2_2.jpg")).toURL();
> GridCoverage gc = wir.read(null);
> CoordinateReferenceSystem crs = gc.getCoordinateReferenceSystem();
> crs = CRS.decode("EPSG:27200");
>
> and in 2.3_M0 I must do via:
>
> BufferedImage image = ImageIO.read(new File("data/nz2_2.jpg"));
> WorldFile wf = new WorldFile(new File("data/nz2_2.jgw"));
> WritableRaster wr = image.getRaster();
> GeneralEnvelope envelope = new GeneralEnvelope(new
> Rectangle2D(wr.getBounds());
> GridCoverageFactory factory =
> org.geotools.coverage.FactoryFinder.getGridCoverageFactory(null);
> GridCoverage2D gc = factory.create("Map", wr, envelope);
> CoordinateReferenceSystem crs = CRS.decode("EPSG:27200");
>                 gc = factory.create(gc.getName(), gc.getRenderedImage(),
> crs, gc.getGridGeometry().getGridToCoordinateSystem(),
> gc.getSampleDimensions(), null, null);
>
> In this case I get
> Oct 10, 2006 3:37:21 PM StreamingRenderer processStylers
> SEVERE: null
> java.lang.NullPointerException
>        at com.vividsolutions.jts.geom.Envelope.init(Envelope.java:254)
>        at com.vividsolutions.jts.geom.Envelope.<init>(Envelope.java:186)
>        at
> org.geotools.geometry.jts.ReferencedEnvelope.<init>(ReferencedEnvelope.java:112)
>        at
> org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer.<init>(GridCoverageRenderer.java:158)
>        at StreamingRenderer.renderRaster(StreamingRenderer.java:1717)
>        at StreamingRenderer.processSymbolizers(StreamingRenderer.java:1578)
>        at StreamingRenderer.process(StreamingRenderer.java:1522)
>        at StreamingRenderer.processStylers(StreamingRenderer.java:1464)
>        at StreamingRenderer.paint(StreamingRenderer.java:529)
>        at StreamingRenderer.paint(StreamingRenderer.java:393)
>        at JMapPane.paintComponent(JMapPane.java:396)
>        at javax.swing.JComponent.paint(JComponent.java:1005)
>        at javax.swing.JComponent.paintChildren(JComponent.java:842)
>        etc, etc
>
> Nothing gets plotted, and more over the scale of what gets plotted (data
> from the shapefiles) seems to be all wrong.
>
> Any ideas? Thanx
> gaby
>
>
> --
> ***************************************************************
> **     Gabriella Turek               [EMAIL PROTECTED]      **
> ** National Institute of Water & Atmospheric Research (NIWA) **
> ** PO Box 8602 Christchurch New Zealand +64-3-348-8987x3724  **
> ***************************************************************
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>


-- 
-------------------------------------------------------
Eng. Simone Giannecchini
President /CEO GeoSolutions

http://www.geo-solutions.it

-------------------------------------------------------

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to