提问者:小点点

将纬度/经度转换为简单圆柱投影上的图像坐标(像素坐标)


我从谷歌地球拍摄了一张图像,其所有 4 个角的纬度/经度都是已知的。我正在使用GPS传感器捕获纬度/经度。我必须使用 java 将这些捕获的纬度/经度转换为图像坐标(像素坐标)。我将使用图像坐标来模拟车辆在静态地图上移动(图像取自谷歌地球)。

我找到了这个公式并尝试实现它

    < li >确定1653x1012图像中最左侧的经度(X) < li >确定1653x1012图像中最东边的经度(Y) < li >确定经度-差异(Z = Y - X) < li >确定1653x1012图像的最北端纬度(A) < li >确定1653x1012图像(B)中最南边的纬度 < li >确定纬度-Diff (C = A - B)给定纬度和经度,以确定他们单击了哪个像素:

J =输入经度K =输入纬度

计算X像素

XPixel = CInt(((Y - J) / CDbl(Z)) * 1653)

计算Y像素

YPixel = CInt(((A - K) / CDbl(C)) * 1012)

这是我用的代码。

    import java.awt.geom.Point2D;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.util.ArrayList;
    import java.util.List;

    public class LatLongService {
        private static LatLongService latLangService;
        private BufferedReader reader = null;
        private String st;

        private LatLongService() {
            try {
                reader = new BufferedReader(new FileReader(new File(
                        "resources/GPS_lat_long_2.txt")));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public static LatLongService getInstance() {
            if (latLangService == null)
                latLangService = new LatLongService();
            return latLangService;
        }

        public List<Point2D> readLatLongList() {
            List<Point2D> pointList = new ArrayList<Point2D>();
            StringBuffer xStr;
            StringBuffer yStr = new StringBuffer();
            try {
                while ((st = reader.readLine()) != null) {
                    xStr = new StringBuffer(st.substring(0, st.indexOf(',')));
                    yStr = new StringBuffer(st.substring(st.indexOf(',') + 2,
                            st.length()));
                    Point2D pt = new Point2D.Double(
                            new Double(xStr.toString()).doubleValue(), new Double(
                                    yStr.toString()).doubleValue());
                    pointList.add(pt);
                }
            } catch (Exception e) {
                e.printStackTrace();
                try {
                    reader.close();
                } catch (Exception e2) {
                    e.printStackTrace();
                }
            }
            return pointList;
        }


    public List<Point2D> convertLatLongToCoord(List<Point2D> coordinate) {
            List<Point2D> latLong = new ArrayList<Point2D>();
            double westMostLong = -79.974642;
            double eastMostLong = -79.971244;
            double longDiff = eastMostLong - westMostLong; // (rightmost_longitude -
                                                            // leftmost_longitude)

            double northMostLat = 39.647556;
            double southMostLat = 39.644675;
            double latDiff = northMostLat - southMostLat; // (topmost_latitude -
                                                            // bottommost_latitude)
            for (Point2D coord : coordinate) {
                double j = coord.getY();
                double k = coord.getX();

                double XPixel = (((eastMostLong - j) / longDiff) * 1653);
                double YPixel = (((northMostLat - k) / latDiff) * 1012);

                Point2D actualCoord = new Point2D.Double(XPixel, YPixel);
                latLong.add(actualCoord);
            }
            return latLong;
        }
    }

我从GPS传感器获得的一些GPS纬度/长度

输入纬度输入经度(39.64581,-79.97168) (39.64651,-79.97275) (39.646915,-79.97342) (39.646538,-79.97279)

[IMG]http://i59 . tinypic . com/nbqkk 3 . png[/IMG]

图中的红线显示了传感器获取GPS坐标时遵循的路径。

然而,当我使用此公式将Lat/Long坐标转换为像素坐标时。转换后的像素坐标不一致,如下图所示:

图 X 图像 Y (212.0977045, 613.3120444) (732.6127134, 367.4251996) (1058.542672, 225.1620965) (752.0712184, 357.5897258)

X,Y(像素)坐标的变化太大。因此,当我尝试根据像素坐标移动车辆时,车辆不会遵循红线或至少接近红线。

车辆在红线上方或红线下方移动,但不在红线上移动。

对于基于像素坐标的车辆平滑移动,理想情况下,我希望从纬度/经度到图像坐标的转换如下:

所需图像X所需图像Y (1290,409) (1289,409) (1288,409) (1287,409)

但我要买这个。

图 X 图像 Y (212.0977045, 613.3120444) (732.6127134, 367.4251996) (1058.542672, 225.1620965) (752.0712184, 357.5897258)

我希望我能够传达我的问题。


共2个答案

匿名用户

纬度和经度不是距离。

http://geography . about . com/cs/latitude longitude/a/latlong . htm

我最近从事了一个使用GPS的Arduino项目。我遵循了将纬度和经度转换为北向和东向 (UTM) 的微型地理 API 方法。

使用链接中的库,你可以完成这个转换:http://www.ibm.com/developerworks/library/j-coordconvert/

然后得到最大的东向和北向并计算尺度

private synchronized void scale() {
        int w = 800;
        int h = 600;

        this.scale = Math.min(
                w / (maxEasting - minEasting),
                h / (maxNorthing - minNorthing));

        oEasting = minEasting;
        oNorthing = minNorthing;
    }

转换成X和Y

private int applyScale(double km) {
        return (int) (km * scale);
    }

    private int convertX(double easting) {
        return applyScale(easting - oEasting);
    }

    private int convertY(double northing, int height) {
        return 600/*height*/ - applyScale(northing - oNorthing);
    }

来源:微地理

匿名用户

下面的代码可以编译并回答你的问题

[1] (39.64581,-79.97168) -> 102,363
[2] (39.64651,-79.97275) -> 354,217
[3] (39.646915,-79.97342) -> 512,133
[4] (39.646538,-79.97279) -> 363,212
[5] (39.646458,-79.97264) -> 328,228

您可能已互换 x-y 坐标。在这种情况下,x == 经度,y == 纬度。

import java.util.*;
import java.awt.geom.*;

public class LatLong {

        private  int  imageW,  imageH;
        private final static   double   west = -79.974642,      north = 39.647556,
                                        east = -79.971244,      south = 39.644675;

        public LatLong (int w, int h) {
                imageW = w;
                imageH = h;
        }

        public List<Point2D> convertLatLongToCoord (List<Point2D> coordinate) {
            List<Point2D> latLong = new ArrayList<Point2D>();
            for (Point2D coord : coordinate) {
                double  x = coord.getY(),       px = imageW * (x-east) / (west-east),
                        y = coord.getX(),       py = imageH * (y-north)/(south-north);
                latLong.add (new Point2D.Double(px,py));
            }
            return latLong;
        }

        public static void main (String[] args) {
                double[] latit = {39.64581, 39.64651, 39.646915, 39.646538, 39.646458},
                        longit = {-79.97168, -79.97275, -79.97342, -79.97279, -79.97264};

                List<Point2D> pointList = new ArrayList<Point2D>();
                for (int i = 0 ; i < latit.length ; i++)
                        pointList.add (new Point2D.Double(latit[i], longit[i]));

                List<Point2D> pixels = new LatLong (800,600).convertLatLongToCoord (pointList);

                for (int i = 0 ; i < latit.length ; i++)
                        System.out.println ("[" + (i+1) + "]\t(" + latit[i] + "," + longit[i] + ") -> " +
                                (int) (pixels.get(i).getX()) + "," + (int) (pixels.get(i).getY()));
}}