Revision 21407

View differences:

org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.240/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	<artifactId>org.gvsig.raster.gdal</artifactId>
5
	<packaging>pom</packaging>
6
	<version>2.2.240</version>
7
	<name>${project.artifactId}</name>
8
	<description>GDAL raster data provider for gvSIG</description>
9
	<inceptionYear>2011</inceptionYear>
10

  
11
	<parent>
12
		<groupId>org.gvsig</groupId>
13
		<artifactId>org.gvsig.desktop</artifactId>
14
		<version>2.0.432</version>
15
	</parent>
16

  
17
	<properties>
18
		<!-- El plugin versions:use-latest-versions falla con scope import -->
19
		<!-- asi que toca usar el versions:update-properties que si que funciona -->
20
		<org.gvsig.gdal.version>1.0.227</org.gvsig.gdal.version>
21
		<org.gvsig.raster.version>2.2.253</org.gvsig.raster.version>
22
	</properties>
23

  
24
	<repositories>
25
		<repository>
26
			<id>gvsig-public-http-repository</id>
27
			<name>gvSIG maven public HTTP repository</name>
28
			<url>http://devel.gvsig.org/m2repo/j2se</url>
29
			<releases>
30
				<enabled>true</enabled>
31
				<updatePolicy>daily</updatePolicy>
32
				<checksumPolicy>warn</checksumPolicy>
33
			</releases>
34
			<snapshots>
35
				<enabled>true</enabled>
36
				<updatePolicy>daily</updatePolicy>
37
				<checksumPolicy>warn</checksumPolicy>
38
			</snapshots>
39
		</repository>
40
	</repositories>
41

  
42
	<scm>
43
		<connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.240</connection>
44
		<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.240</developerConnection>
45
		<url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.240</url>
46
	</scm>
47

  
48
	<build>
49
		<plugins>
50
			<plugin>
51
				<groupId>org.apache.maven.plugins</groupId>
52
				<artifactId>maven-release-plugin</artifactId>
53
				<configuration>
54
					<tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.gdal/tags/</tagBase>
55
					<goals>deploy</goals>
56
				</configuration>
57
			</plugin>
58
		</plugins>
59
	</build>
60

  
61
	<developers>
62
		<developer>
63
			<id>nbrodin</id>
64
			<name>Nacho Brodin</name>
65
			<email>nachobrodin@gmail.com</email>
66
			<roles>
67
				<role>Architect</role>
68
				<role>Developer</role>
69
			</roles>
70
		</developer>
71
	</developers>
72

  
73
	<dependencyManagement>
74
		<dependencies>
75
			<dependency>
76
				<groupId>org.gvsig</groupId>
77
				<artifactId>org.gvsig.raster</artifactId>
78
				<version>${org.gvsig.raster.version}</version>
79
				<type>pom</type>
80
				<scope>import</scope>
81
			</dependency>
82

  
83
			<dependency>
84
				<groupId>org.gvsig</groupId>
85
				<artifactId>org.gvsig.gdal</artifactId>
86
				<version>${org.gvsig.gdal.version}</version>
87
				<type>pom</type>
88
				<scope>import</scope>
89
			</dependency>
90

  
91
                        <dependency>
92
				<groupId>org.gvsig</groupId>
93
				<artifactId>org.gvsig.raster.gdal.app.common</artifactId>
94
				<version>2.2.14-SNAPSHOT</version>
95
				<type>zip</type>
96
			</dependency>
97

  
98
			<dependency>
99
				<groupId>org.gvsig</groupId>
100
				<artifactId>org.gvsig.raster.gdal.io</artifactId>
101
				<version>2.2.240</version>
102
			</dependency>
103

  
104
		</dependencies>
105
	</dependencyManagement>
106

  
107
	<modules>
108
		<module>org.gvsig.raster.gdal.io</module>
109
		<module>org.gvsig.raster.gdal.app</module>
110
	</modules>
111

  
112
</project>
113

  
0 114

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.240/org.gvsig.raster.gdal.io/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
    <modelVersion>4.0.0</modelVersion>
4
    <artifactId>org.gvsig.raster.gdal.io</artifactId>
5
    <packaging>jar</packaging>
6
    <name>${project.artifactId}</name>
7
    <parent>
8
        <groupId>org.gvsig</groupId>
9
        <artifactId>org.gvsig.raster.gdal</artifactId>
10
        <version>2.2.240</version>
11
    </parent>
12
	
13
    <dependencies>
14
        <dependency>
15
            <groupId>org.gdal</groupId>
16
            <artifactId>gdal</artifactId>
17
            <scope>compile</scope>
18
        </dependency>
19
        <dependency>
20
            <groupId>org.gvsig</groupId>
21
            <artifactId>org.gvsig.raster.cache.lib.api</artifactId>
22
            <scope>compile</scope>
23
        </dependency>
24
        <dependency>
25
            <groupId>org.gvsig</groupId>
26
            <artifactId>org.gvsig.raster.lib.api</artifactId>
27
            <scope>compile</scope>
28
        </dependency>
29
        <dependency>
30
            <groupId>org.gvsig</groupId>
31
            <artifactId>org.gvsig.raster.lib.impl</artifactId>
32
            <scope>compile</scope>
33
        </dependency>
34
        <dependency>
35
            <groupId>org.gvsig</groupId>
36
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
37
            <scope>compile</scope>
38
        </dependency>
39
        <dependency>
40
            <groupId>org.gvsig</groupId>
41
            <artifactId>org.gvsig.remoteclient</artifactId>
42
            <scope>compile</scope>
43
        </dependency>
44
        <dependency>
45
            <groupId>org.gvsig</groupId>
46
            <artifactId>org.gvsig.tools.lib</artifactId>
47
            <scope>compile</scope>
48
        </dependency>
49
        <dependency>
50
            <groupId>org.gvsig</groupId>
51
            <artifactId>org.gvsig.projection.api</artifactId>
52
            <scope>compile</scope>
53
        </dependency>
54
        <dependency>
55
            <groupId>org.gvsig</groupId>
56
            <artifactId>org.gvsig.projection.cresques.impl</artifactId>
57
            <scope>runtime</scope>
58
        </dependency>
59
        <dependency>
60
            <groupId>org.gvsig</groupId>
61
            <artifactId>org.gvsig.compat.api</artifactId>
62
            <scope>compile</scope>
63
        </dependency>
64
        <dependency>
65
            <groupId>org.gvsig</groupId>
66
            <artifactId>org.gvsig.compat.se</artifactId>
67
            <scope>runtime</scope>
68
        </dependency>
69
        <dependency>
70
            <groupId>org.gvsig</groupId>
71
            <artifactId>org.gvsig.fmap.dal.api</artifactId>
72
            <scope>compile</scope>
73
        </dependency>
74
        <dependency>
75
            <groupId>org.gvsig</groupId>
76
            <artifactId>org.gvsig.fmap.dal.impl</artifactId>
77
            <scope>runtime</scope>
78
        </dependency>
79
        <dependency>
80
            <groupId>org.gvsig</groupId>
81
            <artifactId>org.gvsig.fmap.dal.file.lib</artifactId>
82
            <scope>compile</scope>
83
        </dependency>
84
        <dependency>
85
            <groupId>org.gvsig</groupId>
86
            <artifactId>org.gvsig.fmap.dal.spi</artifactId>
87
            <scope>compile</scope>
88
        </dependency>
89
        <dependency>
90
            <groupId>org.gvsig</groupId>
91
            <artifactId>org.gvsig.fmap.geometry.api</artifactId>
92
            <scope>compile</scope>
93
        </dependency>
94

  
95
    </dependencies>
96

  
97

  
98
</project>
0 99

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.240/org.gvsig.raster.gdal.io/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.gdal.io.DefaultGdalIOLibrary
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.240/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/memory/io/MemoryRasterProvider.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.memory.io;
23

  
24
import java.awt.geom.AffineTransform;
25
import java.awt.geom.Point2D;
26
import java.awt.geom.Rectangle2D;
27
import java.io.File;
28

  
29
import org.cresques.cts.ICoordTrans;
30

  
31
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
32
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
33
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
34
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
35
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
36
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
37
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException;
38
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
39
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
40
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
41
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
42
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
43
import org.gvsig.metadata.MetadataLocator;
44
import org.gvsig.raster.cache.tile.provider.TileServer;
45
import org.gvsig.raster.impl.buffer.SpiRasterQuery;
46
import org.gvsig.raster.impl.datastruct.ExtentImpl;
47
import org.gvsig.raster.impl.provider.AbstractRasterProvider;
48
import org.gvsig.raster.impl.provider.RasterProvider;
49
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
50
import org.gvsig.raster.impl.store.properties.DataStoreTransparency;
51
import org.gvsig.tools.ToolsLocator;
52
import org.gvsig.tools.task.TaskStatus;
53

  
54
/**
55
 * Driver para datos cargados en un objeto IBuffer
56
 * @author Nacho Brodin (nachobrodin@gmail.com)
57
 *
58
 */
59
public class MemoryRasterProvider extends AbstractRasterProvider {
60
	public static String        NAME                     = "Gdal Store";
61
	public static String        DESCRIPTION              = "Gdal Raster file";
62
	public static final String  METADATA_DEFINITION_NAME = "GdalStore";
63

  
64
	private Extent              v                        = null;
65
	protected Buffer            buffer                   = null;
66
	private Extent 		        extent                   = null;
67
	private boolean             open                     = false;
68

  
69
	public static void register() {
70
	}
71

  
72
	public void registerTileProviderFormats(Class<RasterProvider> c) {
73

  
74
	}
75

  
76
	/**
77
	 * Mandatory constructor to instantiate an empty provider
78
	 */
79
	public MemoryRasterProvider() {}
80

  
81
	/**
82
	 * Constructor. Asigna el buffer de datos y la extensi?n
83
	 * @param proj Proyecci?n
84
	 * @param buf Buffer
85
	 * @throws NotSupportedExtensionException
86
	 */
87
	public MemoryRasterProvider(AbstractRasterDataParameters params,
88
			DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
89
		super(params, storeServices, ToolsLocator.getDynObjectManager()
90
				.createDynObject(
91
						MetadataLocator.getMetadataManager().getDefinition(
92
								METADATA_DEFINITION_NAME)));
93
		setParam(storeServices, params);
94
		if(!(params instanceof MemoryDataParameters))
95
			throw new NotSupportedExtensionException("Buffer not supported");
96

  
97
		extent = ((MemoryDataParameters)params).getExtent();
98
		this.buffer = ((MemoryDataParameters)params).getBuffer();
99

  
100
		if(extent != null) {
101
			double psX = (extent.maxX() - extent.minX()) / buffer.getWidth();
102
			double psY = (extent.minY() - extent.maxY()) / buffer.getHeight();
103
			ownTransformation = new AffineTransform(psX, 0, 0, psY, extent.minX(), extent.maxY());
104
		} else
105
			ownTransformation = new AffineTransform(1, 0, 0, -1, 0, buffer.getHeight());
106

  
107
		if(buffer == null)
108
			throw new NotSupportedExtensionException("Buffer invalid");
109

  
110
		load();
111
		bandCount = buffer.getBandCount();
112

  
113
		//Obtenemos el tipo de dato de gdal y lo convertimos el de RasterBuf
114
		int[] dt = new int[buffer.getBandCount()];
115
		for (int i = 0; i < dt.length; i++)
116
			dt[i] = buffer.getDataType();
117
		setDataType(dt);
118
		open = true;
119
	}
120

  
121
	public RasterProvider load() {
122
		return this;
123
	}
124

  
125
	public boolean isOpen() {
126
		return open;
127
	}
128

  
129
	public void close() {
130
		buffer = null;
131
		open = false;
132
	}
133

  
134
	/**
135
	 * Asigna el extent de la vista actual.
136
	 */
137
	public void setView(Extent e) {
138
		v = e;
139
	}
140

  
141
	/**
142
	 * Obtiene extent de la vista actual
143
	 */
144
	public Extent getView() {
145
		return v;
146
	}
147

  
148
	/**
149
	 * Obtiene la anchura del fichero
150
	 */
151
	public double getWidth() {
152
		return buffer.getWidth();
153
	}
154

  
155
	/**
156
	 * Obtiene la altura del fichero
157
	 */
158
	public double getHeight() {
159
		return buffer.getHeight();
160
	}
161

  
162
	public void reProject(ICoordTrans rp) {
163
	}
164

  
165
	/**
166
	 * Obtiene la orientaci?n de la imagen a partir del signo del tama?o de pixel para poder
167
	 * asignarlo en el setView. Esto es util para poder conocer como debe leerse la image,
168
	 * de abajo a arriba, de arriba a abajo, de izquierda a derecha o de derecha a izquierda.
169
	 * La posici?n habitual es la que el pixel size en X es positivo y en Y negativo leyendose
170
	 * en este caso las X de menor a mayor y las Y de mayor a menor. Los casos posibles son:
171
	 * <UL>
172
	 * <LI><B>X > 0; Y < 0;</B> {true, false}</LI>
173
	 * <LI><B>X > 0; Y > 0;</B> {true, true}</LI>
174
	 * <LI><B>X < 0; Y > 0;</B> {false, true}</LI>
175
	 * <LI><B>X < 0; Y < 0;</B> {false, false}</LI>
176
	 * </UL>
177
	 *
178
	 * @return
179
	 */
180
	/*private boolean[] getOrientation(){
181
		boolean[] orientation = {true, false};
182
		return orientation;
183
	}*/
184

  
185
	public Object getData(int x, int y, int band) {
186
		if(buffer.getDataType() == Buffer.TYPE_BYTE){
187
			return new Integer(buffer.getElemByte(y, x, band));
188
		}else if(buffer.getDataType() == Buffer.TYPE_SHORT){
189
			return new Integer(buffer.getElemShort(y, x, band));
190
		}else if(buffer.getDataType() == Buffer.TYPE_INT){
191
			return new Integer(buffer.getElemInt(y, x, band));
192
		}else if(buffer.getDataType() == Buffer.TYPE_FLOAT){
193
			return new Float(buffer.getElemFloat(y, x, band));
194
		}else if(buffer.getDataType() == Buffer.TYPE_DOUBLE){
195
			return new Double(buffer.getElemDouble(y, x, band));
196
		}
197
		return null;
198
	}
199

  
200

  
201
	/**
202
	 * Devuelve el tama?o de bloque
203
	 * @return Tama?o de bloque
204
	 */
205
	public int getBlockSize(){
206
		return 0;
207
	}
208

  
209
	/**
210
	 * Obtiene el flag que dice si la imagen est? o no georreferenciada
211
	 * @return true si est? georreferenciada y false si no lo est?.
212
	 */
213
	public boolean isGeoreferenced() {
214
		return (this.extent != null);
215
	}
216

  
217
	/**
218
	 * Informa de si el driver ha supersampleado en el ?ltimo dibujado. Es el driver el que colocar?
219
	 * el valor de esta variable cada vez que dibuja.
220
	 * @return true si se ha supersampleado y false si no se ha hecho.
221
	 */
222
	public boolean isSupersampling() {
223
		return false;
224
	}
225

  
226
	/**
227
	 * @return Returns the dataType.
228
	 */
229
	public int[] getDataType() {
230
		int[] dt = new int[buffer.getBandCount()];
231
		for (int i = 0; i < dt.length; i++)
232
			dt[i] = buffer.getDataType();
233
		return dt;
234
	}
235

  
236
	/**
237
	 * Ajusta los puntos pasados por par?metro a los l?mites del buffer. Es decir si alguno excede
238
	 * los l?mites por arriba o por abajo los ajusta.
239
	 * @param begin Punto inicial
240
	 * @param end Punto final
241
	 */
242
	private void adjustPointsToBufferLimits(Point2D begin, Point2D end) {
243
		if(begin.getX() < 0)
244
			begin.setLocation(0, begin.getY());
245
		if(begin.getY() > buffer.getHeight())
246
			begin.setLocation(begin.getX(), buffer.getHeight());
247
		if(end.getY() < 0)
248
			end.setLocation(begin.getX(), 0);
249
		if(end.getX() > buffer.getWidth())
250
			begin.setLocation(buffer.getWidth(), begin.getY());
251
	}
252

  
253
	public void loadBuffer(SpiRasterQuery q)
254
			throws ProcessInterruptedException, RasterDriverException {
255
		getWindow(q.getAdjustedRequestBoundingBox(), q.getBandList(), q.getBufferForProviders(), q.getTaskStatus());
256
	}
257

  
258
	public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf, TaskStatus status) {
259
		Point2D begin = worldToRaster(new Point2D.Double(ex.getULX(), ex.getULY()));
260
		Point2D end = worldToRaster(new Point2D.Double(ex.getLRX(), ex.getLRY()));
261
		setView(ex);
262

  
263
		adjustPointsToBufferLimits(begin, end);
264

  
265
		switch(buffer.getDataType()){
266
		case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, 1, 1, begin, bandList); break;
267
		case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, 1, 1, begin, bandList); break;
268
		case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, 1, 1, begin, bandList); break;
269
		case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, 1, 1, begin, bandList); break;
270
		case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, 1, 1, begin, bandList); break;
271
		}
272
		return rasterBuf;
273
	}
274

  
275
	public Buffer getWindow(double x, double y, double w, double h,
276
			BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) {
277
		Point2D begin = worldToRaster(new Point2D.Double(x, y));
278
		Point2D end = worldToRaster(new Point2D.Double(x + w, y - h));
279
		setView(new ExtentImpl(x, y, x + w, y - h));
280

  
281
		adjustPointsToBufferLimits(begin, end);
282

  
283
		switch(buffer.getDataType()){
284
		case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, 1, 1, begin, bandList); break;
285
		case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, 1, 1, begin, bandList); break;
286
		case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, 1, 1, begin, bandList); break;
287
		case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, 1, 1, begin, bandList); break;
288
		case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, 1, 1, begin, bandList); break;
289
		}
290
		return rasterBuf;
291
	}
292

  
293
	public Buffer getWindow(Extent extent, int bufWidth, int bufHeight,
294
			BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) {
295
		Point2D begin = worldToRaster(new Point2D.Double(extent.getMin().getX(), extent.getMax().getY()));
296
		Point2D end = worldToRaster(new Point2D.Double(extent.getMax().getX(), extent.getMin().getY()));
297
		setView(extent);
298

  
299
		adjustPointsToBufferLimits(begin, end);
300

  
301
		//Ancho y alto en pixels (double) del area seleccionada.
302
		double w = Math.abs(end.getX() - begin.getX());
303
		double h = Math.abs(end.getY() - begin.getY());
304

  
305
		//Relaci?n entre el n?mero de pixels del buffer origen (area seleccionada) y el destino
306
		double stepX = w / ((double)bufWidth);
307
		double stepY = h / ((double)bufHeight);
308

  
309
		//Escritura separada en 5 llamadas para mejorar el rendimiento
310
		switch(buffer.getDataType()){
311
		case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, stepX, stepY, begin, bandList); break;
312
		case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, stepX, stepY, begin, bandList); break;
313
		case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, stepX, stepY, begin, bandList); break;
314
		case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, stepX, stepY, begin, bandList); break;
315
		case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, stepX, stepY, begin, bandList); break;
316
		}
317

  
318
		/*int xPx = 0, yPx = 0;
319
		for (int iBand = 0; iBand < rasterBuf.getBandCount(); iBand++) {
320
			yPx = 0;
321
			for(double row = begin.getY(); yPx < bufHeight; row += stepY) {
322
				xPx = 0;
323
				for(double col = begin.getX(); xPx < bufWidth; col += stepX) {
324
					switch(buffer.getDataType()){
325
					case Buffer.TYPE_BYTE: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemByte((int)row, (int)col, iBand)); break;
326
					case Buffer.TYPE_SHORT: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemShort((int)row, (int)col, iBand)); break;
327
					case Buffer.TYPE_INT: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemInt((int)row, (int)col, iBand)); break;
328
					case Buffer.TYPE_FLOAT: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemFloat((int)row, (int)col, iBand)); break;
329
					case Buffer.TYPE_DOUBLE: rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemDouble((int)row, (int)col, iBand)); break;
330
					}
331
					xPx ++;
332
				}
333
				yPx ++;
334
			}
335
		}*/
336
		return rasterBuf;
337
	}
338

  
339
	/**
340
	 * Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores
341
	 * se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a
342
	 * escribir, el punto inicial en coordenadas pixel (double) y el incremento.
343
	 * @param rasterBuf Buffer donde se escriben los datos
344
	 * @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario
345
	 * ya que el buffer destino no tiene porque tener el mismo ancho que el de origen. Este valor suele ser ancho_buffer_origen / ancho_buffer_destino.
346
	 * @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario
347
	 * ya que el buffer destino no tiene porque tener el mismo alto que el de origen. Este valor suele ser alto_buffer_origen / alto_buffer_destino.
348
	 * @param begin pixel donde se comienza a leer en el buffer de origen. Este valor es decimal ya que no tiene porque empezar a leerse al principio
349
	 * del pixel. Esto es util cuando se supersamplea.
350
	 */
351
	private void writeByteBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) {
352
		int xPx = 0, yPx = 0;
353
		for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
354
			int[] drawableBands = bandList.getBufferBandToDraw(new File(this.getURIOfFirstProvider()).getAbsolutePath(), iBand);
355
			if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1))
356
				continue;
357
			for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) {
358
				yPx = 0;
359
				for(double row = begin.getY(); (yPx < rasterBuf.getHeight() && row < buffer.getHeight()); row += stepY) {
360
					xPx = 0;
361
					for(double col = begin.getX(); (xPx < rasterBuf.getWidth() && col < buffer.getWidth()); col += stepX) {
362
						rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemByte((int)row, (int)col, iBand));
363
						xPx ++;
364
					}
365
					yPx ++;
366
				}
367
			}
368
		}
369
	}
370

  
371
	/**
372
	 * Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores
373
	 * se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a
374
	 * escribir, el punto inicial en coordenadas pixel (double) y el incremento.
375
	 * @param rasterBuf Buffer donde se escriben los datos
376
	 * @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario
377
	 * ya que el buffer destino no tiene porque tener el mismo ancho que el de origen. Este valor suele ser ancho_buffer_origen / ancho_buffer_destino.
378
	 * @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario
379
	 * ya que el buffer destino no tiene porque tener el mismo alto que el de origen. Este valor suele ser alto_buffer_origen / alto_buffer_destino.
380
	 * @param begin pixel donde se comienza a leer en el buffer de origen. Este valor es decimal ya que no tiene porque empezar a leerse al principio
381
	 * del pixel. Esto es util cuando se supersamplea.
382
	 */
383
	private void writeShortBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) {
384
		int xPx = 0, yPx = 0;
385
		for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
386
			int[] drawableBands = bandList.getBufferBandToDraw(new File(this.getURIOfFirstProvider()).getAbsolutePath(), iBand);
387
			if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1))
388
				continue;
389
			for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) {
390
				yPx = 0;
391
				for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) {
392
					xPx = 0;
393
					for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) {
394
						rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemShort((int)row, (int)col, iBand));
395
						xPx ++;
396
					}
397
					yPx ++;
398
				}
399
			}
400
		}
401
	}
402

  
403
	/**
404
	 * Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores
405
	 * se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a
406
	 * escribir, el punto inicial en coordenadas pixel (double) y el incremento.
407
	 * @param rasterBuf Buffer donde se escriben los datos
408
	 * @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario
409
	 * ya que el buffer destino no tiene porque tener el mismo ancho que el de origen. Este valor suele ser ancho_buffer_origen / ancho_buffer_destino.
410
	 * @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario
411
	 * ya que el buffer destino no tiene porque tener el mismo alto que el de origen. Este valor suele ser alto_buffer_origen / alto_buffer_destino.
412
	 * @param begin pixel donde se comienza a leer en el buffer de origen. Este valor es decimal ya que no tiene porque empezar a leerse al principio
413
	 * del pixel. Esto es util cuando se supersamplea.
414
	 */
415
	private void writeIntBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) {
416
		int xPx = 0, yPx = 0;
417
		for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
418
			int[] drawableBands = bandList.getBufferBandToDraw(new File(this.getURIOfFirstProvider()).getAbsolutePath(), iBand);
419
			if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1))
420
				continue;
421
			for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) {
422
				yPx = 0;
423
				for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) {
424
					xPx = 0;
425
					for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) {
426
						rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemInt((int)row, (int)col, iBand));
427
						xPx ++;
428
					}
429
					yPx ++;
430
				}
431
			}
432
		}
433
	}
434

  
435
	/**
436
	 * Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores
437
	 * se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a
438
	 * escribir, el punto inicial en coordenadas pixel (double) y el incremento.
439
	 * @param rasterBuf Buffer donde se escriben los datos
440
	 * @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario
441
	 * ya que el buffer destino no tiene porque tener el mismo ancho que el de origen. Este valor suele ser ancho_buffer_origen / ancho_buffer_destino.
442
	 * @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario
443
	 * ya que el buffer destino no tiene porque tener el mismo alto que el de origen. Este valor suele ser alto_buffer_origen / alto_buffer_destino.
444
	 * @param begin pixel donde se comienza a leer en el buffer de origen. Este valor es decimal ya que no tiene porque empezar a leerse al principio
445
	 * del pixel. Esto es util cuando se supersamplea.
446
	 */
447
	private void writeFloatBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) {
448
		int xPx = 0, yPx = 0;
449
		for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
450
			int[] drawableBands = bandList.getBufferBandToDraw(new File(this.getURIOfFirstProvider()).getAbsolutePath(), iBand);
451
			if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1))
452
				continue;
453
			for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) {
454
				yPx = 0;
455
				for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) {
456
					xPx = 0;
457
					for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) {
458
						rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemFloat((int)row, (int)col, iBand));
459
						xPx ++;
460
					}
461
					yPx ++;
462
				}
463
			}
464
		}
465
	}
466

  
467
	/**
468
	 * Escribe sobre el buffer pasado por par?metro los valores solicitados, desde el buffer de la clase. Los valores
469
	 * se solicitan a trav?s de los par?metros. En ellos se especifica el tama?o del buffer de destino, las bandas a
470
	 * escribir, el punto inicial en coordenadas pixel (double) y el incremento.
471
	 * @param rasterBuf Buffer donde se escriben los datos
472
	 * @param stepX Incremento en X. Cada vez que se escribe un pixel en X se incrementa el contador en stepX pixels. Esto es necesario
473
	 * ya que el buffer destino no tiene porque tener el mismo ancho que el de origen. Este valor suele ser ancho_buffer_origen / ancho_buffer_destino.
474
	 * @param stepY Incremento en Y. Cada vez que se escribe un pixel en Y se incrementa el contador en stepY pixels. Esto es necesario
475
	 * ya que el buffer destino no tiene porque tener el mismo alto que el de origen. Este valor suele ser alto_buffer_origen / alto_buffer_destino.
476
	 * @param begin pixel donde se comienza a leer en el buffer de origen. Este valor es decimal ya que no tiene porque empezar a leerse al principio
477
	 * del pixel. Esto es util cuando se supersamplea.
478
	 */
479
	private void writeDoubleBuffer(Buffer rasterBuf, double stepX, double stepY, Point2D begin, BandList bandList) {
480
		int xPx = 0, yPx = 0;
481
		for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
482
			int[] drawableBands = bandList.getBufferBandToDraw(new File(this.getURIOfFirstProvider()).getAbsolutePath(), iBand);
483
			if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1))
484
				continue;
485
			for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) {
486
				yPx = 0;
487
				for(double row = begin.getY(); yPx < rasterBuf.getHeight(); row += stepY) {
488
					xPx = 0;
489
					for(double col = begin.getX(); xPx < rasterBuf.getWidth(); col += stepX) {
490
						rasterBuf.setElem(yPx, xPx, iBand, buffer.getElemDouble((int)row, (int)col, iBand));
491
						xPx ++;
492
					}
493
					yPx ++;
494
				}
495
			}
496
		}
497
	}
498

  
499
	/*
500
	 *  (non-Javadoc)
501
	 * @see org.gvsig.raster.dataset.RasterDataset#getWindowRaster(int, int, org.gvsig.raster.dataset.BandList, org.gvsig.raster.dataset.Buffer)
502
	 */
503
//	public Buffer getWindow(int x, int y, BandList bandList, Buffer rasterBuf) {
504
//		int w = rasterBuf.getWidth();
505
//		int h = rasterBuf.getHeight();
506
//		setView(
507
//				new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(),
508
//							getWidth(),
509
//							getHeight(),
510
//							new Rectangle2D.Double(x, y, w, h)))
511
//				);
512
//
513
//		for(int iBand = 0; iBand < buffer.getBandCount(); iBand ++){
514
//			int[] drawableBands = bandList.getBufferBandToDraw(this.getURIOfFirstProvider(), iBand);
515
//			if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1))
516
//				continue;
517
//			if(buffer.getDataType() == Buffer.TYPE_BYTE) {
518
//				for(int drawBands = 0; drawBands < drawableBands.length; drawBands++) {
519
//					for(int line = y; line < (y + h); line ++)
520
//						for(int col = x; col < (x + w); col ++)
521
//							rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemByte(line, col, drawableBands[drawBands]));
522
//				}
523
//			}else if(buffer.getDataType() == Buffer.TYPE_SHORT){
524
//				for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){
525
//					for(int line = y; line < (y + h); line ++)
526
//						for(int col = x; col < (x + w); col ++)
527
//							rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemShort(line, col, drawableBands[drawBands]));
528
//				}
529
//			}else if(buffer.getDataType() == Buffer.TYPE_INT){
530
//				for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){
531
//					for(int line = y; line < (y + h); line ++)
532
//						for(int col = x; col < (x + w); col ++)
533
//							rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemInt(line, col, drawableBands[drawBands]));
534
//				}
535
//			}else if(buffer.getDataType() == Buffer.TYPE_FLOAT){
536
//				for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){
537
//					for(int line = y; line < (y + h); line ++)
538
//						for(int col = x; col < (x + w); col ++)
539
//							rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemFloat(line, col, drawableBands[drawBands]));
540
//				}
541
//			}else if(buffer.getDataType() == Buffer.TYPE_DOUBLE){
542
//				for(int drawBands = 0; drawBands < drawableBands.length; drawBands++){
543
//					for(int line = y; line < (y + h); line ++)
544
//						for(int col = x; col < (x + w); col ++)
545
//							rasterBuf.setElem((line - y), (col - x), drawableBands[drawBands], buffer.getElemDouble(line, col, drawableBands[drawBands]));
546
//				}
547
//			}
548
//		}
549
//		return rasterBuf;
550
//	}
551

  
552
	public Buffer getWindow(int x, int y, int w, int h,
553
			BandList bandList, Buffer rasterBuf, TaskStatus status) {
554
		setView(
555
				new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(),
556
							getWidth(),
557
							getHeight(),
558
							new Rectangle2D.Double(x, y, w, h)))
559
				);
560

  
561
		//Relaci?n entre el n?mero de pixels del buffer origen (area seleccionada) y el destino
562
		double stepX = w / ((double)rasterBuf.getWidth());
563
		double stepY = h / ((double)rasterBuf.getHeight());
564
		switch(buffer.getDataType()){
565
		case Buffer.TYPE_BYTE: writeByteBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break;
566
		case Buffer.TYPE_SHORT: writeShortBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break;
567
		case Buffer.TYPE_INT: writeIntBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break;
568
		case Buffer.TYPE_FLOAT: writeFloatBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break;
569
		case Buffer.TYPE_DOUBLE: writeDoubleBuffer(rasterBuf, stepX, stepY, new Point2D.Double(x, y), bandList); break;
570
		}
571
		return rasterBuf;
572
	}
573

  
574
	public Object readCompleteLine(int line, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
575
		switch(buffer.getDataType()){
576
		case Buffer.TYPE_BYTE: return buffer.getLineFromBandByte(line, band);
577
		case Buffer.TYPE_SHORT: return buffer.getLineFromBandShort(line, band);
578
		case Buffer.TYPE_INT: return buffer.getLineFromBandInt(line, band);
579
		case Buffer.TYPE_FLOAT: return buffer.getLineFromBandFloat(line, band);
580
		case Buffer.TYPE_DOUBLE: return buffer.getLineFromBandDouble(line, band);
581
		}
582
		return null;
583
	}
584

  
585
	public Object readBlock(int pos, int blockHeight, double scale) throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
586
		if(pos < 0)
587
			throw new InvalidSetViewException("Request out of grid");
588

  
589
		if((pos + blockHeight) > buffer.getHeight())
590
			blockHeight = Math.abs(buffer.getHeight() - pos);
591

  
592
		switch(buffer.getDataType()){
593
		case Buffer.TYPE_BYTE:
594
			byte[][][] bufb = new byte[getBandCount()][][];
595
			for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
596
				for (int row = 0; row < blockHeight; row++) {
597
					bufb[iBand][row] = buffer.getLineFromBandByte(row, iBand);
598
				}
599
			}
600
			return bufb;
601
		case Buffer.TYPE_SHORT:
602
			short[][][] bufs = new short[getBandCount()][][];
603
			for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
604
				for (int row = 0; row < blockHeight; row++) {
605
					bufs[iBand][row] = buffer.getLineFromBandShort(row, iBand);
606
				}
607
			}
608
			return bufs;
609
		case Buffer.TYPE_INT:
610
			int[][][] bufi = new int[getBandCount()][][];
611
			for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
612
				for (int row = 0; row < blockHeight; row++) {
613
					bufi[iBand][row] = buffer.getLineFromBandInt(row, iBand);
614
				}
615
			}
616
			return bufi;
617
		case Buffer.TYPE_FLOAT:
618
			float[][][] buff = new float[getBandCount()][][];
619
			for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
620
				for (int row = 0; row < blockHeight; row++) {
621
					buff[iBand][row] = buffer.getLineFromBandFloat(row, iBand);
622
				}
623
			}
624
			return buff;
625
		case Buffer.TYPE_DOUBLE:
626
			double[][][] bufd = new double[getBandCount()][][];
627
			for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
628
				for (int row = 0; row < blockHeight; row++) {
629
					bufd[iBand][row] = buffer.getLineFromBandDouble(row, iBand);
630
				}
631
			}
632
			return bufd;
633
		}
634
		return null;
635
	}
636

  
637
		/**
638
	 * Obtiene el objeto que contiene el estado de la transparencia
639
	 */
640
	public Transparency getTransparency() {
641
		if(transparency == null)
642
			transparency = new DataStoreTransparency(getColorInterpretation());
643
		return transparency;
644
	}
645

  
646
	public int getOverviewCount(int band) throws BandAccessException, RasterDriverException {
647
		if(band >= getBandCount())
648
			throw new BandAccessException("Wrong band");
649
		return 0;
650
	}
651

  
652
	public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException {
653
		if (band >= getBandCount())
654
			throw new BandAccessException("Wrong band");
655
		return 0;
656
	}
657

  
658
	public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException {
659
		if (band >= getBandCount())
660
			throw new BandAccessException("Wrong band");
661
		return 0;
662
	}
663

  
664
	public boolean isOverviewsSupported() {
665
		return false;
666
	}
667

  
668
	public String getProviderName() {
669
		return NAME;
670
	}
671

  
672
        public String getName() {
673
		return "buffer"+this.hashCode();
674
	}
675

  
676
        public String getFullName() {
677
		return this.getName();
678
	}
679

  
680
	public void setStatus(RasterProvider provider) {
681
		if(provider instanceof MemoryRasterProvider) {
682
			//Not implemented yet
683
		}
684
	}
685

  
686
	public TileServer getTileServer() {
687
		return null;
688
	}
689

  
690
    public void addFile(File file) throws InvalidSourceException {
691
        // Do nothing
692
    }
693

  
694
    public void removeFile(File file) {
695
        // Do nothing
696
    }
697

  
698
}
0 699

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.240/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/memory/io/MemoryDataParameters.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
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28
package org.gvsig.raster.memory.io;
29

  
30
import org.gvsig.fmap.dal.DataStoreParameters;
31
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
32
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
33
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters;
34

  
35
/**
36
 * Parameters for the memory provider
37
 * @author Nacho Brodin (nachobrodin@gmail.com)
38
 */
39
public class MemoryDataParameters extends AbstractRasterFileDataParameters {
40
	private final String id = "memory";
41
	private Buffer buffer = null;
42
	private Extent extent = null;
43
	
44
	/**
45
	 * Constructor vacio
46
	 */
47
	public MemoryDataParameters() {
48
	}
49
	
50
	/**
51
	 * Contructor
52
	 * @param buf buffer del driver
53
	 * @param ext extensi?n del buffer
54
	 */
55
	public MemoryDataParameters(Buffer buf, Extent ext) {
56
		this.buffer = buf;
57
		this.extent = ext;
58
	}
59
	
60
	/**
61
	 * Obtiene el buffer de datos
62
	 * @return Buffer
63
	 */
64
	public Buffer getBuffer() {
65
		return buffer;
66
	}
67
	
68
	/**
69
	 * Asigna el buffer de datos
70
	 * @param buffer Buffer
71
	 */
72
	public void setBuffer(Buffer buffer) {
73
		this.buffer = buffer;
74
	}
75
	
76
	/**
77
	 * Obtiene la extensi?n del buffer de datos
78
	 * @return Extent
79
	 */
80
	public Extent getExtent() {
81
		return extent;
82
	}
83
	
84
	/**O
85
	 * Asigna la extensi?n del buffer de datos
86
	 * @param extent
87
	 */
88
	public void setExtent(Extent extent) {
89
		this.extent = extent;
90
	}
91

  
92
	/**
93
	 * Obtiene el identificador del driver
94
	 * @return String 
95
	 */
96
	public String getFormatID() {
97
		return id;
98
	}
99
	
100
	/*
101
	 * (non-Javadoc)
102
	 * @see org.gvsig.fmap.dal.DataStoreParameters#getDataStoreName()
103
	 */
104
	public String getDataStoreName() {
105
		return MemoryRasterProvider.NAME;
106
	}
107
	
108
	/*
109
	 * (non-Javadoc)
110
	 * @see org.gvsig.fmap.dal.DataStoreParameters#getDescription()
111
	 */
112
	public String getDescription() {
113
		return MemoryRasterProvider.DESCRIPTION;
114
	}
115

  
116
    @Override
117
    public boolean isTheSameStore(DataStoreParameters dsp) {
118
        return this.equals(dsp);
119
    }
120
}
0 121

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.240/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/util/DefaultCRSUtils.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.gdal.util;
23

  
24
import org.cresques.cts.ICRSFactory;
25
import org.cresques.cts.IProjection;
26
import org.gdal.osr.SpatialReference;
27

  
28
import org.gvsig.fmap.crs.CRSFactory;
29
import org.gvsig.fmap.dal.coverage.util.CRSUtils;
30

  
31
/**
32
 * Esta clase se encarga de hacer la conversion entre Wkt e IProjection.
33
 *
34
 * El uso se hace mediante dos llamadas estaticas que son:
35
 * convertIProjectionToWkt y
36
 * convertWktToIProjection.
37
 *
38
 * Antes de usarlos, hay que saber si tenemos acceso a gvSIG e intentar coger el
39
 * factory desde all?.
40
 * Ya que su uso consume tiempo y espacio de memoria y es preferible
41
 * reaprovechar ese objeto ya
42
 * creado. Esto se hace con setCRSFactory.
43
 *
44
 * En caso de no asignarse el ya existente, el crear? uno interno y lo dejara en
45
 * una variable estatica.
46
 *
47
 * @version 11/07/2008
48
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
49
 */
50
public class DefaultCRSUtils implements CRSUtils {
51

  
52
    private ICRSFactory factory = null;
53

  
54
    public void setCRSFactory(ICRSFactory factory) {
55
        this.factory = factory;
56
    }
57

  
58
    /**
59
     * Devuelve el CRSFactory asignado desde fuera o creado desde dentro, todo
60
     * depende de como se haya
61
     * usado.
62
     *
63
     * @param code
64
     * @return
65
     */
66
    private IProjection getCRS(String code) {
67
        if (factory == null)
68
            factory = CRSFactory.getCRSFactory(); // new ProjectionPool();
69
        return factory.get(code);
70
    }
71

  
72
    public IProjection convertWktToIProjection(String wkt) {
73
        if (wkt == null || wkt.equals(""))
74
            return null;
75

  
76
        String code = null;
77
        String name = null;
78

  
79
        SpatialReference oSRSSource = new SpatialReference();
80

  
81
        oSRSSource.ImportFromWkt(wkt);
82

  
83
        code = oSRSSource.GetAuthorityCode("PROJCS");
84
        if (code == null)
85
            code = oSRSSource.GetAuthorityCode("GEOGCS");
86
        name = oSRSSource.GetAuthorityName("PROJCS");
87
        if (name == null)
88
            name = oSRSSource.GetAuthorityName("GEOGCS");
89
        try {
90
            if (name != null && code != null)
91
                return getCRS(name + ":" + code);
92
        } catch (NumberFormatException ex) {
93
            return null;
94
        }
95

  
96
        return null;
97
    }
98

  
99
    public String convertIProjectionToWkt(IProjection projection) {
100
        if (projection == null)
101
            return null;
102
        return projection.export(ICRSFactory.FORMAT_WKT);
103
    }
104
}
0 105

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.240/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/overview/GdalOverviewBuilder.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.gdal.overview;
23

  
24
import org.gvsig.addo.BuildingOverviewsException;
25
import org.gvsig.addo.IOverviewIncrement;
26
import org.gvsig.addo.Jaddo;
27
import org.gvsig.addo.WritingException;
28
import org.gvsig.fmap.dal.coverage.exception.OverviewException;
29
import org.gvsig.fmap.dal.coverage.process.BaseIncrementableTask;
30
import org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder;
31

  
32
/**
33
 * Servicios ofrecidos por el proceso de construcci?n de overviews. Esta
34
 * implementaci?n usa gdal para construir las overviews.
35
 * 
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public class GdalOverviewBuilder implements OverviewBuilder {
39
	private Jaddo        build         = new Jaddo();
40
	private int          value         = 0;
41

  
42
	/**
43
	 * Bindings between an IOverviewIncrement and a BaseIncrementableTask
44
	 * @author Nacho Brodin (nachobrodin@gmail.com)
45
	 */
46
	class ProcessBinding implements IOverviewIncrement {
47
		private BaseIncrementableTask  task = null;
48
		
49
		public ProcessBinding(BaseIncrementableTask task) {
50
			this.task = task;	
51
		}
52
		
53
		public int getPercent() {
54
			return task.getPercent();
55
		}
56

  
57
		public void setPercent(int value) {
58
			task.setPercent(value);
59
		}
60
	}
61
	
62
	/*
63
	 * (non-Javadoc)
64
	 * @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#buildOverviews(int, java.lang.String, int[])
65
	 */
66
	public void buildOverviews(int resamplingAlg, String file, int[] overviews)
67
			throws OverviewException {
68
		try {
69
			build.buildOverviews(resamplingAlg, file, overviews);
70
		} catch (BuildingOverviewsException e) {
71
			throw new OverviewException("Error building overviews", e);
72
		} catch (WritingException e) {
73
			throw new OverviewException("Error writing overviews", e);
74
		}
75
	}
76

  
77
	/*
78
	 * (non-Javadoc)
79
	 * @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#getPercent()
80
	 */
81
	public int getPercent() {
82
		return value;
83
	}
84

  
85
	/*
86
	 * (non-Javadoc)
87
	 * @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#setIncrementListener(org.gvsig.addo.IOverviewIncrement)
88
	 */
89
	public void setIncrementListener(BaseIncrementableTask incr) {
90
		build.setIncrementListener(new ProcessBinding(incr));
91
	}
92

  
93
	/*
94
	 * (non-Javadoc)
95
	 * @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#setPercent(int)
96
	 */
97
	public void setPercent(int value) {
98
		this.value = value;
99
	}
100
}
0 101

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.240/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/PngWriter.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.gdal.io;
23

  
24
import java.awt.geom.AffineTransform;
25
import java.io.File;
26
import java.io.IOException;
27

  
28
import org.cresques.cts.IProjection;
29
import org.gvsig.fmap.dal.coverage.RasterLocator;
30
import org.gvsig.fmap.dal.coverage.datastruct.Params;
31
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
32
import org.gvsig.fmap.dal.coverage.store.DataServerWriter;
33
import org.gvsig.jgdal.GdalDataset;
34
import org.gvsig.jgdal.GdalDriver;
35
import org.gvsig.jgdal.GdalException;
36
import org.gvsig.raster.gdal.io.features.PngFeatures;
37
import org.gvsig.raster.impl.store.WriteFileFormatFeatures;
38
import org.gvsig.raster.impl.store.writer.DefaultRasterWriter;
39
import org.gvsig.raster.util.DefaultProviderServices;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.extensionpoint.ExtensionPoint;
42
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
43
/**
44
 * Driver para la escritura de Png.
45
 * Este driver utiliza GdalWriter para salvar Png.
46
 * La escritura de un png no es posible utilizando un servidor de datos
47
 * como el que usan los drivers comunes por lo que ser? necesario salvar antes
48
 * a Tif con el driver de Gdal para posteriormente convertir la imagen completa
49
 * a png. El problema que tiene es el mismo del jpg y es que el dataset solo soporta la
50
 * escritura rw y no rw+.
51
 *
52
 * @version 22/07/2008
53
 * @author Nacho Brodin (nachobrodin@gmail.com)
54
 */
55
public class PngWriter extends DefaultRasterWriter {
56

  
57
	// Datos de registro de drivers
58
	public static void register() {
59
		DefaultProviderServices pInfo = (DefaultProviderServices)RasterLocator.getManager().getProviderServices();
60
		ExtensionPointManager extensionPoints =ToolsLocator.getExtensionPointManager();
61
		ExtensionPoint point=extensionPoints.get("RasterWriter");
62
		point.append("png", "", PngWriter.class);
63
		pInfo.getFileFeature().put("png", new PngFeatures());
64
	}
65

  
66
	private GdalWriter gdalWriter = null;
67
	private String     outTif     = null;
68
	private String     outPng     = null;
69

  
70
	/**
71
	 * Carga los par?metros de este driver.
72
	 */
73
	public void loadParams(String ident) {
74
		WriteFileFormatFeatures wfff = (WriteFileFormatFeatures) pInfo.getFileFeature().get(ident);
75
		wfff.loadParams();
76
		driverParams = wfff.getParams();
77
	}
78
	
79
	/*
80
	 * (non-Javadoc)
81
	 * @see org.gvsig.fmap.dal.coverage.store.RasterWriter#getProviderName()
82
	 */
83
	public String getProviderName() {
84
		return GdalProvider.NAME;
85
	}
86

  
87
	/**
88
	 * Constructor para la obtenci?n de par?metros del driver
89
	 * @param drvType Tipo de driver
90
	 */
91
	public PngWriter(String fileName) {
92
		ident = fileUtil.getExtensionFromFileName(fileName);
93
		driver = ((WriteFileFormatFeatures) pInfo.getFileFeature().get(ident)).getDriverName();
94
		gdalWriter = new GdalWriter(fileName);
95

  
96
		loadParams(ident);
97
	}
98

  
99
	/**
100
	 * Constructor para salvar datos servidos por el cliente
101
	 * @param dataWriter Objeto servidor de datos para el driver de escritura
102
	 * @param outSizeX N?mero de pixels en X de la imagen de salida
103
	 * @param outSizeY N?mero de pixels en Y de la imagen de salida
104
	 * @param outFilename Fichero de salida
105
	 * @param extentMaxX Posici?n en X m?xima del extent
106
	 * @param extentMinX Posici?n en X m?nima del extent
107
	 * @param extentMaxY Posici?n en Y m?xima del extent
108
	 * @param extentMinY Posici?n en Y m?nima del extent
109
	 * @param nBands N?mero de bandas
110
	 * @param drvType Tipo de driver
111
	 * @throws GdalException
112
	 * @throws IOException
113
	 */
114
	public PngWriter(DataServerWriter dataWriter,
115
							String outFileName,
116
							Integer nBands,
117
							AffineTransform at,
118
							Integer outSizeX,
119
							Integer outSizeY,
120
							Integer dataType,
121
							Params params,
122
							IProjection proj,
123
							Boolean geo)throws GdalException, IOException  {
124
		ident = fileUtil.getExtensionFromFileName(outFileName);
125
		driver = ((WriteFileFormatFeatures) pInfo.getFileFeature().get(ident)).getDriverName();
126
		outPng = outFileName;
127
		outTif = outFileName.substring(0, outFileName.lastIndexOf("."));
128
		outTif += ".tif";
129
		this.at = at;
130

  
131
		gdalWriter = new GdalWriter(dataWriter, outTif, nBands, at, outSizeX, outSizeY, dataType, params, proj, geo);
132
		if (params == null)
133
			loadParams(ident);
134
		else
135
			this.driverParams = params;
136
	}
137

  
138
	/**
139
	 * Asigna el tipo de driver con el que se salvar? la imagen
140
	 * @param drvType Tipo de driver
141
	 */
142
	public void setDriverType(String drvType) {
143
		gdalWriter.setDriverType(drvType);
144
	}
145

  
146
		/**
147
	 * Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
148
	 * @throws IOException
149
	 */
150
	public void fileWrite() throws IOException, ProcessInterruptedException {
151
		gdalWriter.fileWrite();
152
	}
153

  
154
	/**
155
	 * Realiza una copia en el formato especificado.
156
	 * @throws IOException
157
	 */
158
	public static void createCopy(GdalDriver driverDst, String dst, String src,
159
			boolean bstrict, String[] params) throws IOException, GdalException {
160
		GdalWriter.createCopy(driverDst, dst, src, bstrict, params);
161
	}
162

  
163
	/**
164
	 * Realiza la escritura de datos con los datos que le pasa el cliente.
165
	 * @throws IOException
166
	 */
167
	public void dataWrite() throws IOException, ProcessInterruptedException {
168
		if(colorInterp != null)
169
			gdalWriter.setColorBandsInterpretation(colorInterp.getValues());
170
		gdalWriter.dataWrite();
171
		if (gdalWriter.isWrite()) {
172
			gdalWriter.writeClose();
173
			if (outTif != null) {
174
				GdalDriver driver = null;
175
				try {
176
					driver = GdalDataset.getDriverByName("PNG");
177
					GdalWriter.createCopy(driver, outPng, outTif, false, gdalWriter.gdalParamsFromRasterParams(driverParams));
178
				} catch (GdalException exc) {
179
					throw new IOException("No se ha podido obtener el driver.");
180
				}
181
				File file = new File(outTif);
182
				file.delete();
183
			}
184
		}
185
	}
186

  
187
	/**
188
	 * Cancela el salvado de datos.
189
	 */
190
	public void writeCancel() {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff