Hi Martin,
Thanks very much for this detailed response but I think I haven't made
myself clear. The ground pixels are not regularly-spaced, nor are
they parallel/perpendicular to any coordinate axes. I effectively
have a List of Polygons, which may be arbitrarily-oriented. This is
vector, not raster data.
Currently I'm using an algorithm like this:
BufferedImage im = new BufferedImage(IMAGE_WIDTH,
IMAGE_HEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D)im.getGraphics();
for (Retrieval retrieval : swath.getRetrievals()) {
Color color = getColor(retrieval.getTotalOzone());
g2d.setPaint(color);
Polygon polygon = getPolygon(retrieval.getGroundPixel());
g2d.fillPolygon(polygon);
}
ImageIO.write(im, "png", new File(imageFileName));
Where getColor() gets the colour representing the value of ozone and
getPolygon() converts the ground pixel (in lat-lon coordinates) to a
polygon in image space (integer coordinates).
I was wondering if GeoTools has an equivalent routine that I could use.
Cheers, Jon
2009/1/20 Martin Desruisseaux <[email protected]>:
> Hello Jon
>
> Jon Blower a écrit :
>> I'm looking for a way of rendering an image of some satellite data.
>> Each "ground pixel" in the data is represented as a quadrilateral in
>> lat-lon coordinates, and each pixel is associated with a numerical
>> value (ozone concentration in this case). (I guess this is a
>> DiscretePolygonCoverage in ISO19123 terminology.) Does anyone have
>> any hints for how I could use GeoTools to do this? I've looked
>> through the User Guide and javadocs for the latest GeoTools but am
>> getting a bit lost in FeatureCollections and the Feature model.
>
> According ISO 19123, a Coverage is a Feature. However in GeoTools
> implementation
> this relationship is not yet implemented; Coverages are still living alone, so
> we can ommit Feature for now.
>
> GridCoverage2D were designed for the kind of work you are reporting (I'm an
> oceanographer working with Sea Surface Temperature, Chlorophyl-a
> concentrations,
> etc.). The steps depends slightly on whatever your data are Ozone
> concentration
> as floating point values (case A) or integer values to be converted to Ozone
> concentration through a linear relationship (ozone = value*scale + offset; I
> will call that "case B").
>
> STEP 1
> ------
> If you are in case A:
>
> Get your data as a matrix of floating point values. Values must be straight
> ozone concentration. IMPORTANT: missing values (if any) must be Float.NaN,
> NOT some magic value like -9999. Example (see the construction of the
> Raster,
> you can ommit the remainding for now):
>
> http://svn.geotools.org/trunk/demo/coverage-use/src/main/java/org/geotools/demo/coverage/FloatRasterDemo.java
>
> If you are in case B:
>
> Get your integer data as a RenderedImage.
>
>
> Step 2:
> -------
> Choose some "scale" and "offset" factor for converting integer data to ozone
> concentration. Note: for the remaining of this discussion, I will call the
> integer data "packed values" and the ozone concentration "geophysics values".
>
> If you are in case B:
>
> "scale" and "offset" are directly the values that you use for converting
> your packed values to geophysics values. You will need also to specify the
> "nodata" value, if any.
>
> If you are in case B:
>
> Choose a "scale", "offset" and "nodata" value as if you were converting
> some (non-existant for now) packed values to ozone values. I suggest that
> you choose "0" for "nodata", and that you adjust "scale" and "offset" in
> such a way that "scale + offset" give approximatively the minimal expected
> geophysics values, and "255*scale + offset" gives approximatively the
> maximal expected geophysics values. It is not a big deal if some geophysics
> values exists outside that range.
>
>
> Step 3:
> -------
> Creates Category from the above values (note: I arbitrarily use Color.GRAY for
> "nodata", but choose any color you wish. I also assume that you have applied
> my
> suggestion of using 0 for "nodata", but you can change the number below if you
> selected an other values. Just make sure that the ranges don't overlaps):
>
> Category nodataCategory = new Category("No data", Color.GRAY, 0);
> Category ozoneCategory = new Category("Ozone", colors, 1, 255, scale,
> offset);
>
> http://javadoc.geotools.fr/snapshot/org/geotools/coverage/Category.html#Category(java.lang.CharSequence,%20java.awt.Color[],%20org.geotools.util.NumberRange,%20double,%20double)
>
> Note: "palette" is an array having the colors you wish apply. The first
> element
> in this array is the color to apply to the minimal ozone concentration, and
> the
> last element is the color to apply to the maximum ozone concentration. The
> array
> length doesn't have to be 255. GeoTools will interpolate colors as needed.
>
>
> Step 4:
> ------
> Create a GridSampleDimension with the above categories using this constructor:
>
> http://javadoc.geotools.fr/snapshot/org/geotools/coverage/GridSampleDimension.html#GridSampleDimension(java.lang.CharSequence,%20org.geotools.coverage.Category[],%20javax.measure.unit.Unit)
>
> If you are in case A:
>
> Once your GridSampleDimension is created (lets call it sd), invoke:
>
> sd = sd.geophysics(true).
>
> If you are in case B, *don't* do the above step (or do it with a "false"
> value in argument).
>
>
> Step 5:
> -------
> Create a GridCoverage2D using the above SampleDimension and your raster:
>
> http://javadoc.geotools.fr/snapshot/org/geotools/coverage/grid/GridCoverageFactory.html#create(java.lang.CharSequence,%20java.awt.image.WritableRaster,%20org.opengis.geometry.Envelope,%20org.geotools.coverage.GridSampleDimension[])
>
> You have other constructors - pickup the one most convenient for you.
>
>
> Step 6:
> -------
> Use your coverage. You have different views according what you want to do:
>
> * If you want to do analyses, use:
>
> coverage = coverage.view(ViewType.GEOPHYSICS);
> double[] data = null;
> data = coverage.evaluate(coordinate, data);
>
> TIP: the above does not interpolate. If you want interpolations,
> do: coverage = Operations.interpolate(coverage, "bilinear");
>
> * If you want to display, use:
>
> coverage = coverage.view(ViewType.RENDERED);
>
> Note that in this case, the "evaluate" method returns packed
> values, not geophysics values.
>
>
> Martin
>
--
Dr Jon Blower
Technical Director, Reading e-Science Centre
Environmental Systems Science Centre
University of Reading
Harry Pitt Building, 3 Earley Gate
Reading RG6 6AL. UK
Tel: +44 (0)118 378 5213
Fax: +44 (0)118 378 6413
[email protected]
http://www.nerc-essc.ac.uk/People/Staff/Blower_J.htm
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users