Revision 1406

View differences:

org.gvsig.raster/tags/buildNumber_32/org.gvsig.raster/org.gvsig.raster.fmap/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.fmap.FmapRasterLibrary
org.gvsig.raster/tags/buildNumber_32/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/fmap/FmapRasterLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
 
23
package org.gvsig.raster.fmap;
24

  
25
import org.gvsig.fmap.dal.DALLibrary;
26
import org.gvsig.fmap.dal.coverage.RasterLibrary;
27
import org.gvsig.fmap.dal.raster.CoverageStore;
28
import org.gvsig.fmap.mapcontext.MapContextLibrary;
29
import org.gvsig.fmap.mapcontext.layers.LayerFactory;
30
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster;
31
import org.gvsig.raster.fmap.layers.StatusLayerRaster;
32
import org.gvsig.raster.fmap.legend.ColorTableLegend;
33
import org.gvsig.tools.library.AbstractLibrary;
34
import org.gvsig.tools.library.Library;
35
import org.gvsig.tools.library.LibraryException;
36

  
37
/**
38
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
39
 */
40
public class FmapRasterLibrary extends AbstractLibrary {
41

  
42
	@SuppressWarnings("deprecation")
43
	public FmapRasterLibrary() {
44
		super(FmapRasterLibrary.class, Library.TYPE.IMPL);
45
		require(DALLibrary.class);
46
		require(MapContextLibrary.class);
47
		require(RasterLibrary.class);
48
	}
49
	
50
	@Override
51
	protected void doInitialize() throws LibraryException {
52
	}
53

  
54
	@Override
55
	protected void doPostInitialize() throws LibraryException {
56
		DefaultFLyrRaster.registerPersistence();
57
		StatusLayerRaster.registerPersistence();
58
		ColorTableLegend.registerPersistence();
59
		LayerFactory.getInstance().registerLayerToUseForStore(
60
				CoverageStore.class,
61
				DefaultFLyrRaster.class);
62
	}
63
}
64

  
0 65

  
org.gvsig.raster/tags/buildNumber_32/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/fmap/roi/VectorialROIsReader.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.fmap.roi;
23

  
24
import java.awt.Color;
25
import java.io.File;
26
import java.util.ArrayList;
27
import java.util.HashMap;
28

  
29
import org.cresques.cts.IProjection;
30
import org.gvsig.fmap.dal.DALLocator;
31
import org.gvsig.fmap.dal.DataManager;
32
import org.gvsig.fmap.dal.coverage.exception.FileNotExistsException;
33
import org.gvsig.fmap.dal.coverage.grid.Grid;
34
import org.gvsig.fmap.dal.coverage.grid.ROI;
35
import org.gvsig.fmap.dal.exception.DataException;
36
import org.gvsig.fmap.dal.exception.InitializeException;
37
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
38
import org.gvsig.fmap.dal.feature.Feature;
39
import org.gvsig.fmap.dal.feature.FeatureSet;
40
import org.gvsig.fmap.dal.feature.FeatureStore;
41
import org.gvsig.fmap.dal.feature.FeatureType;
42
import org.gvsig.fmap.dal.store.shp.SHPStoreParameters;
43
import org.gvsig.fmap.dal.store.shp.SHPStoreProvider;
44
import org.gvsig.fmap.geom.primitive.Envelope;
45
import org.gvsig.fmap.geom.primitive.NullGeometry;
46
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
47
import org.gvsig.fmap.mapcontext.layers.LayerFactory;
48
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
49
import org.gvsig.tools.dispose.DisposableIterator;
50

  
51

  
52
public class VectorialROIsReader {
53
	private HashMap<String, ROI>   rois         = null;
54
	private Grid                   grid         = null;
55
	private Envelope               bbox         = null;
56
	private FeatureStore           featureStore = null; 
57

  
58

  
59
	@SuppressWarnings("deprecation")
60
	public VectorialROIsReader(
61
			String filename, 
62
			Grid grid, 
63
			IProjection projection,
64
			Envelope bbox) throws LoadLayerException, FileNotExistsException {
65
		this.grid = grid;
66
		this.bbox = bbox;
67
		File file = new File(filename);
68
		if(file.exists()) {
69
			DataManager datamanager = DALLocator.getDataManager();
70
			SHPStoreParameters params = null;
71
			try {
72
				params = (SHPStoreParameters)datamanager.createStoreParameters(SHPStoreProvider.NAME);
73
				params.setCRS(projection);
74
			} catch (InitializeException e) {
75
				throw new LoadLayerException(file.getName(),e);
76
			} catch (ProviderNotRegisteredException e) {
77
				throw new LoadLayerException(file.getName(),e);
78
			}
79
			params.setFile(file);
80
			FLyrVect fLyrVect = (FLyrVect)LayerFactory.getInstance().createLayer("layer1", params);
81
			featureStore = fLyrVect.getFeatureStore();
82
		} else
83
			throw new FileNotExistsException("file not found");
84
	}
85
	
86
	public VectorialROIsReader(
87
			FeatureStore featureStore, 
88
			Grid grid, 
89
			IProjection projection, 
90
			Envelope bbox) {
91
		this.grid = grid;
92
		this.bbox = bbox;
93
		this.featureStore = featureStore;
94
	}
95

  
96
	@SuppressWarnings("deprecation")
97
	public ArrayList<ROI> read(ArrayList<ROI> existingROIs) throws InvalidROIsShpException, DataException{
98
		FeatureType featureType=featureStore.getDefaultFeatureType();
99

  
100
		int nameFieldIndex = featureType.getIndex("name");
101
		int rFiledIndex = featureType.getIndex("R");
102
		int gFiledIndex = featureType.getIndex("G");
103
		int bFiledIndex = featureType.getIndex("B");
104

  
105
		if (existingROIs != null)
106
			rois = new HashMap<String, ROI>();
107
		if (existingROIs != null)
108
			for (int i = 0; i < existingROIs.size(); i++) {
109
				VectorialROI roi = (VectorialROI)existingROIs.get(i);
110
				rois.put(roi.getName(), roi);
111
			}
112
		String roiName;
113
		int r = 255, g = 0, b = 0;
114
		FeatureSet set = null;
115
		DisposableIterator features = null;
116
		try {
117
			set = featureStore.getFeatureSet();
118
			features = set.iterator();
119
			String defaultROIName = "ROI";
120
			while (features.hasNext()) {
121
				Feature feature = (Feature) features.next();
122
				
123
				if(feature.getDefaultGeometry() == null || 
124
				   feature.getDefaultGeometry() instanceof NullGeometry)
125
					continue;
126
				if(feature.getDefaultGeometry() != null && 
127
				   !feature.getDefaultGeometry().getEnvelope().intersects(bbox))
128
					continue;
129

  
130
				if(nameFieldIndex >= 0)
131
					roiName = feature.getString(nameFieldIndex).toString();
132
				else {
133
					try {
134
						Thread.sleep(50); //Aseguramos un identificador ?nico
135
					} catch (InterruptedException e) {
136
					}
137
					roiName = defaultROIName + "-" + System.currentTimeMillis();
138
				}
139
				VectorialROI roi = null;
140
				if (!rois.containsKey(roiName)) {
141
					roi = new VectorialROI(grid);
142
					roi.setName(roiName);
143
					if(rFiledIndex >= 0)
144
						r = ((Number) feature.get(rFiledIndex)).intValue();
145
					if(gFiledIndex >= 0)
146
						g = ((Number) feature.get(gFiledIndex)).intValue();
147
					if(bFiledIndex >= 0)
148
						b = ((Number) feature.get(bFiledIndex)).intValue();
149
					roi.setColor(new Color(r, g, b));
150
					rois.put(roi.getName(), roi);
151
				} else
152
					roi = (VectorialROI) rois.get(roiName);
153
				roi.addGeometry(feature.getDefaultGeometry());
154
			}
155
		} finally {
156
			if (features != null)
157
				features.dispose();
158
			if (set != null)
159
				set.dispose();
160
		}
161
		return new ArrayList<ROI>(rois.values());
162
	}
163
}
0 164

  
org.gvsig.raster/tags/buildNumber_32/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/fmap/roi/InvalidROIsShpException.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.fmap.roi;
23

  
24
import org.gvsig.tools.exception.BaseException;
25

  
26
public class InvalidROIsShpException extends BaseException {
27

  
28
	private static final long serialVersionUID = 5095144339285844477L;
29

  
30
	/**
31
	 * Constructor. Asigna el texto de la excepci?n
32
	 * @param msg
33
	 */
34
	public InvalidROIsShpException(String msg){
35
		super(msg, "", 0);
36
	}
37

  
38
}
0 39

  
org.gvsig.raster/tags/buildNumber_32/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/fmap/roi/VectorialROI.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
package org.gvsig.raster.fmap.roi;
24

  
25
import java.awt.geom.Rectangle2D;
26
import java.util.ArrayList;
27
import java.util.List;
28

  
29
import org.gvsig.fmap.dal.coverage.RasterLocator;
30
import org.gvsig.fmap.dal.coverage.RasterManager;
31
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
32
import org.gvsig.fmap.dal.coverage.grid.AbstractROI;
33
import org.gvsig.fmap.dal.coverage.grid.Grid;
34
import org.gvsig.fmap.geom.Geometry;
35
import org.gvsig.tools.ToolsLocator;
36
import org.gvsig.tools.dynobject.DynStruct;
37
import org.gvsig.tools.persistence.PersistenceManager;
38
import org.gvsig.tools.persistence.PersistentState;
39
import org.gvsig.tools.persistence.exception.PersistenceException;
40

  
41
/**
42
 * Clase que representa una regi?n de interes conformada por
43
 * elementos vectoriales.
44
 *
45
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
46
 *
47
 */
48
public class VectorialROI extends AbstractROI {
49

  
50
	/**
51
	 * Array de geometr?as (IGeometry) que definen el ROI.
52
	 */
53
	private ArrayList<Geometry>		geometries   = null;
54
	/**
55
	 * Extent m?ximo de todas las geometrias
56
	 */
57
	private Extent                  extent       = null;
58

  
59
	public VectorialROI(Grid grid) {
60
		super(grid);
61
		geometries = new ArrayList<Geometry>();
62
	}
63

  
64
	/*
65
	 * (non-Javadoc)
66
	 * @see org.gvsig.raster.grid.roi.ROI#isInside(double, double, double, double)
67
	 */
68
	public boolean isInside(double x, double y, double w, double h) {
69
		if((x + w) < extent.minX() || x > extent.maxX() || (y - h) > extent.maxY() || y < extent.minY())
70
			return false;
71
		for (int i = 0; i < geometries.size(); i++) {
72
			Rectangle2D celda = new Rectangle2D.Double(x, y, w, h);
73
			if(((Geometry)geometries.get(i)).intersects(celda))
74
				return true;
75
		}
76
		return false;
77
	}
78

  
79
	/*
80
	 * (non-Javadoc)
81
	 * @see org.gvsig.raster.grid.roi.ROI#isInGrid(int, int)
82
	 */
83
	public boolean isInGrid(int x, int y) {
84
		double newX = x - xOffset;
85
		double newY = y - yOffset;
86
		//newY = getNY() - (newY + 1);
87
		if (newX >= 0 && newX <= getNX() && newY >= 0 && newY <= getNY()){
88
			//Cooordendas pixel a coordenadas "reales".
89
			double cellSize = getCellSize();
90
			double mapX = this.getGridExtent().getMin().getX()+newX*cellSize;
91
			double mapY = this.getGridExtent().getMax().getY()-newY*cellSize;
92
			for (int i = 0; i < geometries.size(); i++){
93
				Rectangle2D celda = new Rectangle2D.Double(mapX, mapY-cellSize, cellSize, cellSize);
94
				if(((Geometry)geometries.get(i)).intersects(celda))
95
					return true;
96
			}
97
		}
98
		return false;
99
	}
100

  
101
	/**
102
	 * A?ade una geometr?a a la ROI
103
	 *
104
	 * @param geometry
105
	 */
106
	public void addGeometry(Geometry geometry){
107
		RasterManager rManager = RasterLocator.getManager();
108
		geometries.add(geometry);
109
		double cellSize = getGridExtent().getCellSize();
110

  
111
		Rectangle2D geometryBounds = geometry.getBounds();
112
		if(extent == null)
113
			extent = rManager.getDataStructFactory().createExtent(geometryBounds.getMinX(), 
114
					geometryBounds.getMaxY(), 
115
					geometryBounds.getMaxX(), 
116
					geometryBounds.getMinY());
117
		else
118
			extent = rManager.getDataStructFactory().createExtent(Math.min(geometryBounds.getMinX(), extent.minX()),
119
									Math.max(geometryBounds.getMaxY(), extent.maxY()),
120
									Math.max(geometryBounds.getMaxX(), extent.maxX()),
121
									Math.min(geometryBounds.getMinY(), extent.minY()));
122

  
123
		double minX = geometryBounds.getMinX() - Math.abs(geometryBounds.getMinX() - getGrid().getGridExtent().getMin().getX()) % cellSize;
124
		double minY = (geometryBounds.getMinY()) - (Math.abs(geometryBounds.getMinY() - getGrid().getGridExtent().getMin().getY())) % cellSize;
125
		double maxX = (geometryBounds.getMaxX()  + cellSize) - Math.abs(geometryBounds.getMaxX() - getGrid().getGridExtent().getMin().getX()) % cellSize;
126
		double maxY = (geometryBounds.getMaxY() + cellSize) - (Math.abs(geometryBounds.getMaxY() - getGrid().getGridExtent().getMin().getY())) % cellSize;
127

  
128
		if (geometries.size() > 1){
129
			minX = Math.min(minX,getGridExtent().getMin().getX());
130
			minY = Math.min(minY,getGridExtent().getMin().getY());
131
			maxX = Math.max(maxX,getGridExtent().getMax().getX());
132
			maxY = Math.max(maxY,getGridExtent().getMax().getY());
133
		}
134

  
135
		getGridExtent().setXRange(minX, maxX);
136
		getGridExtent().setYRange(minY, maxY);
137

  
138
		xOffset = (int)((minX - getGrid().getGridExtent().getMin().getX())/cellSize);
139
		yOffset = (int)((getGrid().getGridExtent().getMax().getY()- maxY)/cellSize);
140
		getStatistic().setCalculated(false);
141
		//getStatistic().setAdvancedStatisticCalculated(false);
142
	}
143

  
144
	/**
145
	 * Eliminar la geometr?a con ?ndice <code>index</code> de la ROI
146
	 *
147
	 * @param index indice de la geometr?a a eliminar
148
	 */
149
	public void deleteGeometry(int index){
150
		geometries.remove(index);
151
		getStatistic().setCalculated(false);
152
		//getStatistic().setAdvancedStatisticCalculated(false);
153

  
154
		//TODO: Reajustar el Extent.
155
	}
156

  
157
	/**
158
	 * Elimina todas las geometr?as que definen la ROI.
159
	 *
160
	 */
161
	public void clear(){
162
		geometries.clear();
163
		getStatistic().setCalculated(false);
164
		//getStatistic().setAdvancedStatisticCalculated(false);
165

  
166
		//TODO: Reajustar el Extent.
167
	}
168

  
169
	/**
170
	 *
171
	 * @return ArryList con las geometr?as que definen la ROI
172
	 */
173
	public ArrayList<Geometry> getGeometries() {
174
		return geometries;
175
	}
176

  
177
	@SuppressWarnings("unchecked")
178
	@Override
179
	public void loadFromState(PersistentState state)
180
	throws PersistenceException {
181
		super.loadFromState(state);
182
		List<Geometry> aux = state.getList("geometries");
183
		this.geometries = new ArrayList<Geometry>();
184
		this.geometries.addAll(aux);
185
		
186
		this.extent = (Extent)state.get("extent");
187
	}
188

  
189
	@Override
190
	public void saveToState(PersistentState state) throws PersistenceException {
191
		super.saveToState(state);
192
		state.set("geometries", geometries);		
193
		state.set("extent", extent);
194
	}	
195

  
196
	public static void registerPersistence() {
197
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
198
		DynStruct definition = manager.getDefinition(PERSISTENT_NAME);
199
		if( definition == null ) {
200
			definition = manager.addDefinition(
201
					VectorialROI.class,
202
					PERSISTENT_NAME,
203
					PERSISTENT_DESCRIPTION,
204
					null, 
205
					null
206
			);
207
			definition.addDynFieldList("geometries").setClassOfItems(Geometry.class).setMandatory(false);
208
			definition.addDynFieldObject("extent").setClassOfValue(Extent.class).setMandatory(true);
209
		}
210
	}
211
}
0 212

  
org.gvsig.raster/tags/buildNumber_32/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/fmap/roi/VectorialROIsWriter.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.fmap.roi;
23

  
24
import java.io.File;
25
import java.util.ArrayList;
26
import java.util.Iterator;
27

  
28
import org.cresques.cts.IProjection;
29
import org.gvsig.fmap.dal.DALLocator;
30
import org.gvsig.fmap.dal.DataManager;
31
import org.gvsig.fmap.dal.exception.DataException;
32
import org.gvsig.fmap.dal.feature.EditableFeature;
33
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
34
import org.gvsig.fmap.dal.feature.EditableFeatureType;
35
import org.gvsig.fmap.dal.feature.FeatureStore;
36
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
37
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
38
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
39
import org.gvsig.fmap.geom.Geometry;
40
import org.gvsig.tools.dataTypes.DataTypes;
41

  
42
/**
43
 * Clase dedicada a la escritura de ROIs en formato en disco (formato shape).
44
 *
45
 * Si las ROIs a escribir incluyen distintos tipos de geometr?as la escritura se
46
 * realizar? en distintos shape files, uno para poligonos, otro para polil?neas y
47
 * otro para puntos.
48
 *
49
 * @author Diego Guerrero (diego.guerrero@uclm.es)
50
 *
51
 */
52
public class VectorialROIsWriter {
53
	private String 			baseFilename 		= null;
54
	private IProjection 	projection 			= null;
55
	private int 			iPolygon;
56
	private int 			iPoint;
57
	private int 			iPolyline;
58
	private FeatureStore 	surfaceFS			= null;
59
	private FeatureStore 	pointFS				= null;
60
	private FeatureStore 	curveFS				= null;
61

  
62

  
63
	/**
64
	 * Constructor.
65
	 *
66
	 * @param baseFilename ruta base para formar los nombres de fichero (ruta/prefijo)
67
	 * @param projection CRS de las geometr?as.
68
	 */
69
	public VectorialROIsWriter(String baseFilename, IProjection projection) {
70
		this.baseFilename = baseFilename;
71
		this.projection = projection;
72
	}
73

  
74
	/**
75
	 * Escribe el Array de ROIs pasado como par?metro.
76
	 *
77
	 * @param rois Array de VectorialROI
78
	 */
79
	public void write (VectorialROI rois[]) {
80
		boolean monoType = true;
81
		int geometryType = -1;
82
		ArrayList<Geometry> geometries = null;
83

  
84
		Object values[] = new Object[4];
85

  
86
		if (baseFilename.endsWith(".shp"))
87
			baseFilename = baseFilename.replaceAll(".shp", "");
88

  
89
		for (int i = 0; i < rois.length; i++) {
90
			geometries = rois[i].getGeometries();
91
			for (Iterator<Geometry> iterator = geometries.iterator(); iterator.hasNext();) {
92
				if (geometryType < 0)
93
					geometryType = ((Geometry) iterator.next()).getType();
94
				else
95
					if (geometryType != ((Geometry) iterator.next()).getType()) {
96
						monoType = false;
97
						break;
98
					}
99
			}
100
		}
101

  
102
		if (monoType) {
103
			create(baseFilename + ".shp", projection, geometryType);
104
		} else {
105
			create(baseFilename + "_polygons" + ".shp", projection, Geometry.TYPES.SURFACE);
106
			create(baseFilename + "_points" + ".shp", projection, Geometry.TYPES.POINT);
107
			create(baseFilename + "_polylines" + ".shp", projection, Geometry.TYPES.CURVE);
108
		}
109

  
110
		for (int i = 0; i < rois.length; i++) {
111
			geometries = rois[i].getGeometries();
112
			values[0] = rois[i].getName();
113
			values[1] = new Integer(rois[i].getColor().getRed());
114
			values[2] = new Integer(rois[i].getColor().getGreen());
115
			values[3] = new Integer(rois[i].getColor().getBlue());
116

  
117

  
118
			for (Iterator<Geometry> iterator = geometries.iterator(); iterator.hasNext();) {
119
				Geometry geometry = (Geometry) iterator.next();
120
				addFeature(geometry, values);
121
			}
122
		}
123
		try {
124
			if (surfaceFS != null)
125
				surfaceFS.finishEditing();
126
			if (pointFS != null)
127
				pointFS.finishEditing();
128
			if (curveFS != null)
129
				curveFS.finishEditing();
130
		} catch (DataException e) {
131
			e.printStackTrace();
132
		}
133

  
134
	}
135

  
136
	private void addFeature(Geometry geom, Object[] values) {
137
		try {
138
			switch (geom.getType()) {
139
			case Geometry.TYPES.SURFACE:
140
				if (surfaceFS != null) {
141
					EditableFeature ef = surfaceFS.createNewFeature();
142
					ef.set("name", values[0]);
143
					ef.set("R", values[1]);
144
					ef.set("G", values[2]);
145
					ef.set("B", values[3]);
146
					ef.set("GEOMETRY", geom);
147
					surfaceFS.insert(ef);
148
					iPolygon++;
149
				}
150
				break;
151

  
152
			case Geometry.TYPES.POINT:
153
				if (pointFS != null){
154
					EditableFeature ef=pointFS.createNewFeature();
155
					ef.set("name", values[0]);
156
					ef.set("R", values[1]);
157
					ef.set("G", values[2]);
158
					ef.set("B", values[3]);
159
					ef.set("GEOMETRY", geom);
160
					pointFS.insert(ef);
161
					iPoint++;
162
				}
163
				break;
164

  
165
			case Geometry.TYPES.CURVE:
166
				if (curveFS != null){
167
					EditableFeature ef=curveFS.createNewFeature();
168
					ef.set("name", values[0]);
169
					ef.set("R", values[1]);
170
					ef.set("G", values[2]);
171
					ef.set("B", values[3]);
172
					ef.set("GEOMETRY", geom);
173
					curveFS.insert(ef);
174
					iPolyline++;
175
				}
176
				break;
177

  
178
			default:
179
				return;
180
			}
181
		} catch (Exception e) {
182
			e.printStackTrace();
183
		}
184

  
185
	}
186

  
187
	@SuppressWarnings("deprecation")
188
	private void create(String filename, IProjection crs, int geometryType) {
189
		File newFile=new File(filename);
190
		try {
191
			DataManager datamanager = DALLocator.getDataManager();
192
			FilesystemServerExplorerParameters explorerParams;
193

  
194
			explorerParams = (FilesystemServerExplorerParameters) datamanager.createServerExplorerParameters(FilesystemServerExplorer.NAME);
195

  
196
			explorerParams.setRoot(newFile.getParent());
197
			FilesystemServerExplorer explorer=(FilesystemServerExplorer) datamanager.createServerExplorer(explorerParams);
198
			NewFeatureStoreParameters newParams = (NewFeatureStoreParameters) explorer.getAddParameters(newFile);
199
			
200
			EditableFeatureType featureType = getFeatureType(newParams);
201
			EditableFeatureAttributeDescriptor efad=featureType.add("GEOMETRY", org.gvsig.fmap.geom.DataTypes.GEOMETRY);
202
			efad.setGeometryType(geometryType);
203
			efad.setSRS(crs);
204
			featureType.setDefaultGeometryAttributeName("GEOMETRY");
205

  
206
			explorer.add(newParams.getDataStoreName(), newParams, true);
207

  
208
			switch (geometryType) {
209
			case Geometry.TYPES.SURFACE:
210
				surfaceFS = (FeatureStore) datamanager.createStore(newParams);
211
				surfaceFS.edit(FeatureStore.MODE_APPEND);
212
				break;
213

  
214
			case Geometry.TYPES.POINT:
215
				pointFS = (FeatureStore) datamanager.createStore(newParams);
216
				pointFS.edit(FeatureStore.MODE_APPEND);
217
				break;
218

  
219
			case Geometry.TYPES.CURVE:
220
				curveFS = (FeatureStore) datamanager.createStore(newParams);
221
				curveFS.edit(FeatureStore.MODE_APPEND);
222
				break;
223

  
224
			default:
225
				return;
226
			}
227
		} catch (Exception e) {
228
			e.printStackTrace();
229
		}
230

  
231
	}
232

  
233
	private EditableFeatureType getFeatureType(NewFeatureStoreParameters newParams) {
234
		EditableFeatureType eft = (EditableFeatureType)newParams.getDefaultFeatureType();
235

  
236
		eft.add("name", DataTypes.STRING, 20);
237

  
238
		eft.add("R", DataTypes.INT, 4);
239

  
240
		eft.add("G", DataTypes.INT, 4);
241

  
242
		eft.add("B", DataTypes.INT, 4);
243

  
244
		return eft;
245
	}
246
}
0 247

  
org.gvsig.raster/tags/buildNumber_32/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/fmap/tool/behavior/TransformedRectangleBehavior.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.fmap.tool.behavior;
23

  
24
import java.awt.BasicStroke;
25
import java.awt.Color;
26
import java.awt.Image;
27
import java.awt.Point;
28
import java.awt.Rectangle;
29
import java.awt.RenderingHints;
30
import java.awt.event.MouseEvent;
31
import java.awt.geom.AffineTransform;
32
import java.awt.geom.NoninvertibleTransformException;
33
import java.awt.geom.Point2D;
34
import java.awt.geom.Rectangle2D;
35
import java.awt.image.BufferedImage;
36

  
37
import org.gvsig.fmap.IconThemeHelper;
38
import org.gvsig.fmap.geom.GeometryLocator;
39
import org.gvsig.fmap.geom.GeometryManager;
40
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
41
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
42
import org.gvsig.fmap.geom.primitive.Envelope;
43
import org.gvsig.fmap.mapcontext.ViewPort;
44
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
45
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
46
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
47
import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent;
48
import org.gvsig.fmap.mapcontrol.tools.Listeners.RectangleListener;
49
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener;
50
import org.slf4j.Logger;
51
import org.slf4j.LoggerFactory;
52

  
53

  
54
/**
55
 * Comportamiento de una selecci?n por rectangulo con una transformaci?n
56
 * aplicada. El resultado visual es la selecci?n como un rectangulo com?n con
57
 * el rectangulo transformado superpuesto.
58
 *
59
 * @author Nacho Brodin (nachobrodin@gmail.com)
60
 *
61
 */
62
@SuppressWarnings("deprecation")
63
public class TransformedRectangleBehavior extends Behavior {
64
	private static final GeometryManager	geomManager		 = GeometryLocator.getGeometryManager();
65
	private static final Logger 			logger 			 = LoggerFactory.getLogger(GeometryManager.class);
66
	/**
67
	 * First point of the rectangle area, that represents a corner.
68
	 */
69
	private Point2D             			m_FirstPoint     = null;
70

  
71
	/**
72
	 * Second point of the rectangle area, that represents the opposite corner of the first,
73
	 *  along the diagonal.
74
	 */
75
	private Point2D              			m_LastPoint     = null;
76

  
77
	/**
78
	 * Tool listener used to work with the <code>MapControl</code> object.
79
	 *
80
	 * @see #getListener()
81
	 * @see #setListener(ToolListener)
82
	 */
83
	private RectangleListener   			listener        = null;
84
	private AffineTransform      			at              = null;
85
	private BasicStroke          			stroke          = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[]{5.0f}, 0.0f);
86

  
87
	/**
88
	 * <p>Creates a new behavior for selecting rectangle areas.</p>
89
	 *
90
	 * @param zili listener used to permit this object to work with the associated <code>MapControl</code>
91
	 */
92
	public TransformedRectangleBehavior(RectangleListener zili) {
93
		listener = zili;
94
	}
95

  
96
	/**
97
	 * Asigna la matriz de transformaci?n para el cuadro externo.
98
	 * @param at AffineTransform
99
	 */
100
	public void setAffineTransform(AffineTransform at) {
101
		this.at = at;
102
	}
103

  
104
	/* (non-Javadoc)
105
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.IBehavior#getImageCursor()
106
	 */
107
	public Image getImageCursor(){
108
		return IconThemeHelper.getImage("rectangle-select-cursor");
109
	}
110
	
111
	/*
112
	 * (non-Javadoc)
113
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
114
	 */
115
	public void paintComponent(MapControlDrawer mapControlDrawer) {
116
		BufferedImage img = getMapControl().getImage();
117
		RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
118
		hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
119
		mapControlDrawer.setRenderingHints(hints);
120
		mapControlDrawer.drawImage(img, 0, 0);
121
		mapControlDrawer.setColor(Color.black);
122
		//g.setXORMode(Color.white);
123

  
124
		// Borramos el anterior
125
		Rectangle r = new Rectangle();
126

  
127
		// Dibujamos el actual
128
		if ((m_FirstPoint != null) && (m_LastPoint != null)) {
129
			r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
130
			mapControlDrawer.drawRect(r.x, r.y, r.width, r.height);
131
		}
132

  
133
		//Dibujamos el cuadro exterior
134
		if(at != null) {
135
			Point2D.Double ul = new Point2D.Double(r.x, r.y);
136
			Point2D.Double ur = new Point2D.Double(r.x + r.width, r.y);
137
			Point2D.Double ll = new Point2D.Double(r.x, r.y + r.height);
138
			Point2D.Double lr = new Point2D.Double(r.x + r.width, r.y + r.height);
139

  
140
			Point2D center = new Point2D.Double((r.width) / 2.0, (r.height) / 2.0);
141
			AffineTransform T1 = new AffineTransform(1D, 0, 0, 1, -center.getX(), -center.getY());
142
			AffineTransform R1 = new AffineTransform(1D, at.getShearY() / at.getScaleY(), at.getShearX() / at.getScaleX(), 1, 0, 0);
143
			AffineTransform T2 = new AffineTransform(1D, 0, 0, 1, center.getX(), center.getY());
144
			T2.concatenate(R1);
145
			T2.concatenate(T1);
146

  
147
			try {
148
				T2.inverseTransform(ul, ul);
149
				T2.inverseTransform(ll, ll);
150
				T2.inverseTransform(ur, ur);
151
				T2.inverseTransform(lr, lr);
152

  
153
				Point2D.Double ptMin = new Point2D.Double(	Math.min(Math.min(ul.getX(), ur.getX()), Math.min(ll.getX(), lr.getX())),
154
															Math.min(Math.min(ul.getY(), ur.getY()), Math.min(ll.getY(), lr.getY())));
155
				Point2D.Double ptMax = new Point2D.Double(	Math.max(Math.max(ul.getX(), ur.getX()), Math.max(ll.getX(), lr.getX())),
156
															Math.max(Math.max(ul.getY(), ur.getY()), Math.max(ll.getY(), lr.getY())));
157
				double w = ptMax.getX() - ptMin.getX();
158
				double h = ptMax.getY() - ptMin.getY();
159

  
160
				mapControlDrawer.setStroke(stroke);
161
				mapControlDrawer.transform(T2);
162
				mapControlDrawer.drawRect((int)ptMin.getX(), (int)ptMin.getY(), (int)w, (int)h);
163
				mapControlDrawer.transform(at.createInverse());
164
			} catch (NoninvertibleTransformException e) {
165
				return;
166
			}
167
		}
168
		//g.setPaintMode();
169
	}
170

  
171
	/*
172
	 * (non-Javadoc)
173
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mousePressed(java.awt.event.MouseEvent)
174
	 */
175
	public void mousePressed(MouseEvent e) {
176
		if (e.getButton() == MouseEvent.BUTTON1) {
177
			m_FirstPoint = e.getPoint();
178
			getMapControl().repaint();
179
		}
180
		if (listener.cancelDrawing()) {
181
			getMapControl().cancelDrawing();
182
			getMapControl().repaint();
183
		}
184
	}
185

  
186
	/*
187
	 * (non-Javadoc)
188
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseReleased(java.awt.event.MouseEvent)
189
	 */
190
	public void mouseReleased(MouseEvent e) throws BehaviorException {
191
	    if (m_FirstPoint == null) return;
192
		Point2D p1;
193
		Point2D p2;
194
		Point pScreen = e.getPoint();
195

  
196
		ViewPort vp = getMapControl().getMapContext().getViewPort();
197

  
198
		p1 = vp.toMapPoint(m_FirstPoint);
199
		p2 = vp.toMapPoint(pScreen);
200

  
201
		if (e.getButton() == MouseEvent.BUTTON1) {
202
			//	Fijamos el nuevo extent
203
			double minX = Math.min(p1.getX(), p2.getX());
204
			double minY = Math.min(p1.getY(), p2.getY());
205
			double maxX = Math.max(p1.getX(), p2.getX());
206
			double maxY = Math.max(p1.getY(), p2.getY());
207
			Envelope env = null;
208
			try {
209
				env = geomManager.createEnvelope(minX, minY, maxX, maxY, SUBTYPES.GEOM2D);
210
			} catch (CreateEnvelopeException e1) {
211
				logger.error("Error creating the envelope", e);
212
			}
213

  
214
			Rectangle2D rectPixel = new Rectangle();
215
			rectPixel.setFrameFromDiagonal(m_FirstPoint, pScreen);
216

  
217
			EnvelopeEvent event = new EnvelopeEvent(env, e, rectPixel);
218
			listener.rectangle(event);
219
		}
220

  
221
		m_FirstPoint = null;
222
		m_LastPoint = null;
223
	}
224

  
225
	/*
226
	 * (non-Javadoc)
227
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseDragged(java.awt.event.MouseEvent)
228
	 */
229
	public void mouseDragged(MouseEvent e) {
230
		m_LastPoint = e.getPoint();
231
		getMapControl().repaint();
232
	}
233

  
234
	/**
235
	 * <p>Sets a tool listener to work with the <code>MapControl</code> using this behavior.</p>
236
	 *
237
	 * @param listener a <code>RectangleListener</code> object for this behavior
238
	 */
239
	public void setListener(ToolListener listener) {
240
		this.listener = (RectangleListener) listener;
241
	}
242

  
243
	/*
244
	 * (non-Javadoc)
245
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
246
	 */
247
	public ToolListener getListener() {
248
		return listener;
249
	}
250
}
0 251

  
org.gvsig.raster/tags/buildNumber_32/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/fmap/tool/SaveRasterListenerImpl.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.fmap.tool;
23

  
24
import java.awt.Image;
25
import java.awt.geom.Rectangle2D;
26

  
27
import org.gvsig.fmap.geom.primitive.Envelope;
28
import org.gvsig.fmap.mapcontrol.MapControl;
29
import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent;
30
import org.gvsig.fmap.mapcontrol.tools.Listeners.RectangleListener;
31

  
32

  
33

  
34
/**
35
* Implementaci?n de la interfaz RectangleListener como herramienta para
36
* realizar un Salvado a Raster.
37
*
38
* @author Nacho Brodin (nachobrodin@gmail.com)
39
*/
40
public class SaveRasterListenerImpl implements RectangleListener {
41
	protected MapControl mapCtrl;
42

  
43
	protected Rectangle2D pixelRect = null;
44
	protected Envelope rect = null;
45

  
46
	/**
47
	 * Crea un nuevo RectangleListenerImpl.
48
	 *
49
	 * @param mapCtrl MapControl.
50
	 */
51
	public SaveRasterListenerImpl(MapControl mapCtrl) {
52
		this.mapCtrl = mapCtrl;
53
	}
54

  
55
	/**
56
	 * @see com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener#rectangle(com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent)
57
	 */
58
	public void rectangle(EnvelopeEvent event) {
59
		rect = event.getWorldCoordRect();
60
		pixelRect = event.getPixelCoordRect();
61
	}
62

  
63
//	/**
64
//	 * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
65
//	 */
66
//	public Cursor getCursor() {
67
//		return cur;
68
//	}
69

  
70
	/**
71
	 * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
72
	 */
73
	public boolean cancelDrawing() {
74
	    System.out.println("cancelDrawing del SaveRasterListenerImpl");
75
		return true;
76
	}
77

  
78
	public Image getImageCursor() {
79
		return null;
80
	}
81

  
82
}
0 83

  
org.gvsig.raster/tags/buildNumber_32/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/fmap/legend/ImageLegend.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.fmap.legend;
23

  
24
import java.awt.Image;
25

  
26
import org.gvsig.fmap.mapcontext.layers.operations.IHasImageLegend;
27
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
28
import org.gvsig.fmap.mapcontext.rendering.legend.IRasterLegend;
29
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener;
30
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
31
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
32
import org.gvsig.tools.persistence.PersistentState;
33
import org.gvsig.tools.persistence.exception.PersistenceException;
34

  
35
/**
36
 * This object is for rasters which returns its legend as a image
37
 * @author Nacho Brodin (nachobrodin@gmail.com)
38
 *
39
 */
40
public class ImageLegend implements IRasterLegend, IHasImageLegend {
41
	private Image    image = null;
42
	
43
	public ImageLegend(Image image) {
44
		this.image = image;
45
	}
46
	
47
	public Image getImageLegend() {
48
		return image;
49
	}
50
	
51
	public Object clone() throws CloneNotSupportedException {
52
		return new ImageLegend(image);
53
	}
54
	
55
	public void addLegendListener(LegendContentsChangedListener listener) {
56
		
57
	}
58

  
59
	public ILegend cloneLegend() {
60
		try {
61
			return (ILegend)clone();
62
		} catch (CloneNotSupportedException e) {
63
		}
64
		return null;
65
	}
66

  
67
	public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) {
68
		
69
	}
70

  
71
	public ISymbol getDefaultSymbol() {
72
		return null;
73
	}
74

  
75
	public LegendContentsChangedListener[] getListeners() {
76
		return null;
77
	}
78

  
79
	public void removeLegendListener(LegendContentsChangedListener listener) {
80
		
81
	}
82

  
83
	public void loadFromState(PersistentState state)
84
			throws PersistenceException {
85
		
86
	}
87

  
88
	public void saveToState(PersistentState state) throws PersistenceException {
89
		
90
	}
91

  
92
	public String getPathImage() {
93
		return null;
94
	}
95

  
96
}
0 97

  
org.gvsig.raster/tags/buildNumber_32/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/fmap/legend/ColorTableLegend.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.fmap.legend;
23

  
24
import java.awt.Color;
25
import java.util.Arrays;
26
import java.util.List;
27

  
28
import org.gvsig.fmap.dal.coverage.RasterLocator;
29
import org.gvsig.fmap.dal.coverage.datastruct.ColorItem;
30
import org.gvsig.fmap.dal.coverage.store.props.ColorTable;
31
import org.gvsig.fmap.dal.coverage.util.MathUtils;
32
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedLegend;
33
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
34
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener;
35
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
36
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
37
import org.gvsig.symbology.SymbologyLocator;
38
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
39
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.dynobject.DynStruct;
42
import org.gvsig.tools.persistence.PersistenceManager;
43
import org.gvsig.tools.persistence.PersistentState;
44
import org.gvsig.tools.persistence.exception.PersistenceException;
45

  
46
/**
47
 * Leyenda para tablas de color aplicadas a un raster.
48
 *
49
 * @version 27/06/2007
50
 * @author Nacho Brodin (nachobrodin@gmail.com)
51
 */
52
public class ColorTableLegend implements IClassifiedLegend, ILegend {
53
	public static final String  COLOR_TABLE_LEGEND_DYNCLASS_NAME = "ColorTableLegend";
54
	private static final String FIELD_SYMBOLS                    = "symbols";
55
	private static final String FIELD_DESCRIPTIONS               = "descriptions";
56

  
57
	private ISymbol[]           symbols                          = null;
58
	private String[]            desc                             = null;
59

  
60
	/**
61
	 * Crea una leyenda de tipo ColorTableLegend a partir de un objeto ColorTable
62
	 * @param colorTable
63
	 * @return ColorTableLegend
64
	 */
65
	public static ColorTableLegend createLegend(ColorTable colorTable) {
66
		if ((colorTable == null) || (colorTable.getColorItems() == null))
67
			return null;
68
		MathUtils math = RasterLocator.getManager().getMathUtils();
69
		
70
		ILineSymbol line = SymbologyLocator.getSymbologyManager().createSimpleLineSymbol();
71
		line.setLineColor(Color.BLACK);
72
		ISymbol[] symbol = new ISymbol[colorTable.getColorItems().size()];
73
		String[] desc = new String[colorTable.getColorItems().size()];
74

  
75
		String nameClass = null;
76
		for (int i = 0; i < colorTable.getColorItems().size(); i++) {
77
			IFillSymbol s = SymbologyLocator.getSymbologyManager().createSimpleFillSymbol();
78
			s.setOutline(line);
79
			s.setFillColor(((ColorItem) colorTable.getColorItems().get(i)).getColor());
80
			nameClass = ((ColorItem) colorTable.getColorItems().get(i)).getNameClass();
81
			if ((nameClass == null) || (nameClass.equals(""))){
82
				if (i < (colorTable.getColorItems().size() - 1)){
83
					desc[i] = "[" + math.format(((ColorItem) colorTable.getColorItems().get(i)).getValue(), 2) + " , " + math.format(((ColorItem) colorTable.getColorItems().get(i + 1)).getValue(), 2) + "[ ";
84
				}else{
85
					desc[i] = "[" + math.format(((ColorItem) colorTable.getColorItems().get(i)).getValue(), 2) + "] ";
86
				}
87
			}else{
88
				desc[i] = ((ColorItem) colorTable.getColorItems().get(i)).getNameClass();
89
			}	
90
			symbol[i] = s;
91
		}
92

  
93
		return new ColorTableLegend(symbol, desc);
94
	}
95

  
96
	/**
97
	 * Leyenda para tablas de color raster.
98
	 * @param s Lista de simbolos
99
	 * @param d Lista de descripciones de simbolos
100
	 */
101
	public ColorTableLegend(ISymbol[] s, String[] d) {
102
		symbols = s;
103
		desc = d;
104
	}
105

  
106
	/**
107
	 * Empty constructor used only for persistence purposes.
108
	 */
109
	public ColorTableLegend() {
110
	}
111

  
112
	/*
113
	 * (non-Javadoc)
114
	 * @see com.iver.cit.gvsig.fmap.rendering.IClassifiedLegend#getDescriptions()
115
	 */
116
	public String[] getDescriptions() {
117
		return desc;
118
	}
119

  
120
	/*
121
	 * (non-Javadoc)
122
	 * @see com.iver.cit.gvsig.fmap.rendering.IClassifiedLegend#getSymbols()
123
	 */
124
	public ISymbol[] getSymbols() {
125
		return symbols;
126
	}
127

  
128
	/*
129
	 * (non-Javadoc)
130
	 * @see com.iver.cit.gvsig.fmap.rendering.IClassifiedLegend#getValues()
131
	 */
132
	public Object[] getValues() {
133
		return desc;
134
	}
135

  
136
	/*
137
	 * (non-Javadoc)
138
	 * @see com.iver.cit.gvsig.fmap.rendering.ILegend#cloneLegend()
139
	 */
140
	public ILegend cloneLegend() {
141
		return null;
142
	}
143

  
144
	/*
145
	 * (non-Javadoc)
146
	 * @see com.iver.cit.gvsig.fmap.rendering.ILegend#getDefaultSymbol()
147
	 */
148
	public ISymbol getDefaultSymbol() {
149
		return null;
150
	}
151

  
152
	/*
153
	 * (non-Javadoc)
154
	 * @see com.iver.cit.gvsig.fmap.rendering.ILegend#getSLDString(java.lang.String)
155
	 */
156
	public String getSLDString(String layerName) {
157
		return null;
158
	}
159

  
160
	/*
161
	 * (non-Javadoc)
162
	 * @see com.iver.utiles.IPersistance#getClassName()
163
	 */
164
	public String getClassName() {
165
		return null;
166
	}
167

  
168
	public void addLegendListener(LegendContentsChangedListener listener) {
169
		// TODO Auto-generated method stub
170
	}
171

  
172
	public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) {
173
		// TODO Auto-generated method stub
174
		
175
	}
176

  
177
	public LegendContentsChangedListener[] getListeners() {
178
		// TODO Auto-generated method stub
179
		return null;
180
	}
181

  
182
	
183
	public void removeLegendListener(LegendContentsChangedListener listener) {
184
		// TODO Auto-generated method stub
185
	}
186

  
187
	@Override
188
	public Object clone() throws CloneNotSupportedException {
189
		// TODO Auto-generated method stub
190
		return super.clone();
191
	}
192

  
193
	private void setDescriptions(String[] descriptions) {
194
		this.desc = descriptions;
195
	}
196

  
197
	private void setSymbols(ISymbol[] symbols) {
198
		this.symbols = symbols;
199
	}
200

  
201
	@SuppressWarnings("unchecked")
202
	public void loadFromState(PersistentState state)
203
			throws PersistenceException {
204
		List<ISymbol> symbols = (List<ISymbol>) state.get(FIELD_SYMBOLS);
205
		setSymbols(symbols.toArray(new ISymbol[symbols.size()]));
206

  
207
		List<String> descriptions =
208
				(List<String>) state.get(FIELD_DESCRIPTIONS);
209
		setDescriptions(descriptions.toArray(new String[descriptions.size()]));
210
	}
211

  
212
	public void saveToState(PersistentState state) throws PersistenceException {
213
		state.set(FIELD_SYMBOLS, Arrays.asList(getSymbols()));
214
		state.set(FIELD_DESCRIPTIONS, Arrays.asList(getDescriptions()));
215
	}
216

  
217
	public static void registerPersistence() {
218
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
219
		DynStruct definition = manager.addDefinition(
220
				ColorTableLegend.class,
221
				COLOR_TABLE_LEGEND_DYNCLASS_NAME,
222
				COLOR_TABLE_LEGEND_DYNCLASS_NAME + " Persistence definition",
223
				null, 
224
				null
225
		);
226

  
227
		// Symbols
228
		definition.addDynFieldList(FIELD_SYMBOLS).setClassOfItems(ISymbol.class).setMandatory(true);
229
		// Descriptions
230
		definition.addDynFieldList(FIELD_DESCRIPTIONS).setClassOfItems(String.class).setMandatory(true);
231

  
232
	}
233

  
234
}
0 235

  
org.gvsig.raster/tags/buildNumber_32/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/fmap/layers/Multiresolution.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff