All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.ac.ceh.dynamo.GridMapImage Maven / Gradle / Ivy

Go to download

A Spring MVC plugin for creating dynamic MapServer maps with freemarker templates

There is a newer version: 1.3
Show newest version
package uk.ac.ceh.dynamo;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import uk.ac.ceh.dynamo.GridMapRequestFactory.GridMapRequest;

/**
 * A grid map reader which will process a buffered images with regards to a 
 * grid map request and allow reading of the colours for grid squares present in
 * that image.
 * @author Christopher Johnson
 */
public class GridMapImage {
    private Map squaresColours;
    private Map> colouredSquares;
    
    /**
     * Constructor for processing the given image against the given gridmaprequest
     * @param image the image to read colours from
     * @param request the grid map request used for creating the image
     */
    public GridMapImage(BufferedImage image, GridMapRequest request) {
        this.squaresColours = new HashMap<>();
        this.colouredSquares = new HashMap<>();
        
        int squareSize = request.getAmountOfPixelsForGrid();
        
        for(int y=0; y getGridSquaresByColour(Color colour) {
        return Collections.unmodifiableList(getMutableGridSquaresByColour(colour));
    }
    
    private void addColouredSquare(GridSquare square, Color colour) {
        squaresColours.put(square, colour);
        getMutableGridSquaresByColour(colour).add(square);
    }
    
    private List getMutableGridSquaresByColour(Color colour) {
        if(!colouredSquares.containsKey(colour)) {
            colouredSquares.put(colour, new ArrayList());
        }
        return colouredSquares.get(colour);
    }
    
    private static GridSquare getGridSquareAtPixel(int x, int y, GridMapRequest request) {
        int[] griddedBBox = request.getGriddedBBox();
        return new GridSquare(
            griddedBBox[0] + x * request.getResolution(),
            griddedBBox[1] + y * request.getResolution(),
            request.getResolution());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy