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/GtCRSCatalogManager.java
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 |
/** |
Also available in: Unified diff