Package org.opengis.geometry.primitive

Examples of org.opengis.geometry.primitive.PrimitiveFactory


    }
    /** 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
         // - Start and end params for the CurveSegments will be set
         List<CurveSegment> segmentList = new ArrayList<CurveSegment>();
         for( int i=0; i<points.size();i++){
             int start = i;
             int end = (i+1)%points.size();
             DirectPosition point1 = points.getDirectPosition( start, null );
             DirectPosition point2 = points.getDirectPosition( end, null );
             LineSegment segment = geometryFactory.createLineSegment( point1, point2 );
             segmentList.add( segment );
         }
         Curve curve = primitiveFactory.createCurve( segmentList );
         curves.add( curve);        
         Ring ring = primitiveFactory.createRing( curves );
         SurfaceBoundary boundary = primitiveFactory.createSurfaceBoundary(ring,new ArrayList());
         Surface surface = primitiveFactory.createSurface(boundary);        
    }
View Full Code Here


        return (T) ois.readObject();
    }
   
    private Surface createSurfaceFast(double[] array ) {
        PositionFactory postitionFactory = builder.getPositionFactory();
        PrimitiveFactory primitiveFactory = builder.getPrimitiveFactory();
        GeometryFactory geometryFactory = builder.getGeometryFactory();
        CoordinateReferenceSystem crs = builder.getCoordinateReferenceSystem();
       
        int length = array.length / crs.getCoordinateSystem().getDimension();
        PointArray closedPoints = postitionFactory.createPointArray( array, 0, length );
        LineString lines = geometryFactory.createLineString(closedPoints);       
        List<CurveSegment> segmentList = new ArrayList<CurveSegment>();
        segmentList.add(lines);
       
        Curve curve = primitiveFactory.createCurve(segmentList);
       
        List<OrientableCurve> curves = new ArrayList<OrientableCurve>();       
        curves.add(curve);
       
        Ring ring = primitiveFactory.createRing(curves);
        SurfaceBoundary surfaceBoundary = primitiveFactory.createSurfaceBoundary( ring, Collections.EMPTY_LIST );      
        return primitiveFactory.createSurface(surfaceBoundary);
    }
View Full Code Here

                          op.setExpectedResult( point );
                        }
                        else { // try parsing this thing as WKT
                          GeometryBuilder builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
                            GeometryFactory geomFact = builder.getGeometryFactory();
                            PrimitiveFactory primFact = builder.getPrimitiveFactory();
                            WKTParser wktFactory = new WKTParser(geomFact, primFact, null, builder.getAggregateFactory());
                            try {
                                Object expectedResult = wktFactory.parse(operationValue);
                                op.setExpectedResult(expectedResult);
                                testCase.addTestOperation(op);
View Full Code Here

 
  public void testCurveAgain() {

    GeometryBuilder builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
    PositionFactory posF = builder.getPositionFactory();
    PrimitiveFactory primF = builder.getPrimitiveFactory();
    GeometryFactory geomF = builder.getGeometryFactory();   

//     create directpositions
    DirectPosition start = posF.createDirectPosition(new double[]{ 48.44, -123.37 });
    DirectPosition middle = posF.createDirectPosition(new double[]{ 47, -122 });
    DirectPosition end = posF.createDirectPosition(new double[]{ 46.5, -121.5 });

//     add directpositions to a list
    ArrayList<Position> positions = new ArrayList<Position>();
    positions .add(start);
    positions.add(middle);
    positions.add(end);

//     create linestring from directpositions
    LineString line = geomF.createLineString(positions);

//     create curvesegments from line
    ArrayList<CurveSegment> segs = new ArrayList<CurveSegment>();
    segs.add(line);

//     create curve
    Curve curve = primF.createCurve(segs);   
   
    // get points from curve
    List<? extends CurveSegment> segs2 = curve.getSegments();
    Iterator<? extends CurveSegment> iter = segs2.iterator();
    PointArray samplePoints = null;
View Full Code Here

  public Geometry transform(CoordinateReferenceSystem newCRS,
      MathTransform transform) throws MismatchedDimensionException, TransformException {

    // loop through each point in this curve and transform it to the new CRS, then
    // use the new points to build a new curve and return that.
    PrimitiveFactory primitiveFactory = new PrimitiveFactoryImpl(newCRS, getPositionFactory());
    GeometryFactory geometryFactory = new GeometryFactoryImpl(newCRS, getPositionFactory());
   
    DirectPositionImpl dp1 = null;
    List<DirectPosition> currentpositions = asDirectPositions();
    Iterator<DirectPosition> iter = currentpositions.iterator();
    List<Position> newpositions = new ArrayList<Position>();
    while (iter.hasNext()) {
      DirectPosition thispos = (DirectPosition) iter.next();
      dp1 = new DirectPositionImpl(newCRS);
      dp1 = (DirectPositionImpl) transform.transform(thispos, dp1);
      newpositions.add(dp1);
    }
   
    // use the new positions list to build a new curve and return it
    LineString lineString = geometryFactory.createLineString(newpositions);
    List curveSegmentList = Collections.singletonList(lineString);
    CurveImpl newCurve = (CurveImpl) primitiveFactory.createCurve(curveSegmentList);
    return newCurve;
     
  }
View Full Code Here

   */
  public Geometry transform(CoordinateReferenceSystem newCRS,
      MathTransform transform) throws MismatchedDimensionException, TransformException {

    PositionFactory newPositionFactory = new PositionFactoryImpl(newCRS, getPositionFactory().getPrecision());
    PrimitiveFactory newPrimitiveFactory = new PrimitiveFactoryImpl(newCRS, newPositionFactory);
    DirectPosition dp1 = new DirectPositionImpl(newCRS);
    dp1 = transform.transform(((PointImpl)this).getPosition(), dp1);
    return newPrimitiveFactory.createPoint( dp1 );
     
  }
View Full Code Here

  public Geometry transform(CoordinateReferenceSystem newCRS,
      MathTransform transform) throws TransformException {

    // loop through each ring in this Surface and transform it to the new CRS, then
    // use the new rings to build a new Surface and return that.
    PrimitiveFactory primitiveFactory = new PrimitiveFactoryImpl(newCRS, getPositionFactory());
   
    List<Ring> currentRings = this.getBoundaryRings();
    Iterator<Ring> iter = currentRings.iterator();
    Ring newExterior = null;
    List<Ring> newInteriors = new ArrayList<Ring>();
    while (iter.hasNext()) {
      Ring thisRing = (Ring) iter.next();
     
      // exterior Ring should be first element in the list
      if (newExterior == null) {
        newExterior = (Ring) thisRing.transform(newCRS, transform );
      }
      else {
        newInteriors.add((Ring) thisRing.transform(newCRS, transform));
      }
    }
   
    // use the new Ring list to build a new Surface and return it
    SurfaceBoundaryImpl surfaceBoundary = (SurfaceBoundaryImpl) primitiveFactory.createSurfaceBoundary(newExterior, newInteriors);
    SurfaceImpl newSurface = (SurfaceImpl) primitiveFactory.createSurface(surfaceBoundary);
    return newSurface;
     
  }
View Full Code Here

        } catch (ParserConfigurationException e) {
            throw new RuntimeException("", e);
        }

        GeometryFactory geomFact = new GeometryFactoryImpl(DefaultGeographicCRS.WGS84);
        PrimitiveFactory primFact = new PrimitiveFactoryImpl(DefaultGeographicCRS.WGS84);
        PositionFactory posFact = null;
        wktFactory = new WKTParser(geomFact, primFact, posFact, null );
    }
View Full Code Here

  public Geometry transform(CoordinateReferenceSystem newCRS,
      MathTransform transform) throws MismatchedDimensionException, TransformException {

    // loop through each point in this Ring and transform it to the new CRS, then
    // use the new points to build a new Ring and return that.
    PrimitiveFactory primitiveFactory = new PrimitiveFactoryImpl(newCRS, getPositionFactory());
    GeometryFactory geometryFactory = new GeometryFactoryImpl(newCRS, getPositionFactory());
   
    DirectPositionImpl dp1 = null;
    List<DirectPosition> currentpositions = this.asDirectPositions();
    Iterator<DirectPosition> iter = currentpositions.iterator();
    List<Position> newpositions = new ArrayList<Position>();
    while (iter.hasNext()) {
      DirectPosition thispos = (DirectPosition) iter.next();
     
      dp1 = new DirectPositionImpl(newCRS);
      dp1 = (DirectPositionImpl) transform.transform( thispos, dp1);
      newpositions.add(dp1);
    }
   
    // use the new positions list to build a new Ring and return it
    LineString lineString = geometryFactory.createLineString(newpositions);
    List curveSegmentList = Collections.singletonList(lineString);
    CurveImpl newCurve = (CurveImpl) primitiveFactory.createCurve(curveSegmentList);
    ArrayList<OrientableCurve> curveList = new ArrayList<OrientableCurve>();
    curveList.add(newCurve);
    Ring newRing = primitiveFactory.createRing(curveList);
    return newRing;
     
  }
View Full Code Here

    public static Geometry jtsToGo1(
            final com.vividsolutions.jts.geom.Geometry jtsGeom,
            final CoordinateReferenceSystem crs) {

        Hints hints = new Hints( Hints.CRS, crs );
        PrimitiveFactory pf = GeometryFactoryFinder.getPrimitiveFactory(hints);
        GeometryFactory gf = GeometryFactoryFinder.getGeometryFactory(hints);

        String geomType = jtsGeom.getGeometryType();
        if (geomType.equalsIgnoreCase("Point")) {
            com.vividsolutions.jts.geom.Point jtsPoint =
                (com.vividsolutions.jts.geom.Point) jtsGeom;
            DirectPosition dp = pointToDirectPosition(jtsPoint, crs);
            Point result = pf.createPoint(dp);
            return result;
       
        } else if (geomType.equalsIgnoreCase("LineString")) {
            com.vividsolutions.jts.geom.LineString jtsLineString =
                (com.vividsolutions.jts.geom.LineString) jtsGeom;
            int numPoints = jtsLineString.getNumPoints();
            LineString ls = gf.createLineString(new ArrayList());
            List pointList = ls.getControlPoints();
            for (int i=0; i<numPoints; i++) {
                pointList.add(coordinateToDirectPosition(jtsLineString.getCoordinateN(i), crs));
            }
            ArrayList segments = new ArrayList();
            segments.add(ls);
            Curve result = pf.createCurve(segments);
            return result;
       
        } else if (geomType.equalsIgnoreCase("LinearRing")) {
            Ring result = linearRingToRing(
                    (com.vividsolutions.jts.geom.LinearRing) jtsGeom, crs);
            return result;
       
        } else if (geomType.equalsIgnoreCase("Polygon")) {
            com.vividsolutions.jts.geom.Polygon jtsPolygon =
                (com.vividsolutions.jts.geom.Polygon) jtsGeom;
            Ring externalRing = linearRingToRing(
                    (com.vividsolutions.jts.geom.LinearRing) jtsPolygon.getExteriorRing(),
                    crs);
            int n = jtsPolygon.getNumInteriorRing();
            ArrayList internalRings = new ArrayList();
            for (int i=0; i<n; i++) {
                internalRings.add(linearRingToRing(
                    (com.vividsolutions.jts.geom.LinearRing) jtsPolygon.getInteriorRingN(i),
                    crs));
            }
            SurfaceBoundary boundary = pf.createSurfaceBoundary(externalRing,
                    internalRings);
            Polygon polygon = gf.createPolygon(boundary);
            ArrayList patches = new ArrayList();
            patches.add(polygon);
            PolyhedralSurface result = gf.createPolyhedralSurface(patches);
View Full Code Here

TOP

Related Classes of org.opengis.geometry.primitive.PrimitiveFactory

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.