OK, so I think I've got the ArcGridReader to work for me however there
are some issues. But first:

My code reads as follows (I am plotting wind speed data):

URL arcURL = (new File("data/chch/sw250.asc")).toURL();
ArcGridReader agr = new ArcGridReader(arcURL);
GridCoverage2D gc2 = (GridCoverage2D)agr.read(null);

URL sldURL = (new File("data/chch/wind_speed.sld")).toURL();
SLDParser stylereader = new
SLDParser(StyleFactoryFinder.createStyleFactory(), sldURL);
Style[] style = stylereader.readXML();
FeatureTypeStyle[] fts =style[0].getFeatureTypeStyles();                        
        
Rule[] rules = fts[0].getRules();                               
Symbolizer[]  symb = rules[0].getSymbolizers();
ColorMap cm1 = ((RasterSymbolizer)symb[0]).getColorMap();

//My data lies between 13 and 62.8 m/s
double scale  = 50.0;  // Put a real scale factory here if you know it.
double offset = 13.0;  // Put a real offset value here if you know it.
                                
Color nv = new Color(0,0,0);
Color c0 = new Color(204,255,255);
Color c1 = new Color(153,255,255);
Color c2 = new Color(102,255,255);
Color c3 = new Color(51,255,255);
Color c4 = new Color(0,255,255);
Color c5 = new Color(0,204,255);
Category speed = new Category("Wind speed", new Color[]
{c0,c1,c2,c3,c4,c5}, 1, 256, scale, offset);
GridSampleDimension band = new GridSampleDimension("Speed", new
Category[] {Category.NODATA, speed}, SI.METER.divide(SI.SECOND));

RenderedImage image = gc2.getRenderedImage();
ImageLayout layout = new ImageLayout();
layout.setColorModel(band.getColorModel());
RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);
image = FormatDescriptor.create(image, DataBuffer.TYPE_FLOAT, hints);
GridCoverageFactory factory = FactoryFinder.getGridCoverageFactory(null);
gc2 = factory.create("Wind speed", image,
(GridGeometry2D)gc2.getGridGeometry(), new GridSampleDimension[] {band},
null, null);
RasterSymbolizer rs2 = sb.createRasterSymbolizer(cm1, 0.3);
DefaultMapLayer windlayer = new DefaultMapLayer(gc2, sb.createStyle(rs2));


1) In principle, I shouldn't need to extract the ColorMap from the SLD,
   I should just be able to say:

DefaultMapLayer windlayer = new DefaultMapLayer(gc2, style[0]);
However when I do so, any information about opacity is lost.
This must be a bug


2) I should be able to use a  ColorMap cm1 = sb.createColorMap(.......);
instead of an SLD but this does not seem to work at all. I see in the
mailing list archive that Alessio Fabiani on 2005-10-19 said
"RasterSymbolizer actually does not anything !!!"
  Therefore, this appears to be still true???

3)I still can't get my image colors to work out right, I get shades of
gray rather than shades of my chosen color.

If I could only get this to work just right, I would post it to the
WIKI.....
Thanx in advance to anyone who may be able to elucidate some of these
points....
gaby


My SLD:
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld";
xmlns:ogc="http://www.opengis.net/ogc";
xmlns:xlink="http://www.w3.org/1999/xlink";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://www.opengis.net/sld
http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd";
version="1.0.0">
<UserLayer>
  <Name>raster_layer</Name>
  <UserStyle>
    <Name>raster</Name>
    <Title>A boring default style</Title>
    <Abstract>A sample style for rasters</Abstract>
    <FeatureTypeStyle>
                        <Name>test</Name>
      <Rule>
                          <Name>Rule for displaying rasters</Name>
        <RasterSymbolizer>
            <Opacity>0.5</Opacity>
            <ColorMap>
               <ColorMapEntry color="#000000" quantity="-9999"
label="nodata" opacity="0.0"/>
               <ColorMapEntry color="#ccffff" quantity="13"
label="values" opacity="0.5" />
               <ColorMapEntry color="#99ffff" quantity="23"
label="values" opacity="0.5" />
               <ColorMapEntry color="#66ffff" quantity="33"
label="values" opacity="0.5" />
               <ColorMapEntry color="#33ffff" quantity="43"
label="values" opacity="0.5" />
               <ColorMapEntry color="#00ffff" quantity="53"
label="values" opacity="0.5" />
               <ColorMapEntry color="#00ccff" quantity="63"
label="values" opacity="0.5" />

            </ColorMap>
        </RasterSymbolizer>
      </Rule>
    </FeatureTypeStyle>
  </UserStyle>
</UserLayer>
</StyledLayerDescriptor>

-- 
***************************************************************
**     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

Reply via email to