Package org.geotools.referencing

Examples of org.geotools.referencing.GeodeticCalculator


    try {
      if (null == mapBounds) {
        throw new LayerException(ExceptionCode.MAP_MAX_EXTENT_MISSING);
      }
      Crs crs = geoService.getCrs2(mapCrsKey);
      GeodeticCalculator calculator = new GeodeticCalculator(crs);
      Coordinate center = new Coordinate(0.5 * (mapBounds.getX() + mapBounds.getMaxX()),
          0.5 * (mapBounds.getY() + mapBounds.getMaxY()));
      calculator.setStartingPosition(new DirectPosition2D(crs, center.getX(), center.getY()));
      calculator.setDestinationPosition(new DirectPosition2D(crs, center.getX() + 1, center.getY()));
      return calculator.getOrthodromicDistance();
    } catch (TransformException e) {
      throw new LayerException(e, ExceptionCode.TRANSFORMER_CREATE_LAYER_TO_MAP_FAILED);
    }
  }
View Full Code Here


      if (referencePixelLatLong.getWidth() > 360) {
        scale = referencePixelLatLong.getWidth() / 18;
        minX = 0;
        maxX = 180;
      }
      GeodeticCalculator calc = new GeodeticCalculator();
      double centerY = centeredYWithinWorld(referencePixelLatLong);
      calc.setStartingGeographicPoint(minX, centerY);
      calc.setDestinationGeographicPoint(maxX, centerY);
      return calc.getOrthodromicDistance() * scale;
    } catch (FactoryException e) {
      ProjectPlugin.log("error transforming: " + referencePixel
          + " to latlong", e);
      return -1;
    } catch (TransformException e) {
View Full Code Here

            try {
                Coordinate c = tmsProperties.centerPoint;
                Envelope env = new Envelope(c);
                // TODO when bounds are really available change this
                GeodeticCalculator gc = new GeodeticCalculator(tmsCrs);
                gc.setStartingGeographicPoint(c.x, c.y);
                gc.setDirection(-45, 10000.0);
                Point2D p1 = gc.getDestinationGeographicPoint();
                env.expandToInclude(p1.getX(), p1.getY());
                gc.setDirection(135, 10000.0);
                Point2D p2 = gc.getDestinationGeographicPoint();
                env.expandToInclude(p2.getX(), p2.getY());

                ReferencedEnvelope tmpBounds = new ReferencedEnvelope(env, DefaultGeographicCRS.WGS84);
                bounds = tmpBounds.transform(tmsCrs, true);
View Full Code Here

        DistanceUnit projUnit = DistanceUnit.fromProjection(getProjection());

        double geoWidthInInches;
        if (projUnit == DistanceUnit.DEGREES) {
            GeodeticCalculator calculator = new GeodeticCalculator(getProjection());
            final double centerY = bboxAdjustedToScreen.centre().y;
            calculator.setStartingGeographicPoint(bboxAdjustedToScreen.getMinX(), centerY);
            calculator.setDestinationGeographicPoint(bboxAdjustedToScreen.getMaxX(), centerY);
            double geoWidthInEllipsoidUnits = calculator.getOrthodromicDistance();
            DistanceUnit ellipsoidUnit = DistanceUnit.fromString(calculator.getEllipsoid().getAxisUnit().toString());

            geoWidthInInches = ellipsoidUnit.convertTo(geoWidthInEllipsoidUnits, DistanceUnit.IN);
        } else {
            // (scale * width ) / dpi = geowidith
            geoWidthInInches = projUnit.convertTo(bboxAdjustedToScreen.getWidth(), DistanceUnit.IN);
View Full Code Here

    private ReferencedEnvelope computeGeodeticBBox(final double geoWidthInInches, final double geoHeightInInches) {
        try {

            CoordinateReferenceSystem crs = getProjection();

            GeodeticCalculator calc = new GeodeticCalculator(crs);

            DistanceUnit ellipsoidUnit = DistanceUnit.fromString(calc.getEllipsoid().getAxisUnit().toString());
            double geoWidth = DistanceUnit.IN.convertTo(geoWidthInInches, ellipsoidUnit);
            double geoHeight = DistanceUnit.IN.convertTo(geoHeightInInches, ellipsoidUnit);

            DirectPosition2D directPosition2D = new DirectPosition2D(this.center.x, this.center.y);
            directPosition2D.setCoordinateReferenceSystem(crs);
            calc.setStartingPosition(directPosition2D);

            final int west = -90;
            calc.setDirection(west, geoWidth / 2.0);
            double minGeoX =  calc.getDestinationPosition().getOrdinate(0);

            final int east = 90;
            calc.setDirection(east, geoWidth / 2.0);
            double maxGeoX = calc.getDestinationPosition().getOrdinate(0);

            final int south = 180;
            calc.setDirection(south, geoHeight / 2.0);
            double minGeoY = calc.getDestinationPosition().getOrdinate(1);

            final int north = 0;
            calc.setDirection(north, geoHeight / 2.0);
            double maxGeoY = calc.getDestinationPosition().getOrdinate(1);

            return new ReferencedEnvelope(
                    rollLongitude(minGeoX), rollLongitude(maxGeoX),
                    rollLatitude(minGeoY), rollLatitude(maxGeoY), crs);
        } catch (TransformException e) {
View Full Code Here

        return path.toURI();
    }

    private DistanceUnit getUnit(final MapBounds bounds) {
        GeodeticCalculator calculator = new GeodeticCalculator(bounds.getProjection());
        return DistanceUnit.fromString(calculator.getEllipsoid().getAxisUnit().toString());
    }
View Full Code Here

    @Test
    public final void testAzimuth() {

        final int N_RUN = 1000000;

        GeodeticCalculator geodeticCalculator = new GeodeticCalculator();

        Random rand = new Random(42);
        List<Coordinate> from = new ArrayList<>(N_RUN);
        List<Coordinate> to = new ArrayList<>(N_RUN);

        // Add fixed points
        from.add(new Coordinate(0, 45));
        to.add(new Coordinate(0, 45)); // Undefined: 180 deg
        assertTrue(DirectionUtils.getAzimuth(from.get(0), to.get(0)) == 180);

        from.add(new Coordinate(0, 45));
        to.add(new Coordinate(0.1, 45)); // East: 90 deg
        assertTrue(DirectionUtils.getAzimuth(from.get(1), to.get(1)) == 90);

        from.add(new Coordinate(0, 45));
        to.add(new Coordinate(0, 45.1)); // North: 0 deg
        assertTrue(DirectionUtils.getAzimuth(from.get(2), to.get(2)) == 0);

        from.add(new Coordinate(0, 45));
        to.add(new Coordinate(-0.1, 45)); // West: -90 deg
        assertTrue(DirectionUtils.getAzimuth(from.get(3), to.get(3)) == -90);

        from.add(new Coordinate(0, 45));
        to.add(new Coordinate(0, 44.9)); // South: 180 deg
        assertTrue(DirectionUtils.getAzimuth(from.get(4), to.get(4)) == 180);

        for (int i = 0; i < N_RUN; i++) {
            Coordinate a = new Coordinate(rand.nextDouble() * 0.1, 45 + rand.nextDouble() * 0.1);
            Coordinate b = new Coordinate(rand.nextDouble() * 0.1, 45 + rand.nextDouble() * 0.1);
            from.add(a);
            to.add(b);
        }

        double[] exactAzimuths = new double[from.size()];
        double[] approxAzimuths = new double[to.size()];

        long start = System.currentTimeMillis();
        for (int i = 0; i < from.size(); i++) {
            geodeticCalculator.setStartingGeographicPoint(from.get(i).x, from.get(i).y);
            geodeticCalculator.setDestinationGeographicPoint(to.get(i).x, to.get(i).y);
            exactAzimuths[i] = geodeticCalculator.getAzimuth();
        }
        long exactTimeMs = System.currentTimeMillis() - start;
        System.out.println("GeodeticCalculator exact azimuth: " + exactTimeMs + "ms for " + N_RUN
                + " computations.");

View Full Code Here

        // go along road then random
        public void run() {
            LOG.info(String.format("Producing %d random endpoints within radius %2.2fm around %s.",
                    n, radius, useStops ? "stops" : "streets"));
            List<Vertex> vertices = new ArrayList<Vertex>();
            GeodeticCalculator gc = new GeodeticCalculator();
            Class<?> klasse = useStops ? TransitStop.class : StreetVertex.class;
            for (Vertex v : graph.getVertices())
                if (klasse.isInstance(v))
                    vertices.add(v);
            Random random = new Random();
            if (seed != null)
                random.setSeed(seed);
            Collections.shuffle(vertices, random);
            vertices = vertices.subList(0, n);
            try {
                writer.writeRecord( new String[] {"n", "name", "lon", "lat"} );
                int i = 0;
                for (Vertex v : vertices) {
                    Coordinate c;
                    if (v instanceof StreetVertex) {
                        LineString ls = ((StreetVertex)v).getOutgoing().iterator().next().getGeometry();
                        int numPoints = ls.getNumPoints();
                        LocationIndexedLine lil = new LocationIndexedLine(ls);
                        int seg = random.nextInt(numPoints);
                        double frac = random.nextDouble();
                        LinearLocation ll = new LinearLocation(seg, frac);
                        c = lil.extractPoint(ll);
                    } else {
                        c = v.getCoordinate();
                    }
                    // perturb
                    double distance = random.nextDouble() * radius;
                    double azimuth = random.nextDouble() * 360 - 180;
                    // double x = c.x + r * Math.cos(theta);
                    // double y = c.y + r * Math.sin(theta);
                    gc.setStartingGeographicPoint(c.x, c.y);
                    gc.setDirection(azimuth, distance);
                    Point2D dest = gc.getDestinationGeographicPoint();
                    String name = v.getName();
                    String[] entries = new String[] {
                            Integer.toString(i), name,
                            Double.toString(dest.getX()), Double.toString(dest.getY())
                    };
View Full Code Here

        /*
         * Need to synchronize because we use a single instance of a Map (CALCULATORS) as well as
         * shared instances of GeodeticCalculator and GeneralDirectPosition (POSITIONS). None of
         * them are thread-safe.
         */
        GeodeticCalculator gc = (GeodeticCalculator) CALCULATORS.get(crs);

        if (gc == null) {
            gc = new GeodeticCalculator(crs);
            CALCULATORS.put(crs, gc);
        }
        assert crs.equals(gc.getCoordinateReferenceSystem()) : crs;

        final GeneralDirectPosition pos = POSITIONS[Math.min(POSITIONS.length - 1, crs
                .getCoordinateSystem().getDimension())];
        pos.setCoordinateReferenceSystem(crs);
        copy(p1, pos.ordinates);
        gc.setStartingPosition(pos);
        copy(p2, pos.ordinates);
        gc.setDestinationPosition(pos);

        return gc.getOrthodromicDistance();
    }
View Full Code Here

     * @param crs CoordinateReferenceSystem for which to construct a new GridConvergenceAngleCalc.
     * @throws Exception
     */
    public GridConvergenceAngleCalc(CoordinateReferenceSystem crs) throws Exception {
        this.crs = crs;
        this.geoCalc = new GeodeticCalculator(this.crs);
        this.upAxisDimension = determineUpAxisDimension();
        //
        // If we could not find the "up" axis ... meaning up on the map/screen
        // not in the vertical ... then throw an exception
        //
View Full Code Here

TOP

Related Classes of org.geotools.referencing.GeodeticCalculator

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.