Package org.opengis.referencing.cs

Examples of org.opengis.referencing.cs.CoordinateSystemAxis


    System.out.println("Identified Datum object:");
    printIdentifierStuff(clark1866datum);
   
    map.clear();
    map.put("name", "<lat>, <long>");
    CoordinateSystemAxis latAxis = org.geotools.referencing.cs.DefaultCoordinateSystemAxis.GEODETIC_LATITUDE;
    CoordinateSystemAxis longAxis = org.geotools.referencing.cs.DefaultCoordinateSystemAxis.GEODETIC_LONGITUDE;
    EllipsoidalCS ellipsCS = csFactory.createEllipsoidalCS(map, latAxis, longAxis);
   
    map.clear();
    map.put("name", "NAD 27");
    map.put("authority", "9999");
View Full Code Here


    // Create a geocentric CRS
    //
    // Create a collection of axes for the coordinate system.
    map.clear();
    map.put("name", "Cartesian X axis");
    CoordinateSystemAxis xAxis = csFactory.createCoordinateSystemAxis(map, "X",
            AxisDirection.GEOCENTRIC_X, SI.METER);
   
    map.clear();
    map.put("name", "Cartesian Y axis");
    CoordinateSystemAxis yAxis = csFactory.createCoordinateSystemAxis(map, "Y",
            AxisDirection.GEOCENTRIC_Y, SI.METER);
   
    map.clear();
    map.put("name", "Cartesian Z axis");
    CoordinateSystemAxis zAxis = csFactory.createCoordinateSystemAxis(map, "Z",
            AxisDirection.GEOCENTRIC_Z, SI.METER);
   
    map.clear();
    map.put("name", "Rendered Cartesian CS");
    CartesianCS worldCS = csFactory.createCartesianCS(map, xAxis, yAxis, zAxis);
   
    // Now, the geocentric coordinate reference system that we'd use for output - eg to a 3D
    // renderer
    map.clear();
    map.put("name", "Output Cartesian CS");
    CoordinateReferenceSystem geocentricCRS = crsFactory.createGeocentricCRS(map, wgs84Datum,
            worldCS);
    System.out.println("Geocentric CRS: " + geocentricCRS.toWKT());
   
    //
    // Create a geograyhic CRS for the Airy 1830 ellipsoid
    // map.clear();
    // map.put("name", "Airy 1830");
    // Ellipsoid airyEllipse =
    // datumFactory.createFlattenedSphere(map, 6377563.396, 299.3249646, SI.METER);
   
    map.clear();
    map.put("name", "Geodetic North axis");
    CoordinateSystemAxis northAxis = csFactory.createCoordinateSystemAxis(map, "N",
            AxisDirection.NORTH, NonSI.DEGREE_ANGLE);
   
    map.clear();
    map.put("name", "Geodetic East axis");
    CoordinateSystemAxis eastAxis = csFactory.createCoordinateSystemAxis(map, "E",
            AxisDirection.EAST, NonSI.DEGREE_ANGLE);
   
    map.clear();
    map.put("name", "Geodetic Height axis");
    CoordinateSystemAxis heightAxis = csFactory.createCoordinateSystemAxis(map, "Up",
            AxisDirection.UP, SI.METER);
   
    map.clear();
    map.put("name", "<long>,<lat> Airy 1830 geodetic");
    EllipsoidalCS airyCS = csFactory.createEllipsoidalCS(map, eastAxis, northAxis, heightAxis);
View Full Code Here

     * @see DefaultEllipsoidalCS#usingUnit
     */
    final CoordinateSystemAxis[] axisUsingUnit(final Unit<?> unit) throws IllegalArgumentException {
        CoordinateSystemAxis[] newAxis = null;
        for (int i=0; i<axis.length; i++) {
            CoordinateSystemAxis a = axis[i];
            if (!unit.equals(a.getUnit())) {
                DefaultCoordinateSystemAxis converted;
                if (a instanceof DefaultCoordinateSystemAxis) {
                    converted = (DefaultCoordinateSystemAxis) a;
                } else {
                    converted = new DefaultCoordinateSystemAxis(a);
View Full Code Here

     * specific to that implementation.
     */
    private static DefaultCoordinateSystemAxis[] getDefaultAxis(final CoordinateSystem cs) {
        final DefaultCoordinateSystemAxis[] axis = new DefaultCoordinateSystemAxis[cs.getDimension()];
        for (int i=0; i<axis.length; i++) {
            final CoordinateSystemAxis a = cs.getAxis(i);
            DefaultCoordinateSystemAxis c = DefaultCoordinateSystemAxis.getPredefined(a);
            if (c == null) {
                if (a instanceof DefaultCoordinateSystemAxis) {
                    c = (DefaultCoordinateSystemAxis) a;
                } else {
View Full Code Here

            wrappers[i] = new ComparableAxisWrapper(axis[i]);
        }
        Arrays.sort(wrappers);
        boolean changed = false;
        for (int i=0; i<axis.length; i++) {
            final CoordinateSystemAxis a = wrappers[i].axis;
            changed |= (axis[i] != a);
            axis[i] = a;
        }
        return changed;
    }
View Full Code Here

     * The preference will be given to the longitude axis, if found.
     */
    static Unit<Angle> getAngularUnit(final CoordinateSystem coordinateSystem) {
        Unit<Angle> unit = NonSI.DEGREE_ANGLE;
        for (int i=coordinateSystem.getDimension(); --i>=0;) {
            final CoordinateSystemAxis axis = coordinateSystem.getAxis(i);
            final Unit<?> candidate = axis.getUnit();
            if (NonSI.DEGREE_ANGLE.isCompatible(candidate)) {
                unit = candidate.asType(Angle.class);
                if (AxisDirection.EAST.equals(axis.getDirection().absolute())) {
                    break; // Found the longitude axis.
                }
            }
        }
        return unit;
View Full Code Here

    /**
     * Update the converters.
     */
    private void update() {
        for (int i=getDimension(); --i>=0;) {
            final CoordinateSystemAxis axis = getAxis(i);
            final AxisDirection   direction = axis.getDirection().absolute();
            final Unit<?>              unit = axis.getUnit();
            if (AxisDirection.EAST.equals(direction)) {
                longitudeAxis      = i;
                longitudeConverter = unit.getConverterTo(NonSI.DEGREE_ANGLE);
                continue;
            }
View Full Code Here

                /*
                 * For three-dimensional Geographic CRS, extracts the axis having a direction
                 * like "North", "North-East", "East", etc. If we find exactly two of them,
                 * we can build a new GeographicCRS using them.
                 */
                CoordinateSystemAxis axis0 = null, axis1 = null;
                int count = 0;
                for (int i=0; i<dimension; i++) {
                    final CoordinateSystemAxis axis = cs.getAxis(i);
search:             if (DefaultCoordinateSystemAxis.isCompassDirection(axis.getDirection())) {
                        switch (count++) {
                            case 0: axis0 = axis; break;
                            case 1: axis1 = axis; break;
                            default: break search;
                        }
View Full Code Here

            if (cs != null) { // Should never be null, but check as a paranoiac safety.
                DirectPosition sourcePt = null;
                DirectPosition targetPt = null;
                final int dimension = cs.getDimension();
                for (int i=0; i<dimension; i++) {
                    final CoordinateSystemAxis axis = cs.getAxis(i);
                    if (axis == null) { // Should never be null, but check as a paranoiac safety.
                        continue;
                    }
                    final double min = envelope.getMinimum(i);
                    final double max = envelope.getMaximum(i);
                    final double  v1 = axis.getMinimumValue();
                    final double  v2 = axis.getMaximumValue();
                    final boolean b1 = (v1 > min && v1 < max);
                    final boolean b2 = (v2 > min && v2 < max);
                    if (!b1 && !b2) {
                        continue;
                    }
                    if (sourcePt == null) {
                        sourcePt = new GeneralDirectPosition(dimension);
                        for (int j=0; j<dimension; j++) {
                            sourcePt.setOrdinate(j, envelope.getMedian(j));
                        }
                    }
                    if (b1) {
                        sourcePt.setOrdinate(i, v1);
                        transformed.add(targetPt = mt.transform(sourcePt, targetPt));
                    }
                    if (b2) {
                        sourcePt.setOrdinate(i, v2);
                        transformed.add(targetPt = mt.transform(sourcePt, targetPt));
                    }
                    sourcePt.setOrdinate(i, envelope.getMedian(i));
                }
            }
        }

        // check the target CRSS
        /*
         * Special case for polar stereographic, if the envelope contains the origin, then
         * the whole set of longitudes should be included
         */
        final CoordinateReferenceSystem targetCRS = operation.getTargetCRS();
        if (targetCRS == null) {
            return transformed;
        }
        GeneralEnvelope generalEnvelope = toGeneralEnvelope(envelope);
        MapProjection sourceProjection = CRS.getMapProjection(sourceCRS);
        if (sourceProjection instanceof PolarStereographic) {
            PolarStereographic ps = (PolarStereographic) sourceProjection;
            ParameterValue<?> fe = ps.getParameterValues().parameter(
                    MapProjection.AbstractProvider.FALSE_EASTING.getName().getCode());
            double originX = fe.doubleValue();
            ParameterValue<?> fn = ps.getParameterValues().parameter(
                    MapProjection.AbstractProvider.FALSE_NORTHING.getName().getCode());
            double originY = fn.doubleValue();
            DirectPosition2D origin = new DirectPosition2D(originX, originY);
            if (generalEnvelope.contains(origin)) {
                if (targetCRS instanceof GeographicCRS) {
                    DirectPosition lowerCorner = transformed.getLowerCorner();
                    if (getAxisOrder(targetCRS) == AxisOrder.NORTH_EAST) {
                        lowerCorner.setOrdinate(1, -180);
                        transformed.add(lowerCorner);
                        lowerCorner.setOrdinate(1, 180);
                        transformed.add(lowerCorner);
                    } else {
                        lowerCorner.setOrdinate(0, -180);
                        transformed.add(lowerCorner);
                        lowerCorner.setOrdinate(0, 180);
                        transformed.add(lowerCorner);
                    }
                } else {
                    // there is no guarantee that the whole range of longitudes will make
                    // sense for the target projection. We do a 1deg sampling as a compromise
                    // between
                    // speed and accuracy
                    DirectPosition lc = transformed.getLowerCorner();
                    DirectPosition uc = transformed.getUpperCorner();
                    for (int j = -180; j < 180; j++) {
                        expandEnvelopeByLongitude(j, lc, transformed, targetCRS);
                        expandEnvelopeByLongitude(j, uc, transformed, targetCRS);
                    }

                }
            } else {
                // check where the point closes to the origin is, make sure it's included
                // in the tranformation points
                if (generalEnvelope.getMinimum(0) < originX
                        && generalEnvelope.getMaximum(0) > originX) {
                    DirectPosition lc = generalEnvelope.getLowerCorner();
                    lc.setOrdinate(0, originX);
                    mt.transform(lc, lc);
                    transformed.add(lc);
                    DirectPosition uc = generalEnvelope.getUpperCorner();
                    uc.setOrdinate(0, originX);
                    mt.transform(uc, uc);
                    transformed.add(uc);
                }
                if (generalEnvelope.getMinimum(1) < originY
                        && generalEnvelope.getMaximum(1) > originY) {
                    DirectPosition lc = generalEnvelope.getLowerCorner();
                    lc.setOrdinate(1, originY);
                    mt.transform(lc, lc);
                    transformed.add(lc);
                    DirectPosition uc = generalEnvelope.getUpperCorner();
                    uc.setOrdinate(1, originY);
                    mt.transform(uc, uc);
                    transformed.add(uc);
                }

            }
        }
       
        /*
         * Now takes the target CRS in account...
         */
        transformed.setCoordinateReferenceSystem(targetCRS);
        final CoordinateSystem targetCS = targetCRS.getCoordinateSystem();
        if (targetCS == null) {
            // It should be an error, but we keep this method tolerant.
            return transformed;
        }
        /*
         * Checks for singularity points. For example the south pole is a singularity point in
         * geographic CRS because we reach the maximal value allowed on one particular geographic
         * axis, namely latitude. This point is not a singularity in the stereographic projection,
         * where axis extends toward infinity in all directions (mathematically) and south pole
         * has nothing special apart being the origin (0,0).
         *
         * Algorithm:
         *
         * 1) Inspect the target axis, looking if there is any bounds. If bounds are found, get
         *    the coordinates of singularity points and project them from target to source CRS.
         *
         *    Example: if the transformed envelope above is (80°S to 85°S, 10°W to 50°W), and if
         *             target axis inspection reveal us that the latitude in target CRS is bounded
         *             at 90°S, then project (90°S,30°W) to source CRS. Note that the longitude is
         *             set to the the center of the envelope longitude range (more on this later).
         *
         * 2) If the singularity point computed above is inside the source envelope, add that
         *    point to the target (transformed) envelope.
         *
         * Note: We could choose to project the (-180, -90), (180, -90), (-180, 90), (180, 90)
         * points, or the (-180, centerY), (180, centerY), (centerX, -90), (centerX, 90) points
         * where (centerX, centerY) are transformed from the source envelope center. It make
         * no difference for polar projections because the longitude is irrelevant at pole, but
         * may make a difference for the 180° longitude bounds.  Consider a Mercator projection
         * where the transformed envelope is between 20°N and 40°N. If we try to project (-180,90),
         * we will get a TransformException because the Mercator projection is not supported at
         * pole. If we try to project (-180, 30) instead, we will get a valid point. If this point
         * is inside the source envelope because the later overlaps the 180° longitude, then the
         * transformed envelope will be expanded to the full (-180 to 180) range. This is quite
         * large, but at least it is correct (while the envelope without expansion is not).
         */
        DirectPosition sourcePt = null;
        DirectPosition targetPt = null;
        final int dimension = targetCS.getDimension();
        for (int i=0; i<dimension; i++) {
            final CoordinateSystemAxis axis = targetCS.getAxis(i);
            if (axis == null) { // Should never be null, but check as a paranoiac safety.
                continue;
            }
            boolean testMax = false; // Tells if we are testing the minimal or maximal value.
            do {
                final double extremum = testMax ? axis.getMaximumValue() : axis.getMinimumValue();
                if (Double.isInfinite(extremum) || Double.isNaN(extremum)) {
                    /*
                     * The axis is unbounded. It should always be the case when the target CRS is
                     * a map projection, in which case this loop will finish soon and this method
                     * will do nothing more (no object instantiated, no MathTransform inversed...)
View Full Code Here

  // sample implemenation with get/test
  public CoordinateSystemAxis createCoordinateSystemAxis(String code)
      throws FactoryException {
    final String key = toKey(code);
    CoordinateSystemAxis axis = (CoordinateSystemAxis) cache.get(key);
    if (axis == null) {
      try {
        cache.writeLock(key);
        axis = (CoordinateSystemAxis) cache.peek(key);
        if (axis == null) {
View Full Code Here

TOP

Related Classes of org.opengis.referencing.cs.CoordinateSystemAxis

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.