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

eu.limetri.api.grid.util.StandardGridHelper Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (C) 2008-2013 LimeTri. All rights reserved.
 *
 * AgroSense is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * There are special exceptions to the terms and conditions of the GPLv3 as it
 * is applied to this software, see the FLOSS License Exception
 * .
 *
 * AgroSense is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * AgroSense. If not, see .
 */

package eu.limetri.api.grid.util;

import com.vividsolutions.jts.geom.Envelope;
import eu.limetri.api.grid.GridCellSize;
import eu.limetri.api.grid.StandardSizeGrid;

import java.awt.Dimension;

/**
 * TODO: add a port of RasterHelper in the new fixed cell Grid format.
 * 
 * FIXME: JR 201402: 
 * check if this one is still needed, 
 * original version worked with TemporaryGrid (from agrosense.client.grid which module no longer exists)
 * 
 * @author johan
 */
public abstract class StandardGridHelper extends RasterGridHelper {
    private final GridCellSize gridCellSize;
    private StandardSizeGrid grid;

    public StandardGridHelper(GridCellSize gridCellSize) {
        this.gridCellSize = gridCellSize;
    }
    
    public StandardGridHelper() {
        this(StandardSizeGrid.DEFAULT_CELL_SIZE);
    }

    @Override
    protected final void postInitEnvelope() {
        // "snap to grid"
        envelope.expandToInclude(StandardSizeGrid.makeBoundingBox(envelope, gridCellSize));
    }
    
    @Override
    protected final void initDimensions() {
        Dimension d = gridCellSize.getDimension(envelope);
        nRows = (int)d.getHeight();
        nCols = (int)d.getWidth();
    }

//    @Override
//    public Integer getX(double lon) {
//        return gridCellSize.getCell(boundingBox, new Coordinate(lon, miny)).x;
//    }
//    @Override
//    public Integer getY(double lat) {
//        return gridCellSize.getCell(boundingBox, new Coordinate(minx, lat)).y;
//    } 

    public StandardSizeGrid getGrid() {
        if (grid == null) {
            grid = new StandardSizeGrid(gridCellSize, createCoverage());
        }
        return grid;
    }
    
    public static StandardGridHelper getDefault(Envelope env, GridCellSize gridCellSize) {
        return new DefaultImpl(env, gridCellSize);
    }

    public static class DefaultImpl extends StandardGridHelper {

        public DefaultImpl(Envelope env, GridCellSize gridCellSize) {
            super(gridCellSize);
            envelope.expandToInclude(env);
        }

        @Override
        protected void initEnvelope() {
            // keep size as set in ctor.
        }
        
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy