Revision 4180 org.gvsig.raster.wcs/trunk/org.gvsig.raster.wcs/org.gvsig.raster.wcs.io/src/main/java/org/gvsig/raster/wcs/io/WCSProvider.java

View differences:

WCSProvider.java
7 7
import java.awt.geom.Rectangle2D;
8 8
import java.io.File;
9 9
import java.io.IOException;
10
import java.net.URI;
11
import java.net.URISyntaxException;
10 12
import java.net.URL;
11 13
import java.util.ArrayList;
12 14
import java.util.Hashtable;
13 15

  
16
import org.apache.commons.io.FilenameUtils;
14 17
import org.apache.commons.lang3.StringUtils;
15
import org.cresques.cts.IProjection;
18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20

  
16 21
import org.gvsig.fmap.dal.DALLocator;
17 22
import org.gvsig.fmap.dal.DataStore;
18 23
import org.gvsig.fmap.dal.DataStoreParameters;
......
24 29
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException;
25 30
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
26 31
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
32
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException;
27 33
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
28 34
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
29 35
import org.gvsig.fmap.dal.coverage.exception.QueryException;
......
34 40
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer;
35 41
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
36 42
import org.gvsig.fmap.dal.exception.InitializeException;
43
import org.gvsig.fmap.dal.exception.OpenException;
37 44
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
38 45
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
39 46
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
40 47
import org.gvsig.metadata.MetadataLocator;
41 48
import org.gvsig.raster.cache.tile.provider.TileServer;
42
import org.gvsig.raster.impl.buffer.DefaultRasterQuery;
43 49
import org.gvsig.raster.impl.buffer.SpiRasterQuery;
44 50
import org.gvsig.raster.impl.datastruct.BandListImpl;
45 51
import org.gvsig.raster.impl.datastruct.DatasetBandImpl;
......
68 74
	public static final String          METADATA_DEFINITION_NAME = "WcsStore";
69 75

  
70 76
	private Extent                      viewRequest              = null;
71
	private static Hashtable<URL, WCSConnector>    
77
	private static Hashtable<URL, WCSConnector>
72 78
	drivers                  = new Hashtable<URL, WCSConnector> ();
73 79
	private boolean                     open                     = false;
74 80
	private DataStoreTransparency       fileTransparency         = null;
75 81
	private File                        lastRequest              = null;
76
	private AbstractRasterProvider      lastRequestProvider      = null; 
82
	private AbstractRasterProvider      lastRequestProvider      = null;
83
	private static final Logger         logger                    = LoggerFactory.getLogger(WCSProvider.class);
77 84

  
85

  
78 86
	public static void register() {
79 87
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
80 88
		if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
......
96 104
	 * Constructor. Abre el dataset.
97 105
	 * @param proj Proyecci?n
98 106
	 * @param fName Nombre del fichero
107
	 * @throws OpenException
99 108
	 * @throws NotSupportedExtensionException
109
     * @deprecated use {@link #WCSProvider(URI)}, this constructor will be removed in gvSIG 2.5
100 110
	 */
101
	public WCSProvider(String params) throws InitializeException {
111
	public WCSProvider(String params) throws InitializeException, OpenException {
102 112
		super(params);
113
        logger.info("Deprecated use of WCSProvider constructor");
103 114
		if(params instanceof String) {
104 115
			WCSDataParametersImpl p = new WCSDataParametersImpl();
105
			p.setURI((String)params);
116
            try {
117
                p.setURI(new URI((String) params));
118
            } catch (URISyntaxException e) {
119
                throw new OpenException("Can't create URI from" + (String) params, e);
120
            }
106 121
			super.init(p, null, ToolsLocator.getDynObjectManager()
107 122
					.createDynObject(
108 123
							MetadataLocator.getMetadataManager().getDefinition(
......
111 126
		}
112 127
	}
113 128

  
129

  
130
    /**
131
     * Constructor. Abre el dataset.
132
     * @param proj Proyecci?n
133
     * @param fName Nombre del fichero
134
     * @throws NotSupportedExtensionException
135
     */
136
    public WCSProvider(URI uri) throws InitializeException {
137
        super(uri);
138
        WCSDataParametersImpl p = new WCSDataParametersImpl();
139
        p.setURI(uri);
140
        super.init(
141
            p,
142
            null,
143
            ToolsLocator.getDynObjectManager().createDynObject(
144
                MetadataLocator.getMetadataManager().getDefinition(DataStore.METADATA_DEFINITION_NAME)));
145
        init(p, null);
146
    }
147

  
114 148
	public WCSProvider(WCSDataParametersImpl params,
115 149
			DataStoreProviderServices storeServices) throws InitializeException {
116 150
		super(params, storeServices, ToolsLocator.getDynObjectManager()
......
129 163
		WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
130 164
		URL url = null;
131 165
		try {
132
			url = new URL(p.getURI());
166
			url = p.getURI().toURL();
133 167
		} catch (Exception e) {
134 168
			throw new RemoteServiceException("Malformed URL",e);
135 169
		}
......
146 180
	 * @param proj Proyecci?n
147 181
	 * @param param Parametros de carga
148 182
	 * @throws NotSupportedExtensionException
149
	 * @throws RasterDriverException 
183
	 * @throws RasterDriverException
150 184
	 */
151 185
	public void init (DataStoreParameters params,
152 186
			DataStoreProviderServices storeServices) throws InitializeException {
......
204 238
		double resolutionX = e.width() / getWidth();
205 239
		double resolutionY = e.height() / getHeight();
206 240
		ownTransformation = new AffineTransform(
207
				resolutionX, 
208
				0, 
209
				0, 
210
				-resolutionY, 
241
				resolutionX,
242
				0,
243
				0,
244
				-resolutionY,
211 245
				e.getULX() - (resolutionX / 2),
212 246
				e.getULY() - (resolutionY / 2));
213 247
		externalTransformation = (AffineTransform) ownTransformation.clone();
......
223 257
		try {
224 258
			p.setFormat("image/tiff");
225 259
			if(p.getSRSCode() == null){
226
				WCSConnector connector = WCSProvider.getConnectorFromURL(new URL(p.getURI()));
260
				WCSConnector connector = WCSProvider.getConnectorFromURL(p.getURI().toURL());
227 261
				ArrayList srs = connector.getSRSs(p.getCoverageName());
228 262
				if(!srs.isEmpty() && !StringUtils.isBlank((String)srs.get(0))){
229 263
					p.setSRSID((String) srs.get(0));
......
265 299
		return fileTransparency;
266 300
	}
267 301

  
268
	public String translateFileName(String fileName) {
269
		return fileName;
302
	public URI translateURI(URI uri) {
303
		return uri;
270 304
	}
271 305

  
272 306
	public void setView(Extent e) {
......
303 337
	}
304 338

  
305 339
	/**
306
	 * When the remote layer has fixed size this method downloads the file and return its reference. 
340
	 * When the remote layer has fixed size this method downloads the file and return its reference.
307 341
	 * File layer has in the long side FIXED_SIZE pixels and the bounding box is complete. This file could be
308 342
	 * useful to build an histogram or calculate statistics. This represents a sample of data.
309 343
	 * @return
......
321 355
	 * Reads a complete block of data and returns an tridimensional array of the right type. This function is useful
322 356
	 * to read a file very fast without setting a view. In a WCS service when the size is fixed then it will read the
323 357
	 * entire image but when the source hasn't pixel size it will read a sample of data. This set of data will have
324
	 * the size defined in FIXED_SIZE. 
325
	 * 
358
	 * the size defined in FIXED_SIZE.
359
	 *
326 360
	 * @param pos Posici?n donde se empieza  a leer
327 361
	 * @param blockHeight Altura m?xima del bloque leido
328 362
	 * @return Object que es un array tridimendional del tipo de datos del raster. (Bandas X Filas X Columnas)
......
330 364
	 * @throws FileNotOpenException
331 365
	 * @throws RasterDriverException
332 366
	 */
333
	public Object readBlock(int pos, int blockHeight, double scale) 
367
	public Object readBlock(int pos, int blockHeight, double scale)
334 368
			throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
335 369
		File lastFile = getFileLayer();
336 370
		BandList bandList = new BandListImpl();
......
396 430
			bandList.setDrawableBands(new int[]{0, 1, 2});*/
397 431

  
398 432
			RasterQuery q = RasterLocator.getManager().createQuery();
399
			q.setAreaOfInterest(lastRequestProvider.getExtent(), 
400
					(int)lastRequestProvider.getWidth(), 
433
			q.setAreaOfInterest(lastRequestProvider.getExtent(),
434
					(int)lastRequestProvider.getWidth(),
401 435
					(int)lastRequestProvider.getHeight());
402 436
			q.setAllDrawableBands();
403 437
			q.setAdjustToExtent(true);
......
510 544
	 * @return
511 545
	 * a georeferencing file
512 546
	 */
513
	private String getWorldFile(String file){		
547
	private String getWorldFile(String file){
514 548
		String worldFile = file;
515 549
		int index = file.lastIndexOf(".");
516
		if (index > 0) {			
550
		if (index > 0) {
517 551
			worldFile = file.substring(0, index) + getExtensionWorldFile();
518 552
		} else {
519 553
			worldFile = file + getExtensionWorldFile();
......
552 586
	}
553 587

  
554 588
	public boolean needEnhanced() {
555
		return (getDataType()[0] != Buffer.TYPE_BYTE || 
589
		return (getDataType()[0] != Buffer.TYPE_BYTE ||
556 590
				(getBandCount() == 1 && getDataType()[0] == Buffer.TYPE_BYTE));
557 591
	}
558 592

  
......
615 649
	 * @throws RasterDriverException
616 650
	 * @throws ProcessInterruptedException
617 651
	 */
618
	public Buffer getBuffer(BandList bandList, File lastFile, 
652
	public Buffer getBuffer(BandList bandList, File lastFile,
619 653
			double ulx, double uly, double lrx, double lry) throws RasterDriverException, ProcessInterruptedException {
620 654
		try {
621 655
			//El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
......
654 688
		WCSStatus wcsStatus = loadWCSStatus(ex.toRectangle2D());
655 689

  
656 690
		lastRequest = downloadFile(
657
				wcsStatus, 
658
				ex, 
659
				query.getAdjustedBufWidth(), 
691
				wcsStatus,
692
				ex,
693
				query.getAdjustedBufWidth(),
660 694
				query.getAdjustedBufHeight());
661 695

  
662 696
		if (lastRequest == null) {
......
686 720
	 * @param buf
687 721
	 * @param bandList
688 722
	 * @return
689
	 * @throws RasterDriverException 
723
	 * @throws RasterDriverException
690 724
	 */
691 725
	private void loadInitialInfo() throws RasterDriverException {
692 726
		WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
......
733 767
	/*private Buffer changeBufferDataType(int newDataType, Buffer buf, BandList bandList) {
734 768
		Buffer newBuffer = null;
735 769
		if(buf.getDataType() != newDataType) {
736
			newBuffer = DefaultRasterManager.getInstance().createReadOnlyBuffer(newDataType, buf.getWidth(), buf.getHeight(), buf.getBandCount()); 
770
			newBuffer = DefaultRasterManager.getInstance().createReadOnlyBuffer(newDataType, buf.getWidth(), buf.getHeight(), buf.getBandCount());
737 771
			buf.free();
738
		} else 
772
		} else
739 773
			return buf;
740 774

  
741 775
		bandList.clear();
......
750 784
		return newBuffer;
751 785
	}*/
752 786

  
753
	/*public Buffer getWindow(int x, int y, int w, int h, 
787
	/*public Buffer getWindow(int x, int y, int w, int h,
754 788
			BandList bandList, Buffer rasterBuf, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
755 789
		Point2D p1 = rasterToWorld(new Point2D.Double(x, y));
756 790
		Point2D p2 = rasterToWorld(new Point2D.Double(x + w, y + h));
......
879 913
		}
880 914
		if (format.indexOf("png") >= 0){
881 915
			return "png";
882
		}	
916
		}
883 917
		if (format.indexOf("xml") >= 0){
884 918
			return "xml";
885
		}	
919
		}
886 920
		if (format.indexOf("gif") >= 0){
887 921
			return "gif";
888 922
		}
......
894 928
		}
895 929
		if (format.indexOf("jpg") >= 0
896 930
				|| format.indexOf("jpeg") >= 0){
897
			return "jpg";			 
931
			return "jpg";
898 932
		}
899 933
		return "xml";
900 934
	}
......
912 946
		return true;
913 947
	}
914 948

  
915
	public String getRMFFile() {
916
		if(lastRequest != null)
917
			return fileUtil.getNameWithoutExtension(lastRequest.getAbsolutePath()) + ".rmf";
949
	public File getRMFFile() {
950
		if(lastRequest != null) {
951
		    return new File(FilenameUtils.removeExtension(lastRequest.getAbsolutePath()) + ".rmf");
952
		}
918 953
		return null;
919 954
	}
920 955

  
......
924 959
		return histogram;
925 960
	}
926 961

  
962
    /* (non-Javadoc)
963
     * @see org.gvsig.raster.impl.provider.RasterProvider#addFile(java.io.File)
964
     */
965
    @Override
966
    public void addFile(File file) throws InvalidSourceException {
967
        // Do nothing
968

  
969
    }
970

  
971
    /* (non-Javadoc)
972
     * @see org.gvsig.raster.impl.provider.RasterProvider#removeFile(java.io.File)
973
     */
974
    @Override
975
    public void removeFile(File file) {
976
        // Do nothing
977

  
978
    }
979

  
927 980
}

Also available in: Unified diff