public static void main2(String[] args) {
try {
// Prepare Coordinate System and Evelope
CoordinateReferenceSystem crs = DefaultEngineeringCRS.CARTESIAN_2D;
DirectPosition minDp = new DirectPosition2D(crs, 10.0, 10.0);
DirectPosition maxDp = new DirectPosition2D(crs, 1000.0, 1000.0);
Envelope env = new GeneralEnvelope(new GeneralDirectPosition(minDp),
new GeneralDirectPosition(maxDp));
// Lets Generate some known points that will define interpolation
HashMap /*<DirectPosition2D, Float>*/ pointsAndValues = new HashMap();
pointsAndValues.put(new DirectPosition2D(crs, 130, 805), 6.5);
pointsAndValues.put(new DirectPosition2D(crs, 14, 105), 1.5);
pointsAndValues.put(new DirectPosition2D(crs, 45, 78), -9.5);
pointsAndValues.put(new DirectPosition2D(crs, 905, 28), 7.5);
pointsAndValues.put(new DirectPosition2D(crs, 123, 185), 16.5);
pointsAndValues.put(new DirectPosition2D(crs, 104, 215), -21.5);
pointsAndValues.put(new DirectPosition2D(crs, 45, 708), -9.5);
pointsAndValues.put(new DirectPosition2D(crs, 905, 350), 17.5);
pointsAndValues.put(new DirectPosition2D(crs, 905, 850), -45.5);
//now we can construct the Interpolation Object
TPSInterpolation interpolation = new TPSInterpolation(pointsAndValues, 2, 2, env);
// we can get and show coverage
(new GridCoverageFactory()).create("Intepolated Coverage", interpolation.get2DGrid(),
env).show();
// or we can interpolate value in any DirectPosition
System.out.print(interpolation.getValue(new DirectPosition2D(12.34, 15.123)));
/* AbstractInterpolation interpoaltion = new TPSInterpolation(
generatePositionsWithValues(env,15, 5),
env.getLength(0)/500,
env.getLength(1)/500,