Revision 22307

View differences:

trunk/extensions/extRasterTools-SE/src/org/gvsig/fmap/raster/layers/FLyrRasterSE.java
40 40
import org.apache.log4j.Logger;
41 41
import org.cresques.cts.IProjection;
42 42
import org.gvsig.fmap.raster.legend.ColorTableLegend;
43
import org.gvsig.jogr.CrsGdalException;
44
import org.gvsig.jogr.OGRException;
45
import org.gvsig.jogr.OGRSpatialReference;
46 43
import org.gvsig.raster.RasterLibrary;
47 44
import org.gvsig.raster.buffer.BufferFactory;
48 45
import org.gvsig.raster.dataset.CompositeDataset;
......
60 57
import org.gvsig.raster.datastruct.ColorTable;
61 58
import org.gvsig.raster.datastruct.Extent;
62 59
import org.gvsig.raster.datastruct.ViewPortData;
63
import org.gvsig.raster.datastruct.serializer.ColorTableLibraryPersistence;
60
import org.gvsig.raster.datastruct.persistence.ColorTableLibraryPersistence;
64 61
import org.gvsig.raster.grid.Grid;
65 62
import org.gvsig.raster.grid.GridException;
66 63
import org.gvsig.raster.grid.GridPalette;
......
78 75
import org.gvsig.raster.hierarchy.IStatistics;
79 76
import org.gvsig.raster.process.RasterTask;
80 77
import org.gvsig.raster.process.RasterTaskQueue;
78
import org.gvsig.raster.projection.CRS;
81 79
import org.gvsig.raster.util.ColorConversion;
82 80
import org.gvsig.raster.util.Historical;
83 81
import org.gvsig.raster.util.MathUtils;
84 82
import org.gvsig.raster.util.RasterToolsUtil;
85 83

  
86 84
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
87
import com.iver.andami.PluginServices;
88 85
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
89 86
import com.iver.cit.gvsig.exceptions.layers.ReloadLayerException;
90 87
import com.iver.cit.gvsig.fmap.ViewPort;
......
104 101
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem;
105 102
import com.iver.cit.gvsig.fmap.rendering.ILegend;
106 103
import com.iver.cit.gvsig.fmap.rendering.LegendListener;
107
import com.iver.cit.gvsig.project.documents.view.gui.IView;
108
import com.iver.cit.gvsig.project.documents.view.gui.View;
109 104
import com.iver.utiles.NotExistInXMLEntity;
110 105
import com.iver.utiles.XMLEntity;
111 106
import com.iver.utiles.swing.threads.Cancellable;
......
114 109
 * @author Nacho Brodin (nachobrodin@gmail.com)
115 110
 */
116 111
public class FLyrRasterSE extends FLyrDefault implements IRasterProperties, IRasterDataset, InfoByPoint, Classifiable, IRasterOperations, IRasterLayerActions, ILayerState {
117
	private boolean             isPrinting          = false;
112
	protected boolean           isPrinting          = false;
118 113
	private boolean             mustTileDraw        = false;
119 114
	private boolean             mustTilePrint       = true;
120 115
	private int                 maxTileDrawWidth    = 200;
......
142 137
	private ArrayList           rois                = null;
143 138
	private RasterDrawStrategy  strategy            = null;
144 139
	static private IConfiguration configuration       = new DefaultLayerConfiguration();
140
	
141
	private BufferedImage         image               = null;
145 142

  
146 143
	/**
147 144
	 * Tipo de valor no data asociado a la capa.
......
329 326
	 * @return IProjection
330 327
	 */
331 328
	public IProjection readProjection() {
332
		String code = null;
333
		String name = null;
334 329
		try {
335
			if (dataset.getWktProjection() != null && !dataset.getWktProjection().equals("")) {
336
				OGRSpatialReference oSRSSource = new OGRSpatialReference();
337
				try {
338
					OGRSpatialReference.importFromWkt(oSRSSource, dataset.getWktProjection());
339
					code = oSRSSource.getAuthorityCode("PROJCS");
340
					if (code == null)
341
						code = oSRSSource.getAuthorityCode("GEOGCS");
342
					name = oSRSSource.getAuthorityName("PROJCS");
343
					if (name == null)
344
						name = oSRSSource.getAuthorityName("GEOGCS");
345
					try {
346
						return CRSFactory.getCRS(name + ":" + code);
347
					} catch (NumberFormatException ex) {
348
						return null;
349
					}
350
				} catch (OGRException e) {
351
					Logger.getLogger(getClass().getName()).debug("Problemas obteniendo el c?digo EPSG", e);
352
				} catch (CrsGdalException e) {
353
					Logger.getLogger(getClass().getName()).debug("Problemas obteniendo el c?digo EPSG", e);
354
				}
355
			}
356

  
357
		} catch (RasterDriverException e1) {
358
			Logger.getLogger(getClass().getName()).debug("Problemas accediendo a getWktProjection. Driver no inicializado", e1);
330
			CRS.setCRSFactory(CRSFactory.cp);
331
			return CRS.convertWktToIProjection(dataset.getWktProjection());
332
		} catch (RasterDriverException e) {
333
			Logger.getLogger(getClass().getName()).debug("Problemas accediendo a getWktProjection. Driver no inicializado", e);
359 334
		}
360 335
		return null;
361 336
	}
......
514 489
	 * 		com.iver.utiles.swing.threads.Cancellable)
515 490
	 */
516 491
	public void draw(BufferedImage image, Graphics2D g, ViewPort vp, Cancellable cancel, double scale) throws ReadDriverException {
492
		this.image = image;
517 493
		RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
518 494
		task.setEvent(null);
519 495

  
......
658 634
	}
659 635

  
660 636
	/**
661
	 * Obtiene el valor del pixel del Image en la posici?n real x,y
662
	 * @param x Posici?n x
663
	 * @param y Posici?n y
664
	 * @return valor de pixel
665
	 */
666
	public int[] getPixel(double wcx, double wcy) {
667
		if (!isOpen())
668
			return null;
669

  
670
		int[] argb = { -1, -1, -1, -1 };
671
		if (wcx <= getMaxX() && wcx >= getMinX() && wcy <= getMaxY() && wcy >= getMinY()) {
672
			View theView = (View) PluginServices.getMDIManager().getActiveWindow();
673
			if (theView instanceof IView) {
674
				// BufferedImage buf = ((IView) theView).getMapControl().getImage();
675
				Point2D p = ((IView) theView).getMapControl().getViewPort().fromMapPoint(wcx, wcy);
676
				return getPixel((int) p.getX(), (int) p.getY());
677
			}
678
		}
679
		return argb;
680
	}
681

  
682
	/**
683 637
	 * Obtiene el valor del pixel del Image en la posici?n x,y
684 638
	 * @param x Posici?n x
685 639
	 * @param y Posici?n y
686 640
	 * @return valor de pixel
687 641
	 */
688 642
	public int[] getPixel(int pxx, int pxy) {
689
		if (!isOpen())
690
			return null;
691
		//TODO: Esto hay que rehacerlo ya que es dependiente de la vista
692 643
		int[] argb = { -1, -1, -1, -1 };
693
		View theView = (View) PluginServices.getMDIManager().getActiveWindow();
694
		BufferedImage buf = null;
695
		if (theView instanceof IView)
696
			buf = ((IView) theView).getMapControl().getImage();
697
		if (pxx >= 0 && pxx < buf.getWidth() && pxy >= 0 && pxy < buf.getHeight()) {
698
			if (theView instanceof IView) {
699
				int value = buf.getRGB(pxx, pxy);
700
				argb[0] = ((value & 0xff000000) >> 24);
701
				argb[1] = ((value & 0x00ff0000) >> 16);
702
				argb[2] = ((value & 0x0000ff00) >> 8);
703
				argb[3] = (value & 0x000000ff);
704
			}
644
		if (!isOpen() || (image == null))
645
			return argb;
646
		if (pxx >= 0 && pxx < image.getWidth() && pxy >= 0 && pxy < image.getHeight()) {
647
			int value = image.getRGB(pxx, pxy);
648
			argb[0] = ((value & 0xff000000) >> 24);
649
			argb[1] = ((value & 0x00ff0000) >> 16);
650
			argb[2] = ((value & 0x0000ff00) >> 8);
651
			argb[3] = (value & 0x000000ff);
705 652
		}
706 653
		return argb;
707 654
	}
......
1184 1131
	 * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getTocImageIcon()
1185 1132
	 */
1186 1133
	public ImageIcon getTocImageIcon() {
1187
		/*if(!isOpen())
1188
			return new ImageIcon(MapControl.class.getResource("images/map_ico_ko.gif"));*/
1189
		return PluginServices.getIconTheme().get("map-ok-ico");
1134
		return new ImageIcon(getClass().getResource("images/map_ico_ok.gif"));
1190 1135
	}
1191 1136

  
1192 1137
	/*
......
1292 1237
	 * @see org.gvsig.fmap.raster.IRasterFile#getFileName()
1293 1238
	 */
1294 1239
	public String[] getFileName(){
1295
		int nFiles = dataset.getDatasetCount();
1240
		int nFiles = 0;
1241
		if (dataset != null)
1242
			nFiles = dataset.getDatasetCount();
1296 1243
		String[] s = new String[nFiles];
1297 1244
		for (int i = 0; i < nFiles; i++)
1298 1245
			s[i] = dataset.getDataset(i)[0].getFName();
......
1678 1625
	 * @throws IOException
1679 1626
	 */
1680 1627
	public void saveGeoToRmf() throws IOException {
1681
		if(!isOpen())
1628
		if (!isOpen())
1682 1629
			return;
1683 1630
		getDataSource().saveGeoToRmf();
1684 1631
		affineTransformList.clear();

Also available in: Unified diff