Revision 1026

View differences:

org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/store/parameter/NewRasterStoreParameters.java
1
package org.gvsig.fmap.dal.coverage.store.parameter;
2

  
3
import java.awt.geom.AffineTransform;
4

  
5
import org.cresques.cts.IProjection;
6
import org.gvsig.fmap.dal.NewDataStoreParameters;
7
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
8
import org.gvsig.fmap.dal.coverage.datastruct.Params;
9
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
10

  
11
/**
12
 * This class represents parameters that we need to create a new
13
 * raster source.
14
 *
15
 * @author Nacho Brodin (nachobrodin@gmail.com)
16
 */
17
public interface NewRasterStoreParameters extends NewDataStoreParameters {
18
	public static String          FILENAME               = "fileName";
19
	public static String          BUFFER                 = "buffer";
20
	public static String          COLORINTERPRETATION    = "colorInterpretation";
21
	public static String          SRS                    = "srs";
22
	public static String          PARAMS                 = "driverparams";
23
	public static String          BAND                   = "band";
24
	public static String          WKT                    = "wktproj";
25
	public static String          AFFINETRANSFORM        = "affineTransform";
26
	
27
	/**
28
	 * Sets the name of the file to save
29
	 * @param fileName
30
	 */
31
	public void setFileName(String fileName);
32
	
33
	/**
34
	 * Sets the buffer with data loaded
35
	 * @param buffer
36
	 */
37
	public void setBuffer(Buffer buffer);
38
	
39
	/**
40
	 * Sets the color interpretation. Constants with color interpretation are
41
	 * declared int {@link ColorInterpretation} class.
42
	 * @param colorInterpretation
43
	 */
44
	public void setColorInterpretation(String[] colorInterpretation);
45
	
46
	/**
47
	 * Sets the projection
48
	 * @param projection
49
	 */
50
	public void setProjection(IProjection projection);
51
	
52
	/**
53
	 * Sets the driver parameters. This method is useful when the parameters are loaded 
54
	 * using the driver GUI. If this parameters does not exists then it will use generic
55
	 * configuration.
56
	 * @param params
57
	 */
58
	public void setDriverParams(Params params);
59
	
60
	/**
61
	 * Sets the projection using Wkt notation
62
	 * @param wkt
63
	 */
64
	public void setWktProjection(String wkt);
65
	
66
	/**
67
	 * Sets the number of band in the buffer that will be saved. If this value is greater
68
	 * than zero only one band (n) will be written. If this value is lower than zero 
69
	 * then all bands will be written. This is the value by default. 
70
	 * @param n
71
	 */
72
	public void setBand(int n);
73
	
74
	/**
75
	 * This method is maintained to keep compatibility with the old system. It is recommended
76
	 * not to use. If the buffer don't have bounding box the affine transform will be the 
77
	 * identity and if not the affine transform will be calculated using the geographic information.
78
	 * 
79
	 * @param at
80
	 * @deprecated 
81
	 */
82
	public void setAffineTransform(AffineTransform at);
83
	
84
	/**
85
	 * This method is maintained to keep compatibility with the old system. It is recommended
86
	 * not to use. If the buffer don't have bounding box the affine transform will be the 
87
	 * identity and if not the affine transform will be calculated using the geographic information.
88
	 * 
89
	 * @return AffineTransform
90
	 */
91
	public AffineTransform getAffineTransform();
92
	
93
	/**
94
	 * Gets the number of band in the buffer that will be saved. If this value is greater
95
	 * than zero only one band (n) will be written. If this value is lower than zero 
96
	 * then all bands will be written. This is the value by default. 
97
	 * @return
98
	 */
99
	public int getBand();
100
	
101
	/**
102
	 * Gets the projection using Wkt notation
103
	 * @return
104
	 */
105
	public String getWktProjection();
106
	
107
	/**
108
	 * Gets the driver parameters. This method is useful when the parameters are loaded 
109
	 * using the driver GUI. If this parameters does not exists then it will use generic
110
	 * configuration.
111
	 * @return
112
	 */
113
	public Params getDriverParams();
114
	
115
	/**
116
	 * Gets the name of the file to save
117
	 * @return
118
	 */
119
	public String getFileName();
120
	
121
	/**
122
	 * Gets the buffer with data loaded
123
	 * @return
124
	 */
125
	public Buffer getBuffer();
126
	
127
	/**
128
	 * Gets the color interpretation. Constants with color interpretation are
129
	 * declared int {@link ColorInterpretation} class.
130
	 * @return
131
	 */
132
	public String[] getColorInterpretation();
133
	
134
	/**
135
	 * Gets the projection
136
	 * @return
137
	 */
138
	public IProjection getProjection();
139
	
140
	public void setPercent(int n);
141
	
142
	public int getPercent();
143
}
144

  
0 145

  
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/AbstractNewRasterStoreParameters.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.impl.store;
24

  
25
import java.awt.geom.AffineTransform;
26

  
27
import org.cresques.cts.IProjection;
28
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
29
import org.gvsig.fmap.dal.coverage.datastruct.Params;
30
import org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters;
31

  
32
/**
33
 * This class represents parameters that we need to create a new
34
 * raster source.
35
 *
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public abstract class AbstractNewRasterStoreParameters extends AbstractRasterFileDataParameters 
39
	implements NewRasterStoreParameters {
40
	private int        percent = 0;
41
	
42
	/*
43
	 * (non-Javadoc)
44
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#getBuffer()
45
	 */
46
	public Buffer getBuffer() {
47
		return (Buffer)getDynValue(BUFFER);
48
	}
49

  
50
	/*
51
	 * (non-Javadoc)
52
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#getColorInterpretation()
53
	 */
54
	public String[] getColorInterpretation() {
55
		return (String[])getDynValue(COLORINTERPRETATION);
56
	}
57

  
58
	/*
59
	 * (non-Javadoc)
60
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#getFileName()
61
	 */
62
	public String getFileName() {
63
		return (String)getDynValue(FILENAME);
64
	}
65

  
66
	/*
67
	 * (non-Javadoc)
68
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#getProjection()
69
	 */
70
	public IProjection getProjection() {
71
		return (IProjection)getDynValue(SRS);
72
	}
73
	
74
	/*
75
	 * (non-Javadoc)
76
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#getDriverParams()
77
	 */
78
	public Params getDriverParams() {
79
		return (Params)getDynValue(PARAMS);
80
	}
81
	
82
	/*
83
	 * (non-Javadoc)
84
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#setDriverParams(org.gvsig.fmap.dal.coverage.datastruct.Params)
85
	 */
86
	public void setDriverParams(Params params) {
87
		this.setDynValue(PARAMS, params);
88
	}
89
	
90
	/*
91
	 * (non-Javadoc)
92
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#setBuffer(org.gvsig.fmap.dal.coverage.dataset.Buffer)
93
	 */
94
	public void setBuffer(Buffer buffer) {
95
		this.setDynValue(BUFFER, buffer);
96
	}
97
	
98
	/*
99
	 * (non-Javadoc)
100
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#getBand()
101
	 */
102
	public int getBand() {
103
		if(getDynValue(BAND) == null)
104
			return -1;
105
		return (Integer)getDynValue(BAND);
106
	}
107
	
108
	/*
109
	 * (non-Javadoc)
110
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#setBand(int)
111
	 */
112
	public void setBand(int n) {
113
		this.setDynValue(BAND, n);
114
	}
115
	
116
	/*
117
	 * (non-Javadoc)
118
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#setAffineTransform(java.awt.geom.AffineTransform)
119
	 */
120
	public void setAffineTransform(AffineTransform at) {
121
		this.setDynValue(AFFINETRANSFORM, at);
122
	}
123
	
124
	/*
125
	 * (non-Javadoc)
126
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#getAffineTransform()
127
	 */
128
	public AffineTransform getAffineTransform() {
129
		if(getDynValue(AFFINETRANSFORM) != null)
130
			return (AffineTransform)getDynValue(AFFINETRANSFORM);
131
		return null;
132
	}
133
	
134
	/*
135
	 * (non-Javadoc)
136
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#setWktProjection(java.lang.String)
137
	 */
138
	public void setWktProjection(String wkt) {
139
		this.setDynValue(WKT, wkt);
140
	}
141
	
142
	/*
143
	 * (non-Javadoc)
144
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#getWktProjection()
145
	 */
146
	public String getWktProjection() {
147
		return (String)getDynValue(WKT);
148
	}
149

  
150
	/*
151
	 * (non-Javadoc)
152
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#setColorInterpretation(java.lang.String[])
153
	 */
154
	public void setColorInterpretation(String[] colorInterpretation) {
155
		this.setDynValue(COLORINTERPRETATION, colorInterpretation);
156
	}
157

  
158
	/*
159
	 * (non-Javadoc)
160
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#setFileName(java.lang.String)
161
	 */
162
	public void setFileName(String fileName) {
163
		this.setDynValue(FILENAME, fileName);
164
	}
165

  
166
	/*
167
	 * (non-Javadoc)
168
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#setProjection(org.cresques.cts.IProjection)
169
	 */
170
	public void setProjection(IProjection projection) {
171
		this.setDynValue(SRS, projection);
172
	}
173
	
174
	/*
175
	 * (non-Javadoc)
176
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#setPercent(int)
177
	 */
178
	public void setPercent(int n) {
179
		this.percent = n;
180
	}
181
	
182
	/*
183
	 * (non-Javadoc)
184
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters#getPercent()
185
	 */
186
	public int getPercent() {
187
		return percent;
188
	}
189
}
0 190

  
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/AbstractRasterDataParameters.java
20 20
*
21 21
*/
22 22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28 23
package org.gvsig.raster.impl.store;
29 24

  
30 25
import org.cresques.cts.IProjection;
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalNewRasterStoreParameters.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 org.gvsig.raster.impl.store.AbstractNewRasterStoreParameters;
25

  
26
/**
27
 * Parameters for creating a Gdal store
28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29
 */
30
public class GdalNewRasterStoreParameters extends AbstractNewRasterStoreParameters {
31

  
32
	public String getDataStoreName() {
33
		return GdalProvider.NAME;
34
	}
35

  
36
	public String getDescription() {
37
		return GdalProvider.DESCRIPTION;
38
	}
39

  
40
}
0 41

  
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalFilesystemServerExplorer.java
27 27

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

  
30
import java.awt.geom.AffineTransform;
30 31
import java.io.File;
31 32
import java.io.FileInputStream;
33
import java.io.IOException;
32 34

  
33 35
import org.gvsig.fmap.dal.DALLocator;
34 36
import org.gvsig.fmap.dal.DataManager;
......
36 38
import org.gvsig.fmap.dal.DataStoreParameters;
37 39
import org.gvsig.fmap.dal.NewDataStoreParameters;
38 40
import org.gvsig.fmap.dal.coverage.RasterLocator;
41
import org.gvsig.fmap.dal.coverage.datastruct.Params;
42
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
43
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
44
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
45
import org.gvsig.fmap.dal.coverage.store.DataServerWriter;
46
import org.gvsig.fmap.dal.coverage.store.RasterWriter;
47
import org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters;
39 48
import org.gvsig.fmap.dal.exception.CreateException;
40 49
import org.gvsig.fmap.dal.exception.DataException;
41 50
import org.gvsig.fmap.dal.exception.RemoveException;
42 51
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider;
43 52
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices;
44 53
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters;
54
import org.gvsig.tools.locator.LocatorException;
45 55

  
46 56
public class GdalFilesystemServerExplorer extends AbstractFilesystemServerExplorerProvider {
47 57
	
......
67 77
	 */
68 78
	public void create(NewDataStoreParameters parameters, boolean overwrite)
69 79
			throws CreateException {
70
		throw new UnsupportedOperationException();
80
		NewRasterStoreParameters p = null;
81
		if(parameters instanceof NewRasterStoreParameters)
82
			 p = (NewRasterStoreParameters)parameters;
83
		
84
		DataServerWriter dataWriter = RasterLocator.getManager().createDataServerWriter();
85
		dataWriter.setBuffer(p.getBuffer(), -1);
86
		Params params;
87
		try {
88
			if(p.getDriverParams() != null)
89
				params = p.getDriverParams();
90
			else
91
				params = RasterLocator.getManager().createWriter(p.getFileName()).getParams();
92
			
93
			AffineTransform affineTransform = p.getAffineTransform();
94
			if(affineTransform != null) {
95
				if(p.getBuffer().getDataExtent() != null) {
96
					double x = p.getBuffer().getDataExtent().getMinX();
97
					double y = p.getBuffer().getDataExtent().getMaxY();
98
					double pixelSizeX = p.getBuffer().getDataExtent().getWidth() / p.getBuffer().getWidth();
99
					double pixelSizeY = p.getBuffer().getDataExtent().getHeight() / p.getBuffer().getHeight();
100
					affineTransform = new AffineTransform(pixelSizeX, 0, 0, pixelSizeY, x, y);
101
				} else {
102
					affineTransform = new AffineTransform();
103
				}
104
			}
105
			
106
			RasterWriter writer = RasterLocator.getManager().createWriter(
107
					dataWriter, 
108
					p.getFileName(),
109
					p.getBuffer().getBandCount(), 
110
					affineTransform, 
111
					p.getBuffer().getWidth(),
112
					p.getBuffer().getHeight(), 
113
					p.getBuffer().getDataType(), 
114
					params, 
115
					null);
116
			if(p.getColorInterpretation() != null)
117
				writer.setColorBandsInterpretation(p.getColorInterpretation());
118
			writer.setWkt(p.getWktProjection());
119
			
120
			writer.dataWrite();
121
			writer.writeClose();
122
		} catch (LocatorException e) {
123
			throw new CreateException("", e);
124
		} catch (NotSupportedExtensionException e) {
125
			throw new CreateException("", e);
126
		} catch (RasterDriverException e) {
127
			throw new CreateException("", e);
128
		} catch (ProcessInterruptedException e) {
129
			//Fin del proceso
130
		} catch (IOException e) {
131
			throw new CreateException("", e);
132
		}
71 133
	}
72 134

  
73 135
	/*
......
75 137
	 * @see org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider#getCreateParameters()
76 138
	 */
77 139
	public NewDataStoreParameters getCreateParameters() throws DataException {
78
		return null;
140
		return new GdalNewRasterStoreParameters();
79 141
	}
80 142

  
81 143
	/*
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalDataParameters.java
20 20
*
21 21
*/
22 22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28 23
package org.gvsig.raster.gdal.io;
29 24

  
30 25
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
org.gvsig.raster.ermapper/trunk/org.gvsig.raster.ermapper/org.gvsig.raster.ermapper.io/src/main/java/org/gvsig/raster/ermapper/io/ErmapperNewRasterStoreParameters.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.ermapper.io;
23

  
24
import org.gvsig.raster.impl.store.AbstractNewRasterStoreParameters;
25

  
26
/**
27
 * Parameters for creating a Ermapper store
28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29
 */
30
public class ErmapperNewRasterStoreParameters extends AbstractNewRasterStoreParameters {
31

  
32
	public String getDataStoreName() {
33
		return ErmapperProvider.NAME;
34
	}
35

  
36
	public String getDescription() {
37
		return ErmapperProvider.DESCRIPTION;
38
	}
39

  
40
}
41

  
0 42

  
org.gvsig.raster.ermapper/trunk/org.gvsig.raster.ermapper/org.gvsig.raster.ermapper.io/src/main/java/org/gvsig/raster/ermapper/io/ErmapperFilesystemServerExplorer.java
35 35
import org.gvsig.fmap.dal.DataStoreParameters;
36 36
import org.gvsig.fmap.dal.NewDataStoreParameters;
37 37
import org.gvsig.fmap.dal.coverage.RasterLocator;
38
import org.gvsig.fmap.dal.coverage.store.DataServerWriter;
39
import org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters;
38 40
import org.gvsig.fmap.dal.exception.CreateException;
39 41
import org.gvsig.fmap.dal.exception.DataException;
40 42
import org.gvsig.fmap.dal.exception.RemoveException;
......
66 68
	 */
67 69
	public void create(NewDataStoreParameters parameters, boolean overwrite)
68 70
			throws CreateException {
69
		throw new UnsupportedOperationException();
71
		NewRasterStoreParameters p = null;
72
		if(parameters instanceof NewRasterStoreParameters)
73
			 p = (NewRasterStoreParameters)parameters;
74
		
75
		DataServerWriter dataWriter = RasterLocator.getManager().createDataServerWriter();
76
		dataWriter.setBuffer(p.getBuffer(), -1);
70 77
	}
71 78

  
72 79
	/*
......
74 81
	 * @see org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider#getCreateParameters()
75 82
	 */
76 83
	public NewDataStoreParameters getCreateParameters() throws DataException {
77
		return null;
84
		return new ErmapperNewRasterStoreParameters();
78 85
	}
79 86

  
80 87
	/*

Also available in: Unified diff