forked from orbisgis/cts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ticket orbisgis#96 add Extent to CRS
- Loading branch information
Showing
9 changed files
with
290 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/org/cts/op/CheckInExtentCoordinateOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.cts.op; | ||
|
||
import org.cts.Identifier; | ||
import org.cts.IllegalCoordinateException; | ||
import org.cts.crs.CoordinateReferenceSystem; | ||
import org.cts.cs.Extent; | ||
|
||
import java.util.Arrays; | ||
|
||
|
||
public class CheckInExtentCoordinateOperation extends AbstractCoordinateOperation { | ||
|
||
Extent extent; | ||
|
||
public CheckInExtentCoordinateOperation(CoordinateReferenceSystem crs) { | ||
super(new Identifier(CoordinateOperation.class, "extent of '" + crs.getName() + "'")); | ||
this.extent = crs; | ||
} | ||
|
||
/** | ||
* Check if coord lies in extent. If it is inside, coord is returned as is, | ||
* else, a IllegalCoordinateException is thrown. | ||
* | ||
* @param coord coordinate to check | ||
* @return the same coordinates array | ||
* @throws IllegalCoordinateException if <code>coord</code> does not lie in extent. | ||
* @throws org.cts.op.CoordinateOperationException if this operation | ||
* failed during the transformation process. | ||
*/ | ||
public double[] transform(double[] coord) throws IllegalCoordinateException { | ||
if (extent == null || extent.isInside(coord)) return coord; | ||
throw new IllegalCoordinateException("Coord " + Arrays.toString(coord) + " is not within " + getName()); | ||
} | ||
|
||
/** | ||
* Return the inverse CoordinateOperation, or throw a | ||
* NonInvertibleOperationException. If op.inverse() is not null, | ||
* <pre> | ||
* op.inverse().transform(op.transform(point)); | ||
* </pre> should let point unchanged. | ||
*/ | ||
public CoordinateOperation inverse() { | ||
return this; | ||
} | ||
|
||
///** | ||
// * Returns the maximum precision | ||
// */ | ||
//public double getPrecision() { | ||
// return 1E-9; | ||
//} | ||
|
||
///** | ||
// * @return true if this operation does not change coordinates. | ||
// */ | ||
//public boolean isIdentity() { | ||
// return true; | ||
//} | ||
|
||
/** | ||
* Returns whether coord is consistent with source and target CRS. | ||
*/ | ||
//public boolean isInside(double[] coord) { | ||
// if (extent == null || extent.isInside(coord)) return true; | ||
// throw new IllegalCoordinateException("Coordinates " + coord + " does not lie in extent"); | ||
//} | ||
} |
Oops, something went wrong.