Package org.geotools.geometry.iso

Examples of org.geotools.geometry.iso.PositionFactoryImpl


 
  private void _testPrimitiveObjects2D(PicoContainer c) {
   
    PrimitiveFactoryImpl pf = (PrimitiveFactoryImpl) c.getComponentInstanceOfType(PrimitiveFactory.class);
    GeometryFactory cf = (GeometryFactoryImpl)c.getComponentInstanceOfType(GeometryFactory.class);
    PositionFactoryImpl posf = (PositionFactoryImpl) c.getComponentInstanceOfType(PositionFactory.class);
    //PrimitiveFactory pf = aFactory.getPrimitiveFactory();
    //GeometryFactory cf = aFactory.getGeometryFactoryImpl();
   
    // public PrimitiveImpl createPrimitive(Envelope envelope);
    // indirect: public SurfaceImpl createSurface(SurfaceBoundary boundary);
    // indirect: public SurfaceImpl createSurfaceByDirectPositions(List<DirectPosition> positions);
    // indirect: public SurfaceBoundaryImpl createSurfaceBoundary(Ring exterior, List<Ring> interiors);
    // indirect: public Ring createRingByDirectPositions(List<DirectPosition> directPositions);
    DirectPosition dp1 = posf.createDirectPosition(new double[]{10, 10});
    DirectPosition dp2 = posf.createDirectPosition(new double[]{70, 30});
    Envelope env1 = cf.createEnvelope(dp1, dp2);
    PrimitiveImpl prim1 = (PrimitiveImpl) pf.createPrimitive(env1);
    assertNotNull(prim1);
   
  }
View Full Code Here


 
  private void _testPrimitiveObjects2o5D(PicoContainer c) {
   
    PrimitiveFactoryImpl pf = (PrimitiveFactoryImpl) c.getComponentInstanceOfType(PrimitiveFactory.class);
    GeometryFactory cf = (GeometryFactoryImpl)c.getComponentInstanceOfType(GeometryFactory.class);
    PositionFactoryImpl posf = (PositionFactoryImpl) c.getComponentInstanceOfType(PositionFactory.class);
    //PrimitiveFactory pf = aFactory.getPrimitiveFactory();
    //GeometryFactory cf = aFactory.getGeometryFactoryImpl();
   
    // public PrimitiveImpl createPrimitive(Envelope envelope);
    // indirect: public SurfaceImpl createSurface(SurfaceBoundary boundary);
View Full Code Here

    return container;   
  }
 
  private void _testCompositePoint(PicoContainer c) {
   
    PositionFactoryImpl positionFactory = (PositionFactoryImpl) c.getComponentInstanceOfType(PositionFactory.class);
    ComplexFactoryImpl complf = (ComplexFactoryImpl) c.getComponentInstanceOfType(ComplexFactory.class);
     
    // testcreateCompositeCurve()
    PointImpl p1 = new PointImpl( positionFactory.createDirectPosition(new double[]{50, 20}) );
    PointImpl p2 = new PointImpl( positionFactory.createDirectPosition(new double[]{70, 80}) );
   
    CompositePoint comppoint1 = complf.createCompositePoint(p1);
    CompositePoint comppoint2 = complf.createCompositePoint(p2);
   
    assertNotNull(comppoint1);
View Full Code Here

  }
 
  protected void createPointAndTest(PicoContainer c, double[] ords) {
   
    // create point and position factories from pico container
    PositionFactoryImpl positionFactory = (PositionFactoryImpl) c.getComponentInstanceOfType( PositionFactory.class );
    PrimitiveFactoryImpl primitiveFactory = (PrimitiveFactoryImpl) c.getComponentInstanceOfType( PrimitiveFactory.class );
    assertSame( positionFactory.getCoordinateReferenceSystem(), primitiveFactory.getCoordinateReferenceSystem() );
    assertNotNull(positionFactory);
    assertNotNull(primitiveFactory);
   
    // create position and point
    DirectPosition here = positionFactory.createDirectPosition(ords);
    Point point = primitiveFactory.createPoint(here);
    assertNotNull(here.getCoordinateReferenceSystem());
    assertNotNull(point.getCoordinateReferenceSystem());
    assertEquals(here.getCoordinateReferenceSystem(), point.getCoordinateReferenceSystem());
    assertEquals(here, point.getDirectPosition());
View Full Code Here

        builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);               
    }
    /** We need to create a large surface with 7000 points */
    public void testLargeSurfaceFactory(){
        DefaultGeographicCRS crs = DefaultGeographicCRS.WGS84;
        PositionFactory postitionFactory = new PositionFactoryImpl( crs );
        PrimitiveFactory primitiveFactory = new PrimitiveFactoryImpl( crs, postitionFactory );
        GeometryFactory geometryFactory = new GeometryFactoryImpl( crs, postitionFactory );
       
        int NUMBER = 100000;
         double delta = 360.0 / (double) NUMBER;
         PointArray points = postitionFactory.createPointArray();
         for( double angle = 0.0; angle < 360.0; angle += delta ){
             double ordinates[] = new double[]{
                     Math.sin( Math.toRadians(angle) ),
                     Math.cos( Math.toRadians(angle) )
             };
             DirectPosition point = postitionFactory.createDirectPosition( ordinates );
             points.add( point );
         }
         List<OrientableCurve> curves = new ArrayList<OrientableCurve>();       
         // A curve will be created
         // - The curve will be set as parent curves for the Curve segments
View Full Code Here

    return container;   
  }
 
  private void _testCompositeCurve(PicoContainer c) {
   
    PositionFactoryImpl positionFactory = (PositionFactoryImpl) c.getComponentInstanceOfType(PositionFactory.class);
    ComplexFactoryImpl complf = (ComplexFactoryImpl) c.getComponentInstanceOfType(ComplexFactory.class);
    PrimitiveFactoryImpl pf = (PrimitiveFactoryImpl) c.getComponentInstanceOfType(PrimitiveFactory.class);
    GeometryFactoryImpl geomFact = (GeometryFactoryImpl) c.getComponentInstanceOfType(GeometryFactory.class);
     
    // testcreateCompositeCurve()
    ArrayList<Position> line1 = new ArrayList<Position>();
    line1.add(new PositionImpl(positionFactory.createDirectPosition(new double[]{50, 20})));
    line1.add(new PositionImpl(positionFactory.createDirectPosition(new double[]{30, 30})));
    line1.add(new PositionImpl(positionFactory.createDirectPosition(new double[]{20, 50})));
    line1.add(new PositionImpl(positionFactory.createDirectPosition(new double[]{20, 70})));

    ArrayList<Position> line2 = new ArrayList<Position>();
    line2.add(new PositionImpl(positionFactory.createDirectPosition(new double[]{20, 70})));
    line2.add(new PositionImpl(positionFactory.createDirectPosition(new double[]{40, 80})));
    line2.add(new PositionImpl(positionFactory.createDirectPosition(new double[]{70, 80})));

    ArrayList<Position> line3 = new ArrayList<Position>();
    line3.add(new PositionImpl(positionFactory.createDirectPosition(new double[]{70, 80})));
    line3.add(new PositionImpl(positionFactory.createDirectPosition(new double[]{90, 70})));
    line3.add(new PositionImpl(positionFactory.createDirectPosition(new double[]{100, 60})));
    line3.add(new PositionImpl(positionFactory.createDirectPosition(new double[]{100, 40})));

    ArrayList<Position> line4 = new ArrayList<Position>();
    line4.add(new PositionImpl(positionFactory.createDirectPosition(new double[]{100, 40})));
    line4.add(new PositionImpl(positionFactory.createDirectPosition(new double[]{80, 30})));
    line4.add(new PositionImpl(positionFactory.createDirectPosition(new double[]{50, 20})));
    ArrayList<CurveSegment> tLineList1 = new ArrayList<CurveSegment>();
    tLineList1.add(geomFact.createLineString(line1));
    tLineList1.add(geomFact.createLineString(line2));

    ArrayList<CurveSegment> tLineList2 = new ArrayList<CurveSegment>();
View Full Code Here

  }
 
  private void _testLineString1(PicoContainer c) {
   
    GeometryFactoryImpl tGeomFactory = (GeometryFactoryImpl) c.getComponentInstanceOfType(GeometryFactory.class);
    PositionFactoryImpl tPosFactory = (PositionFactoryImpl) c.getComponentInstanceOfType(PositionFactory.class);
    PrimitiveFactoryImpl tPrimFactory = (PrimitiveFactoryImpl) c.getComponentInstanceOfType(PrimitiveFactory.class);
   
    PositionImpl p1 = new PositionImpl(tPosFactory.createDirectPosition(new double[]{-500}));
    PositionImpl p2 = new PositionImpl(tPosFactory.createDirectPosition(new double[]{-3030}));
    PositionImpl p3 = new PositionImpl(tPosFactory.createDirectPosition(new double[]{050}));
    PositionImpl p4 = new PositionImpl(tPosFactory.createDirectPosition(new double[]{3030}));
    PositionImpl p5 = new PositionImpl(tPosFactory.createDirectPosition(new double[]{500}));

    LineStringImpl line1 = null;
   
    /* Testing constructor of LineString with Array with size of 0 */
   
    ////System.out.println("\n***** TEST: Constructors");
    //PositionImpl arrayOfPoints[] = new PositionImpl[0];
    ArrayList<Position> positionList = new ArrayList<Position>();
    try {
      line1 = tGeomFactory.createLineString(positionList);
    } catch (IllegalArgumentException e) {
      //System.out.println("LineStringImpl - Number of Positions in array: 0 - Not accepted");
    }
    assertEquals(line1,null);

    /* Testing constructor of LineString with Array with size of 1 */

    positionList.add(p1);
    try {
      line1 = tGeomFactory.createLineString(positionList);
    } catch (IllegalArgumentException e) {
      //System.outprintln("LineStringImpl - Number of Positions in array: 1 - Not accepted");
    }
    assertEquals(line1 , null);

    /* Testing constructor of LineString with Array with size of 2 */

    positionList.add(p2);
    try {
      line1 = tGeomFactory.createLineString(positionList);
      //System.outprintln("LineStringImpl - Number of Positions in array: 2 - accepted");
    } catch (IllegalArgumentException e) {
      //System.outprintln("LineStringImpl - Number of Positions in array: 2 - Not accepted");
    }
    assertNotNull(line1);
   
    /* Testing constructor of LineString with Array with size of 5 */

    positionList.add(p3);
    positionList.add(p4);
    positionList.add(p5);
    try {
      line1 = tGeomFactory.createLineString(positionList);
      //System.outprintln("LineStringImpl - Number of Positions in array: 5 - accepted");
      //System.outprintln("\n" + line1);

    } catch (IllegalArgumentException e) {
      //System.outprintln("\nLineStringImpl - Number of Positions in array: 5 - Not accepted");
    }
    assertNotNull(line1);

    // ***** getEnvelope()
    //System.outprintln("\n***** TEST: .envelope()");
    //System.outprintln("Envelope of the LineString is " +  line1.getEnvelope());

    // ***** getStartPoint();
    //System.outprintln("\n***** TEST: .startPoint()");
    //System.outprintln("StartPoint: " + line1.getStartPoint());
    assertEquals(line1.getStartPoint().getOrdinate(0) , -50.0);
    assertEquals(line1.getStartPoint().getOrdinate(1) , 0.0);

    // ***** getEndPoint();
    //System.outprintln("\n***** TEST: .endPoint()");
    //System.outprintln("EndPoint: " + line1.getEndPoint());
    assertEquals(line1.getEndPoint().getOrdinate(0) , 50.0);
    assertEquals(line1.getEndPoint().getOrdinate(1) , 0.0);
   
    // Set curve for further LineString tests
    ArrayList<CurveSegment> tLineList = new ArrayList<CurveSegment>();
    tLineList.add(line1);
   
    CurveImpl curve1 = tPrimFactory.createCurve(tLineList);
    line1.setCurve(curve1);
   
    // ***** length()
    //System.outprintln("\n***** TEST: .length()");
    //System.outprintln("Length of LineString is " + line1.length());
    assertEquals(14422, Math.round(line1.length() * 100));

    // ***** getStartParam();
    //System.outprintln("\n***** TEST: .startParam()");
    //System.outprintln("StartParam: " + line1.getStartParam());
    assertEquals(line1.getStartParam() , 0.0);

    // ***** getEndParam();
    //System.outprintln("\n***** TEST: .endParam()");
    //System.outprintln("EndParam: " + line1.getEndParam());
    assertEquals(14422, Math.round(line1.getEndParam() * 100));

    // ***** getStartConstructiveParam();
    //System.outprintln("\n***** TEST: .startConstrParam()");
    //System.outprintln("ConstrStartParam: " + line1.getStartConstructiveParam());
    assertEquals(line1.getStartConstructiveParam() , 0.0);
   
    // ***** getEndConstructiveParam();
    //System.outprintln("\n***** TEST: .endConstrParam()");
    //System.outprintln("ConstrEndParam: " + line1.getEndConstructiveParam());
    assertEquals(line1.getEndConstructiveParam() , 1.0);

   
   
    // Receive LineSegments from LineString
    List<LineSegment> segments = line1.asLineSegments();
    assertEquals(segments.size() , 4);

    LineSegment seg1 = segments.get(0);
    LineSegment seg2 = segments.get(1);
    LineSegment seg3 = segments.get(2);
    LineSegment seg4 = segments.get(3);

    //System.outprintln("LineSegment: " + seg1); 
    //System.outprintln("LineSegment: " + seg2); 

    // ***** LineSegment.getStartParam()
    //System.outprintln(seg1.getStartParam());
    assertEquals(seg1.getStartParam() , 0.0);
   
    // ***** LineSegment.getEndParam()
    //System.outprintln(seg1.getEndParam());
    assertEquals( 36, Math.round(seg1.getEndParam()) );

    //System.outprintln(seg2.getStartParam());
    assertEquals( 36, Math.round(seg2.getStartParam()) );
   
    //System.outprintln(seg2.getEndParam());
    assertEquals( 72, Math.round(seg2.getEndParam()) );
   
    // ***** LineSegment.getStartConstructiveParam()
    // ***** LineSegment.getEndConstructiveParam()
    //System.outprintln(seg1.getStartConstructiveParam());
    assertEquals(seg1.getStartConstructiveParam() , 0.0);
    //System.outprintln(seg1.getEndConstructiveParam());
    assertEquals(seg1.getEndConstructiveParam() , 0.25);
    assertEquals(segments.get(1).getStartConstructiveParam() , 0.25);
    assertEquals(segments.get(1).getEndConstructiveParam() , 0.50);
    assertEquals(segments.get(2).getStartConstructiveParam() , 0.50);
    assertEquals(segments.get(2).getEndConstructiveParam() , 0.75);
    assertEquals(segments.get(3).getStartConstructiveParam() , 0.75);
    assertEquals(segments.get(3).getEndConstructiveParam() , 1.0);


    // ***** LineSegment.forParam(double)
    // Parameter for forParam() is 0.0 (startparam)
    DirectPosition resultPos = seg1.forParam(0.0);
    //System.outprintln(resultPos);
    assertEquals(resultPos.getOrdinate(0) , -50.0);
    assertEquals(resultPos.getOrdinate(1) , 0.0);

    // Parameter for forParam() is endparam
    resultPos = seg1.forParam(seg1.getEndParam());
    //System.outprintln(resultPos);
    assertEquals(resultPos.getOrdinate(0) , -30.0);
    assertEquals(resultPos.getOrdinate(1) , 30.0);

    // Parameter for startParam out of param range
    resultPos = null;
    try {
      resultPos = seg1.forParam(180);
    } catch(IllegalArgumentException e) {
      // Shall throw exception
    }
    //System.outprintln(resultPos);
    assertEquals(resultPos , null);

    resultPos = seg1.forParam(30);
    //System.outprintln(resultPos);
   
    // ***** LineSegment.getControlPoints()
    assertEquals(seg1.getControlPoints().size() , 2);
   
    // ***** LineSegment.asLineSegments()
    assertEquals(seg2.asLineSegments().size() , 1);
   
    // ***** forParam(double distance)
    double[] dp = line1.forParam(0).getCoordinate();
    assertEquals( -50.0, dp[0] );
    assertEquals( 0.0, dp[1]);
   
    dp = line1.forParam(line1.length()).getCoordinate();
    assertEquals(50.0, dp[0]);
    assertEquals(0.0, dp[1]);
   
    dp = line1.forParam(seg1.getEndParam()).getCoordinate();
    assertEquals(-30.0, dp[0]);
    assertEquals(30.0, dp[1]);

    dp = line1.forParam(50).getCoordinate();
    ////System.outprintln("forParam: " + dp[0] + "," + dp[1]);
    assertEquals(Math.round(dp[0]*1000) , -18397);
    assertEquals(Math.round(dp[1]*1000) , 37735);

    // ***** forConstructiveParam(double distance)
    dp = line1.forConstructiveParam(0.0).getCoordinate();
        assertEquals(-50.0, dp[0] );
        assertEquals(0.0, dp[1]);

    dp = line1.forConstructiveParam(1.0).getCoordinate();
        assertEquals(50.0, dp[0]);
        assertEquals(0.0, dp[1]);
   
    dp = line1.forConstructiveParam(50 / line1.length()).getCoordinate();
        assertEquals(Math.round(dp[0]*1000) , -18397);
        assertEquals(Math.round(dp[1]*1000) , 37735);

    // ***** getTangent(double distance)
    dp = line1.getTangent(0);
    ////System.outprintln("tangent: " + dp[0] + "," + dp[1]);
        assertEquals(Math.round(dp[0]*1000) , -49445);
        assertEquals(Math.round(dp[1]*1000) , 832);

    dp = line1.getTangent(40);
        assertEquals(Math.round(dp[0]*100) , -2589);
        assertEquals(Math.round(dp[1]*100) , 3274);

    dp = line1.getTangent(line1.getEndParam());
    //System.outprintln("tangent: " + dp[0] + "," + dp[1]);
        assertEquals(Math.round(dp[0]*100) , 5055);
        assertEquals(Math.round(dp[1]*100) , -83);
   
    // ***** merge(LineString)
    PositionImpl p6 = new PositionImpl(tPosFactory.createDirectPosition(new double[]{8040}));
    PositionImpl p7 = new PositionImpl(tPosFactory.createDirectPosition(new double[]{13060}));
    ArrayList<Position> positionList2 = new ArrayList<Position>();
    positionList2.add(p5);
    positionList2.add(p6);
    positionList2.add(p7);
    LineStringImpl line2 = tGeomFactory.createLineString(positionList2);
View Full Code Here

 
  public void testBoundaryEquals() {
   
    CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
    PicoContainer container = container( crs ); // normal 2D
    PositionFactoryImpl pf = (PositionFactoryImpl ) container.getComponentInstanceOfType( PositionFactory.class );
    PrimitiveFactoryImpl prf = (PrimitiveFactoryImpl) container.getComponentInstanceOfType( PrimitiveFactory.class );
   
    // create surfaceboundary object
   
    // build exterior ring
    DirectPosition one = pf.createDirectPosition(new double[]{280,560});
    DirectPosition two = pf.createDirectPosition(new double[]{60,180});
    DirectPosition three = pf.createDirectPosition(new double[]{720,80});
    LineSegment edge1 = new LineSegmentImpl( one, two, 0.0 );
    LineSegment edge2 = new LineSegmentImpl( two, three, 0.0 );
    LineSegment edge3 = new LineSegmentImpl( three, one, 0.0 );
   
    List<OrientableCurve> edges = new ArrayList<OrientableCurve>();
    edges.add( new CurveImpl( edge1 ));
    edges.add( new CurveImpl( edge2 ));
    edges.add( new CurveImpl( edge3 ));
    Ring exterior = new RingImpl( edges );
   
    // build interior ring
    DirectPosition one2 = pf.createDirectPosition(new double[]{420,360});
    DirectPosition two2 = pf.createDirectPosition(new double[]{200,360});
    DirectPosition three2 = pf.createDirectPosition(new double[]{320,180});
    LineSegment edge1_1 = new LineSegmentImpl( one2, two2, 0.0 );
    LineSegment edge2_1 = new LineSegmentImpl( two2, three2, 0.0 );
    LineSegment edge3_1 = new LineSegmentImpl( three2, one2, 0.0 );
   
    edges = new ArrayList<OrientableCurve>();
View Full Code Here

 
  public void testMultiSurface() {
   
    CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
    PicoContainer container = container( crs ); // normal 2D
    PositionFactoryImpl pf = (PositionFactoryImpl ) container.getComponentInstanceOfType( PositionFactory.class );
    PrimitiveFactoryImpl primf = (PrimitiveFactoryImpl ) container.getComponentInstanceOfType( PrimitiveFactory.class );
    AggregateFactoryImpl agf = (AggregateFactoryImpl) container.getComponentInstanceOfType( AggregateFactory.class );
   
    List<DirectPosition> directPositionList = new ArrayList<DirectPosition>();
    directPositionList.add(pf.createDirectPosition(new double[] {20, 10}));
    directPositionList.add(pf.createDirectPosition(new double[] {40, 10}));
    directPositionList.add(pf.createDirectPosition(new double[] {50, 40}));
    directPositionList.add(pf.createDirectPosition(new double[] {30, 50}));
    directPositionList.add(pf.createDirectPosition(new double[] {10, 30}));
    directPositionList.add(pf.createDirectPosition(new double[] {20, 10}));

    Ring exteriorRing = primf.createRingByDirectPositions(directPositionList);
    List<Ring> interiors = new ArrayList<Ring>();
   
    SurfaceBoundaryImpl surfaceBoundary1 = primf.createSurfaceBoundary(exteriorRing, interiors );
View Full Code Here

 
  public void testGoodPoint() throws Exception {
    CoordinateReferenceSystem crs = CRS.decode( "EPSG:4326");   
    assertNotNull( crs );

    PositionFactory positionFactory = new PositionFactoryImpl(crs, new PrecisionModel());
    PrimitiveFactory primitiveFactory = new PrimitiveFactoryImpl(crs, positionFactory); // null;
   
    assertEquals( crs, primitiveFactory.getCoordinateReferenceSystem() );
   
    Point point = primitiveFactory.createPoint( new double[]{1,1} );
View Full Code Here

TOP

Related Classes of org.geotools.geometry.iso.PositionFactoryImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.