简体   繁体   中英

X,Y image coordinate to Latitude and Longitude with rotation

ok, i have these image overlay data from Google Earth, like this:

North: -7.340917
South: -7.34100
East: 112.751217
West: 112.751167
Rotation: 25.0000

and i have successfully converted my image point (x,y) to Lat, Lng with these functions:

static Double DEGREES_PER_RADIAN = 180 / Math.PI;
static Double RADIAN_PER_DEGREES = Math.PI / 180;

public static double Gudermannian(double y)
{
    return Math.atan(Math.sinh(y)) * DEGREES_PER_RADIAN;
}

public static double GudermannianInv(double latitude)
{
    double sign = Math.signum(latitude);
    double sin = Math.sin(latitude * RADIAN_PER_DEGREES * sign);
    return sign * (Math.log((1.0 + sin) / (1.0 - sin)) / 2.0);
}

Double mapLatNorth = -7.340917;
Double mapLatSouth = -7.34100;
Double mapLonWest = 112.751167;
Double mapLonEast = 112.751217;

Double ymax = GudermannianInv(mapLatNorth);
Double ymin = GudermannianInv(mapLatSouth);                 
Float latPoint = (float) Gudermannian(ymax - ( ((double) pointY / imgHeight) * (ymax - ymin) )) ;

Double mapLonDelta = mapLonEast - mapLonWest;
Float lngPoint = (float) (mapLonWest + pointX / imgWidth * mapLonDelta);

the values i get from

latPoint

and

lngPoint

is correct, however it is not rotated yet. my question is: how to rotate those Lat/Lng values 25 degrees?

i have failed to get Latitude/Longitude value from Ewan Todd 's answer at Calculate lat/lng of corners of ground overlay from kml-file

This should be possible by simple 2D rotation and should be like this:

public Float rotateLatitudeAround(Float lat, double angle, Point center) {
    lat = center.lat + (Math.cos(Math.toRadians(angle)) * (lat - center.lat) - Math.sin(Math.toRadians(angle)) * (lon - center.lon));
    return lat;
}

public Float rotateLongitudeAround(Float lon, double angle, Point center) {
    lon = center.lon + (Math.sin(Math.toRadians(angle)) * (lat - center.lat) + Math.cos(Math.toRadians(angle)) * (lon - center.lon));
    return lon;
}

but change

center.lat 

to

center.getLatitudeE6()/1E6 

or something.

EDIT: I did forget this will only work for points x,y. But you could first get the points of the lat, lon related to the maps' projections center and after it getting back the lat, lon values from the projections reverse map?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM