java - 生成圆半径坐标到KML中的坐标

标签 java kml

我有圆心和半径的坐标。我需要知道圆的坐标,以便在 KML 中添加圆。

我编写了一个生成较低位置的脚本,但当插入到 KML 中时,他使它们变成椭圆而不是圆圈。帮助理解什么是什么?

import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
int[] a = new int[10];
double[] ar1;
double  ar2[];
    a[1]=5;

    double centerLat = (44.507693* Math.PI) / 180.0;  //rad
    double centerLng = (34.152739* Math.PI) / 180.0; //rad        
    double dist = 1/ 6371.0; 
    double lan;
     for (int x = 0; x <= 360; x += 1)
    {
        double brng = x * Math.PI / 180.0;         //rad
        double latitude = Math.asin(Math.sin(centerLat) * Math.cos(dist) +    Math.cos(centerLat) * Math.sin(dist) * Math.cos(brng));
        double longitude = ((centerLng + Math.atan2(Math.sin(brng) *   Math.sin(dist)* Math.cos(centerLat), Math.cos(dist) - Math.sin(centerLat) 
        * Math.sin(latitude))) * 180.0) / Math.PI;
        lan=(latitude * 180.0) / Math.PI; //, longitude));
        System.out.println(""+lan+"  "+longitude );
    }
}

}

最佳答案

你的公式是正确的。下面是完整的 Java 代码,用于生成圆的坐标并输出为具有多边形几何形状的 KML 地标。

public class Codechef {

  public static void main(String[] args) {

    double centerLat = Math.toRadians(44.507693);
    double centerLng = Math.toRadians(34.152739);
    double diameter = 1; // diameter of circle in km
    double dist = diameter / 6371.0; 

    // start generating KML
    System.out.println("<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n"+
        "<Placemark><Polygon><outerBoundaryIs><LinearRing><coordinates>");

    for (int x = 0; x <= 360; x ++)
    {
        double brng = Math.toRadians(x);
        double latitude = Math.asin(Math.sin(centerLat) * Math.cos(dist) + Math.cos(centerLat) * Math.sin(dist) * Math.cos(brng));
        double longitude = 
        centerLng + Math.atan2(Math.sin(brng) * Math.sin(dist)* Math.cos(centerLat), Math.cos(dist) - Math.sin(centerLat)
            * Math.sin(latitude)) ;
        System.out.printf(" %f,%f", Math.toDegrees(longitude), Math.toDegrees(latitude));
    }
    System.out.println("</coordinates></LinearRing></outerBoundaryIs></Polygon>");
    System.out.println("</Placemark></kml>");
    }

}

关于java - 生成圆半径坐标到KML中的坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35774756/

相关文章:

java - 更改类实例中函数的主体

java - 当映射包含 DTO 列表的对象成功时,为什么映射 DTO 列表会失败?

python - KML 到 Python 中的字符串?

java - 使用 BLOB 对象将图像插入 SQL 表时出现异常

java - 类级约束验证错误使 Arjuna TwoPhaseCoordinator.beforeCompletion 失败

java - 处理来自 @Service 类的 JSP 页面异常

google-maps - KML 文件中的缩放级别

java - 如何使用 Java 从 KML 即时创建 KMZ 文件

javascript - Google Maps API KML 图层限制

google-maps - 将大型 KML 分解为多个(较小的)KML