Hei Michael, Alberto and Larry,

yep. What I was suggesting is to use IRasterLayer and the related generic classes and basically copy them with a slight name change to avoid confusion [1]. This way we could develop on raster functionality based on the sextante interfaces and access classes. I.e. it was not just about loading raster files, because the sextante raster file is just a normal tiff image too, but loaded with Pirols plugin, which is what the Sextante-OJ interface needs as input.

With respect to Albertos question: yes, we may need to update them from time to time. But i think these classes will not have much changes in the future.

In case you want to have a look at the classes I did a commit of those to a new branch: /branches/sstein/

the classes are to be found in
org.openjump.core.rasterimage.sextante.*

stefan

[1] I think I changed only the name of the Sextante class OpenJUMPRasterLayer to OpenJUMPSextanteRasterLayer , which provides a way to convert openjump data (raster and vector) in (abstract) sextante datatypes.

Note, I also add an example plugin that for instance converts a loaded raster into a vector grid. So you can see how it works

PS: btw another option would be to look into GDMS

Michaël Michaud wrote:
Hi Stefan,

Sorry, my knowledge about raster managment is very poor.
I thought you already added Sextante raster classes (File> Open> Image raster (Sextante))
Isn't it enough to benefit from Sextante algorithm library ?
Could you briefly explain what is missing in OpenJUMP.
From what you and Alberto said, I understand that OpenJUMP and AdbToolbox have their own loaders and renderers, but there is no OJ interface to define how to access raster data in a way independant from loader implementation (maybe like IRasterLayer from Sextante) ? Is that the point ?

Michaël

Larry Becker a écrit :
    I actually asked a couple of months ago if other people would
    accept if
    I commit the basic Raster classes used in Sextante. There was not much
    exitement/repsonse ;)


Sorry for the lack of response Stefan. I just haven't had time to study Sextante, and didn't feel qualified to comment.

Larry

/*
 * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI 
 * for visualizing and manipulating spatial features with geometry and 
attributes.
 *
 * JUMP is Copyright (C) 2003 Vivid Solutions
 *
 * This class implements extensions to JUMP and is
 * Copyright (C) Stefan Steiniger.
 * 
 * This program 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 2
 * of the License, or (at your option) any later version.
 * 
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * 
 * For more information, contact:
 * Stefan Steiniger
 * perri...@gmx.de
 */

/*****************************************************
 * created:             28.Oct.2009
 * last modified:                                       
 *                                      
 * 
 * @author sstein
 * 
 * description:
 *      
 *  
 *****************************************************/

package ca.ucalgary.engg.moveantools.ojplugin;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Point2D;
import java.util.List;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;

import org.openjump.core.apitools.FeatureSchemaTools;
import org.openjump.core.apitools.LayerTools;
import org.openjump.core.rasterimage.RasterImageLayer;
import org.openjump.core.rasterimage.sextante.OpenJUMPSextanteRasterLayer;
import 
org.openjump.core.rasterimage.sextante.rasterWrappers.GridWrapperNotInterpolated;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jump.feature.AttributeType;
import com.vividsolutions.jump.feature.BasicFeature;
import com.vividsolutions.jump.feature.Feature;
import com.vividsolutions.jump.feature.FeatureCollection;
import com.vividsolutions.jump.feature.FeatureDataset;
import com.vividsolutions.jump.feature.FeatureSchema;
import com.vividsolutions.jump.task.TaskMonitor;
import com.vividsolutions.jump.workbench.WorkbenchContext;
import com.vividsolutions.jump.workbench.model.StandardCategoryNames;
import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
import com.vividsolutions.jump.workbench.plugin.PlugInContext;
import com.vividsolutions.jump.workbench.plugin.ThreadedPlugIn;
import com.vividsolutions.jump.workbench.ui.GUIUtil;
import com.vividsolutions.jump.workbench.ui.MultiInputDialog;
import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller;

/**
 * @description: creates a polygon grid from the current selected raster image
 * @TODO: I was going todo this as a normal plugin, but this won't work since
 * raster images are Layerables and not layer objects, so the drop down list 
doesn't
 * display them
 *      
 * @author sstein
 *
 **/
public class CreatePolygonGridFromSelectedImageLayerPlugIn extends 
AbstractPlugIn implements ThreadedPlugIn{
  
    private PlugInContext context = null;
    private MultiInputDialog dialog;
    
    private String sSidebar ="Create Polygon Grid from Image";
        public String sRemoveZeroCells = "remove cells with values =< 0";
        public String sMaxCellsToDisplay = "max cells to display";
        
    GeometryFactory gfactory = new GeometryFactory();
        public int maxCells = 200000;
        public boolean removeZeroCells = false;
        
        
    public void initialize(PlugInContext context) throws Exception {
                                
                FeatureInstaller featureInstaller = new 
FeatureInstaller(context.getWorkbenchContext());
                featureInstaller.addMainMenuItem(
                        this,                                                   
        //exe
                        new String[] {"OJ-Sextante"},   //menu path
                        "Create Polygon Grid from Image", 
                        false,                  //checkbox
                        null,                   //icon
                        createEnableCheck(context.getWorkbenchContext())); 
//enable check
    }

    public static MultiEnableCheck createEnableCheck(WorkbenchContext 
workbenchContext) {
        EnableCheckFactory checkFactory = new 
EnableCheckFactory(workbenchContext);

        return new MultiEnableCheck()
                        
.add(checkFactory.createAtLeastNLayerablesMustBeSelectedCheck(1, 
RasterImageLayer.class));
    }
    
    /**
     *...@inheritdoc
     */
    public String getIconString() {
        return null;
    }
   
    
        public boolean execute(PlugInContext context) throws Exception{
        //Unlike ValidatePlugIn, here we always call #initDialog because we want
        //to update the layer comboboxes.
        initDialog(context);
        dialog.setVisible(true);
        if (!dialog.wasOKPressed()) {
            return false;
        }
        else{
                this.getDialogValues(dialog); 
        }
        return true;        
        }

        public void run(TaskMonitor monitor, PlugInContext context)
                        throws Exception {
                monitor.allowCancellationRequests();
                GeometryFactory gf = new GeometryFactory();
                //-- get the rasterimage layer
        RasterImageLayer rLayer = (RasterImageLayer) 
LayerTools.getSelectedLayerable(context, RasterImageLayer.class);
        
        if (rLayer==null){
            context.getWorkbenchFrame().warnUser("no layer selected");
            return;
        }
                
                //-- create a sextante raster layer since it is easier to handle
                OpenJUMPSextanteRasterLayer rstLayer = new 
OpenJUMPSextanteRasterLayer();
                rstLayer.create(rLayer);
                // create a gridwrapper to later access the cells
                GridWrapperNotInterpolated gwrapper = new 
GridWrapperNotInterpolated(rstLayer, rstLayer.getLayerGridExtent());
                //-- create the FeatureSchema
                FeatureSchema fs = new FeatureSchema();
                fs.addAttribute("geometry", AttributeType.GEOMETRY);
                int numBands = rstLayer.getBandsCount();
                for (int i = 0; i < numBands; i++) {
                        fs.addAttribute("band_" + i, AttributeType.DOUBLE);
                }
                //-- create a new empty dataset
                FeatureCollection fd = new FeatureDataset(fs);
                //-- create points
                monitor.report("creating polygons");
                int nx = rstLayer.getLayerGridExtent().getNX();
                int ny = rstLayer.getLayerGridExtent().getNY();
                double halfCellDim = 0.5 * 
rstLayer.getLayerGridExtent().getCellSize();
                int numPoints = nx * ny;
                if(numPoints > this.maxCells){
                        context.getWorkbenchFrame().warnUser("more than "+ 
this.maxCells+ " polys to generate - stopped! cells: " + numPoints );
                        return;
                }
                for (int x = 0; x < nx; x++) {//cols
                        for (int y = 0; y < ny; y++) {//rows
                                Feature ftemp = new BasicFeature(fs); 
                                Point2D pt = 
rstLayer.getLayerGridExtent().getWorldCoordsFromGridCoords(x, y);               
           
                                Coordinate[] coords = new Coordinate[5];
                                coords[0] = new 
Coordinate(pt.getX()-halfCellDim , pt.getY()+halfCellDim); //topleft
                                coords[1] = new 
Coordinate(pt.getX()+halfCellDim , pt.getY()+halfCellDim); //topright
                                coords[2] = new 
Coordinate(pt.getX()+halfCellDim , pt.getY()-halfCellDim); //lowerright
                                coords[3] = new 
Coordinate(pt.getX()-halfCellDim , pt.getY()-halfCellDim); //lowerleft
                                //-- to close poly
                                coords[4] = (Coordinate)coords[0].clone(); 
//topleft
                                //-- create the cell poly
                                LinearRing lr = gf.createLinearRing(coords);
                                Geometry poly = gf.createPolygon(lr, null);
                                ftemp.setGeometry(poly);
                                //-- set attributes
                                double sumvalue = 0;
                                for (int i = 0; i < numBands; i++) {
                                        double value = 
gwrapper.getCellValueAsDouble(x, y, i);
                                        ftemp.setAttribute("band_" + i, value);
                                        sumvalue = sumvalue + value;
                                }
                                //-- add the feature
                                if(this.removeZeroCells == true){
                                        if (sumvalue > 0){
                                                fd.add(ftemp);
                                        }
                                }
                                else{
                                        fd.add(ftemp);
                                }
                                //-- check if user wants to stop
                                if(monitor.isCancelRequested()){
                                        if(fd.size() > 0){
                                                
context.addLayer(StandardCategoryNames.RESULT, rstLayer.getName() + 
"_cancel_grid", fd);
                                        }
                                        return;
                                }
                        }
                }
                //-- output
                if(fd.size() > 0){
                        context.addLayer(StandardCategoryNames.RESULT, 
rstLayer.getName() + "_grid", fd);
                }
        }
    
        private void initDialog(PlugInContext context) {
        
        dialog = new MultiInputDialog(context.getWorkbenchFrame(), "Convert", 
true);
        dialog.setSideBarDescription(sSidebar);
        dialog.addCheckBox(sRemoveZeroCells, removeZeroCells);
        dialog.addIntegerField(sMaxCellsToDisplay, this.maxCells, 10, 
this.sMaxCellsToDisplay);
            //dialog.addDoubleField(T1, 20.0, 4);
        GUIUtil.centreOnWindow(dialog);
    }
    
    private void getDialogValues(MultiInputDialog dialog) {
        this.removeZeroCells =  dialog.getBoolean(sRemoveZeroCells); 
        this.maxCells = dialog.getInteger(this.sMaxCellsToDisplay);
      }
}
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to