Ciao Martin, I copied and pasted (with few modifications) your stile inside the renderer tests and it worked. I am attaching it to this email.
The code used is as follows:
RasterSymbolizerHelper rsh = new RasterSymbolizerHelper(gc,
null);
final UserLayer nl = (UserLayer) sld.getStyledLayers()[0];
final Style style = nl.getUserStyles()[0];
final FeatureTypeStyle fts = style.getFeatureTypeStyles()[0];
final Rule rule = fts.getRules()[0];
RasterSymbolizer rs = (RasterSymbolizer)
rule.getSymbolizers()[0];
rsh.visit(rs);
((GridCoverage2D)rsh.getOutput()).show();
What are the characteristics of your data? A gdalinfo might help.
Let me know if this works.
Simone.
-------------------------------------------------------
Ing. Simone Giannecchini
GeoSolutions S.A.S.
Owner - Software Engineer
Via Carignoni 51
55041 Camaiore (LU)
Italy
phone: +39 0584983027
fax: +39 0584983027
mob: +39 333 8128928
http://www.geo-solutions.it
http://simboss.blogspot.com/
http://www.linkedin.com/in/simonegiannecchini
-------------------------------------------------------
On Mon, Feb 16, 2009 at 6:15 PM, Martin Tomko <[email protected]> wrote:
> Hi Simone,
> I used the one in your example, with changed values that are to be mapped,
> as follows:
> Thanks
> Martin
>
> <?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>
> - <#> <LayerFeatureConstraints>
> <FeatureTypeConstraint />
> </LayerFeatureConstraints>
> - <#> <UserStyle>
> <Name>raster</Name>
> <Title>A boring default style</Title>
> <Abstract>A sample style for rasters</Abstract>
> - <#> <FeatureTypeStyle>
> <FeatureTypeName>Feature</FeatureTypeName>
> - <#> <Rule>
> - <#> <RasterSymbolizer>
> - <#> <!--
>
> ColorMap type="ramp" extended="true">
> <ColorMapEntry color="#000000" quantity="-1.0" opacity="1.0"/>
> <ColorMapEntry color="#ff0000" quantity="0.0" opacity="1.0"/>
> <ColorMapEntry color="#ffff00" quantity="1.0" opacity="1.0"/>
> <ColorMapEntry color="#00ff00" quantity="2.0" opacity="1.0"/>
> <ColorMapEntry color="#00ffff" quantity="3.0" opacity="1.0"/>
> <ColorMapEntry color="#0000ff" quantity="4.0" opacity="1.0"/>
> <ColorMapEntry color="#ff00ff" quantity="5.0" opacity="1.0"/>
> <ColorMapEntry color="#ffffff" quantity="6.0" opacity="1.0"/>
> </ColorMap
> -->
> <Opacity>1.0</Opacity>
> - <#> <ChannelSelection>
> - <#> <GrayChannel>
> <SourceChannelName>1</SourceChannelName>
> - <#> <ContrastEnhancement>
> <Normalize />
> </ContrastEnhancement>
> </GrayChannel>
> </ChannelSelection>
> - <#> <ContrastEnhancement>
> <GammaValue>1</GammaValue>
> </ContrastEnhancement>
> </RasterSymbolizer>
> </Rule>
> </FeatureTypeStyle>
> </UserStyle>
> </UserLayer>
> </StyledLayerDescriptor>
>
>
> Simone Giannecchini wrote:
>>
>> Ciao Martin,
>> please, send over the SLD file you are using.
>>
>>
>> Simone.
>> -------------------------------------------------------
>> Ing. Simone Giannecchini
>> GeoSolutions S.A.S.
>> Owner - Software Engineer
>> Via Carignoni 51
>> 55041 Camaiore (LU)
>> Italy
>>
>> phone: +39 0584983027
>> fax: +39 0584983027
>> mob: +39 333 8128928
>>
>>
>> http://www.geo-solutions.it
>> http://simboss.blogspot.com/
>> http://www.linkedin.com/in/simonegiannecchini
>>
>> -------------------------------------------------------
>>
>>
>>
>> On Mon, Feb 16, 2009 at 5:57 PM, Martin Tomko <[email protected]>
>> wrote:
>>
>>>
>>> Hi Simone,
>>> I have solved the Style factory problem as follows:
>>> SLDParser stylereader = new SLDParser(new StyleFactoryImpl() ,
>>> sldfile);
>>> I have imported the UserLayer, Style and all following classess from
>>> org.geotools.styling (it seems that classes with the same name are also
>>> in
>>> org.opemgis...). The methods called are shown as deprecated (I work with
>>> 2.5-SNAPSHOT thorugh maven). Anyway, I tried to use them.
>>>
>>> I am not able to run your example because of the line:
>>> rsh_SLD.visit(rs_1).show();
>>>
>>> where
>>> SubchainStyleVisitorCoverageProcessingAdapter rsh_SLD = new
>>> RasterSymbolizerHelper(gc, null);
>>> final RasterSymbolizer rs_1 = (RasterSymbolizer)
>>> rule.getSymbolizers()[0];
>>>
>>> where show() cannot be invoked on a type void. Any idea why this is?
>>> I tried a workaround (also tried through theexecute method):
>>> GridCoverage2D tmpgc = (GridCoverage2D)rsh_SLD.getOutput();
>>> tmpgc.show();
>>>
>>> but I am getting the following error:
>>> Feb 16, 2009 5:49:01 PM org.geotools.styling.SLDParser parseUserLayer
>>> INFO: layer name: raster_layer
>>> Exception in thread "main"
>>> org.geotools.coverage.processing.CoverageProcessingException:
>>> java.lang.NullPointerException
>>> at
>>>
>>> org.geotools.renderer.lite.gridcoverage2d.BaseCoverageProcessingNode.getOutput(BaseCoverageProcessingNode.java:339)
>>> at
>>>
>>> org.geotools.renderer.lite.gridcoverage2d.BaseCoverageProcessingNode.getOutput(BaseCoverageProcessingNode.java:42)
>>> at
>>>
>>> org.geotools.renderer.lite.gridcoverage2d.StyleVisitorCoverageProcessingNodeAdapter.getOutput(StyleVisitorCoverageProcessingNodeAdapter.java:180)
>>> at ch.uzh.geo.tomko.GTViewshed.GTtest.main(GTtest.java:207)
>>> Caused by: java.lang.NullPointerException
>>> at
>>>
>>> org.geotools.renderer.lite.gridcoverage2d.RasterSymbolizerHelper.execute(RasterSymbolizerHelper.java:69)
>>> at
>>>
>>> org.geotools.renderer.lite.gridcoverage2d.RasterSymbolizerHelper.execute(RasterSymbolizerHelper.java:48)
>>> at
>>>
>>> org.geotools.renderer.lite.gridcoverage2d.StyleVisitorCoverageProcessingNodeAdapter$1.execute(StyleVisitorCoverageProcessingNodeAdapter.java:140)
>>> at
>>>
>>> org.geotools.renderer.lite.gridcoverage2d.BaseCoverageProcessingNode.checkExecuted(BaseCoverageProcessingNode.java:235)
>>> at
>>>
>>> org.geotools.renderer.lite.gridcoverage2d.BaseCoverageProcessingNode.getOutput(BaseCoverageProcessingNode.java:337)
>>> ... 3 more
>>>
>>> Any help more than welcome,
>>> Martin
>>>
>>>
>>> Simone Giannecchini wrote:
>>>
>>>>
>>>> Ciao Martin,
>>>> a way to achieve that is by using the RasterSymbolizer (2.5.0 and
>>>> successive releases).
>>>> See http://docs.codehaus.org/display/GEOTOOLS/Raster+Symbolizer+support
>>>> for more information.
>>>>
>>>>
>>>> Simone.
>>>> -------------------------------------------------------
>>>> Ing. Simone Giannecchini
>>>> GeoSolutions S.A.S.
>>>> Owner - Software Engineer
>>>> Via Carignoni 51
>>>> 55041 Camaiore (LU)
>>>> Italy
>>>>
>>>> phone: +39 0584983027
>>>> fax: +39 0584983027
>>>> mob: +39 333 8128928
>>>>
>>>>
>>>> http://www.geo-solutions.it
>>>> http://simboss.blogspot.com/
>>>> http://www.linkedin.com/in/simonegiannecchini
>>>>
>>>> -------------------------------------------------------
>>>>
>>>>
>>>>
>>>> On Mon, Feb 16, 2009 at 3:59 PM, Martin Tomko <[email protected]>
>>>> wrote:
>>>>
>>>>
>>>>>
>>>>> Dear all,
>>>>> I am creating a gridcoverage2D (and consequently a geotiff, based on
>>>>> processing of a source geotiff DEM), and I want to quickly visualize
>>>>> the
>>>>> results of the analysis. Instead of opening it in some GIS, I would
>>>>> like
>>>>> to assign a color model to the result.and display it through the show()
>>>>> method. I tried to change the viewtype, but it does not seem to help.
>>>>>
>>>>> My GridCoverage2D is created as follows:
>>>>>
>>>>> WritableRaster hor = ...;
>>>>> GridCoverage2D gchor = gcFactoryhor.create("hor", hor, env);
>>>>> gchor.view(ViewType.GEOPHYSICS);
>>>>> gchor.show();
>>>>>
>>>>> and I use a GeoTiffWriter to output the geoTiff. Note that ArcMap open
>>>>> the geotiff fine (requiring classification to assign colors), as well
>>>>> as
>>>>> a normal image viewer (e.g., XnView), but the result is just a binary
>>>>> nodata/anydata black and white rendering.
>>>>>
>>>>> I see that it is possible to assign colors in the GridCoverage2D gchor
>>>>> =
>>>>> gcFactoryhor.create(...) part, but I am not sure how to map the values
>>>>> in the raster to the colors. Any hints welcome.
>>>>>
>>>>> Thanks
>>>>> Martin
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> ------------------------------------------------------------------------------
>>>>> Open Source Business Conference (OSBC), March 24-25, 2009, San
>>>>> Francisco,
>>>>> CA
>>>>> -OSBC tackles the biggest issue in open source: Open Sourcing the
>>>>> Enterprise
>>>>> -Strategies to boost innovation and cut costs with open source
>>>>> participation
>>>>> -Receive a $600 discount off the registration fee with the source code:
>>>>> SFAD
>>>>> http://p.sf.net/sfu/XcvMzF8H
>>>>> _______________________________________________
>>>>> Geotools-gt2-users mailing list
>>>>> [email protected]
>>>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>>
>
>
> --
> Martin Tomko
> Postdoctoral Research Assistant Geographic Information Systems Division
> Department of Geography
> University of Zurich - Irchel
> Winterthurerstr. 190
> CH-8057 Zurich, Switzerland
>
> email: [email protected]
> site: http://www.geo.uzh.ch/~mtomko
> mob: +41-788 629 558
> tel: +41-44-6355256
> fax: +41-44-6356848
>
>
raster_dem.sld
Description: Binary data
------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H
_______________________________________________ Geotools-gt2-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
