本文整理汇总了Java中org.geotools.referencing.GeodeticCalculator类的典型用法代码示例。如果您正苦于以下问题:Java GeodeticCalculator类的具体用法?Java GeodeticCalculator怎么用?Java GeodeticCalculator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GeodeticCalculator类属于org.geotools.referencing包,在下文中一共展示了GeodeticCalculator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDistance
import org.geotools.referencing.GeodeticCalculator; //导入依赖的package包/类
/**
* Returns the distance between two coordinates given as longitude and
* latitude
*
* @param firstLongitude
* @param firstLatitude
* @param secondLongitude
* @param secondLatitude
* @return distance (round to long)
*/
public static Long getDistance(final Double firstLongitude, final Double firstLatitude, final Double secondLongitude, final Double secondLatitude) {
Double distance = 0.0;
final GeodeticCalculator cal = new GeodeticCalculator();
cal.setStartingGeographicPoint(firstLongitude, firstLatitude);
cal.setDestinationGeographicPoint(secondLongitude, secondLatitude);
distance = cal.getOrthodromicDistance();
final int totalmeters = distance.intValue();
final int km = totalmeters / 1000;
float remaining_cm = (float) (distance - totalmeters) * 10000;
remaining_cm = Math.round(remaining_cm);
// System.out.println("Distance = " + km + "km " + meters + "m " + cm +
// "cm");
return distance.longValue();
}
示例2: mouseMoved
import org.geotools.referencing.GeodeticCalculator; //导入依赖的package包/类
public void mouseMoved(Point imagePosition,Object glContext) {
this.imagePosition = imagePosition;
if (active) {
try{
if (initPosition != null) {
GeodeticCalculator gc=Positioning.computeDistance(LayerManager.getIstanceManager().getCurrentImageLayer().getImageReader().getGeoTransform(),initPosition,endPosition,imagePosition);
//pd.setDistance(""+Math.sqrt((init[0]-end[0])*(init[0]-end[0])+(init[1]-end[1])*(init[1]-end[1]))+" Meters");
pd.setDistance("" + (float)(Math.round(gc.getOrthodromicDistance()*1000))/1000 + " Meters");
}
pd.setImagePosition(imagePosition);
}catch(Exception e){
logger.warn(e.getMessage());
}
}
}
示例3: mouseClicked
import org.geotools.referencing.GeodeticCalculator; //导入依赖的package包/类
public void mouseClicked(Point imagePosition, int button,Object graphicContext) {
if (pd.getCheckDistance()) {
if (initPosition == null) {
initPosition = imagePosition;
} else if (endPosition == null) {
endPosition = imagePosition;
try{
GeodeticCalculator gc=Positioning.computeDistance(LayerManager.getIstanceManager().getCurrentImageLayer().getImageReader().getGeoTransform(),initPosition,endPosition,imagePosition);
pd.setDistance("" + (float)(Math.round(gc.getOrthodromicDistance()*1000))/1000 + " Meters");
}catch(Exception e){
logger.warn(e.getMessage());
}
} else {
initPosition = null;
endPosition = null;
pd.setDistance("NA");
}
}
}
示例4: calcPixelSize
import org.geotools.referencing.GeodeticCalculator; //导入依赖的package包/类
public void calcPixelSize()
{
double[] pixelsize = {0.0, 0.0};
// should be in the image reader class
// get pixel size
double[] latlonorigin = getGeoFromPixel(0, 0, "EPSG:4326");
double[] latlon = getGeoFromPixel(100, 0, "EPSG:4326");
// use the geodetic calculator class to calculate distances in meters
GeodeticCalculator gc = new GeodeticCalculator();
gc.setStartingGeographicPoint(latlonorigin[0], latlonorigin[1]);
gc.setDestinationGeographicPoint(latlon[0], latlon[1]);
pixelsize[0] = gc.getOrthodromicDistance() / 100;
latlon = getGeoFromPixel(0, 100, "EPSG:4326");
gc.setDestinationGeographicPoint(latlon[0], latlon[1]);
pixelsize[1] = gc.getOrthodromicDistance() / 100;
this.pixelSize=pixelsize;
}
示例5: getImageAzimuth
import org.geotools.referencing.GeodeticCalculator; //导入依赖的package包/类
/**
*
*/
public double getImageAzimuth(){
double az = 0;
try{
//compute the azimuth considering the two left corners of the image
//azimuth angle in degrees between 0 and +180
double[] endingPoint = getGeoTransform().getGeoFromPixel(getWidth() / 2, 0);//, "EPSG:4326");
double[] startingPoint = getGeoTransform().getGeoFromPixel(getWidth() / 2, getHeight() - 1);//, "EPSG:4326");
GeodeticCalculator gc = new GeodeticCalculator();
gc.setStartingGeographicPoint(startingPoint[0], startingPoint[1]);
gc.setDestinationGeographicPoint(endingPoint[0], endingPoint[1]);
az = gc.getAzimuth();
}catch(GeoTransformException ge){
logger.warn(ge.getLocalizedMessage());
}
return az;
}
示例6: distance
import org.geotools.referencing.GeodeticCalculator; //导入依赖的package包/类
public static Vector3D distance(GeoPoint p, GeoPoint q) {
GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(p.lon, p.lat);
calc.setDestinationGeographicPoint(q.lon, q.lat);
double dist = calc.getOrthodromicDistance();
double alpha = calc.getAzimuth(); // The azimuth, in decimal degrees
// from -180° to +180°.
Rotation r = new Rotation(RotationOrder.ZXZ, 0, 0,
-FastMath.toRadians(alpha));
Vector3D trip = r.applyTo(new Vector3D(0, 1, 0)).scalarMultiply(dist);
trip = new Vector3D(trip.getX(), trip.getY(), q.ele - p.ele);
// in meters
return trip;
}
示例7: getDestinationFrom
import org.geotools.referencing.GeodeticCalculator; //导入依赖的package包/类
public GPXEntry getDestinationFrom(GPXEntry v) {
// assert time.after(v.time);
double x = getX();
double y = getY();
double z = getZ();
Vector3D mirror = new Vector3D(y, x, z);
// Velocity newv = new Velocity(
// new Vector3D(v.getY(), v.getX(), v.getZ()), v.time.getTime());
// reference:
// http://stackoverflow.com/questions/3917340/geotools-how-to-do-dead-reckoning-and-course-calculations-using-geotools-class
GeodeticCalculator calc = new GeodeticCalculator();
// It's odd! setStartingGeographicPoint accept longitude first
calc.setStartingGeographicPoint(v.lon, v.lat);
// calc.setDirection(FastMath.toDegrees(Math.PI / 2 - v.getAzimuth()),
// v.getHorizontalSpeed() * diff);
calc.setDirection(FastMath.toDegrees(mirror.getAlpha()), getNorm());
Point2D p = calc.getDestinationGeographicPoint();
// It's odd! getDestinationGeographicPoint returns longitude first
return new GPXEntry(p.getY(), p.getX(), getZ(), time.getTime());
}
示例8: calculateOrthometricLength
import org.geotools.referencing.GeodeticCalculator; //导入依赖的package包/类
/**
* This method calculates the orthometric length in meters of a LineString
* given in SRID EPSG:4326. LineString must be in WGS84 (EPSG:4326). If no
* SRID defined or other SRID defined than EPSG:4326 the method will return
* 0. Furthermore 0 is returned, if the LineString is null.
*
* @param line
* @param calc
* @return
*/
public static double calculateOrthometricLength(LineString line) {
double distance = 0;
if (line != null) {
if (line.getSRID() == 4326) {
GeodeticCalculator calc = new GeodeticCalculator();
for (int i = 0; i < line.getCoordinates().length - 1; i++) {
Coordinate p1 = line.getCoordinates()[i];
Coordinate p2 = line.getCoordinates()[i + 1];
calc.setStartingGeographicPoint(p1.x, p2.y);
calc.setDestinationGeographicPoint(p2.x, p2.y);
distance += calc.getOrthodromicDistance();
}
}
}
return distance;
}
示例9: testWithGeotools
import org.geotools.referencing.GeodeticCalculator; //导入依赖的package包/类
public void testWithGeotools() throws MatrixException {
Coordinate c1 = new Coordinate(11, 46, 0);
Coordinate c2 = new Coordinate(11.001, 46.001, 0);
GeodeticCalculator gc = new GeodeticCalculator(DefaultGeographicCRS.WGS84);
gc.setStartingGeographicPoint(c1.x, c1.y);
gc.setDestinationGeographicPoint(c2.x, c2.y);
double orthodromicDistance = gc.getOrthodromicDistance();
ENU enu = new ENU(c1);
Coordinate ce1 = enu.wgs84ToEnu(c1);
Coordinate ce2 = enu.wgs84ToEnu(c2);
double distance = ce1.distance(ce2);
assertTrue(isDeltaOk(orthodromicDistance, distance));
Coordinate c1Back = enu.enuToWgs84(ce1);
Coordinate c2Back = enu.enuToWgs84(ce2);
assertEquals(0, c1.distance(c1Back), 0.000001);
assertEquals(0, c2.distance(c2Back), 0.000001);
}
示例10: distanceInCrs
import org.geotools.referencing.GeodeticCalculator; //导入依赖的package包/类
private double distanceInCrs(double inMeters,
double[] refXY,
CoordinateReferenceSystem crs) throws TransformException {
double dist = 0;
// calculate the distance in meters of 0.01 * refY in the ref CRS
double[] sp = {refXY[0], refXY[1]};
double[] dp = {refXY[0], refXY[1] * 1.01};
GeodeticCalculator gc = new GeodeticCalculator(crs);
gc.setStartingPosition(new DirectPosition2D(crs, sp[0], sp[1]));
gc.setDestinationPosition(new DirectPosition2D(crs, dp[0], dp[1]));
double refY01InMeters = gc.getOrthodromicDistance();
// now, calculate the CRS distance as a proportional of 0.01 * refY
dist = inMeters * (refXY[1] * 0.01) / refY01InMeters;
return dist;
}
示例11: getUnitLength
import org.geotools.referencing.GeodeticCalculator; //导入依赖的package包/类
private double getUnitLength(String mapCrsKey, Bbox mapBounds) throws LayerException {
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);
}
}
示例12: computeDistance
import org.geotools.referencing.GeodeticCalculator; //导入依赖的package包/类
public static GeodeticCalculator computeDistance(GeoTransform gt,Point initPosition,Point endPosition,Point imagePosition) throws GeoTransformException {
double[] init = gt.getGeoFromPixel(initPosition.x, initPosition.y);
double[] end = null;
GeodeticCalculator gc = new GeodeticCalculator();
//Point2D initPoint = new Point2D.Double(init[1], init[0]);
gc.setStartingGeographicPoint(init[0], init[1]);
//Point2D endPoint = null;
if (endPosition != null) {
end = gt.getGeoFromPixel(endPosition.x, endPosition.y);
//endPoint = new Point2D.Double(end[1], end[0]);
gc.setDestinationGeographicPoint(end[0], end[1]);
} else {
end = gt.getGeoFromPixel(imagePosition.x, imagePosition.y);
//endPoint = new Point2D.Double(end[1], end[0]);
gc.setDestinationGeographicPoint(end[0], end[1]);
}
return gc;
}
示例13: getImageAzimuth
import org.geotools.referencing.GeodeticCalculator; //导入依赖的package包/类
public double getImageAzimuth() throws GeoTransformException {
double az = 0;
//compute the azimuth considering the two left corners of the image
//azimuth angle in degrees between 0 and +180
double[] endingPoint = getGeoTransform().getGeoFromPixel(getWidth() / 2, 0);
double[] startingPoint = getGeoTransform().getGeoFromPixel(getWidth() / 2, getHeight() - 1);
GeodeticCalculator gc = new GeodeticCalculator();
gc.setStartingGeographicPoint(startingPoint[0], startingPoint[1]);
gc.setDestinationGeographicPoint(endingPoint[0], endingPoint[1]);
az = gc.getAzimuth();
return az;
}
示例14: getBoxShape
import org.geotools.referencing.GeodeticCalculator; //导入依赖的package包/类
/**
* Returns boundaries of a box shape which centre is the point defined by the
* given longitude and latitude. The distance between the center point and the
* edges of the box is defined in meters by the given distance. Based on standard
* EPSG:4326 long/lat projection. The result is an array of length 4 where
* the values at each index are:
*
* <ul>
* <li>Index 0: Maximum latitude (north edge of box shape).</li>
* <li>Index 1: Maxium longitude (east edge of box shape).</li>
* <li>Index 2: Minimum latitude (south edge of box shape).</li>
* <li>Index 3: Minumum longitude (west edge of box shape).</li>
* </ul>
*
* @param longitude the longitude.
* @param latitude the latitude.
* @param distance the distance in meters to each box edge.
* @return an array of length 4.
*/
public static double[] getBoxShape( double longitude, double latitude, double distance )
{
double[] box = new double[4];
GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint( longitude, latitude );
calc.setDirection( 0, distance );
Point2D north = calc.getDestinationGeographicPoint();
calc.setDirection( 90, distance );
Point2D east = calc.getDestinationGeographicPoint();
calc.setDirection( 180, distance );
Point2D south = calc.getDestinationGeographicPoint();
calc.setDirection( -90, distance );
Point2D west = calc.getDestinationGeographicPoint();
box[0] = north.getY();
box[1] = east.getX();
box[2] = south.getY();
box[3] = west.getX();
return box;
}
示例15: getDistanceBetweenTwoPoints
import org.geotools.referencing.GeodeticCalculator; //导入依赖的package包/类
/**
* Computes the distance between two points.
*
* @param from the origin point.
* @param to the end point.
* @return the orthodromic distance between the given points.
*/
public static double getDistanceBetweenTwoPoints( Point2D from, Point2D to)
{
GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint( from );
calc.setDestinationGeographicPoint( to);
return calc.getOrthodromicDistance();
}