Revision 1890
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.reproject_deprecated/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.raster.tools.algorithm.reproject.RasterReprojectAlgorithmLibrary |
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.reproject_deprecated/src/main/java/org/gvsig/raster/tools/algorithm/reproject/ReprojectException.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.tools.algorithm.reproject; |
|
23 |
|
|
24 |
|
|
25 |
/** |
|
26 |
* This exception is thrown if happen problems processing data with this algorithm. |
|
27 |
* |
|
28 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
29 |
* |
|
30 |
*/ |
|
31 |
public class ReprojectException extends Exception { |
|
32 |
private static final long serialVersionUID = -3022090543908771484L; |
|
33 |
|
|
34 |
public ReprojectException(String msg){ |
|
35 |
super(msg); |
|
36 |
} |
|
37 |
|
|
38 |
public ReprojectException(String msg, Throwable e){ |
|
39 |
super(msg, e); |
|
40 |
} |
|
41 |
} |
|
0 | 42 |
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.reproject_deprecated/src/main/java/org/gvsig/raster/tools/algorithm/reproject/ReprojectProcess.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.tools.algorithm.reproject; |
|
23 |
|
|
24 |
import java.util.HashMap; |
|
25 |
|
|
26 |
import javax.swing.SwingUtilities; |
|
27 |
|
|
28 |
import org.cresques.cts.IProjection; |
|
29 |
import org.gvsig.fmap.dal.coverage.exception.CloneException; |
|
30 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
31 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
32 |
import org.gvsig.i18n.Messages; |
|
33 |
import org.gvsig.raster.tools.algorithm.base.RasterBaseAlgorithmLibrary; |
|
34 |
import org.gvsig.raster.tools.algorithm.base.process.RasterProcess; |
|
35 |
|
|
36 |
/** |
|
37 |
* Process to reproject layers. The size of the new image and the pixel size can |
|
38 |
* be passed by parameter. If some of these values are zero everyone are calculated |
|
39 |
* automatically |
|
40 |
* |
|
41 |
* 10/12/2007 |
|
42 |
* @author Nacho Brodin nachobrodin@gmail.com |
|
43 |
*/ |
|
44 |
public class ReprojectProcess extends RasterProcess { |
|
45 |
public static String[] INTERP_METHODS = new String[]{"Nearest", "Bilinear", "InverseDistance"}; |
|
46 |
|
|
47 |
public static String RASTER_STORE = "RasterStore"; |
|
48 |
public static String PATH = "Path"; |
|
49 |
public static String DST_PROJECTION = "DST_Projection"; |
|
50 |
public static String SRC_PROJECTION = "SRC_Projection"; |
|
51 |
public static String SIZEX = "SizeX"; |
|
52 |
public static String SIZEY = "SizeY"; |
|
53 |
public static String CELLSIZE = "CellSize"; |
|
54 |
public static String FILENAME = "FileName"; |
|
55 |
public static String TIME = "Time"; |
|
56 |
public static String INTERPOLATION = "Interpolation"; |
|
57 |
|
|
58 |
private RasterDataStore store = null; |
|
59 |
private String filename = null; |
|
60 |
private IProjection projdst = null; |
|
61 |
private IProjection projsrc = null; |
|
62 |
private Reproject reproject = null; |
|
63 |
private long milis = 0; |
|
64 |
private int w = 0; |
|
65 |
private int h = 0; |
|
66 |
private double cellSize = 0; |
|
67 |
private int interpolation = 0; |
|
68 |
|
|
69 |
public static void registerParameters() { |
|
70 |
RASTER_STORE = RasterBaseAlgorithmLibrary.registerInputParameter(RASTER_STORE, RasterDataStore.class); |
|
71 |
PATH = RasterBaseAlgorithmLibrary.registerInputParameter(PATH, String.class); |
|
72 |
DST_PROJECTION = RasterBaseAlgorithmLibrary.registerInputParameter(DST_PROJECTION, IProjection.class); |
|
73 |
SRC_PROJECTION = RasterBaseAlgorithmLibrary.registerInputParameter(SRC_PROJECTION, IProjection.class); |
|
74 |
SIZEX = RasterBaseAlgorithmLibrary.registerInputParameter(SIZEX, Integer.class); |
|
75 |
SIZEY = RasterBaseAlgorithmLibrary.registerInputParameter(SIZEY, Integer.class); |
|
76 |
CELLSIZE = RasterBaseAlgorithmLibrary.registerInputParameter(CELLSIZE, Double.class); |
|
77 |
INTERPOLATION = RasterBaseAlgorithmLibrary.registerInputParameter(INTERPOLATION, Integer.class); |
|
78 |
|
|
79 |
FILENAME = RasterBaseAlgorithmLibrary.registerOutputParameter(FILENAME, String.class); |
|
80 |
TIME = RasterBaseAlgorithmLibrary.registerOutputParameter(TIME, Long.class); |
|
81 |
} |
|
82 |
|
|
83 |
/* |
|
84 |
* (non-Javadoc) |
|
85 |
* @see org.gvsig.rastertools.RasterProcess#init() |
|
86 |
*/ |
|
87 |
public void init() { |
|
88 |
store = getParam(RASTER_STORE) != null ? (RasterDataStore)getParam(RASTER_STORE) : null; |
|
89 |
filename = getStringParam(PATH); |
|
90 |
projdst = getParam(DST_PROJECTION) != null ? (IProjection) getParam(DST_PROJECTION) : null; |
|
91 |
projsrc = getParam(SRC_PROJECTION) != null ? (IProjection) getParam(SRC_PROJECTION) : null; |
|
92 |
w = getIntParam(SIZEX); |
|
93 |
h = getIntParam(SIZEY); |
|
94 |
cellSize = getDoubleParam(CELLSIZE); |
|
95 |
interpolation = getIntParam(INTERPOLATION); |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* M?todo donde se ejecutar? el Thread, aqu? se reproyecta el raster. |
|
100 |
*/ |
|
101 |
public void process() throws ProcessInterruptedException { |
|
102 |
long t1 = new java.util.Date().getTime(); |
|
103 |
insertLineLog(Messages.getText("reprojecting")); |
|
104 |
|
|
105 |
try { |
|
106 |
store = store.cloneDataStore(); |
|
107 |
} catch (CloneException e1) { |
|
108 |
messageBoxError("error_reprojecting", this, e1); |
|
109 |
} |
|
110 |
|
|
111 |
reproject = new Reproject(store, filename, interpolation, this); |
|
112 |
try { |
|
113 |
int result = reproject.warp(projdst, projsrc, w, h, cellSize); |
|
114 |
if(result != 0) { |
|
115 |
if (incrementableTask != null) { |
|
116 |
incrementableTask.processFinalize(); |
|
117 |
setProgressActive(false); |
|
118 |
} |
|
119 |
messageBoxError("transformation_not_possible", this); |
|
120 |
return; |
|
121 |
} |
|
122 |
|
|
123 |
long t2 = new java.util.Date().getTime(); |
|
124 |
milis = t2 - t1; |
|
125 |
|
|
126 |
SwingUtilities.invokeLater(new Runnable() { |
|
127 |
public void run() { |
|
128 |
if (externalActions != null) { |
|
129 |
HashMap<String, Object> map = new HashMap<String, Object>(); |
|
130 |
map.put(FILENAME, filename); |
|
131 |
map.put(TIME, new Long(milis)); |
|
132 |
externalActions.end(map); |
|
133 |
} |
|
134 |
} |
|
135 |
}); |
|
136 |
} catch (ReprojectException e) { |
|
137 |
if (incrementableTask != null) |
|
138 |
incrementableTask.processFinalize(); |
|
139 |
messageBoxError("error_reprojecting", this, e); |
|
140 |
} |
|
141 |
} |
|
142 |
|
|
143 |
/* |
|
144 |
* (non-Javadoc) |
|
145 |
* @see org.gvsig.raster.tools.app.basic.raster.process.RasterProcess#getResult() |
|
146 |
*/ |
|
147 |
public Object getResult() { |
|
148 |
HashMap<String, Object> map = new HashMap<String, Object>(); |
|
149 |
map.put(FILENAME, filename); |
|
150 |
map.put(TIME, new Long(milis)); |
|
151 |
return map; |
|
152 |
} |
|
153 |
|
|
154 |
/* |
|
155 |
* (non-Javadoc) |
|
156 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent() |
|
157 |
*/ |
|
158 |
public int getPercent() { |
|
159 |
return percent; |
|
160 |
} |
|
161 |
|
|
162 |
/* |
|
163 |
* (non-Javadoc) |
|
164 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle() |
|
165 |
*/ |
|
166 |
public String getTitle() { |
|
167 |
return Messages.getText("reprojecting"); |
|
168 |
} |
|
169 |
} |
|
0 | 170 |
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.reproject_deprecated/src/main/java/org/gvsig/raster/tools/algorithm/reproject/Reproject.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.tools.algorithm.reproject; |
|
23 |
|
|
24 |
import java.awt.geom.Point2D; |
|
25 |
import java.io.File; |
|
26 |
|
|
27 |
import org.cresques.cts.ICoordTrans; |
|
28 |
import org.cresques.cts.IProjection; |
|
29 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
30 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
31 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
32 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
|
33 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
|
34 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
35 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
36 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
37 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
|
38 |
import org.gvsig.raster.tools.algorithm.base.process.RasterProcess; |
|
39 |
import org.gvsig.raster.tools.algorithm.base.util.Interpolation; |
|
40 |
|
|
41 |
|
|
42 |
/** |
|
43 |
* Reprojects a RasterDataStore. |
|
44 |
* |
|
45 |
* @version 30/04/2008 |
|
46 |
* @author Nacho Brodin nachobrodin@gmail.com |
|
47 |
*/ |
|
48 |
public class Reproject { |
|
49 |
private RasterDataStore store = null; |
|
50 |
private String pathDest = null; |
|
51 |
private int interpolationMethod = 0; |
|
52 |
private Interpolation interpolation = null; |
|
53 |
private RasterProcess process = null; |
|
54 |
|
|
55 |
/** |
|
56 |
* Constructor de la clase. |
|
57 |
* @param lyr |
|
58 |
* @param pathDest Ruta de destino |
|
59 |
*/ |
|
60 |
public Reproject(RasterDataStore store, String pathDest, int inter, RasterProcess process) { |
|
61 |
this.store = store; |
|
62 |
this.pathDest = pathDest; |
|
63 |
this.interpolationMethod = inter; |
|
64 |
this.process = process; |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* M?todo para la transformaci?n del raster. |
|
69 |
* @param destinationSrs Proyecci?n destino |
|
70 |
*/ |
|
71 |
public int warp(IProjection destinationSrs, IProjection sourceSrs, int w, int h, double cellSize) throws ReprojectException { |
|
72 |
if (store == null) |
|
73 |
throw new ReprojectException("Capa no valida."); |
|
74 |
if (!store.isReproyectable()) |
|
75 |
throw new ReprojectException("Esta capa no se puede reproyectar."); |
|
76 |
if (destinationSrs == null || destinationSrs.getAbrev() == null) |
|
77 |
throw new ReprojectException("Proyecci?n de destino no valida."); |
|
78 |
|
|
79 |
|
|
80 |
File file = new File(pathDest); |
|
81 |
if (!file.getParentFile().canWrite()) |
|
82 |
throw new ReprojectException("Ruta de destino no valida."); |
|
83 |
|
|
84 |
ICoordTrans transf = sourceSrs.getCT(destinationSrs); |
|
85 |
Extent bbox = store.getExtent(); |
|
86 |
Point2D ul = new Point2D.Double(bbox.getULX(), bbox.getULY()); |
|
87 |
Point2D lr = new Point2D.Double(bbox.getLRX(), bbox.getLRY()); |
|
88 |
//Point2D p = new Point2D.Double(lyr.getFullRasterExtent().getULX(), lyr.getFullRasterExtent().getULY()); |
|
89 |
ul = transf.convert(ul, ul); |
|
90 |
lr = transf.convert(lr, lr); |
|
91 |
Extent newBbox = RasterLocator.getManager().getDataStructFactory().createExtent(ul, lr); |
|
92 |
|
|
93 |
if(w <= 0 || h <= 0 ) { |
|
94 |
double[] size = getSize(bbox, newBbox); |
|
95 |
w = (int)size[0]; |
|
96 |
h = (int)size[1]; |
|
97 |
cellSize = size[2]; |
|
98 |
} |
|
99 |
int dataType = store.getDataType()[0]; |
|
100 |
Buffer buf = RasterLocator.getManager().createBuffer( |
|
101 |
store.getDataType()[0], w, h, store.getBandCount(), true); |
|
102 |
|
|
103 |
NoData nd = RasterLocator.getManager().getDataStructFactory().createDefaultNoData( |
|
104 |
store.getBandCount(), dataType); |
|
105 |
|
|
106 |
RasterQuery query = RasterLocator.getManager().createQuery(); |
|
107 |
query.setAllDrawableBands(); |
|
108 |
query.setAreaOfInterest(); |
|
109 |
query.setReadOnly(true); |
|
110 |
try { |
|
111 |
ICoordTrans t = destinationSrs.getCT(sourceSrs); |
|
112 |
Buffer sourceBuffer = store.query(query); |
|
113 |
if(interpolationMethod < 0) { |
|
114 |
for (int row = 0; row < buf.getHeight(); row++) { |
|
115 |
for (int col = 0; col < buf.getWidth(); col++) { |
|
116 |
Point2D p = transformPoint(newBbox, col, row, cellSize, t); |
|
117 |
writePixel(dataType, sourceBuffer, buf, p, col, row, nd); |
|
118 |
} |
|
119 |
process.updatePercent(row, buf.getHeight()); |
|
120 |
} |
|
121 |
} else { |
|
122 |
interpolation = new Interpolation(sourceBuffer); |
|
123 |
for (int row = 0; row < buf.getHeight(); row++) { |
|
124 |
for (int col = 0; col < buf.getWidth(); col++) { |
|
125 |
Point2D p = transformPoint(newBbox, col, row, cellSize, t); |
|
126 |
writePixelInterpolated(dataType, sourceBuffer, buf, p, col, row, nd, interpolationMethod); |
|
127 |
} |
|
128 |
process.updatePercent(row, buf.getHeight()); |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
process.exportRaster(pathDest, buf, cellSize, newBbox.getULX(), newBbox.getULY()); |
|
133 |
} catch (RasterDriverException e) { |
|
134 |
new ReprojectException("", e); |
|
135 |
} catch (ProcessInterruptedException e) { |
|
136 |
} catch (InvalidSetViewException e) { |
|
137 |
new ReprojectException("", e); |
|
138 |
} |
|
139 |
|
|
140 |
return 0; |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* Writes one pixel in the destination buffer |
|
145 |
* @param type |
|
146 |
* @param sourceBuffer |
|
147 |
* @param buf |
|
148 |
* @param p |
|
149 |
* @param col |
|
150 |
* @param row |
|
151 |
*/ |
|
152 |
private void writePixel(int type, Buffer sourceBuffer, Buffer buf, Point2D p, int col, int row, NoData nd) { |
|
153 |
if(type == Buffer.TYPE_BYTE) { |
|
154 |
if(p.getX() > 0 && p.getX() < sourceBuffer.getWidth() && p.getY() > 0 && p.getY() < sourceBuffer.getHeight()) |
|
155 |
for (int iBand = 0; iBand < store.getBandCount(); iBand++) { |
|
156 |
//if(iBand == 0) |
|
157 |
//System.out.println("Row:" + row + " Col:" + col + " Y:" + (int)p.getY() + " X:" + (int)p.getX()); |
|
158 |
buf.setElem(row, col, iBand, sourceBuffer.getElemByte((int)p.getY(), (int)p.getX(), iBand)); |
|
159 |
} |
|
160 |
else |
|
161 |
for (int iBand = 0; iBand < store.getBandCount(); iBand++) |
|
162 |
buf.setElem(row, col, iBand, nd.getValue().byteValue()); |
|
163 |
} else if(type == Buffer.TYPE_DOUBLE) { |
|
164 |
if(p.getX() > 0 && p.getX() < sourceBuffer.getWidth() && p.getY() > 0 && p.getY() < sourceBuffer.getHeight()) |
|
165 |
for (int iBand = 0; iBand < store.getBandCount(); iBand++) |
|
166 |
buf.setElem(row, col, iBand, sourceBuffer.getElemDouble((int)p.getY(), (int)p.getX(), iBand)); |
|
167 |
else |
|
168 |
for (int iBand = 0; iBand < store.getBandCount(); iBand++) |
|
169 |
buf.setElem(row, col, iBand, nd.getValue().doubleValue()); |
|
170 |
} else if(type == Buffer.TYPE_FLOAT) { |
|
171 |
if(p.getX() > 0 && p.getX() < sourceBuffer.getWidth() && p.getY() > 0 && p.getY() < sourceBuffer.getHeight()) |
|
172 |
for (int iBand = 0; iBand < store.getBandCount(); iBand++) |
|
173 |
buf.setElem(row, col, iBand, sourceBuffer.getElemFloat((int)p.getY(), (int)p.getX(), iBand)); |
|
174 |
else |
|
175 |
for (int iBand = 0; iBand < store.getBandCount(); iBand++) |
|
176 |
buf.setElem(row, col, iBand, nd.getValue().floatValue()); |
|
177 |
} else if(type == Buffer.TYPE_SHORT) { |
|
178 |
if(p.getX() > 0 && p.getX() < sourceBuffer.getWidth() && p.getY() > 0 && p.getY() < sourceBuffer.getHeight()) |
|
179 |
for (int iBand = 0; iBand < store.getBandCount(); iBand++) |
|
180 |
buf.setElem(row, col, iBand, sourceBuffer.getElemShort((int)p.getY(), (int)p.getX(), iBand)); |
|
181 |
else |
|
182 |
for (int iBand = 0; iBand < store.getBandCount(); iBand++) |
|
183 |
buf.setElem(row, col, iBand, nd.getValue().shortValue()); |
|
184 |
} else if(type == Buffer.TYPE_INT) { |
|
185 |
if(p.getX() > 0 && p.getX() < sourceBuffer.getWidth() && p.getY() > 0 && p.getY() < sourceBuffer.getHeight()) |
|
186 |
for (int iBand = 0; iBand < store.getBandCount(); iBand++) |
|
187 |
buf.setElem(row, col, iBand, sourceBuffer.getElemInt((int)p.getY(), (int)p.getX(), iBand)); |
|
188 |
else |
|
189 |
for (int iBand = 0; iBand < store.getBandCount(); iBand++) |
|
190 |
buf.setElem(row, col, iBand, nd.getValue().intValue()); |
|
191 |
} |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* Writes one pixel in the destination buffer |
|
196 |
* @param type |
|
197 |
* @param sourceBuffer |
|
198 |
* @param buf |
|
199 |
* @param p |
|
200 |
* @param col |
|
201 |
* @param row |
|
202 |
*/ |
|
203 |
private void writePixelInterpolated(int type, Buffer sourceBuffer, Buffer buf, Point2D p, int col, int row, NoData nd, int interpMethod) { |
|
204 |
double value = 0; |
|
205 |
if(p.getX() > 0 && p.getX() < sourceBuffer.getWidth() && p.getY() > 0 && p.getY() < sourceBuffer.getHeight()) |
|
206 |
for (int iBand = 0; iBand < store.getBandCount(); iBand++) { |
|
207 |
if(interpMethod == 0) //Nearest neighbor |
|
208 |
value = interpolation.getNearestNeighbour(p.getX(), p.getY(), iBand); |
|
209 |
if(interpMethod == 1) //Bilinear |
|
210 |
value = interpolation.getBilinearValue(p.getX(), p.getY(), iBand); |
|
211 |
if(interpMethod == 2) //Inverse distance |
|
212 |
value = interpolation.getInverseDistance(p.getX(), p.getY(), iBand); |
|
213 |
if(type == Buffer.TYPE_BYTE) |
|
214 |
buf.setElem(row, col, iBand, (byte)value); |
|
215 |
else if(type == Buffer.TYPE_DOUBLE) |
|
216 |
buf.setElem(row, col, iBand, (double)value); |
|
217 |
else if(type == Buffer.TYPE_FLOAT) |
|
218 |
buf.setElem(row, col, iBand, (float)value); |
|
219 |
else if(type == Buffer.TYPE_SHORT) |
|
220 |
buf.setElem(row, col, iBand, (short)value); |
|
221 |
else if(type == Buffer.TYPE_INT) |
|
222 |
buf.setElem(row, col, iBand, (int)value); |
|
223 |
} |
|
224 |
else |
|
225 |
for (int iBand = 0; iBand < store.getBandCount(); iBand++) { |
|
226 |
if(type == Buffer.TYPE_BYTE) |
|
227 |
buf.setElem(row, col, iBand, nd.getValue().byteValue()); |
|
228 |
else if(type == Buffer.TYPE_DOUBLE) |
|
229 |
buf.setElem(row, col, iBand, nd.getValue().doubleValue()); |
|
230 |
else if(type == Buffer.TYPE_FLOAT) |
|
231 |
buf.setElem(row, col, iBand, nd.getValue().floatValue()); |
|
232 |
else if(type == Buffer.TYPE_SHORT) |
|
233 |
buf.setElem(row, col, iBand, nd.getValue().shortValue()); |
|
234 |
else if(type == Buffer.TYPE_INT) |
|
235 |
buf.setElem(row, col, iBand, nd.getValue().intValue()); |
|
236 |
} |
|
237 |
} |
|
238 |
|
|
239 |
/** |
|
240 |
* Transforms the upper left coordinate of a pixel using the transformation |
|
241 |
* which is passed by parameter |
|
242 |
* @param p |
|
243 |
* @param newBbox |
|
244 |
* @param col |
|
245 |
* @param row |
|
246 |
* @param cellSize |
|
247 |
* @param t |
|
248 |
*/ |
|
249 |
private Point2D transformPoint(Extent newBbox, int col, int row, double cellSize, ICoordTrans t) { |
|
250 |
Point2D p = new Point2D.Double( |
|
251 |
newBbox.getULX() + (col * cellSize), |
|
252 |
newBbox.getULY() - (row * cellSize)); |
|
253 |
p = t.convert(p, p); |
|
254 |
p = store.worldToRaster(p); |
|
255 |
return p; |
|
256 |
} |
|
257 |
|
|
258 |
/** |
|
259 |
* Gets the size of the new image |
|
260 |
* @param bbox |
|
261 |
* @param newBbox |
|
262 |
* @return |
|
263 |
*/ |
|
264 |
private double[] getSize(Extent bbox, Extent newBbox) { |
|
265 |
double sumSideOldBBox = bbox.width() + bbox.height(); |
|
266 |
double sumSideNewBBox = newBbox.width() + newBbox.height(); |
|
267 |
double d1x = (bbox.width() * 100) / sumSideOldBBox; |
|
268 |
double d1y = (bbox.height() * 100) / sumSideOldBBox; |
|
269 |
double d2x = (newBbox.width() * 100) / sumSideNewBBox; |
|
270 |
double d2y = (newBbox.height() * 100) / sumSideNewBBox; |
|
271 |
double p2y = (store.getHeight() * d2y) / d1y; |
|
272 |
double p2x = (store.getWidth() * d2x) / d1x; |
|
273 |
double newCellSize = newBbox.width() / p2x; |
|
274 |
return new double[]{Math.round(p2x), Math.round(p2y), newCellSize}; |
|
275 |
} |
|
276 |
} |
|
0 | 277 |
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.reproject_deprecated/src/main/java/org/gvsig/raster/tools/algorithm/reproject/RasterReprojectAlgorithmLibrary.java | ||
---|---|---|
1 |
/* |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.raster.tools.algorithm.reproject; |
|
25 |
|
|
26 |
import org.gvsig.i18n.Messages; |
|
27 |
import org.gvsig.raster.tools.algorithm.base.RasterBaseAlgorithmLibrary; |
|
28 |
import org.gvsig.tools.library.AbstractLibrary; |
|
29 |
import org.gvsig.tools.library.LibraryException; |
|
30 |
|
|
31 |
/** |
|
32 |
* Initialization of RasterReprojectAlgorithmLibrary library. |
|
33 |
* |
|
34 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
35 |
*/ |
|
36 |
public class RasterReprojectAlgorithmLibrary extends AbstractLibrary { |
|
37 |
public static final String PROCESS_LABEL = "RasterReprojectionProcess"; |
|
38 |
|
|
39 |
@Override |
|
40 |
protected void doInitialize() throws LibraryException { |
|
41 |
// Nothing to do |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
protected void doPostInitialize() throws LibraryException { |
|
46 |
//Registers the process and its parameters |
|
47 |
RasterBaseAlgorithmLibrary.register(PROCESS_LABEL, ReprojectProcess.class); |
|
48 |
ReprojectProcess.registerParameters(); |
|
49 |
|
|
50 |
Messages.addResourceFamily( |
|
51 |
"org.gvsig.raster.tools.algorithm.reproject", |
|
52 |
RasterReprojectAlgorithmLibrary.class.getClassLoader(), |
|
53 |
RasterReprojectAlgorithmLibrary.class.getClass().getName()); |
|
54 |
//registerGeoProcess(new RasterReprojectAlgorithmLibrary()); |
|
55 |
} |
|
56 |
} |
|
0 | 57 |
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.reproject_deprecated/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.tools.algorithm.reproject</artifactId> |
|
5 |
<packaging>jar</packaging> |
|
6 |
<name>org.gvsig.raster.tools.algorithm.reproject</name> |
|
7 |
<parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.raster.tools.algorithm</artifactId> |
|
10 |
<version>2.0.1-SNAPSHOT</version> |
|
11 |
</parent> |
|
12 |
<properties> |
|
13 |
<build-dir>${basedir}/../../../build</build-dir> |
|
14 |
</properties> |
|
15 |
<dependencies> |
|
16 |
<dependency> |
|
17 |
<groupId>org.gvsig</groupId> |
|
18 |
<artifactId>org.gvsig.raster.tools.algorithm.base</artifactId> |
|
19 |
<scope>compile</scope> |
|
20 |
</dependency> |
|
21 |
</dependencies> |
|
22 |
</project> |
|
0 | 23 |
Also available in: Unified diff