0

I am trying to render a heatmap using geotools. However, whenever I try to using HeatmapProcess I just get a black box.

Here is my code for creating the GridCoverage2D object and rendering it:

    ProgressListener monitor = null;
    HeatmapProcess process = new HeatmapProcess();
    CoordinateReferenceSystem crs = cape36S;
    ReferencedEnvelope envelope = null;

    try {
        envelope = map.getMaxBounds().transform(crs,true);
        System.out.println(envelope.getCoordinateReferenceSystem().toString());
    } catch (TransformException e) {
        e.printStackTrace();
    } catch (FactoryException e) {
        e.printStackTrace();
    }
    SimpleFeatureCollection featureCollection = DataUtilities.collection(defaultFeatureCollection);
    GridCoverage2D cov = process.execute(
            featureCollection, // data
            5, // radius
            null, // weightAttr
            1, // pixelsPerCell
            envelope, // outputEnv
            1000, // outputWidth
            1000, // outputHeight
            monitor // monitor)
    );
    File file = new File("D:\\style.sld");
    Style style = createFromSLD(file);
    Layer layer = new GridCoverageLayer(cov, style);
    map.addLayer(layer);

Here is the code I am using to load the style:

StyleBuilder builder = new StyleBuilder();
        org.geotools.xml.Configuration configuration = new 
org.geotools.sld.SLDConfiguration();
        org.geotools.xml.Parser parser = new 
org.geotools.xml.Parser(configuration);
        // the xml instance document above
        InputStream xml = new FileInputStream(sldFile.getAbsolutePath());

// parse
StyledLayerDescriptor sld = (StyledLayerDescriptor) parser.parse(xml);
FeatureTypeStyle useful[] = SLD.featureTypeStyles( sld );

Style style = builder.createStyle();
style.setName("Heatmap Style");
style.getDescription().setTitle("Heatmap");
style.getDescription().setAbstract("Heatmap");
style.featureTypeStyles().add(useful[0]);
return style;

Here is the .sld file:

 <?xml version="1.0" encoding="ISO-8859-1"?>
 <StyledLayerDescriptor version="1.0.0"
    xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
    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">
  <NamedLayer>
    <Name>Multi Color Gradient</Name>
    <UserStyle>
      <Title>Multi Color Gradient</Title>
      <FeatureTypeStyle>
           <Rule>
             <RasterSymbolizer>
               <ColorMap>
                 <ColorMapEntry color="#000000" quantity="95" />
                 <ColorMapEntry color="#0000FF" quantity="110" />
                 <ColorMapEntry color="#00FF00" quantity="135" />
                 <ColorMapEntry color="#FF0000" quantity="160" />
                 <ColorMapEntry color="#FF00FF" quantity="185" />
                 <ColorMapEntry color="#FFFF00" quantity="210" />
                 <ColorMapEntry color="#00FFFF" quantity="235" />
                 <ColorMapEntry color="#FFFFFF" quantity="256" />
               </ColorMap>
             </RasterSymbolizer>
           </Rule>
         </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

I thought it might be the style causing the issue but I am not sure.

Can someone see where the error lies?

  • 1
    First thing to try is to save the coverage as a GeoTIFF and test it in your desktop gis. Then you will know if it is a style issue or a heat map issue. – Ian Turton Jul 25 '18 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.