Package org.geotools.geometry.iso.primitive

Examples of org.geotools.geometry.iso.primitive.PrimitiveFactoryImpl


  }
 
  public void testCurveEquals(){
    CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
    PicoContainer container = container( crs ); // normal 2D
    PrimitiveFactoryImpl factory = (PrimitiveFactoryImpl) container.getComponentInstanceOfType( PrimitiveFactoryImpl.class );
    PositionFactory positionFactory = (PositionFactory ) container.getComponentInstanceOfType( PositionFactory.class );
   
    DirectPosition positionA = positionFactory.createDirectPosition(new double[]{10, 10});
    DirectPosition positionB = positionFactory.createDirectPosition(new double[]{70, 30});
   
View Full Code Here


  }
 
  private void _testCurve(GeometryBuilder builder) {
   
    GeometryFactoryImpl tCoordFactory = (GeometryFactoryImpl) builder.getGeometryFactory();
    PrimitiveFactoryImpl tPrimFactory = (PrimitiveFactoryImpl) builder.getPrimitiveFactory();
   
    PositionImpl p1 = new PositionImpl(tCoordFactory.createDirectPosition(new double[]{-500}));
    PositionImpl p2 = new PositionImpl(tCoordFactory.createDirectPosition(new double[]{-3030}));
    PositionImpl p3 = new PositionImpl(tCoordFactory.createDirectPosition(new double[]{050}));
    PositionImpl p4 = new PositionImpl(tCoordFactory.createDirectPosition(new double[]{3030}));
    PositionImpl p5 = new PositionImpl(tCoordFactory.createDirectPosition(new double[]{500}));

    LineStringImpl line1 = null;
   
    ArrayList<Position> positionList = new ArrayList<Position>();
    positionList .add(p1);
    positionList.add(p2);
    positionList.add(p3);
    positionList.add(p4);
    positionList.add(p5);
    line1 = tCoordFactory.createLineString(positionList);

    /* Set parent curve for LineString */
    ArrayList<CurveSegment> tLineList = new ArrayList<CurveSegment>();
    tLineList.add(line1);

    // PrimitiveFactory.createCurve(List<CurveSegment>)
    CurveImpl curve1 = tPrimFactory.createCurve(tLineList);
    //System.out.println("\nCurve1: " + curve1);
   
    assertTrue(curve1.isCycle() == false);
   
    // Set curve for further LineString tests
    line1.setCurve(curve1);

    //System.out.println("\n*** TEST: Curve\n" + curve1);
   
    // ***** getStartPoint()
    //System.out.println("\n*** TEST: .getStartPoint()\n" + curve1.getStartPoint());
    assertTrue(curve1.getStartPoint().getOrdinate(0) == -50);
    assertTrue(curve1.getStartPoint().getOrdinate(1) == 0);
   
    // ***** getEndPoint()
    //System.out.println("\n*** TEST: .getEndPoint()\n" + curve1.getEndPoint());
    assertTrue(curve1.getEndPoint().getOrdinate(0) == 50);
    assertTrue(curve1.getEndPoint().getOrdinate(1) == 0);

    // ***** getStartParam()
    //System.out.println("\n*** TEST: .getStartParam()\n" + curve1.getStartParam());
    assertTrue(curve1.getStartParam() == 0.0);

    // ***** getEndParam()
    //System.out.println("\n*** TEST: .getEndParam()\n" + curve1.getEndParam());
    assertTrue(Math.round(line1.getEndParam()) == 144.0);

    // ***** getStartConstructiveParam()
    //System.out.println("\n*** TEST: .getStartConstructiveParam()\n" + curve1.getStartConstructiveParam());
    assertTrue(curve1.getStartConstructiveParam() == 0.0);

    // ***** getEndConstructiveParam()
    //System.out.println("\n*** TEST: .getEndConstructiveParam()\n" + curve1.getEndConstructiveParam());
    assertTrue(curve1.getEndConstructiveParam() == 1.0);

    // ***** getBoundary()
    //System.out.println("\n*** TEST: .getBoundary()\n" + curve1.getBoundary());
    CurveBoundary cb = curve1.getBoundary();
    assertTrue(cb != null);
    double[] dp = cb.getStartPoint().getDirectPosition().getCoordinate();
    assertTrue(dp[0] == -50);
    assertTrue(dp[1] == 0);
    dp = cb.getEndPoint().getDirectPosition().getCoordinate();
    assertTrue(dp[0] == 50);
    assertTrue(dp[1] == 0);
   
    // ***** getEnvelope()
    //System.out.println("\n*** TEST: .getEnvelope()\n" + curve1.getEnvelope());
    assertTrue(curve1.getEnvelope() != null);
    dp = curve1.getEnvelope().getLowerCorner().getCoordinate();
    assertTrue(dp[0] == -50);
    assertTrue(dp[1] == 0);
    dp = curve1.getEnvelope().getUpperCorner().getCoordinate();
    assertTrue(dp[0] == 50);
    assertTrue(dp[1] == 50);
   
    // ***** forParam(double distance) : DirectPosition
    dp = curve1.forParam(0).getCoordinate();
    assertTrue(dp[0] == -50);
    assertTrue(dp[1] == 0.0);
   
    dp = curve1.forParam(curve1.length()).getCoordinate();
    assertTrue(dp[0] == 50);
    assertTrue(dp[1] == 0.0);
   
    dp = curve1.forParam(50).getCoordinate();
    ////System.out.println("forParam: " + dp[0] + "," + dp[1]);
    assertTrue(Math.round(dp[0]*1000) == -18397);
    assertTrue(Math.round(dp[1]*1000) == 37735);

    // ***** forConstructiveParam(double distance)
    dp = curve1.forConstructiveParam(0.0).getCoordinate();
    assertTrue(dp[0] == -50);
    assertTrue(dp[1] == 0.0);

    dp = curve1.forConstructiveParam(1.0).getCoordinate();
    assertTrue(dp[0] == 50);
    assertTrue(dp[1] == 0.0);
   
    dp = curve1.forConstructiveParam(50 / curve1.length()).getCoordinate();
    assertTrue(Math.round(dp[0]*1000) == -18397);
    assertTrue(Math.round(dp[1]*1000) == 37735);
   
    // ***** getTangent(double distance)
    dp = curve1.getTangent(0);
    ////System.out.println("tangent: " + dp[0] + "," + dp[1]);
    assertTrue(Math.round(dp[0]*1000) == -49445);
    assertTrue(Math.round(dp[1]*1000) == 832);

    dp = curve1.getTangent(40);
    assertTrue(Math.round(dp[0]*100) == -2589);
    assertTrue(Math.round(dp[1]*100) == 3274);

    dp = curve1.getTangent(curve1.getEndParam());
    //System.out.println("tangent: " + dp[0] + "," + dp[1]);
    assertTrue(Math.round(dp[0]*100) == 5055);
    assertTrue(Math.round(dp[1]*100) == -83);
   
    // ***** getRepresentativePoint()
    dp = curve1.getRepresentativePoint().getCoordinate();
    ////System.out.print("REPRER" + dp);
    assertTrue(dp[0] == 0);
    assertTrue(dp[1] == 50);
   
   
    // ***** Curve.Merge(Curve)
   
    DirectPosition p6 = tCoordFactory.createDirectPosition(new double[]{8020});
    DirectPosition p7 = tCoordFactory.createDirectPosition(new double[]{13060});
   
    List<DirectPosition> directPositions = new ArrayList<DirectPosition>();
   
    directPositions.add(p5.getDirectPosition());
    directPositions.add(p6);
    directPositions.add(p7);
    CurveImpl curve2 = (CurveImpl) tPrimFactory.createCurveByDirectPositions(directPositions);
   
    CurveImpl curve3 = curve1.merge(curve2);
    //System.out.println("Curve1: " + curve1);
    //System.out.println("Curve2: " + curve2);
    //System.out.println("Merge: " + curve3);
    // Lists of line1 and line2 are not modified
    assertTrue(curve1.asDirectPositions().size() == 5);
    assertTrue(curve2.asDirectPositions().size() == 3);
    // New LineString has combined positions
    assertTrue(curve3.asDirectPositions().size() == 7);

    curve3 = curve2.merge(curve1);
    //System.out.println("Curve1: " + curve1);
    //System.out.println("Curve2: " + curve2);
    //System.out.println("Merge: " + curve3);
    // Lists of line1 and line2 are not modified
    assertTrue(curve1.asDirectPositions().size() == 5);
    assertTrue(curve2.asDirectPositions().size() == 3);
    // New LineString has combined positions
    assertTrue(curve3.asDirectPositions().size() == 7);
   
    directPositions.remove(0);
    curve2 = (CurveImpl) tPrimFactory.createCurveByDirectPositions(directPositions);
    curve3 =  null;
    try {
      curve3 = curve2.merge(curve1);
    } catch (IllegalArgumentException e){
      //
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 );
    Surface surface = primf.createSurface(surfaceBoundary1);
   
    Set<OrientableSurface> surfaces = new HashSet<OrientableSurface>();
    surfaces.add(surface);
    MultiSurfaceImpl ms = (MultiSurfaceImpl) agf.createMultiSurface(surfaces);
    //System.out.println(ms);
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} );
   
    assertNotNull( point );
    assertEquals( crs, point.getCoordinateReferenceSystem() );
    assertSame( crs, point.getCoordinateReferenceSystem() );   
  }
View Full Code Here

  }
 
  private void _testPoint(GeometryBuilder builder) {
   
    GeometryFactoryImpl tCoordFactory = (GeometryFactoryImpl) builder.getGeometryFactory();
    PrimitiveFactoryImpl tPrimFactory = (PrimitiveFactoryImpl) builder.getPrimitiveFactory();
   
    double[] coord = new double[]{10, 32000};
    Point p1 = tPrimFactory.createPoint(coord);

    // ***** getRepresentativePoint()
    double[] dp = p1.getRepresentativePoint().getCoordinate();
    assertTrue(dp[0] == 10);
    assertTrue(dp[1] == 32000);
   
    DirectPosition dp1 = tCoordFactory.createDirectPosition(coord);
   
    Point p2 = tPrimFactory.createPoint(dp1);
   
    //System.out.println("P1: " + p1);
    //System.out.println("P2: " + p2);
    assertTrue(p1.equals(p2));
   
View Full Code Here

  }

  private void _testCurveBoundary1(GeometryBuilder builder) {

    GeometryFactoryImpl tCoordFactory = (GeometryFactoryImpl) builder.getGeometryFactory();
    PrimitiveFactoryImpl tPrimitiveFactory = (PrimitiveFactoryImpl) builder.getPrimitiveFactory();
   
    DirectPosition dp1 = tCoordFactory.createDirectPosition(new double[] {0, 0});
    DirectPosition dp2 = tCoordFactory.createDirectPosition(new double[] {100, 100});
   
    CurveBoundary curveBoundary1 = tPrimitiveFactory.createCurveBoundary(dp1, dp2);
   
    //System.out.println(curveBoundary1);

    // RepresentativePoint()
    DirectPosition dp = curveBoundary1.getRepresentativePoint();
View Full Code Here

  }

  private void _testSurfaceBoundary1(GeometryBuilder builder) {

    GeometryFactoryImpl tCoordFactory = (GeometryFactoryImpl) builder.getGeometryFactory();
    PrimitiveFactoryImpl tPrimFactory = (PrimitiveFactoryImpl) builder.getPrimitiveFactory();

    /* Defining Positions for LineStrings */
    ArrayList<Position> line1 = new ArrayList<Position>();
    line1.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{50, 20})));
    line1.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{30, 30})));
    line1.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{20, 50})));
    line1.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{20, 70})));

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

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

    ArrayList<Position> line4 = new ArrayList<Position>();
    line4.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{100, 40})));
    line4.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{80, 30})));
    line4.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{50, 20})));
   
    /* Setting up Array of these LineStrings */
    ArrayList<CurveSegment> tLineList1 = new ArrayList<CurveSegment>();
    tLineList1.add(tCoordFactory.createLineString(line1));
    tLineList1.add(tCoordFactory.createLineString(line2));

    ArrayList<CurveSegment> tLineList2 = new ArrayList<CurveSegment>();
    tLineList2.add(tCoordFactory.createLineString(line3));
    tLineList2.add(tCoordFactory.createLineString(line4));

    /* Build Curve */
    CurveImpl curve1 = tPrimFactory.createCurve(tLineList1);
    CurveImpl curve2 = tPrimFactory.createCurve(tLineList2);

   
    /* Build Ring */
    ArrayList<OrientableCurve> curveList = new ArrayList<OrientableCurve>();
    curveList.add(curve1);
    curveList.add(curve2);
   
    Ring exteriorring1 = tPrimFactory.createRing(curveList);

    //System.out.println(exteriorring1);
   
    List<Ring> interiors = new ArrayList<Ring>();
   
    SurfaceBoundary surfaceBoundary1 = tPrimFactory.createSurfaceBoundary(exteriorring1, interiors);
   
    //System.out.println(surfaceBoundary1);

    assertTrue(surfaceBoundary1.isCycle() == true);

View Full Code Here


  private CurveImpl createCurveA(GeometryBuilder builder) {

    GeometryFactoryImpl tCoordFactory = (GeometryFactoryImpl) builder.getGeometryFactory();
    PrimitiveFactoryImpl tPrimFactory = (PrimitiveFactoryImpl) builder.getPrimitiveFactory();
   
    // Self-Intersecting Curve
    // CURVE(30 20, 10 50, 100 120, 100 70, 10 140)
    ArrayList<Position> line1 = new ArrayList<Position>();
    line1.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{30, 20})));
    line1.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{10, 50})));
    line1.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{100, 120})));
    ArrayList<Position> line2 = new ArrayList<Position>();
    line2.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{100, 120})));
    line2.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{100, 70})));
    line2.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{10, 140})));

    /* Setting up Array of these LineStrings */
    ArrayList<CurveSegment> tLineList1 = new ArrayList<CurveSegment>();
    tLineList1.add(tCoordFactory.createLineString(line1));
    tLineList1.add(tCoordFactory.createLineString(line2));

    /* Build Curve */
    return tPrimFactory.createCurve(tLineList1);
   
  }
View Full Code Here

  }

  private CurveImpl createCurveB(GeometryBuilder builder) {

    GeometryFactoryImpl tCoordFactory = (GeometryFactoryImpl) builder.getGeometryFactory();
    PrimitiveFactoryImpl tPrimFactory = (PrimitiveFactoryImpl) builder.getPrimitiveFactory();
   
    // Non-Self-Intersecting Curve
    // CURVE(30 20, 10 50, 100 70, 100 120, 10 140)
    ArrayList<Position> line1 = new ArrayList<Position>();
    line1.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{30, 20})));
    line1.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{10, 50})));
    line1.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{100, 70})));
    ArrayList<Position> line2 = new ArrayList<Position>();
    line2.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{100, 70})));
    line2.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{100, 120})));
    line2.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[]{10, 140})));

    /* Setting up Array of these LineStrings */
    ArrayList<CurveSegment> tLineList1 = new ArrayList<CurveSegment>();
    tLineList1.add(tCoordFactory.createLineString(line1));
    tLineList1.add(tCoordFactory.createLineString(line2));

    /* Build Curve */
    return tPrimFactory.createCurve(tLineList1);
   
  }
View Full Code Here

    assertFalse(point.equals(point3D));
   
    // back to 2D
    builder.setCoordianteReferenceSystem(DefaultGeographicCRS.WGS84);
    PositionFactory pf = builder.getPositionFactory();
    PrimitiveFactoryImpl primf = (PrimitiveFactoryImpl) builder.getPrimitiveFactory();
    AggregateFactory agf = builder.getAggregateFactory();
   
    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>();
   
    SurfaceBoundary surfaceBoundary1 = primf.createSurfaceBoundary(exteriorRing, interiors );
    Surface surface = primf.createSurface(surfaceBoundary1);
   
    Set<OrientableSurface> surfaces = new HashSet<OrientableSurface>();
    surfaces.add(surface);
    MultiSurface ms = agf.createMultiSurface(surfaces);
    //System.out.println(ms);
View Full Code Here

TOP

Related Classes of org.geotools.geometry.iso.primitive.PrimitiveFactoryImpl

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.