GIS面积计算问题

好长时间不更新了,今天说点干货,项目用到的。

1、项目中要用到计算面积的,根据火星坐标;

2、百度找了各种面积计算,google了半天,也没发现那个比较准确;

直接说干货吧。咱也高大上一会,用 ArcGIS

需要的dll有 ESRI.ArcGIS.Client.Toolkit.dll 和 ESRI.ArcGIS.Client.dll 这两个dll即可,不需要那么多的dll,可到官网下载,也可以到dll之家下载(http://www.dllzj.com/ESRI.ArcGIS.Client.dll/

计算面积的代码,这个代码比较简单

 GeometryService geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
 Polygon polygon = new Polygon();
 polygon.SpatialReference = new SpatialReference(4326);//球面坐标
 PointCollection GPSpoints = new PointCollection();//保存84坐标的集合
 for (int i = 0; i < arraytemp.Count; i++)
 {
   JArray arraystr = (JArray)JsonConvert.DeserializeObject(arraytemp[i].ToString());
   GPSpoints.Add(new MapPoint(Convert.ToDouble(arraystr[0].ToString()), Convert.ToDouble(arraystr[1].ToString())));
 }
  polygon.Rings.Add(GPSpoints);

 Graphic graphic = new Graphic();
 graphic.Geometry = polygon;
 IList graphicList = new List(); //构建参数
 graphicList.Add(graphic);
 graphicList = geometryService.Project(graphicList, new SpatialReference(102100));//执行转换
 var args = geometryService.AreasAndLengths(graphicList, LinearUnit.Meter, LinearUnit.Meter, CalculationType.Geodesic);//Geodesic 采用球面面积计算方式 102113
 area = args.Areas[0];

 说下其中的注意点,其中4326指的84坐标,但是国内的地图一般都是火星坐标(腾讯和高德,百度更闹心,直接是自己的坐标),就是加了偏移量的,具体的84坐标和火星坐标的转化,这个可能比较常见,代码如下

        public static string BAIDU_LBS_TYPE = "bd09ll";

        public static double pi = 3.1415926535897932384626;
        public static double a = 6378245.0;
        public static double ee = 0.00669342162296594323;

        /**
         * 84 to 火星坐标系 (GCJ-02) World Geodetic System ==> Mars Geodetic System
         * 
         * @param lat
         * @param lon
         * @return
         */
        public static Gps gps84_To_Gcj02(double lat, double lon)
        {
            if (outOfChina(lat, lon))
            {
                return null;
            }
            double dLat = transformLat(lon - 105.0, lat - 35.0);
            double dLon = transformLon(lon - 105.0, lat - 35.0);
            double radLat = lat / 180.0 * pi;
            double magic = Math.Sin(radLat);
            magic = 1 - ee * magic * magic;
            double sqrtMagic = Math.Sqrt(magic);
            dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
            dLon = (dLon * 180.0) / (a / sqrtMagic * Math.Cos(radLat) * pi);
            double mgLat = lat + dLat;
            double mgLon = lon + dLon;
            return new Gps(mgLat, mgLon);
        }

        /**
         * * 火星坐标系 (GCJ-02) to 84 * * @param lon * @param lat * @return
         * */
        public static Gps gcj_To_Gps84(double lat, double lon)
        {
            Gps gps = transform(lat, lon);
            double lontitude = lon * 2 - gps.getWgLon();
            double latitude = lat * 2 - gps.getWgLat();
            return new Gps(latitude, lontitude);
       

你可能感兴趣的:(java)