Hi,

I do some raster data styling too. Code for this can be found via:
https://github.com/agdturner/digital-welfare/blob/master/src/main/java/uk/ac/leeds/ccg/andyt/projects/digitalwelfare/mapping/DW_Geotools.java

In particular you can follow through from the following method:

    /**
     * Warning this will set g to null.
     * @param normalisation
     * @param styleParameters
     * @param index
     * @param outname
     * @param g
     * @param gc
     * @param foregroundDW_Shapefile0
     * @param foregroundDW_Shapefile1
     * @param backgroundDW_Shapefile
     * @param outputDir
     * @param imageWidth
     * @param showMapsInJMapPane 
     * @param scaleToFirst 
     */
    public static void outputToImageUsingGeoToolsAndSetCommonStyle(
            double normalisation,
            AGDT_StyleParameters styleParameters,
            int index,
            String outname,
            AbstractGrid2DSquareCell g,
            GridCoverage2D gc,
            ArrayList<AGDT_Shapefile> foregroundDW_Shapefile0,
            AGDT_Shapefile foregroundDW_Shapefile1,
            AGDT_Shapefile backgroundDW_Shapefile,
            File outputDir,
            int imageWidth,
            boolean showMapsInJMapPane,
            boolean scaleToFirst) {
        MapContent mc = createMapContent(
                normalisation,
                g,
                gc,
                foregroundDW_Shapefile0,
                foregroundDW_Shapefile1,
                backgroundDW_Shapefile,
                imageWidth,
                styleParameters,
                index,
                scaleToFirst);
        // Set g to null as it is no longer needed. 
        // This is done to prevent any unwanted OutOfMemory Errors being 
encountered.
        g = null;

        int imageHeight = getMapContentImageHeight(mc, imageWidth);
        File outputFile = getOutputFile(
                outputDir,
                outname,
                DW_Maps.png_String);
        File outputImageFile = DW_Maps.getOutputImageFile(
                outputFile, DW_Maps.png_String);

        AGDT_Geotools.writeImageFile(
                //g._Grids_Environment,
                mc,
                imageWidth,
                imageHeight,
                outputImageFile,
                DW_Maps.png_String);

        // Dispose of MapContent to prevent memory leaks
        if (showMapsInJMapPane) {
            // Display mc in a JMapFrame
            JMapFrame.showMap(mc); // Need to not dispose of mc if this is to 
persist!
        } else {
            // Tidy up
            //gc.dispose();
            // Dispose of mc to avoid memory leaks
            //mc.removeLayer(backgroundFeatureLayer);
            List<Layer> layers = mc.layers();
            Iterator<Layer> ite = layers.iterator();
            while (ite.hasNext()) {
                Layer l = ite.next();
//                if (l.equals(backgroundFeatureLayer)) {
//                    System.out.println("Odd this was removed from 
MapContent!");
//                } else {
                l.preDispose();
                l.dispose();
//                }
            }
            //mc.removeLayer(backgroundFeatureLayer);
            mc.dispose();
        }
    }

HTH

Andy
________________________________________
From: andrea antonello [andrea.antone...@gmail.com]
Sent: 01 May 2015 06:15
Cc: geotools users
Subject: Re: [Geotools-gt2-users] Styling rasters

> Are there examples on styling rasters?
> I am trying to style an ascii grid file

We are doing some raster styling here:
https://github.com/moovida/jgrasstools/tree/master/jgrassgears/src/main/java/org/jgrasstools/gears/utils/colors
The code is brought from some older one, so it needs some cleanup, but
there are some default colortables and it should be rather simple to
understand.

Andrea

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to