Package org.opengis.geometry

Examples of org.opengis.geometry.DirectPosition


    private static DirectPosition transformTo2D(GeneralDirectPosition srcPosition, MathTransform transformToWGS84_3D,
            MathTransform transformFromWGS84) throws TransformException {
        if( Double.isNaN( srcPosition.getOrdinate(2)) ){
            srcPosition.setOrdinate(2, 0.0 ); // lazy add 3rd ordinate if not provided to prevent failure
        }
        DirectPosition world3D = transformToWGS84_3D.transform(srcPosition, null );
       
        DirectPosition world2D = new GeneralDirectPosition( DefaultGeographicCRS.WGS84);
        world2D.setOrdinate(0, world3D.getOrdinate(0));
        world2D.setOrdinate(1, world3D.getOrdinate(1));
       
        DirectPosition targetPosition = transformFromWGS84.transform(world2D, null );
        return targetPosition;
    }
View Full Code Here


                    CoordinateReferenceSystem crs2 = acquireCRS(code2);

                    // reproject
                    MathTransform transform = CRS.findMathTransform(crs1, crs2,
                            true);
                    DirectPosition pos = new DirectPosition2D(48.417, 123.35);
                    try {
                        transform.transform(pos, null);
                    } catch (Exception e) {
                        // chomp
                    }
View Full Code Here

    static LineString line(Node node, GeometryFactory gf, CoordinateSequenceFactory csf,
        boolean ring) {
        if (node.hasChild(DirectPosition.class)) {
            List dps = node.getChildValues(DirectPosition.class);
            DirectPosition dp = (DirectPosition) dps.get(0);

            CoordinateSequence seq = csf.create(dps.size(), dp.getDimension());

            for (int i = 0; i < dps.size(); i++) {
                dp = (DirectPosition) dps.get(i);

                for (int j = 0; j < dp.getDimension(); j++) {
                    seq.setOrdinate(i, j, dp.getOrdinate(j));
                }
            }

            return ring ? gf.createLinearRing(seq) : gf.createLineString(seq);
        }

        if (node.hasChild(Point.class)) {
            List points = node.getChildValues(Point.class);
            Coordinate[] coordinates = new Coordinate[points.size()];

            for (int i = 0; i < points.size(); i++) {
                coordinates[i] = ((Point) points.get(0)).getCoordinate();
            }

            return ring ? gf.createLinearRing(coordinates) : gf.createLineString(coordinates);
        }

        if (node.hasChild(Coordinate.class)) {
            List list = node.getChildValues(Coordinate.class);
            Coordinate[] coordinates = (Coordinate[]) list.toArray(new Coordinate[list.size()]);

            return ring ? gf.createLinearRing(coordinates) : gf.createLineString(coordinates);
        }

        if (node.hasChild(DirectPosition[].class)) {
            DirectPosition[] dps = (DirectPosition[]) node.getChildValue(DirectPosition[].class);

            CoordinateSequence seq = null;

            if (dps.length == 0) {
                seq = csf.create(0, 0);
            } else {
                seq = csf.create(dps.length, dps[0].getDimension());

                for (int i = 0; i < dps.length; i++) {
                    DirectPosition dp = (DirectPosition) dps[i];

                    for (int j = 0; j < dp.getDimension(); j++) {
                        seq.setOrdinate(i, j, dp.getOrdinate(j));
                    }
                }
            }

            return ring ? gf.createLinearRing(seq) : gf.createLineString(seq);
View Full Code Here

     *
     * @generated modifiable
     */
    public Object parse(ElementInstance instance, Node node, Object value)
            throws Exception {
        DirectPosition dp = null;

        if ("pos".equals(instance.getName())) {
            String[] CP = instance.getText().split(" ");
            double[] coordinates = new double[CP.length];
            int c = 0;
View Full Code Here

        return dp;
    }

    public Element encode(Object object, Document document, Element value) throws Exception {
        DirectPosition dp = (DirectPosition) object;

        if (dp == null) {
            value.appendChild(document.createElementNS(GML.NAMESPACE, org.geotools.gml3.GML.Null.getLocalPart()));
        }
       
        double[] coordinates = dp.getCoordinate();
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < coordinates.length; i++) {
            sb.append(String.valueOf(coordinates[i]));
View Full Code Here

        value.appendChild(document.createTextNode(sb.toString()));
        return null;
    }
   
    public Object getProperty(Object object, QName name) {
        DirectPosition dp = (DirectPosition) object;
       
        if (name.getLocalPart().equals("dimension")) {
            return dp.getDimension();
        }
       
        return null;
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    public <T> T evaluate(Object object, Class<T> context) {
        Expression param1 = parameters.get(0);
        CoordinateReferenceSystem crs = null;

        DirectPosition geom;
        if (param1.equals(SRS_NAME)) {
            // must be followed by srsName expression, and at least 1 point
            if (parameters.size() < 3 || parameters.size() > 4) {
                throw new IllegalArgumentException(
                        "Wrong number of parameters toDirectPosition function: "
                                + parameters.toString() + ". " + USAGE);
            }
            String srsName = parameters.get(1).evaluate(object, String.class);
            try {
                crs = CRS.decode((String) srsName);
            } catch (NoSuchAuthorityCodeException e) {
                throw new IllegalArgumentException(
                        "Invalid or unsupported SRS name detected for toDirectPosition function: "
                                + srsName + ". Cause: " + e.getMessage());
            } catch (FactoryException e) {
                throw new RuntimeException("Unable to decode SRS name. Cause: " + e.getMessage());
            }
            if (parameters.size() == 3) {
                // 1D
                geom = new DirectPosition1D(crs);
            } else {
                // 2D
                geom = new DirectPosition2D(crs);
                geom.setOrdinate(1, parameters.get(3).evaluate(object, Double.class));
            }
            geom.setOrdinate(0, parameters.get(2).evaluate(object, Double.class));
        } else {
            // should only have points, 1 for 1D, 2 for 2D
            if (parameters.size() > 2) {
                throw new IllegalArgumentException(
                        "Too many parameters for toDirectPosition function: "
                                + parameters.toString() + ". " + USAGE);
            }
            if (parameters.size() == 1) {
                // 1D
                geom = new DirectPosition1D();
            } else {
                // 2D
                geom = new DirectPosition2D();
                geom.setOrdinate(1, parameters.get(1).evaluate(object, Double.class));
            }
            geom.setOrdinate(0, param1.evaluate(object, Double.class));
        }

        return (T) geom;
    }
View Full Code Here

        CoordinateReferenceSystem BC_ALBERS = (CoordinateReferenceSystem) CRS.decode("EPSG:42102");
               
        CoordinateOperation op = ReferencingFactoryFinder.getCoordinateOperationFactory(null).createOperation( WGS84, WGS84 );
        MathTransform math = op.getMathTransform();
               
        DirectPosition pt1 = new GeneralDirectPosition(0.0,0.0);       
        DirectPosition pt2 = math.transform( pt1, null );
        assertNotNull( pt2 );
         
        double pts[] = new double[] {
                1187128,395268, 1187128,396027,
                1188245,396027, 1188245,395268,
View Full Code Here

        CoordinateReferenceSystem crs1 = factory.createCoordinateReferenceSystem("4326");
        CoordinateReferenceSystem crs2 = factory.createCoordinateReferenceSystem("3005");

        // reproject
        MathTransform transform = CRS.findMathTransform(crs1, crs2,true);
        DirectPosition pos = new DirectPosition2D(48.417, 123.35);
        transform.transform(pos, null);
    }
View Full Code Here

        CoordinateReferenceSystem crs1 = factory.createCoordinateReferenceSystem("4326");
        CoordinateReferenceSystem crs2 = factory.createCoordinateReferenceSystem("3005");

        // reproject
        MathTransform transform = CRS.findMathTransform(crs1, crs2,true);
        DirectPosition pos = new DirectPosition2D(48.417, 123.35);
        transform.transform(pos, null);
    }
View Full Code Here

TOP

Related Classes of org.opengis.geometry.DirectPosition

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.