package iso.primitive; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; import org.geotools.geometry.iso.FeatGeomFactoryImpl; import org.geotools.geometry.iso.coordinate.CoordinateFactoryImpl; import org.geotools.geometry.iso.primitive.PrimitiveFactoryImpl; import org.geotools.geometry.iso.primitive.RingImpl; import org.geotools.geometry.iso.primitive.SurfaceBoundaryImpl; import org.geotools.geometry.iso.primitive.SurfaceImpl; import org.opengis.spatialschema.geometry.DirectPosition; import org.opengis.spatialschema.geometry.geometry.Triangle; import org.opengis.spatialschema.geometry.primitive.Ring; import org.opengis.spatialschema.geometry.primitive.Surface; import org.opengis.spatialschema.geometry.primitive.SurfacePatch; /** * @author sanjay * */ public class SurfaceTest extends TestCase { public void testMain() { FeatGeomFactoryImpl tGeomFactory = FeatGeomFactoryImpl.getDefault2D(); // Creates by SurfaceBoundary this._testSurface2(tGeomFactory); // Created by Patches this._testSurface1(tGeomFactory); } private List _testTriangle1(FeatGeomFactoryImpl aGeomFactory) { CoordinateFactoryImpl tCoordFactory = aGeomFactory.getCoordinateFactory(); PrimitiveFactoryImpl tPrimFactory = aGeomFactory.getPrimitiveFactory(); ArrayList tDoubleList = new ArrayList(); tDoubleList.add(new double[][]{{0,0},{100,100},{0, 100}}); tDoubleList.add(new double[][]{{0,100},{100,100},{50,200}}); tDoubleList.add(new double[][]{{50,200},{100,100},{150,200}}); ArrayList triangleList = tCoordFactory.createTriangles(tDoubleList); for (int i=0; i < triangleList.size(); i++) { Triangle triangle1 = triangleList.get(i); System.out.println(triangle1); } //System.out.println(triangle1.get.getEnvelope()); //System.out.println(triangle1.getBoundary()); return triangleList; } /** * Create a surface on basis of SurfacePatches (Triangles) * @param aGeomFactory */ private void _testSurface1(FeatGeomFactoryImpl aGeomFactory) { PrimitiveFactoryImpl tPrimFactory = aGeomFactory.getPrimitiveFactory(); List triangleList = this._testTriangle1(aGeomFactory); List surfacePatches1 = (List)triangleList; Surface surface1 = tPrimFactory.createSurface(surfacePatches1); System.out.print("\n******************* SURFACE GENERATED BY SURFACEPATCHES"); this.testSurfaces((SurfaceImpl) surface1); } public Surface _testSurface2(FeatGeomFactoryImpl aGeomFactory) { CoordinateFactoryImpl tCoordFactory = aGeomFactory.getCoordinateFactory(); PrimitiveFactoryImpl tPrimFactory = aGeomFactory.getPrimitiveFactory(); List directPositionList = new ArrayList(); directPositionList.add(tCoordFactory.createDirectPosition(new double[] {20, 10})); directPositionList.add(tCoordFactory.createDirectPosition(new double[] {40, 10})); directPositionList.add(tCoordFactory.createDirectPosition(new double[] {50, 40})); directPositionList.add(tCoordFactory.createDirectPosition(new double[] {30, 50})); directPositionList.add(tCoordFactory.createDirectPosition(new double[] {10, 30})); directPositionList.add(tCoordFactory.createDirectPosition(new double[] {20, 10})); RingImpl exteriorRing = (RingImpl) tPrimFactory.createRingByDirectPositions(directPositionList); List interiors = new ArrayList(); SurfaceBoundaryImpl surfaceBoundary1 = tPrimFactory.createSurfaceBoundary(exteriorRing, interiors ); Surface surface2 = tPrimFactory.createSurface(surfaceBoundary1); System.out.print("\n******************* SURFACE GENERATED BY SURFACEBOUNDARY"); this.testSurfaces((SurfaceImpl) surface2); // ***** clone() SurfaceImpl surface3 = null; try { surface3 = (SurfaceImpl) surface2.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(surface2 != surface3); this.testSurfaces((SurfaceImpl) surface3); // ***** getRepresentativePoint() double[] dp = surface2.getRepresentativePoint().getCoordinates(); assertTrue(dp[0] == 20); assertTrue(dp[1] == 10); return surface2; } private void testSurfaces(SurfaceImpl surface) { try { System.out.print("\nSurface: " + surface); } catch (NullPointerException e) { } System.out.print("\ngetBoundary: " + surface.getBoundary()); System.out.print("\ngetEnvelope: " + surface.getEnvelope()); System.out.print("\ngetCoordinateDimension: " + surface.getCoordinateDimension()); System.out.print("\ngetDimension: " + surface.getDimension(null)); assertTrue(surface.isCycle() == false); } }