Revision 22773

View differences:

trunk/libraries/libTopology/src/org/gvsig/referencing/TransformBuilderFactory.java
1
/*
2
 * Created on 10-abr-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: 
47
* $Log: 
48
*/
49
package org.gvsig.referencing;
50

  
51
import java.util.ArrayList;
52
import java.util.List;
53
import java.util.Map;
54

  
55
import javax.vecmath.MismatchedSizeException;
56

  
57
import org.geotools.referencefork.geometry.DirectPosition2D;
58
import org.geotools.referencefork.referencing.operation.builder.AdvancedAffineBuilder;
59
import org.geotools.referencefork.referencing.operation.builder.AffineTransformBuilder;
60
import org.geotools.referencefork.referencing.operation.builder.BursaWolfTransformBuilder;
61
import org.geotools.referencefork.referencing.operation.builder.MappedPosition;
62
import org.geotools.referencefork.referencing.operation.builder.MathTransformBuilder;
63
import org.geotools.referencefork.referencing.operation.builder.ProjectiveTransformBuilder;
64
import org.geotools.referencefork.referencing.operation.builder.RubberSheetBuilder;
65
import org.geotools.referencefork.referencing.operation.builder.SimilarTransformBuilder;
66
import org.gvsig.util.ReferencingUtil;
67
import org.opengis.referencing.FactoryException;
68
import org.opengis.referencing.operation.TransformException;
69
import org.opengis.spatialschema.geometry.DirectPosition;
70
import org.opengis.spatialschema.geometry.MismatchedDimensionException;
71
import org.opengis.spatialschema.geometry.MismatchedReferenceSystemException;
72

  
73
public class TransformBuilderFactory {
74
	
75
	//least squares methods
76
	public static final int PROJECTIVE_TRANSFORM = 0;
77
	public static final int AFFINE_TRANSFORM = 1;
78
	public static final int SIMILAR_TRANSFORM = 2;
79
	public static final int BURSA_WOLF_TRANSFORM = 3;
80
	
81
	//TIN 
82
	public static final int RUBBER_SHEET_TRANSFORM = 4;
83
	
84
	
85
	//ADVANCED TRANSFORMATIONS (GRID BASED)
86
	public static final int ADVANCED_AFFINE_TRANSFORM = 5;
87
//	public static final int IDW_WARP_GRID = 6;
88
//	public static final int NADCON_GRID = 7;
89
//	public static final int RS_TRANSFORM = 8;
90
//	public static final int TPS_GRID = 9;
91
	
92
	
93
	
94
	public static MathTransformBuilder createTransformBuilder(int transformType, 
95
													MappedPositionContainer mappedPositionsContainer, 
96
													Map<String, Object> params) 
97
				throws MismatchedDimensionException, 
98
					   MismatchedReferenceSystemException, 
99
					   MismatchedSizeException, 
100
					   FactoryException, 
101
					   TransformException{
102
		MathTransformBuilder solution = null;
103
		List<MappedPosition> mappedPositions = mappedPositionsContainer.getAsList();
104
		
105
		
106
		//TODO SUSTITUIR EL SWITCH POR UN HASHMAP, Y POR EL REGISTRO EST?TICO
107
		//DE M?TODOS DE TRANSFORMACION MEDIANTE PUNTOS DE EXTENSION
108
		switch(transformType){
109
		case PROJECTIVE_TRANSFORM:
110
			solution = new ProjectiveTransformBuilder(mappedPositions);
111
			break;
112
		case AFFINE_TRANSFORM:
113
			solution = new AffineTransformBuilder(mappedPositions);
114
			break;
115
		case SIMILAR_TRANSFORM:
116
			solution = new SimilarTransformBuilder(mappedPositions);
117
			break;
118
		case BURSA_WOLF_TRANSFORM:
119
			solution = new BursaWolfTransformBuilder(mappedPositions);
120
			break;
121
		case RUBBER_SHEET_TRANSFORM:
122
			List<DirectPosition> roi = createRoi(mappedPositions);
123
			solution = new RubberSheetBuilder(mappedPositions, roi);
124
			break;
125
		case ADVANCED_AFFINE_TRANSFORM:
126
			solution = new AdvancedAffineBuilder(mappedPositions);
127
			//aqu? habr?a que a?adir los diferentes constre?imientos con
128
			//solution.setConstraint(String, Object)
129
			break;
130
//		case IDW_WARP_GRID:
131
//			solution = new IDWGridBuilder(mappedPositions, 0d, 0d, null);
132
//			break;
133
//		case NADCON_GRID:
134
//			solution = new NADCONBuilder(mappedPositions, 0d, 0d, null);
135
//			break;
136
//		case RS_TRANSFORM:
137
//			solution = new RSGridBuilder(mappedPositions, 0d, 0d, null, null);
138
//			break;
139
//		case TPS_GRID:
140
//			solution = new TPSGridBuilder(mappedPositions, 0d, 0d, null, null);
141
//			break;
142
		default:
143
			solution = new AffineTransformBuilder(mappedPositions);
144
			break;
145
		}
146
		
147
		return solution;
148
		
149
	}
150
	
151
	public static List<DirectPosition> createRoi(List<MappedPosition> mappedPositions){
152
		List<DirectPosition> solution = new ArrayList<DirectPosition>();
153
		double minX = Double.MAX_VALUE, minY = Double.MAX_VALUE, maxX = Double.MIN_VALUE, maxY = Double.MIN_VALUE;
154
		
155
		for (int i = 0; i < mappedPositions.size(); i++) {
156
			MappedPosition position = mappedPositions.get(i);
157
			DirectPosition source = position.getSource();
158
			double[] sourceCoords = source.getCoordinates();
159
			if(sourceCoords[0] > maxX)
160
				maxX = sourceCoords[0];
161
			if(sourceCoords[0] < minX)
162
				minX = sourceCoords[0];
163
			if(sourceCoords[1] > maxY)
164
				maxY = sourceCoords[1];
165
			if(sourceCoords[1] < minY)
166
				minY = sourceCoords[1];
167
			
168
			
169
			
170
			DirectPosition target = position.getTarget();
171
			double[] targetCoords = target.getCoordinates();
172
			if(targetCoords[0] > maxX)
173
				maxX = targetCoords[0];
174
			if(targetCoords[0] < minX)
175
				minX = targetCoords[0];
176
			if(targetCoords[1] > maxY)
177
				maxY = targetCoords[1];
178
			if(targetCoords[1] < minY)
179
				minY = targetCoords[1];
180
			
181
		}
182
		DirectPosition a = new DirectPosition2D(minX, minY);
183
		DirectPosition b = new DirectPosition2D(minX, maxY);
184
		DirectPosition c = new DirectPosition2D(maxX, minY);
185
		DirectPosition d = new DirectPosition2D(maxX, maxY);
186
		
187
		//azo: this code has been modified for compatibility problem between
188
		//different versions of geoapi (2.0 used in libFMap, and 2.2 needed for
189
		//topology
190
//		DirectPosition a = ReferencingUtil.getInstance().create(new double[]{minX, minY}, null);
191
//		DirectPosition b = ReferencingUtil.getInstance().create(new double[]{minX, maxY}, null);
192
//		DirectPosition c = ReferencingUtil.getInstance().create(new double[]{maxX, minY}, null);
193
//		DirectPosition d = ReferencingUtil.getInstance().create(new double[]{maxX, maxY}, null);
194
		
195
		solution.add(a);
196
		solution.add(b);
197
		solution.add(c);
198
		solution.add(d);
199
		
200
		return solution;
201
	}
202
}
trunk/libraries/libTopology/src/org/gvsig/referencing/MappedPositionContainer.java
1
/*
2
 * Created on 10-abr-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: 
47
* $Log: 
48
*/
49
package org.gvsig.referencing;
50

  
51
import java.util.List;
52

  
53
import org.geotools.referencefork.referencing.operation.builder.MappedPosition;
54

  
55
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
56

  
57
/**
58
 * Container of MappedPosition objects, that represents digitized vector error
59
 * for spatial adjustment process.
60
 * 
61
 * @author Alvaro Zabala
62
 *
63
 */
64
public interface MappedPositionContainer {
65
	public void addMappedPosition(MappedPosition mappedPosition);
66
	public MappedPosition getMappedPosition(int idx);
67
	public int getCount();
68
	public List<MappedPosition> getAsList();
69
	public boolean existsLinksLyr();
70
	public FLyrVect getLinkLyr();
71
}

Also available in: Unified diff