Revision 867
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.catalog.impl/src/main/java/org/gvsig/geotools/proj/catalog/DefaultTransformationDefinition.java | ||
---|---|---|
1 | 1 |
package org.gvsig.geotools.proj.catalog; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
3 | 4 |
import java.util.HashSet; |
4 | 5 |
import java.util.List; |
5 | 6 |
import java.util.Set; |
... | ... | |
8 | 9 |
import org.geotools.referencing.operation.transform.ConcatenatedTransform; |
9 | 10 |
import org.geotools.referencing.wkt.Formatter; |
10 | 11 |
import org.geotools.referencing.wkt.Symbols; |
11 |
import org.gvsig.geotools.proj.catalog.utils.IdentifiedObjectUtils; |
|
12 |
import org.gvsig.geotools.proj.catalog.extent.DefaultExtent; |
|
13 |
import org.gvsig.geotools.proj.catalog.extent.DefaultGeographicBoundingBox; |
|
14 |
import org.gvsig.geotools.proj.catalog.extent.DefaultVerticalExtent; |
|
15 |
import org.gvsig.geotools.proj.catalog.utils.GtUtils; |
|
12 | 16 |
import org.gvsig.proj.catalog.CRSDefinition; |
13 | 17 |
import org.gvsig.proj.catalog.TextSerialization.Format; |
14 | 18 |
import org.gvsig.proj.catalog.TextSerialization.WKTConvention; |
... | ... | |
19 | 23 |
import org.gvsig.proj.catalog.exception.UnsupportedFormatException; |
20 | 24 |
import org.gvsig.proj.catalog.exception.UnsupportedTransformationException; |
21 | 25 |
import org.gvsig.proj.catalog.extent.Extent; |
26 |
import org.gvsig.proj.catalog.extent.GeographicBoundingBox; |
|
27 |
import org.gvsig.proj.catalog.extent.VerticalExtent; |
|
22 | 28 |
import org.opengis.referencing.ReferenceIdentifier; |
23 | 29 |
import org.opengis.referencing.operation.ConcatenatedOperation; |
24 | 30 |
import org.opengis.referencing.operation.CoordinateOperation; |
25 | 31 |
import org.opengis.referencing.operation.MathTransform; |
26 | 32 |
import org.opengis.referencing.operation.PassThroughOperation; |
33 |
import org.opengis.referencing.operation.Projection; |
|
27 | 34 |
import org.opengis.referencing.operation.SingleOperation; |
28 | 35 |
import org.opengis.referencing.operation.Transformation; |
29 | 36 |
|
... | ... | |
106 | 113 |
|
107 | 114 |
@Override |
108 | 115 |
public String getName() { |
109 |
// FIXME: define in API whether null or blank "" is allowed |
|
110 | 116 |
if (operation != null) { |
111 | 117 |
return nameFromOperation(operation); |
112 | 118 |
} |
... | ... | |
133 | 139 |
List<SingleOperation> opList = ((ConcatenatedOperation) op).getOperations(); |
134 | 140 |
for (SingleOperation singleOp: opList) { |
135 | 141 |
if (singleOp instanceof Transformation) { |
136 |
meaningfulName.append("Concat operation using "); |
|
142 |
String id = GtUtils.getIdentifier(singleOp); |
|
143 |
if (id!=null) { |
|
144 |
meaningfulName.append(id).append("-based concat operation").append(" - "); |
|
145 |
} |
|
137 | 146 |
if (singleOp.getName() != null) { |
138 | 147 |
meaningfulName.append(singleOp.getName()); |
139 | 148 |
} |
140 |
String id = IdentifiedObjectUtils.getIdentifier(singleOp); |
|
141 |
if (id!=null) { |
|
142 |
meaningfulName.append("[").append(id).append("]"); |
|
143 |
} |
|
144 | 149 |
} |
145 | 150 |
} |
146 | 151 |
if (op.getName() != null) { |
147 |
if (meaningfulName.length()>0) {
|
|
148 |
meaningfulName.append(" transforming ");
|
|
152 |
if (meaningfulName.length()==0) {
|
|
153 |
meaningfulName.append("Concat operation");
|
|
149 | 154 |
} |
150 |
meaningfulName.append(op.getName().toString().replace("\u21e8", "=>")); |
|
151 | 155 |
} |
152 | 156 |
if (meaningfulName.length()>0) { |
153 | 157 |
return meaningfulName.toString(); |
... | ... | |
167 | 171 |
if (operation==null) { |
168 | 172 |
return null; |
169 | 173 |
} |
170 |
return IdentifiedObjectUtils.getIdentifier(operation);
|
|
174 |
return GtUtils.getIdentifier(operation);
|
|
171 | 175 |
} |
172 | 176 |
|
173 | 177 |
@Override |
... | ... | |
186 | 190 |
operation.getName().getAuthority()==null) { |
187 | 191 |
return null; |
188 | 192 |
} |
189 |
return IdentifiedObjectUtils.getIdentifier(operation.getName().getAuthority().getIdentifiers());
|
|
193 |
return GtUtils.getIdentifier(operation.getName().getAuthority().getIdentifiers());
|
|
190 | 194 |
} |
191 | 195 |
|
192 | 196 |
@Override |
... | ... | |
199 | 203 |
|
200 | 204 |
@Override |
201 | 205 |
public Extent getDomainOfValidity() { |
202 |
// TODO Auto-generated method stub |
|
206 |
org.opengis.metadata.extent.Extent extent = operation.getDomainOfValidity(); |
|
207 |
if (extent != null) { |
|
208 |
String desc; |
|
209 |
if (operation.getDomainOfValidity().getDescription() != null) { |
|
210 |
desc = operation.getDomainOfValidity().getDescription().toString(); |
|
211 |
} |
|
212 |
else { |
|
213 |
desc = null; |
|
214 |
} |
|
215 |
ArrayList<GeographicBoundingBox> horizontalExtentList = new ArrayList<GeographicBoundingBox>(); |
|
216 |
for (org.opengis.metadata.extent.GeographicExtent horizExtent: operation.getDomainOfValidity().getGeographicElements()) { |
|
217 |
if (horizExtent instanceof org.opengis.metadata.extent.GeographicBoundingBox) { |
|
218 |
DefaultGeographicBoundingBox bb = new DefaultGeographicBoundingBox( |
|
219 |
((org.opengis.metadata.extent.GeographicBoundingBox) horizExtent).getWestBoundLongitude(), |
|
220 |
((org.opengis.metadata.extent.GeographicBoundingBox) horizExtent).getEastBoundLongitude(), |
|
221 |
((org.opengis.metadata.extent.GeographicBoundingBox) horizExtent).getNorthBoundLatitude(), |
|
222 |
((org.opengis.metadata.extent.GeographicBoundingBox) horizExtent).getSouthBoundLatitude()); |
|
223 |
horizontalExtentList.add(bb); |
|
224 |
} |
|
225 |
} |
|
226 |
|
|
227 |
ArrayList<VerticalExtent> vertExtentList = new ArrayList<VerticalExtent>(); |
|
228 |
for (org.opengis.metadata.extent.VerticalExtent verticalExtent: operation.getDomainOfValidity().getVerticalElements()) { |
|
229 |
DefaultVerticalExtent ve = new DefaultVerticalExtent( |
|
230 |
new DefaultCRSDefinition(verticalExtent.getVerticalCRS()), |
|
231 |
verticalExtent.getMinimumValue(), |
|
232 |
verticalExtent.getMaximumValue() |
|
233 |
); |
|
234 |
vertExtentList.add(ve); |
|
235 |
} |
|
236 |
return new DefaultExtent(desc, horizontalExtentList, vertExtentList); |
|
237 |
} |
|
203 | 238 |
return null; |
204 | 239 |
} |
205 | 240 |
|
... | ... | |
208 | 243 |
if (operation==null) { |
209 | 244 |
return null; |
210 | 245 |
} |
211 |
return operation.getScope() + "\nRemarks: " + operation.getRemarks(); |
|
246 |
StringBuilder desc = new StringBuilder(); |
|
247 |
CoordinateOperation op = GtUtils.getDefiningOperation(operation); |
|
248 |
if (op!=null) { |
|
249 |
fillDescription(op, desc); |
|
250 |
if (desc.length()>0) { |
|
251 |
return desc.toString(); |
|
252 |
} |
|
253 |
} |
|
254 |
fillDescription(operation, desc); |
|
255 |
return desc.toString(); |
|
212 | 256 |
} |
257 |
|
|
258 |
protected StringBuilder fillDescription(CoordinateOperation op, StringBuilder desc) { |
|
259 |
if (op.getName() != null) { |
|
260 |
desc.append("Summary: Concatenated operation"); |
|
261 |
String id = GtUtils.getIdentifier(op); |
|
262 |
if (id!=null) { |
|
263 |
desc.append(" based on ").append(id).append(","); |
|
264 |
} |
|
265 |
desc.append(" transforming "); |
|
266 |
desc.append(op.getName().toString().replace("\u21e8", "=>")).append("\n"); |
|
267 |
} |
|
268 |
if (op.getScope() != null) { |
|
269 |
desc.append("Scope: ").append(op.getScope()); |
|
270 |
} |
|
271 |
if (op.getRemarks() != null) { |
|
272 |
if (desc.length()>0) { |
|
273 |
desc.append("\nRemarks: "); |
|
274 |
} |
|
275 |
else { |
|
276 |
desc.append("Remarks: "); |
|
277 |
} |
|
278 |
desc.append(op.getRemarks()); |
|
279 |
} |
|
280 |
if (op.getDomainOfValidity() != null && |
|
281 |
op.getDomainOfValidity().getDescription() != null) { |
|
282 |
if (desc.length()>0) { |
|
283 |
desc.append("\nDomain: "); |
|
284 |
} |
|
285 |
else { |
|
286 |
desc.append("Domain: "); |
|
287 |
} |
|
288 |
desc.append(op.getDomainOfValidity().getDescription()); |
|
289 |
} |
|
290 |
return desc; |
|
291 |
} |
|
213 | 292 |
|
214 | 293 |
@Override |
215 | 294 |
public TransformationDefinition getInverseDefinition() |
... | ... | |
231 | 310 |
} |
232 | 311 |
|
233 | 312 |
@Override |
234 |
public String toString(Format format) throws UnsupportedFormatException {
|
|
313 |
public String export(Format format) throws UnsupportedFormatException {
|
|
235 | 314 |
if (format==Format.WKT1) { |
236 | 315 |
return toWKT(); |
237 | 316 |
} |
... | ... | |
239 | 318 |
} |
240 | 319 |
|
241 | 320 |
@Override |
242 |
public String toString(Format format, WKTConvention convention, int indentation) throws UnsupportedFormatException {
|
|
321 |
public String export(Format format, WKTConvention convention, int indentation) throws UnsupportedFormatException {
|
|
243 | 322 |
if (format==Format.WKT1) { |
244 | 323 |
Formatter formatter = new Formatter(Symbols.DEFAULT, indentation); |
245 | 324 |
if (convention==WKTConvention.EPSG) { |
... | ... | |
257 | 336 |
public MathTransform getMathTransform() { |
258 | 337 |
return mathTransform; |
259 | 338 |
} |
260 |
|
|
261 |
/* |
|
339 |
|
|
262 | 340 |
@Override |
263 |
public boolean isIdentity() throws TransformationException {
|
|
264 |
return mathTransform.isIdentity();
|
|
265 |
}*/
|
|
341 |
public String toString() {
|
|
342 |
return getName();
|
|
343 |
} |
|
266 | 344 |
|
267 | 345 |
@Override |
268 | 346 |
public boolean equals(Object obj) { |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.catalog.impl/src/main/java/org/gvsig/geotools/proj/catalog/DefaultCRSDefinition.java | ||
---|---|---|
13 | 13 |
import org.gvsig.geotools.proj.catalog.extent.DefaultExtent; |
14 | 14 |
import org.gvsig.geotools.proj.catalog.extent.DefaultGeographicBoundingBox; |
15 | 15 |
import org.gvsig.geotools.proj.catalog.extent.DefaultVerticalExtent; |
16 |
import org.gvsig.geotools.proj.catalog.utils.IdentifiedObjectUtils;
|
|
16 |
import org.gvsig.geotools.proj.catalog.utils.GtUtils;
|
|
17 | 17 |
import org.gvsig.proj.catalog.CRSDefinition; |
18 | 18 |
import org.gvsig.proj.catalog.CRSType; |
19 | 19 |
import org.gvsig.proj.catalog.CoordinateSystemAxis; |
... | ... | |
114 | 114 |
|
115 | 115 |
@Override |
116 | 116 |
public String getIdentifier() { |
117 |
String id = IdentifiedObjectUtils.getIdentifier(origCrs);
|
|
117 |
String id = GtUtils.getIdentifier(origCrs);
|
|
118 | 118 |
if (id!=null) { |
119 | 119 |
return id; |
120 | 120 |
} |
... | ... | |
158 | 158 |
|
159 | 159 |
@Override |
160 | 160 |
public String getAuthorityName() { |
161 |
return IdentifiedObjectUtils.getIdentifier(origCrs.getName().getAuthority().getIdentifiers());
|
|
161 |
return GtUtils.getIdentifier(origCrs.getName().getAuthority().getIdentifiers());
|
|
162 | 162 |
} |
163 | 163 |
|
164 | 164 |
@Override |
... | ... | |
259 | 259 |
if (wkt!=null) { |
260 | 260 |
return wkt; |
261 | 261 |
} |
262 |
return toString(Format.WKT1);
|
|
262 |
return export(Format.WKT1);
|
|
263 | 263 |
} |
264 | 264 |
|
265 | 265 |
@Override |
... | ... | |
269 | 269 |
|
270 | 270 |
|
271 | 271 |
@Override |
272 |
public String toString(Format format) throws UnsupportedOperationException {
|
|
273 |
return toString(format, null, 2);
|
|
272 |
public String export(Format format) throws UnsupportedOperationException {
|
|
273 |
return export(format, null, 2);
|
|
274 | 274 |
} |
275 | 275 |
|
276 | 276 |
@Override |
277 |
public String toString(TextSerialization.Format format, WKTConvention convention, int indentation) throws UnsupportedOperationException {
|
|
277 |
public String export(TextSerialization.Format format, WKTConvention convention, int indentation) throws UnsupportedOperationException {
|
|
278 | 278 |
// FIXME: should we consider this.wkt if it is not null?? |
279 | 279 |
if (format==Format.WKT1) { |
280 | 280 |
Formatter formatter = new Formatter(Symbols.DEFAULT, indentation); |
... | ... | |
385 | 385 |
return origCrs.equals(((DefaultCRSDefinition)obj).getOrigCRS()); |
386 | 386 |
} |
387 | 387 |
if (obj instanceof CRSDefinition) { |
388 |
return toString(Format.WKT1, WKTConvention.EPSG, 0).equals(((CRSDefinition)obj).toString(Format.WKT1, WKTConvention.EPSG, 0));
|
|
388 |
return export(Format.WKT1, WKTConvention.EPSG, 0).equals(((CRSDefinition)obj).export(Format.WKT1, WKTConvention.EPSG, 0));
|
|
389 | 389 |
} |
390 | 390 |
return false; |
391 | 391 |
} |
... | ... | |
413 | 413 |
return equals(definition); |
414 | 414 |
} |
415 | 415 |
} |
416 |
|
|
417 |
@Override |
|
418 |
public int hashCode() { |
|
419 |
return origCrs.hashCode(); |
|
420 |
} |
|
416 | 421 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.catalog.impl/src/main/java/org/gvsig/geotools/proj/catalog/GtCRSCatalogManager.java | ||
---|---|---|
36 | 36 |
import org.gvsig.geotools.proj.catalog.extent.DefaultExtent; |
37 | 37 |
import org.gvsig.geotools.proj.catalog.extent.DefaultGeographicBoundingBox; |
38 | 38 |
import org.gvsig.geotools.proj.catalog.extent.DefaultVerticalExtent; |
39 |
import org.gvsig.geotools.proj.catalog.utils.IdentifiedObjectUtils;
|
|
39 |
import org.gvsig.geotools.proj.catalog.utils.GtUtils;
|
|
40 | 40 |
import org.gvsig.geotools.proj.catalog.utils.WKTUtils; |
41 | 41 |
import org.gvsig.proj.catalog.CRSCatalogManager; |
42 | 42 |
import org.gvsig.proj.catalog.CRSDefinition; |
... | ... | |
340 | 340 |
try { |
341 | 341 |
crs = CRS.parseWKT(def); |
342 | 342 |
if (CRS.getAxisOrder(crs)==AxisOrder.NORTH_EAST) { |
343 |
String id = IdentifiedObjectUtils.getIdentifier(crs);
|
|
343 |
String id = GtUtils.getIdentifier(crs);
|
|
344 | 344 |
if (id != null && id.startsWith("EPSG:")) { //FIXME: could this also work for other authorities such as ESRI? |
345 | 345 |
internalCrs = CRS.decode(id, true); |
346 | 346 |
} |
... | ... | |
492 | 492 |
CoordinateOperationFactory operationFactory = CRS.getCoordinateOperationFactory(false); |
493 | 493 |
Set<CoordinateOperation> ops = operationFactory.findOperations(sourceCRS, targetCRS); |
494 | 494 |
for (CoordinateOperation op: ops) { |
495 |
if (GtUtils.getIdentifier(op) == null) { |
|
496 |
CoordinateOperation defOp = GtUtils.getDefiningOperation(op); |
|
497 |
if (GtUtils.getIdentifier(defOp) == null) { |
|
498 |
/** |
|
499 |
* When Geotools computes the inverse transformation, we loose the identifier, which |
|
500 |
* makes the transformation quite useless for the final users since they can't distinguish |
|
501 |
* it from any other operation. Therefore, we skip operations lacking an identifier, and |
|
502 |
* we'll add them later requesting the inverse operation. It is quite hacky but I can't see |
|
503 |
* a better approach |
|
504 |
*/ |
|
505 |
continue; |
|
506 |
} |
|
507 |
} |
|
495 | 508 |
DefaultTransformationDefinition def = new DefaultTransformationDefinition(op, sourceDef, targetDef); |
496 | 509 |
transforms.add(def); |
497 | 510 |
} |
511 |
|
|
512 |
// now we'll try the inverse transformation |
|
513 |
ops = operationFactory.findOperations(targetCRS, sourceCRS); |
|
514 |
for (CoordinateOperation op: ops) { |
|
515 |
if (GtUtils.getIdentifier(op) == null) { |
|
516 |
CoordinateOperation defOp = GtUtils.getDefiningOperation(op); |
|
517 |
if (GtUtils.getIdentifier(defOp) == null) { |
|
518 |
continue; |
|
519 |
} |
|
520 |
} |
|
521 |
DefaultTransformationDefinition def = new DefaultTransformationDefinition(op, sourceDef, targetDef); |
|
522 |
transforms.add(def); |
|
523 |
} |
|
498 | 524 |
} catch (FactoryException e) { |
499 | 525 |
// FIXME: we should log instead of raising an exception |
500 | 526 |
throw new UnsupportedTransformationException(e); |
... | ... | |
504 | 530 |
|
505 | 531 |
@Override |
506 | 532 |
public List<TransformationDefinition> getCoordinateTransformations(String source, String target) throws UnsupportedTransformationException { |
507 |
ArrayList<TransformationDefinition> transforms = new ArrayList<TransformationDefinition>(); |
|
508 | 533 |
try { |
509 | 534 |
DefaultCRSDefinition sourceDef = getCRSDefinition(source); |
510 | 535 |
DefaultCRSDefinition targetDef = getCRSDefinition(target); |
511 |
CoordinateReferenceSystem sourceCRS = sourceDef.getInternalCRS(); |
|
512 |
CoordinateReferenceSystem targetCRS = targetDef.getInternalCRS(); |
|
513 |
CoordinateOperationFactory operationFactory = CRS.getCoordinateOperationFactory(false); |
|
514 |
Set<CoordinateOperation> ops = operationFactory.findOperations(sourceCRS, targetCRS); |
|
515 |
for (CoordinateOperation op: ops) { |
|
516 |
DefaultTransformationDefinition def = new DefaultTransformationDefinition(op, sourceDef, targetDef); |
|
517 |
transforms.add(def); |
|
518 |
} |
|
519 |
} catch (FactoryException | UnsupportedCoordinateReferenceSystemException e) { |
|
536 |
return getCoordinateTransformations(sourceDef, targetDef); |
|
537 |
} catch (UnsupportedCoordinateReferenceSystemException e) { |
|
520 | 538 |
// FIXME: we should log instead of raising an exception |
521 | 539 |
throw new UnsupportedTransformationException(e); |
522 | 540 |
} |
523 |
return transforms; |
|
524 | 541 |
} |
525 | 542 |
|
526 | 543 |
/** |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.catalog.impl/src/main/java/org/gvsig/geotools/proj/catalog/utils/IdentifiedObjectUtils.java | ||
---|---|---|
1 |
package org.gvsig.geotools.proj.catalog.utils; |
|
2 |
|
|
3 |
import java.util.Collection; |
|
4 |
|
|
5 |
import org.opengis.metadata.Identifier; |
|
6 |
import org.opengis.referencing.IdentifiedObject; |
|
7 |
import org.opengis.referencing.ReferenceIdentifier; |
|
8 |
|
|
9 |
public class IdentifiedObjectUtils { |
|
10 |
|
|
11 |
public static String getIdentifier(IdentifiedObject object) { |
|
12 |
if (object==null) { |
|
13 |
return null; |
|
14 |
} |
|
15 |
for (ReferenceIdentifier id: object.getIdentifiers()) { |
|
16 |
// return the first one we find |
|
17 |
return id.toString(); |
|
18 |
} |
|
19 |
return null; |
|
20 |
} |
|
21 |
|
|
22 |
public static String getIdentifier(Collection<? extends Identifier> identifiers) { |
|
23 |
if (identifiers != null) { |
|
24 |
for (Identifier id: identifiers) { |
|
25 |
// return the first one we find |
|
26 |
return id.getCode(); |
|
27 |
} |
|
28 |
} |
|
29 |
return null; |
|
30 |
} |
|
31 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.catalog.impl/src/main/java/org/gvsig/geotools/proj/catalog/utils/DistanceCalculator.java | ||
---|---|---|
105 | 105 |
| IllegalArgumentException | IllegalStateException |
106 | 106 |
| IncommensurableException | TransformException |
107 | 107 |
| TransformationException e) { |
108 |
throw new DistanceCalculationException(IdentifiedObjectUtils.getIdentifier(crs), e);
|
|
108 |
throw new DistanceCalculationException(GtUtils.getIdentifier(crs), e);
|
|
109 | 109 |
} |
110 |
throw new DistanceCalculationException(IdentifiedObjectUtils.getIdentifier(crs));
|
|
110 |
throw new DistanceCalculationException(GtUtils.getIdentifier(crs));
|
|
111 | 111 |
} |
112 | 112 |
|
113 | 113 |
/** |
... | ... | |
152 | 152 |
try { |
153 | 153 |
return crs.getConversionFromBase().getMathTransform().inverse(); |
154 | 154 |
} catch (NoninvertibleTransformException e) { |
155 |
throw new TransformationException(IdentifiedObjectUtils.getIdentifier(crs), e);
|
|
155 |
throw new TransformationException(GtUtils.getIdentifier(crs), e);
|
|
156 | 156 |
} |
157 | 157 |
} |
158 | 158 |
if (baseCRS instanceof GeneralDerivedCRS && baseCRS!=crs) { |
... | ... | |
160 | 160 |
MathTransform baseTransform = crs.getConversionFromBase().getMathTransform().inverse(); |
161 | 161 |
ConcatenatedTransform.create(baseTransform, getConversionToGeo((GeneralDerivedCRS)baseCRS)); |
162 | 162 |
} catch (NoninvertibleTransformException e) { |
163 |
throw new TransformationException(IdentifiedObjectUtils.getIdentifier(crs), e);
|
|
163 |
throw new TransformationException(GtUtils.getIdentifier(crs), e);
|
|
164 | 164 |
} |
165 | 165 |
} |
166 |
throw new TransformationException(IdentifiedObjectUtils.getIdentifier(crs));
|
|
166 |
throw new TransformationException(GtUtils.getIdentifier(crs));
|
|
167 | 167 |
} |
168 | 168 |
|
169 | 169 |
public static GeographicCRS getBaseGeographicCRS(GeneralDerivedCRS crs) { |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.catalog.impl/src/main/java/org/gvsig/geotools/proj/catalog/utils/GtUtils.java | ||
---|---|---|
1 |
package org.gvsig.geotools.proj.catalog.utils; |
|
2 |
|
|
3 |
import java.util.Collection; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import org.opengis.metadata.Identifier; |
|
7 |
import org.opengis.referencing.IdentifiedObject; |
|
8 |
import org.opengis.referencing.ReferenceIdentifier; |
|
9 |
import org.opengis.referencing.operation.ConcatenatedOperation; |
|
10 |
import org.opengis.referencing.operation.CoordinateOperation; |
|
11 |
import org.opengis.referencing.operation.PassThroughOperation; |
|
12 |
import org.opengis.referencing.operation.Projection; |
|
13 |
import org.opengis.referencing.operation.SingleOperation; |
|
14 |
import org.opengis.referencing.operation.Transformation; |
|
15 |
|
|
16 |
public class GtUtils { |
|
17 |
|
|
18 |
public static String getIdentifier(IdentifiedObject object) { |
|
19 |
if (object==null) { |
|
20 |
return null; |
|
21 |
} |
|
22 |
for (ReferenceIdentifier id: object.getIdentifiers()) { |
|
23 |
// return the first one we find |
|
24 |
return id.toString(); |
|
25 |
} |
|
26 |
return null; |
|
27 |
} |
|
28 |
|
|
29 |
public static String getIdentifier(Collection<? extends Identifier> identifiers) { |
|
30 |
if (identifiers != null) { |
|
31 |
for (Identifier id: identifiers) { |
|
32 |
// return the first one we find |
|
33 |
return id.getCode(); |
|
34 |
} |
|
35 |
} |
|
36 |
return null; |
|
37 |
} |
|
38 |
|
|
39 |
public static CoordinateOperation getDefiningOperation(CoordinateOperation operation) { |
|
40 |
if (operation instanceof ConcatenatedOperation) { |
|
41 |
List<SingleOperation> opList = ((ConcatenatedOperation) operation).getOperations(); |
|
42 |
for (SingleOperation singleOp: opList) { |
|
43 |
if (singleOp instanceof Transformation) { |
|
44 |
return singleOp; |
|
45 |
} |
|
46 |
} |
|
47 |
for (SingleOperation singleOp: opList) { |
|
48 |
if (singleOp instanceof PassThroughOperation) { |
|
49 |
return getDefiningOperation(singleOp); |
|
50 |
} |
|
51 |
} |
|
52 |
for (SingleOperation singleOp: opList) { |
|
53 |
if (singleOp instanceof Projection) { |
|
54 |
return singleOp; |
|
55 |
} |
|
56 |
} |
|
57 |
} |
|
58 |
else if (operation instanceof PassThroughOperation) { |
|
59 |
return getDefiningOperation(((PassThroughOperation)operation).getOperation()); |
|
60 |
} |
|
61 |
return operation; |
|
62 |
} |
|
63 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.main/src/main/java/org/gvsig/geotools/proj/main/TestCtPanel.java | ||
---|---|---|
1 |
package org.gvsig.geotools.proj.main; |
|
2 |
|
|
3 |
|
|
4 |
import java.awt.Color; |
|
5 |
import java.text.ParseException; |
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
import javax.swing.JFrame; |
|
9 |
import javax.swing.SwingUtilities; |
|
10 |
import javax.swing.tree.DefaultTreeCellRenderer; |
|
11 |
|
|
12 |
import org.apache.log4j.ConsoleAppender; |
|
13 |
import org.apache.log4j.Level; |
|
14 |
import org.apache.log4j.PatternLayout; |
|
15 |
import org.gvsig.proj.CoordinateReferenceSystem; |
|
16 |
import org.gvsig.proj.CoordinateTransformation; |
|
17 |
import org.gvsig.proj.catalog.TransformationDefinition; |
|
18 |
import org.gvsig.proj.catalog.exception.CoordinateReferenceSystemException; |
|
19 |
import org.gvsig.proj.swing.CoordinateReferenceSystemSwingLocator; |
|
20 |
import org.gvsig.proj.swing.CoordinateTransformationSelectorComponent; |
|
21 |
import org.gvsig.proj.swing.impl.CtSelectorController; |
|
22 |
import org.gvsig.proj.swing.impl.DefaultCoordinateReferenceSystemSwingManager; |
|
23 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
24 |
|
|
25 |
public class TestCtPanel { |
|
26 |
|
|
27 |
public TestCtPanel() { |
|
28 |
// TODO Auto-generated constructor stub |
|
29 |
} |
|
30 |
|
|
31 |
public static void main(String[] args) { |
|
32 |
ConsoleAppender console = new ConsoleAppender(); //create appender |
|
33 |
//configure the appender |
|
34 |
String PATTERN = "%d [%p|%c|%C{1}] %m%n"; |
|
35 |
console.setLayout(new PatternLayout(PATTERN)); |
|
36 |
console.setThreshold(Level.ALL); |
|
37 |
console.activateOptions(); |
|
38 |
//add appender to any Logger (here is root) |
|
39 |
org.apache.log4j.Logger.getRootLogger().addAppender(console); |
|
40 |
|
|
41 |
DefaultLibrariesInitializer initializer = new DefaultLibrariesInitializer(); |
|
42 |
initializer.fullInitialize(); |
|
43 |
final JFrame frame = new JFrame(); |
|
44 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
45 |
|
|
46 |
try { |
|
47 |
final DefaultCoordinateReferenceSystemSwingManager manager = (DefaultCoordinateReferenceSystemSwingManager) CoordinateReferenceSystemSwingLocator.getSwingManager(); |
|
48 |
final CoordinateTransformation aTrans; |
|
49 |
final CoordinateReferenceSystem crs25831; |
|
50 |
final CoordinateReferenceSystem crs23030; |
|
51 |
final CoordinateReferenceSystem crs4326; |
|
52 |
List<TransformationDefinition> trans = manager.getCatalogManager().getCoordinateTransformations("EPSG:23030", "EPSG:4326"); |
|
53 |
System.out.println(trans.size()); |
|
54 |
if (trans.size()>35) { |
|
55 |
manager.getTransformationHistory().add(trans.get(33)); |
|
56 |
manager.getTransformationHistory().add(trans.get(35)); |
|
57 |
} |
|
58 |
trans = manager.getCatalogManager().getCoordinateTransformations("EPSG:25830", "EPSG:4326"); |
|
59 |
System.out.println(trans.size()); |
|
60 |
TransformationDefinition aTransDef = trans.get(1); |
|
61 |
manager.getTransformationHistory().add(aTransDef); |
|
62 |
aTrans = manager.getCRSManager().getCoordinateTransformation(aTransDef); |
|
63 |
crs25831 = manager.getCRSManager().getCoordinateReferenceSystem( |
|
64 |
manager.getCatalogManager().getCRSDefinition("EPSG:25831")); |
|
65 |
crs23030 = manager.getCRSManager().getCoordinateReferenceSystem( |
|
66 |
manager.getCatalogManager().getCRSDefinition("EPSG:23030")); |
|
67 |
crs4326 = manager.getCRSManager().getCoordinateReferenceSystem( |
|
68 |
manager.getCatalogManager().getCRSDefinition("EPSG:4326")); |
|
69 |
|
|
70 |
SwingUtilities.invokeLater(new Runnable() { |
|
71 |
public void run() { |
|
72 |
CoordinateTransformationSelectorComponent selector = manager.createCoordinateTransformSelectionComponent(); |
|
73 |
selector.setCoordinateTransformation(aTrans); |
|
74 |
//DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) ((CtSelectorController) selector).getTree().getCellRenderer(); |
|
75 |
//Color c = renderer.getBackgroundSelectionColor(); |
|
76 |
//renderer.setBackgroundSelectionColor(Color.BLUE); |
|
77 |
//renderer.setBackground(Color.YELLOW); |
|
78 |
selector.setSourceCoordinateReferenceSystem(crs23030); |
|
79 |
//selector.setTargetCoordinateReferenceSystem(crs4326); |
|
80 |
|
|
81 |
frame.add(selector.asJComponent()); |
|
82 |
frame.setSize(400, 600); |
|
83 |
//frame.pack(); |
|
84 |
frame.setVisible(true); |
|
85 |
} |
|
86 |
}); |
|
87 |
} catch (CoordinateReferenceSystemException | ParseException e) { |
|
88 |
// TODO Auto-generated catch block |
|
89 |
e.printStackTrace(); |
|
90 |
} |
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
} |
|
95 |
|
|
96 |
|
|
97 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.main/src/main/java/org/gvsig/geotools/proj/main/TestCrsPanel.java | ||
---|---|---|
1 | 1 |
package org.gvsig.geotools.proj.main; |
2 | 2 |
|
3 | 3 |
|
4 |
import java.util.List; |
|
5 |
|
|
4 | 6 |
import javax.swing.JFrame; |
5 | 7 |
import javax.swing.SwingUtilities; |
6 | 8 |
|
7 | 9 |
import org.apache.log4j.ConsoleAppender; |
8 | 10 |
import org.apache.log4j.Level; |
9 | 11 |
import org.apache.log4j.PatternLayout; |
12 |
import org.gvsig.proj.catalog.TransformationDefinition; |
|
13 |
import org.gvsig.proj.catalog.exception.CoordinateReferenceSystemException; |
|
14 |
import org.gvsig.proj.catalog.exception.UnsupportedCoordinateReferenceSystemException; |
|
10 | 15 |
import org.gvsig.proj.swing.CoordinateReferenceSystemSelectorComponent; |
11 | 16 |
import org.gvsig.proj.swing.CoordinateReferenceSystemSwingLocator; |
17 |
import org.gvsig.proj.swing.CoordinateTransformationSelectorComponent; |
|
12 | 18 |
import org.gvsig.proj.swing.impl.DefaultCoordinateReferenceSystemSwingManager; |
13 | 19 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
14 | 20 |
|
... | ... | |
17 | 23 |
public TestCrsPanel() { |
18 | 24 |
// TODO Auto-generated constructor stub |
19 | 25 |
} |
20 |
|
|
26 |
|
|
21 | 27 |
public static void main(String[] args) { |
22 | 28 |
ConsoleAppender console = new ConsoleAppender(); //create appender |
23 | 29 |
//configure the appender |
... | ... | |
32 | 38 |
initializer.fullInitialize(); |
33 | 39 |
final JFrame frame = new JFrame(); |
34 | 40 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
41 |
|
|
42 |
try { |
|
35 | 43 |
DefaultCoordinateReferenceSystemSwingManager manager = (DefaultCoordinateReferenceSystemSwingManager) CoordinateReferenceSystemSwingLocator.getSwingManager(); |
44 |
manager.getCoordinateReferenceSystemHistory().add(manager.getCatalogManager().getCRSDefinition("EPSG:3857")); |
|
45 |
manager.getCoordinateReferenceSystemHistory().add(manager.getCatalogManager().getCRSDefinition("EPSG:23030")); |
|
46 |
|
|
47 |
CoordinateReferenceSystemSelectorComponent selector = manager.createCoordinateReferenceSystemSelectionComponent(); |
|
48 |
selector.setCustomGroupLabel("Layer"); |
|
49 |
|
|
50 |
selector.addCustomCRS(manager.getCatalogManager().getCRSDefinition("EPSG:25830")); |
|
51 |
selector.addCustomCRS(manager.getCatalogManager().getCRSDefinition("EPSG:25831")); |
|
36 | 52 |
|
37 |
CoordinateReferenceSystemSelectorComponent selector = manager.createCoordinateReferenceSystemSelectionComponent(); |
|
38 | 53 |
frame.add(selector.asJComponent()); |
39 | 54 |
frame.setSize(400, 600); |
40 | 55 |
//frame.pack(); |
... | ... | |
43 | 58 |
frame.setVisible(true); |
44 | 59 |
} |
45 | 60 |
}); |
46 |
|
|
61 |
} catch (UnsupportedCoordinateReferenceSystemException e) { |
|
62 |
// TODO Auto-generated catch block |
|
63 |
e.printStackTrace(); |
|
64 |
} |
|
47 | 65 |
} |
48 |
|
|
49 | 66 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.lib.impl/src/main/java/org/gvsig/geotools/proj/lib/DefaultTransformation.java | ||
---|---|---|
123 | 123 |
protected DefaultTransformation clone() throws CloneNotSupportedException { |
124 | 124 |
return new DefaultTransformation(this.mathTransform, this.definition, this.source, this.target); |
125 | 125 |
} |
126 |
|
|
127 |
@Override |
|
128 |
public String toString() { |
|
129 |
return getDefinition().toString(); |
|
130 |
} |
|
126 | 131 |
|
127 | 132 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.lib.impl/src/main/java/org/gvsig/geotools/proj/lib/DefaultCRS.java | ||
---|---|---|
99 | 99 |
} |
100 | 100 |
return false; |
101 | 101 |
} |
102 |
|
|
103 |
@Override |
|
104 |
public int hashCode() { |
|
105 |
return getDefinition().hashCode(); |
|
106 |
} |
|
107 |
|
|
108 |
@Override |
|
109 |
public String toString() { |
|
110 |
return getDefinition().toString(); |
|
111 |
} |
|
102 | 112 |
} |
org.gvsig.geotools.proj/trunk/org.gvsig.geotools.proj/org.gvsig.geotools.proj.lib.impl/src/main/java/org/gvsig/geotools/proj/lib/GtCRSManager.java | ||
---|---|---|
67 | 67 |
defaultDef, source, target); |
68 | 68 |
} |
69 | 69 |
try { |
70 |
return getCoordinateTransformation(definition, definition.toString(Format.WKT1));
|
|
70 |
return getCoordinateTransformation(definition, definition.export(Format.WKT1));
|
|
71 | 71 |
} catch (UnsupportedFormatException | UnsupportedOperationException e) { |
72 | 72 |
throw new UnsupportedTransformationException(); |
73 | 73 |
} |
Also available in: Unified diff