Revision 2420
trunk/extensions/extWCS/src/com/iver/cit/gvsig/fmap/layers/FLyrWCS.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package com.iver.cit.gvsig.fmap.layers; |
42 | 42 |
|
43 |
import java.awt.Component; |
|
43 | 44 |
import java.awt.Graphics2D; |
44 |
import java.awt.Point; |
|
45 | 45 |
import java.awt.geom.Point2D; |
46 | 46 |
import java.awt.geom.Rectangle2D; |
47 | 47 |
import java.awt.image.BufferedImage; |
48 |
import java.awt.image.DataBuffer; |
|
49 | 48 |
import java.io.IOException; |
50 | 49 |
import java.net.URL; |
51 |
import java.util.ArrayList; |
|
52 | 50 |
import java.util.TreeMap; |
53 | 51 |
|
54 | 52 |
import javax.swing.JOptionPane; |
55 | 53 |
|
54 |
import com.iver.andami.PluginServices; |
|
56 | 55 |
import com.iver.cit.gvsig.fmap.DriverException; |
57 | 56 |
import com.iver.cit.gvsig.fmap.ViewPort; |
58 | 57 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
59 | 58 |
import com.iver.cit.gvsig.fmap.drivers.wcs.FMapWCSDriver; |
60 | 59 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
61 | 60 |
import com.iver.cit.gvsig.fmap.services.OGCWCSService; |
61 |
import com.iver.cit.gvsig.gui.View; |
|
62 | 62 |
import com.iver.cit.gvsig.gui.WCSDataSourceAdapter; |
63 | 63 |
import com.iver.cit.gvsig.gui.Panels.WCSParamsPanel; |
64 | 64 |
import com.iver.cit.gvsig.gui.wcs.WCSWizardData; |
... | ... | |
66 | 66 |
import com.iver.utiles.StringUtilities; |
67 | 67 |
import com.iver.utiles.XMLEntity; |
68 | 68 |
|
69 |
import es.uji.lsi.wcs.client.ServerErrorResponseException; |
|
70 |
|
|
69 | 71 |
/** |
70 | 72 |
* Class for the WCS layer. |
71 | 73 |
* |
... | ... | |
73 | 75 |
* |
74 | 76 |
* @author jaume - jaume.dominguez@iver.es |
75 | 77 |
*/ |
76 |
public class FLyrWCS extends FLyrDefault implements RasterOperations{ |
|
78 |
public class FLyrWCS extends FLyrDefault { |
|
79 |
private FMapWCSAdaptor wcs = null; |
|
80 |
|
|
81 |
private String label; |
|
82 |
private WCSParamsPanel toc = null; |
|
77 | 83 |
|
78 |
private FMapWCSAdaptor wcs = null; |
|
79 |
private String label = null; |
|
80 |
private WCSParamsPanel toc = null; |
|
81 |
private int posX = 0, posY = 0; |
|
82 |
private double posXWC = 0, posYWC = 0; |
|
83 |
private int r = 0, g = 0, b = 0; |
|
84 |
|
|
85 |
|
|
86 | 84 |
|
87 | 85 |
/** |
88 | 86 |
* Returns the XMLEntity containing the necessary info for reproduce |
... | ... | |
172 | 170 |
*/ |
173 | 171 |
public synchronized void draw(BufferedImage image, Graphics2D g, |
174 | 172 |
ViewPort viewPort, Cancellable cancel) throws DriverException { |
175 |
wcs.draw(image, g, viewPort, cancel); |
|
173 |
/* This try loop I've moved here is for show an alert window when it is not |
|
174 |
* possible to download the coverage. |
|
175 |
*/ |
|
176 |
try { |
|
177 |
wcs.draw(image, g, viewPort, cancel); |
|
178 |
} catch (ServerErrorResponseException e) { |
|
179 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage(), "Error", |
|
180 |
JOptionPane.ERROR_MESSAGE); |
|
181 |
// View view=(View)PluginServices.getMDIManager().getActiveView(); |
|
182 |
// view.getTOC().layerRemoved(LayerCollectionEvent.createLayerRemovedEvent(this)); |
|
183 |
} |
|
176 | 184 |
} |
177 | 185 |
/** |
178 | 186 |
* Prints the layer. |
... | ... | |
583 | 591 |
* |
584 | 592 |
*/ |
585 | 593 |
public void initFromQueryString(String queryString){ |
586 |
//System.out.println("Query = "+queryString);
|
|
594 |
System.out.println("Query = "+queryString); |
|
587 | 595 |
TreeMap map = new TreeMap(); |
588 | 596 |
String[] params = queryString.split("&"); |
589 | 597 |
for (int i = 0; i < params.length; i++) { |
... | ... | |
651 | 659 |
else if (nombre.equals("BBOX")) continue; |
652 | 660 |
else if (nombre.equals("RESPONSE_CRS")) continue; |
653 | 661 |
else setParameter(nombre+"="+valor); |
654 |
} |
|
655 |
|
|
662 |
} |
|
656 | 663 |
} |
657 |
|
|
658 |
/** |
|
659 |
* Asigna RGB en la posici?n en la que se ha |
|
660 |
* hecho click al mostrar informaci?n del raster. |
|
661 |
* @param r valor de rojo |
|
662 |
* @param g valor de verde |
|
663 |
* @param b valor de azul |
|
664 |
*/ |
|
665 |
public void setRGB(int r, int g, int b){ |
|
666 |
this.r = r; |
|
667 |
this.g = g; |
|
668 |
this.b = b; |
|
669 |
} |
|
670 |
|
|
671 |
/** |
|
672 |
* Devuelve el RasterAdapter de la capa. |
|
673 |
* |
|
674 |
* @return RasterAdapter. |
|
675 |
*/ |
|
676 |
public RasterAdapter getSource() { |
|
677 |
return null; |
|
678 |
} |
|
679 |
|
|
680 |
/** |
|
681 |
* Inserta el RasterAdapter. |
|
682 |
* |
|
683 |
* @param ra RasterAdapter. |
|
684 |
*/ |
|
685 |
public void setSource(RasterAdapter ra) {} |
|
686 |
|
|
687 |
/** |
|
688 |
* Asigna la posici?n en la que se ha hecho click al mostrar |
|
689 |
* informaci?n del raster. |
|
690 |
* @param x Posici?n en X |
|
691 |
* @param y Posici?n en Y |
|
692 |
*/ |
|
693 |
public void setPos(int x, int y){ |
|
694 |
this.posX = x; |
|
695 |
this.posY = y; |
|
696 |
} |
|
697 |
|
|
698 |
/** |
|
699 |
* Asigna la posici?n en coordenadas del mundo real en la que se ha |
|
700 |
* hecho click al mostrar informaci?n del raster. |
|
701 |
* @param x Posici?n en X |
|
702 |
* @param y Posici?n en Y |
|
703 |
*/ |
|
704 |
public void setPosWC(double x, double y){ |
|
705 |
this.posXWC = x; |
|
706 |
this.posYWC = y; |
|
707 |
} |
|
708 |
|
|
709 |
/** |
|
710 |
* Obtiene el valor del pixel del Image en la posici?n x,y |
|
711 |
* @param x Posici?n x |
|
712 |
* @param y Posici?n y |
|
713 |
* @return valor de pixel |
|
714 |
*/ |
|
715 |
public int[] getPixel(double wcx, double wcy){ |
|
716 |
return wcs.getPxRaster().getPixel(wcx, wcy); |
|
717 |
} |
|
718 |
|
|
719 |
public double getMaxX(){ |
|
720 |
return wcs.getPxRaster().getExtent().maxX(); |
|
721 |
} |
|
722 |
|
|
723 |
public double getMaxY(){ |
|
724 |
return wcs.getPxRaster().getExtent().maxY(); |
|
725 |
} |
|
726 |
|
|
727 |
public double getMinX(){ |
|
728 |
return wcs.getPxRaster().getExtent().minX(); |
|
729 |
} |
|
730 |
|
|
731 |
public double getMinY(){ |
|
732 |
return wcs.getPxRaster().getExtent().minY(); |
|
733 |
} |
|
734 |
|
|
735 |
public double getHeight(){ |
|
736 |
return wcs.getGeoRasterFile().getHeight(); |
|
737 |
} |
|
738 |
|
|
739 |
public double getWidth(){ |
|
740 |
return wcs.getGeoRasterFile().getWidth(); |
|
741 |
} |
|
742 |
|
|
743 |
|
|
744 |
/* (non-Javadoc) |
|
745 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(java.awt.Point) |
|
746 |
*/ |
|
747 |
public String queryByPoint(Point p) throws DriverException { |
|
748 |
int index = ((FMapWCSAdaptor) wcs).getGeoRasterFile().getName().lastIndexOf("/"); |
|
749 |
String name = ((FMapWCSAdaptor) wcs).getGeoRasterFile().getName().substring(index + 1); |
|
750 |
String data = "<file:"+name+">\n"; |
|
751 |
|
|
752 |
ArrayList attr = this.getAttributes(); |
|
753 |
data += " <raster\n"; |
|
754 |
data += " File=\""+((FMapWCSAdaptor) wcs).getGeoRasterFile().getName()+"\"\n"; |
|
755 |
for (int i=0; i<attr.size(); i++) { |
|
756 |
Object [] a = (Object []) attr.get(i); |
|
757 |
|
|
758 |
data += " "+a[0].toString()+"="; |
|
759 |
if (a[1].toString() instanceof String) |
|
760 |
data += "\""+a[1].toString()+"\"\n"; |
|
761 |
else |
|
762 |
data += a[1].toString()+"\n"; |
|
763 |
} |
|
764 |
data += " Point=\""+posX+" , "+posY+"\"\n"; |
|
765 |
data += " Point_WC=\""+posXWC+" , "+posYWC+"\"\n"; |
|
766 |
data += " RGB=\""+r+", "+g+", "+b+"\"\n"; |
|
767 |
data += " />\n"; |
|
768 |
|
|
769 |
data += "</file:"+name+">\n"; |
|
770 |
System.out.println(data); |
|
771 |
return data; |
|
772 |
} |
|
773 |
|
|
774 |
/** |
|
775 |
* Obtiene atributos a partir de un georasterfile |
|
776 |
* @return |
|
777 |
*/ |
|
778 |
public ArrayList getAttributes() { |
|
779 |
int index = ((FMapWCSAdaptor) wcs).getGeoRasterFile().getName().lastIndexOf("/"); |
|
780 |
String name = ((FMapWCSAdaptor) wcs).getGeoRasterFile().getName().substring(index + 1); |
|
781 |
ArrayList attr = new ArrayList(); |
|
782 |
String dataType = "Byte"; |
|
783 |
if (wcs.getGeoRasterFile().getDataType() == DataBuffer.TYPE_BYTE) dataType = "Byte"; |
|
784 |
else if (wcs.getPxRaster().getDataType() == DataBuffer.TYPE_SHORT) |
|
785 |
dataType = "Short"; |
|
786 |
else if (wcs.getGeoRasterFile().getDataType() == DataBuffer.TYPE_USHORT) |
|
787 |
dataType = "Unsigned Short"; |
|
788 |
else if (wcs.getGeoRasterFile().getDataType() == DataBuffer.TYPE_INT) |
|
789 |
dataType = "Integer"; |
|
790 |
else if (wcs.getGeoRasterFile().getDataType() == DataBuffer.TYPE_FLOAT) |
|
791 |
dataType = "Float"; |
|
792 |
else if (wcs.getGeoRasterFile().getDataType() == DataBuffer.TYPE_DOUBLE) |
|
793 |
dataType = "Double"; |
|
794 |
else |
|
795 |
dataType = "Unknown"; |
|
796 |
Object [][] a = { |
|
797 |
{"Filename",name}, |
|
798 |
{"Filesize",new Long(wcs.getGeoRasterFile().getFileSize())}, |
|
799 |
{"Width",new Integer(wcs.getGeoRasterFile().getWidth())}, |
|
800 |
{"Height", new Integer(wcs.getGeoRasterFile().getHeight())}, |
|
801 |
{"Bands", new Integer(wcs.getGeoRasterFile().getBandCount())} |
|
802 |
// {"BandDataType", dataType} |
|
803 |
}; |
|
804 |
for (int i=0; i<a.length; i++) |
|
805 |
attr.add(a[i]); |
|
806 |
return attr; |
|
807 |
} |
|
808 | 664 |
} |
Also available in: Unified diff