svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / GeoOperations.java @ 5352
History | View | Annotate | Download (18.4 KB)
1 |
package org.gvsig.georeferencing; |
---|---|
2 |
|
3 |
import java.awt.geom.Point2D; |
4 |
import java.io.BufferedOutputStream; |
5 |
import java.io.BufferedReader; |
6 |
import java.io.BufferedWriter; |
7 |
import java.io.DataOutputStream; |
8 |
import java.io.File; |
9 |
import java.io.FileInputStream; |
10 |
import java.io.FileNotFoundException; |
11 |
import java.io.FileOutputStream; |
12 |
import java.io.IOException; |
13 |
import java.io.InputStreamReader; |
14 |
import java.io.OutputStream; |
15 |
import java.io.OutputStreamWriter; |
16 |
import java.util.zip.DataFormatException; |
17 |
|
18 |
import org.cresques.io.RasterMetaFileTags; |
19 |
import org.gvsig.georeferencing.utils.AffineT; |
20 |
import org.gvsig.georeferencing.utils.MathUtils; |
21 |
import org.gvsig.georeferencing.utils.PointT; |
22 |
import org.xmlpull.v1.XmlPullParserException; |
23 |
import org.xmlpull.v1.XmlPullParserFactory; |
24 |
import org.xmlpull.v1.XmlSerializer; |
25 |
|
26 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
27 |
|
28 |
|
29 |
/**
|
30 |
* Operaciones necesarias para la georreferenciaci?n a partir de la capa de puntos.
|
31 |
* En base a unos puntos de control de origen y otros de destino se crea una matriz
|
32 |
* de transformaci?n para asignar la nueva posici?n a la imagen y crear ficheros
|
33 |
* de georreferenciaci?n en dos formatos: worldfile y rasterMetaFile
|
34 |
*
|
35 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
36 |
*/
|
37 |
public class GeoOperations{ |
38 |
|
39 |
//**********************Vars**********************************
|
40 |
private int order = 1; |
41 |
private PointT[] src = null; |
42 |
private PointT[] dst = null; |
43 |
private AffineT affine = null; |
44 |
private boolean createWorldFile = false; |
45 |
//**********************End Vars******************************
|
46 |
|
47 |
//**********************Methods*******************************
|
48 |
/**
|
49 |
* Constructor
|
50 |
*/
|
51 |
public GeoOperations(){}
|
52 |
|
53 |
/**
|
54 |
* Constructor. Crea las estructuras de puntos y calcula la transformaci?n af?n.
|
55 |
* @param lyr
|
56 |
*/
|
57 |
public GeoOperations(FLyrPoints lyr){
|
58 |
FLyrPoints lyrPoints = lyr; |
59 |
src = new PointT[lyr.getCountPoints()];
|
60 |
dst = new PointT[lyr.getCountPoints()];
|
61 |
int nPoint = 0; |
62 |
for(int i = 0; i<lyr.getCountPoints(); i++){ |
63 |
if(lyr.getPoint(i).active == true){ |
64 |
src[nPoint] = new PointT();
|
65 |
dst[nPoint] = new PointT();
|
66 |
src[nPoint].setX(lyr.getPoint(i).pixelPoint.getX()); |
67 |
src[nPoint].setY(lyr.getPoint(i).pixelPoint.getY()); |
68 |
src[nPoint].setI(lyr.getCountPoints()); |
69 |
dst[nPoint].setX(lyr.getPoint(i).mapPoint.getX()); |
70 |
dst[nPoint].setY(lyr.getPoint(i).mapPoint.getY()); |
71 |
dst[nPoint].setI(lyr.getCountPoints()); |
72 |
nPoint++; |
73 |
} |
74 |
} |
75 |
|
76 |
if(lyr.getCountPoints() >= 3 * 10) |
77 |
order = 3;
|
78 |
else if(lyr.getCountPoints() >= 3 * 6) |
79 |
order = 2;
|
80 |
else
|
81 |
order = 1;
|
82 |
|
83 |
affine = new AffineT();
|
84 |
|
85 |
//Calcular la transformaci?n afin por m?nimos cuadrados
|
86 |
affine = computeLeastSquaresAffine(affine, src, dst, order); |
87 |
} |
88 |
|
89 |
/**
|
90 |
* A partir de la transformaci?n af?n creada en el construtor
|
91 |
* genera un fichero de georreferenciaci?n para la imagen.
|
92 |
* @param lyr Capa de puntos
|
93 |
* @param order Orden del sistema de ecuaciones
|
94 |
* @param widthPx Ancho en pixeles de la imagen a georreferenciar
|
95 |
* @param heightPx Alto en pixeles de la imagen a georreferenciar
|
96 |
* @param file Nombre del fichero raster a georreferenciar
|
97 |
*/
|
98 |
public void createGeorefFile(int widthPx, int heightPx, String file){ |
99 |
try{
|
100 |
File f = new File(file); |
101 |
String nameWorldFile = f.getPath().substring(0, f.getPath().lastIndexOf(".")) + getExtensionWorldFile(file); |
102 |
if(createWorldFile)
|
103 |
createWorldFile(affine, widthPx, heightPx, nameWorldFile); |
104 |
createRasterMetaFile(affine, widthPx, heightPx, nameWorldFile.substring(0, nameWorldFile.lastIndexOf("."))+".rmf"); |
105 |
}catch(IOException ex){ |
106 |
System.err.println("Can't create WorldFile"); |
107 |
} |
108 |
} |
109 |
|
110 |
/**
|
111 |
* A partir de la transformaci?n af?n calculada en el contructor
|
112 |
* transforma los puntos pasados como par?metros.
|
113 |
* @param lyr Capa de puntos
|
114 |
* @param list Lista de puntos a transformar
|
115 |
* @return Lista de puntos transformados
|
116 |
*/
|
117 |
public Point2D[] transformPoints(Point2D[] list){ |
118 |
Point2D[] result = new Point2D[list.length]; |
119 |
for(int i = 0; i < list.length;i++){ |
120 |
double[] pto = transformPoint((int)list[i].getX(), (int)list[i].getY(), affine); |
121 |
result[i] = new Point2D.Double(pto[0], pto[1]); |
122 |
} |
123 |
return result;
|
124 |
} |
125 |
|
126 |
/**
|
127 |
* Crea un fichero de georreferenciaci?n (worldfile) a partir de la transformaci?n af?n. Para
|
128 |
* esto necesita obtener las coordenadas reales de la coordenada en pixels (0,0) y calcular
|
129 |
* el tama?o de pixel.
|
130 |
* @param affine Transformaci?n
|
131 |
* @param widthPx Ancho en pixeles de la imagen a georreferenciar
|
132 |
* @param heightPx Alto en pixeles de la imagen a georreferenciar
|
133 |
* @param nameWordlFile Nombre del fichero de georreferenciaci?n
|
134 |
* @throws IOException
|
135 |
*/
|
136 |
private void createWorldFile(AffineT affine, int widthPx, int heightPx, String nameWordlFile) throws IOException { |
137 |
StringBuffer data = new StringBuffer(); |
138 |
double[] begin = transformPoint(0, 0, affine); |
139 |
double[] end = transformPoint(widthPx, heightPx, affine); |
140 |
File f = new File(nameWordlFile); |
141 |
DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(f)) ); |
142 |
|
143 |
double pixelSizeX = (end[0] - begin[0])/(widthPx - 1); |
144 |
double pixelSizeY = (end[1] - begin[1])/(heightPx - 1); |
145 |
|
146 |
data.append(pixelSizeX+"\n");
|
147 |
data.append("0.0\n");
|
148 |
data.append("0.0\n");
|
149 |
data.append((-1 * pixelSizeY)+"\n"); |
150 |
data.append(""+begin[0]+"\n"); |
151 |
data.append(""+end[1]+"\n"); |
152 |
|
153 |
dos.writeBytes(data.toString()); |
154 |
dos.close(); |
155 |
} |
156 |
|
157 |
/**
|
158 |
* A partir de XmlSerializer se salva la georreferenciaci?n
|
159 |
* @param serializer
|
160 |
* @param min
|
161 |
* @param max
|
162 |
* @param widthPx Ancho en pixeles de la imagen a georreferenciar
|
163 |
* @param heightPx Alto en pixeles de la imagen a georreferenciar
|
164 |
* @throws IOException
|
165 |
*/
|
166 |
private void serializeGeoreferencing(XmlSerializer serializer, double[] min, double[] max, int widthPx, int heightPx) throws IOException { |
167 |
double pixelSizeX = (max[0] - min[0])/(widthPx - 1); |
168 |
double pixelSizeY = (max[1] - min[1])/(heightPx - 1); |
169 |
|
170 |
serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PROJ).text("Projection").endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PROJ).text("\n"); |
171 |
serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.BBOX).text("\n");
|
172 |
serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.POSX).text(""+min[0]).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.POSX).text("\n"); |
173 |
serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.POSY).text(""+max[1]).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.POSY).text("\n"); |
174 |
serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_SIZE_X).text(""+pixelSizeX).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_SIZE_X).text("\n"); |
175 |
serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_SIZE_Y).text(""+ (-1 * pixelSizeY)).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_SIZE_Y).text("\n"); |
176 |
serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.WIDTH).text(""+(max[0] - min[0])).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.WIDTH).text("\n"); |
177 |
serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.HEIGHT).text(""+(max[1] - min[1])).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.HEIGHT).text("\n"); |
178 |
serializer.endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.BBOX).text("\n");
|
179 |
serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.DIM).text("\n");
|
180 |
serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_WIDTH).text(""+widthPx).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_WIDTH).text("\n"); |
181 |
serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_HEIGHT).text(""+heightPx).endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.PX_HEIGHT).text("\n"); |
182 |
serializer.endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.DIM).text("\n");
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* Si ya existe un fichero de georreferenciaci?n se ha creado un fichero .tmp con
|
187 |
* la nueva georreferenciaci?n. Esta funci?n mezcla este temporal con el .rmf existente
|
188 |
* en un nuevo fichero _tmpOutput que ser? renombrado como el nuevo .rmf. Finalmente
|
189 |
* elimina el temporal y el _tmpOutput.
|
190 |
* @param fileName
|
191 |
*/
|
192 |
private void mergeFiles(String fileName){ |
193 |
try{
|
194 |
File rmfFile = new File(fileName); |
195 |
File tmpFile = new File(fileName.substring(0, fileName.lastIndexOf("."))+".tmp"); |
196 |
File out = new File(rmfFile+"_tmpOutput"); |
197 |
|
198 |
BufferedReader inRmf = new BufferedReader(new InputStreamReader(new FileInputStream(rmfFile))); |
199 |
BufferedReader inTmp = new BufferedReader(new InputStreamReader(new FileInputStream(tmpFile))); |
200 |
BufferedWriter outTmp = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(out))); |
201 |
|
202 |
//Leemos el principio del .rmf
|
203 |
String str = inRmf.readLine();
|
204 |
while(!str.startsWith("<"+RasterMetaFileTags.MAIN_TAG)){ |
205 |
outTmp.write(str+"\n");
|
206 |
str = inRmf.readLine(); |
207 |
} |
208 |
outTmp.write(str+"\n");
|
209 |
|
210 |
//Leemos la georreferenciaci?n del .tmp
|
211 |
while(str != null && !str.startsWith("<"+RasterMetaFileTags.LAYER)) |
212 |
str = inTmp.readLine(); |
213 |
while(str != null){ |
214 |
outTmp.write(str+"\n");
|
215 |
str = inTmp.readLine(); |
216 |
} |
217 |
|
218 |
//Saltamos la georreferenciaci?n que ya existia en el .rmf
|
219 |
try{
|
220 |
str = inRmf.readLine(); |
221 |
while(str != null && |
222 |
!str.startsWith("</"+RasterMetaFileTags.LAYER) &&
|
223 |
!str.startsWith("<"+RasterMetaFileTags.GEOPOINTS) &&
|
224 |
!str.startsWith("</"+RasterMetaFileTags.MAIN_TAG))
|
225 |
str = inRmf.readLine(); |
226 |
}catch(Exception exc){ |
227 |
|
228 |
} |
229 |
|
230 |
//Leemos el resto del fichero .rmf
|
231 |
if(!str.startsWith("<"+RasterMetaFileTags.GEOPOINTS)) |
232 |
str = inRmf.readLine(); |
233 |
while(str != null){ |
234 |
outTmp.write(str+"\n");
|
235 |
str = inRmf.readLine(); |
236 |
} |
237 |
|
238 |
outTmp.close(); |
239 |
inRmf.close(); |
240 |
inTmp.close(); |
241 |
|
242 |
//Eliminamos el antiguo .rmf y lo sustituimos
|
243 |
rmfFile.delete(); |
244 |
out.renameTo(rmfFile); |
245 |
tmpFile.delete(); |
246 |
|
247 |
}catch(FileNotFoundException exc){ |
248 |
|
249 |
}catch(IOException exc){ |
250 |
|
251 |
} |
252 |
} |
253 |
|
254 |
/**
|
255 |
* Si no existe crea un fichero .rmf con la georreferenciaci?n de la imagen. Si existe este
|
256 |
* deber? a?adir o modificar la informaci?n de georreferenciaci?n en el fichero.
|
257 |
* Para esto necesita obtener las coordenadas reales de la coordenada en pixels (0,0) y
|
258 |
* calcular el tama?o de pixel.
|
259 |
* @param affine Transformaci?n
|
260 |
* @param widthPx Ancho en pixeles de la imagen a georreferenciar
|
261 |
* @param heightPx Alto en pixeles de la imagen a georreferenciar
|
262 |
* @param nameWordlFile Nombre del fichero de georreferenciaci?n
|
263 |
* @throws IOException
|
264 |
*/
|
265 |
private void createRasterMetaFile(AffineT affine, int widthPx, int heightPx, String nameWorldFile) throws IOException { |
266 |
File file = new File(nameWorldFile); |
267 |
double[] min = transformPoint(0, 0, affine); |
268 |
double[] max = transformPoint(widthPx, heightPx, affine); |
269 |
try{
|
270 |
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null); |
271 |
XmlSerializer serializer = factory.newSerializer(); |
272 |
|
273 |
if(file.exists()){
|
274 |
file = new File(nameWorldFile.substring(0, nameWorldFile.lastIndexOf("."))+".tmp"); |
275 |
serializer.setOutput(new FileOutputStream(file), null); |
276 |
serializer.startDocument(null, null); |
277 |
serializer.ignorableWhitespace("\n\n");
|
278 |
serializer.setPrefix("", RasterMetaFileTags.NAMESPACE);
|
279 |
serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.LAYER).text("\n");
|
280 |
serializeGeoreferencing(serializer, min, max, widthPx, heightPx); |
281 |
serializer.endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.LAYER).text("\n");
|
282 |
serializer.endDocument(); |
283 |
mergeFiles(nameWorldFile); |
284 |
}else{
|
285 |
serializer.setOutput(new FileOutputStream(file), null); |
286 |
serializer.startDocument(null, null); |
287 |
serializer.ignorableWhitespace("\n\n");
|
288 |
serializer.setPrefix("", RasterMetaFileTags.NAMESPACE);
|
289 |
serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.MAIN_TAG).text("\n");
|
290 |
serializer.startTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.LAYER).text("\n");
|
291 |
serializeGeoreferencing(serializer, min, max, widthPx, heightPx); |
292 |
serializer.endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.LAYER).text("\n");
|
293 |
serializer.endTag(RasterMetaFileTags.NAMESPACE, RasterMetaFileTags.MAIN_TAG).text("\n");
|
294 |
serializer.endDocument(); |
295 |
} |
296 |
}catch(XmlPullParserException exc){}
|
297 |
} |
298 |
|
299 |
/**
|
300 |
* Calcula la transformaci?n af?n a partir de los puntos introducidos por el m?todo de
|
301 |
* m?nimos cuadrados.
|
302 |
* @param af Transformaci?n af?n
|
303 |
* @param src Puntos de entrada en coordenadas pixel
|
304 |
* @param dst Puntos de destino en coordenadas del mundo
|
305 |
* @param order Orden del sistema de ecuaciones
|
306 |
*/
|
307 |
public AffineT computeLeastSquaresAffine(AffineT af, PointT[] src, PointT[] dst, int order){ |
308 |
double[] b = new double[dst.length]; |
309 |
int i,cofs;
|
310 |
|
311 |
af.setOrder(order); |
312 |
cofs = order <= 2 ? order*3 : 10; |
313 |
af.mallocCofs(cofs); |
314 |
|
315 |
//First compute the X cofs
|
316 |
for(i = 0; i < dst.length; i++) { |
317 |
b[i] = dst[i].getX(); |
318 |
} |
319 |
|
320 |
af.setCofX(singleLeastSquaresAffine(af.getXcofs(), src, b, order)); |
321 |
|
322 |
//Now compute the Y cofs
|
323 |
for(i = 0; i < dst.length; i++) { |
324 |
b[i] = dst[i].getY(); |
325 |
} |
326 |
|
327 |
af.setCofY(singleLeastSquaresAffine(af.getYcofs(), src, b, order)); |
328 |
|
329 |
return af;
|
330 |
} |
331 |
|
332 |
private double[] singleLeastSquaresAffine(double[] a, PointT[] src, double[] dst, int order){ |
333 |
int i,j;
|
334 |
int n = dst.length;
|
335 |
|
336 |
int points = order <= 2 ? order * 3 : 10; |
337 |
double[][] combined = new double[points][points + 1]; |
338 |
double[][] A = new double[n + 1][points]; |
339 |
double[][] b = new double[n + 1][1]; |
340 |
|
341 |
for(i = 0; i < n; i++) { |
342 |
A[i][0] = 1.0; |
343 |
A[i][1] = src[i].getX();
|
344 |
A[i][2] = src[i].getY();
|
345 |
if(order > 1) { |
346 |
A[i][3] = src[i].getX() * src[i].getX();
|
347 |
A[i][4] = src[i].getX() * src[i].getY();
|
348 |
A[i][5] = src[i].getY() * src[i].getY();
|
349 |
} |
350 |
if(order > 2) { |
351 |
A[i][6] = src[i].getX() * src[i].getX() * src[i].getX();
|
352 |
A[i][7] = src[i].getX() * src[i].getX() * src[i].getY();
|
353 |
A[i][8] = src[i].getX() * src[i].getY() * src[i].getY();
|
354 |
A[i][9] = src[i].getY() * src[i].getY() * src[i].getY();
|
355 |
} |
356 |
b[i][0] = dst[i];
|
357 |
} |
358 |
|
359 |
double[][] Atrans = MathUtils.transpose(A, n, points); |
360 |
double[][] left = MathUtils.multmatrix(Atrans,A,points,n,points); |
361 |
double[][] right = MathUtils.multmatrix(Atrans,b,points,n,1); |
362 |
|
363 |
for(i = 0; i < points; i++) { |
364 |
combined[i][0] = right[i][0]; |
365 |
for(j = 0; j < points; j++) { |
366 |
combined[i][j+1] = left[i][j];
|
367 |
} |
368 |
} |
369 |
|
370 |
try{
|
371 |
combined = solve(combined, points, points+1);
|
372 |
}catch(DataFormatException ex){ |
373 |
System.err.println("Can't solve matrix"); |
374 |
} |
375 |
|
376 |
for(i = 0; i < points; i++) { |
377 |
a[i] = combined[i][0];
|
378 |
} |
379 |
return a;
|
380 |
} |
381 |
|
382 |
|
383 |
private double[][] solve(double[][] mat,int rows,int cols)throws DataFormatException{ |
384 |
int i,j,k;
|
385 |
double d,tmp;
|
386 |
int big;
|
387 |
|
388 |
for(i = 0; i < rows; i++) { |
389 |
// Find largest row
|
390 |
big = i; |
391 |
for(j = i; j < rows; j++) {
|
392 |
if(Math.abs(mat[j][i+1]) > Math.abs(mat[big][i+1])) { |
393 |
big = j; |
394 |
} |
395 |
} |
396 |
// swap row i and row big
|
397 |
for(k = 0; k < cols ; k++) { |
398 |
tmp = mat[i][k]; |
399 |
mat[i][k] = mat[big][k]; |
400 |
mat[big][k] = tmp; |
401 |
} |
402 |
if(mat[i][i+1] == 0) |
403 |
throw new DataFormatException(); |
404 |
|
405 |
d = 1.0 / mat[i][i+1]; |
406 |
for(j = 0; j < cols ; j++) { |
407 |
mat[i][j] *= d; |
408 |
//assert(!isnan(mat[i][j]));
|
409 |
} |
410 |
for(k = 0; k < rows; k++) { |
411 |
if(k == i)
|
412 |
continue;
|
413 |
if(mat[k][i+1] != 0.0) { |
414 |
d = mat[k][i+1] / mat[i][i+1]; |
415 |
for(j = 0; j < cols ; j++) { |
416 |
mat[k][j] -= d*mat[i][j]; |
417 |
//assert(!isnan(mat[k][j]));
|
418 |
} |
419 |
} |
420 |
} |
421 |
} |
422 |
return mat;
|
423 |
} |
424 |
|
425 |
/**
|
426 |
* Obtiene las coordenadas de un punto en coordenadas del mundo a partir de una transformaci?n
|
427 |
* y el punto de entrada en coordenadas de la imagen.
|
428 |
* @param sx Coordenada X del punto de entrada
|
429 |
* @param syz Coordenada Y del punto de entrada
|
430 |
* @param af Transformaci?n
|
431 |
* @return Punto transformado
|
432 |
*/
|
433 |
public double[] transformPoint(int sx, int sy, AffineT af){ |
434 |
double[] p = new double[2]; |
435 |
if(af.getOrder() == 1) { |
436 |
p[0] = af.getCofX(0) + af.getCofX(1) * sx + af.getCofX(2) * sy; |
437 |
p[1] = af.getCofY(0) + af.getCofY(1) * sx + af.getCofY(2) * sy; |
438 |
} |
439 |
else if(af.getOrder() == 2) { |
440 |
p = quadTransformPoint(sx, sy, af); |
441 |
} |
442 |
else {
|
443 |
p = cubicTransformPoint(sx, sy, af); |
444 |
} |
445 |
return p;
|
446 |
} |
447 |
|
448 |
private static double[] quadTransformPoint(int sx, int sy, AffineT af){ |
449 |
double[] p = new double[2]; |
450 |
p[0] = af.getCofX(0) + af.getCofX(1) * sx + af.getCofX(2) * sy + |
451 |
af.getCofX(3) * sx * sx + af.getCofX(4) * sx * sy + af.getCofX(5) * sy * sy; |
452 |
p[1] = af.getCofY(0) + af.getCofY(1) * sx + af.getCofY(2) * sy + |
453 |
af.getCofY(3) * sx * sx + af.getCofY(4) * sx * sy + af.getCofY(5) * sy * sy; |
454 |
return p;
|
455 |
} |
456 |
|
457 |
private static double[] cubicTransformPoint(int sx, int sy, AffineT af){ |
458 |
double[] p = new double[2]; |
459 |
p[0] = af.getCofX(0) + af.getCofX(1) * sx + af.getCofX(2) * sy + |
460 |
af.getCofX(3) * sx * sx + af.getCofX(4) * sx * sy + af.getCofX(5) * sy * sy + |
461 |
af.getCofX(6) * sx * sx * sx + af.getCofX(7) * sx * sx * sy + |
462 |
af.getCofX(8)*sx*sy*sy + af.getCofX(9)*sy*sy*sy; |
463 |
p[1] = af.getCofY(0) + af.getCofY(1) * sx + af.getCofY(2) * sy + |
464 |
af.getCofY(3) * sx * sx + af.getCofY(4) * sx * sy + af.getCofY(5) * sy * sy + |
465 |
af.getCofY(6) * sx * sx * sx + af.getCofY(7) * sx * sx * sy + |
466 |
af.getCofY(8) * sx * sy * sy + af.getCofY(9) * sy * sy * sy; |
467 |
return p;
|
468 |
} |
469 |
//**********************End Methods***************************
|
470 |
|
471 |
//**********************Setters & Getters*********************
|
472 |
/**
|
473 |
* M?todo para notificar si se desea crear o no el fichero de coordenadas .tfw, .wld .jpgw ,...
|
474 |
* @param createWorldFile
|
475 |
*/
|
476 |
public void setCreateWorldFile(boolean createWorldFile) { |
477 |
this.createWorldFile = createWorldFile;
|
478 |
} |
479 |
|
480 |
/**
|
481 |
* Obtiene la extensi?n del fichero de georreferenciaci?n
|
482 |
* @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
|
483 |
* del valor del formato obtenido del servidor. Por defecto asignaremos un .wld
|
484 |
*/
|
485 |
private String getExtensionWorldFile(String file){ |
486 |
String ext = file.substring(file.lastIndexOf(".") + 1); |
487 |
String extWorldFile = ".wld"; |
488 |
if(ext.equals("tif") || ext.equals("tiff")) |
489 |
extWorldFile = ".tfw";
|
490 |
if(ext.equals("jpeg") || ext.equals("jpg")) |
491 |
extWorldFile = ".jpgw";
|
492 |
return extWorldFile;
|
493 |
} |
494 |
//**********************End Setters & Getters*****************
|
495 |
} |