美文网首页
四参数反算以及百度鹰眼绑定

四参数反算以及百度鹰眼绑定

作者: 山华水清 | 来源:发表于2017-12-09 13:36 被阅读27次

    近来有轨迹平滑的需求,发现虽然轨迹平滑了,但是随之而来的是平滑后的轨迹会压盖房子,这就让人无法忍受了。遂放弃,发现我的数学功底不是一般的差,对于底层算法的实现有待提高,加油。还有就是试着把GPS转为平面坐标的点转为WGS84显示到百度里面,使用其鹰眼功能实现去噪,绑路等功能。先这样吧,到时候需要的时候再研究,那时候可能就会出现非吴下阿蒙的我了。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using GeoAPI.CoordinateSystems;
    using GeoAPI.CoordinateSystems.Transformations;
    using LeadMap.Framework.DBProvider;
    using LmDataHandler;
    using LmDataHandler.Utility;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using ProjNet.Converters.WellKnownText;
    using ProjNet.CoordinateSystems;
    using ProjNet.CoordinateSystems.Transformations;
    using RestSharp;
    
    namespace UnitTest
    {
        [TestClass]
        public class UnitTest2
        {
            [TestMethod]
            public void TestMethod1()
            {
                //var wgs84Point = ConvertBj542Wgs84(91670.304, 73375.385);           
                //var dfp= transfer(bj54p[1], bj54p[0], 1, d, -3266736.9496, -439821.9753);
    
                DataBase.sysType = SysType.BS;
                var points = GetPatrolPoints("36798");
                points.ForEach(p =>
                {
                    var cp = P2WGS84(p.Lat, p.Lon);
                    p.Lat = cp[1];
                    p.Lon = cp[0];
                });
                //循环通过restsharp取得坐标点
                int pagesize = 90;
                double pagecount = Math.Ceiling(points.Count / pagesize.Getdouble());
                for (int i = 0; i < pagecount; i++)
                {
                    var pp = points.Skip(i * pagesize).Take(pagesize).ToList();
                    var client = new RestClient("http://yingyan.baidu.com/api/v3/track/addpoints");
                    var request = new RestRequest(Method.POST);
                    request.AddParameter("ak", "AiyoOjdlW2ahgt0uoG2olod2t1dPhx99");
                    request.AddParameter("service_id", "155954");
                    JsonArray jArray = new JsonArray();
                    for (int j = 0; j < pp.Count(); j++)
                    {
                        JsonObject jo = new JsonObject()
                        {
                            {"entity_name", "leadmap02"},
                            {"latitude", pp[j].Lat},
                            {"longitude", pp[j].Lon},
                            {"loc_time", pp[j].Time.DateTimeToUnixTimestamps()},
                            {"coord_type_input", "wgs84"},
                            {"speed", pp[j].Vel},
                        };
                        jArray.Add(jo);
                    }
                    request.AddParameter("point_list", jArray.ToString());
                    IRestResponse response = client.Execute(request);
                    var content = response.Content;
                }
            }
    
            private List<PatrolPoint> GetPatrolPoints(string id)
            {
                var strsql = string.Format(@" select * from TAB_LMPATROLGPSPOINT{1} where PatrolId='{0}' order by Time,No ",
                    id, "201710");
                var pointdt = DataBase.ExecuteDataTable(strsql, DataBase.Gpsconn);
                if (pointdt != null && pointdt.Rows.Count > 0)
                {
                    return DbParameterUtility.ConvertDataTable2ListsP<PatrolPoint>(pointdt).ToList();
                }
                return new List<PatrolPoint>();
            }
    
            private double[] P2WGS84(double x, double y)
            {
                double d = (4.0 / 60.0) + (35.048000 / 3600);
                var mapPoint = transferP(x, y, 1, d, -3266736.9496, -439821.9753);
                return ConvertBj542Wgs84(mapPoint.Y, mapPoint.X);
            }
    
            private double[] ConvertBj542Wgs84(double lat, double lon)
            {
                IProjectedCoordinateSystem fromCS = CoordinateSystemWktReader.Parse(
                        "PROJCS[\"Beijing 1954 / 3-degree Gauss-Kruger CM 120E\",GEOGCS[\"Beijing 1954\",DATUM[\"Beijing_1954\",SPHEROID[\"Krassowsky 1940\",6378245,298.3,AUTHORITY[\"EPSG\",\"7024\"]],TOWGS84[15.8,-154.4,-82.3,0,0,0,0],AUTHORITY[\"EPSG\",\"6214\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4214\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",120],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"2437\"]]")
                    as IProjectedCoordinateSystem;
                GeographicCoordinateSystem toCS = GeographicCoordinateSystem.WGS84;
                CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();
                ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(fromCS, toCS);
                return trans.MathTransform.Transform(new double[] {lat, lon});
            }
    
    
            private double[] ConvertWgs84Bj54(double lat, double lon)
            {
                IProjectedCoordinateSystem fromCS = CoordinateSystemWktReader.Parse(
                        "PROJCS[\"Beijing 1954 / 3-degree Gauss-Kruger CM 120E\",GEOGCS[\"Beijing 1954\",DATUM[\"Beijing_1954\",SPHEROID[\"Krassowsky 1940\",6378245,298.3,AUTHORITY[\"EPSG\",\"7024\"]],TOWGS84[15.8,-154.4,-82.3,0,0,0,0],AUTHORITY[\"EPSG\",\"6214\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4214\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",120],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"2437\"]]")
                    as IProjectedCoordinateSystem;
                GeographicCoordinateSystem toCS = GeographicCoordinateSystem.WGS84;
                CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();
                ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(toCS, fromCS);
                return trans.MathTransform.Transform(new double[] {lat, lon});
            }
    
            private Point movePoint(Point point)
            {
                return new Point(point.getX() - 13.8747376725019, point.getY() + 10);
            }
    
    
            private Point transfer(double x_put, double y_put, double k, double red, double dx, double dy)
            {
                Point point = new Point();
                double x_out;
                double y_out;
    
                y_out = x_put * k * Math.Cos(red / 180 * Math.PI) - y_put * k * Math.Sin(red / 180 * Math.PI) + dx;
                x_out = x_put * k * Math.Sin(red / 180 * Math.PI) + y_put * k * Math.Cos(red / 180 * Math.PI) + dy;
    
                point.setXY(x_out, y_out);
                point.X = point.X - 13.8747376725019;
                point.Y = point.Y + 10;
    
                return point;
            }
    
            private Point transferP(double x_out, double y_out, double k, double red, double dx, double dy)
            {
                Point point = new Point();
                double x_put;
                double y_put;
    
                x_out = x_out + 13.8747376725019;
                y_out = y_out - 10;
                x_put = (Math.Cos(red / 180 * Math.PI) * (y_out - dx) + Math.Sin(red / 180 * Math.PI) * (x_out - dy)) *
                        (1 / k);
                y_put = (Math.Cos(red / 180 * Math.PI) * (x_out - dy) - Math.Sin(red / 180 * Math.PI) * (y_out - dx)) *
                        (1 / k);
    
                point.setXY(x_put, y_put);
                return point;
            }
        }
    }
    
    public class Point
    {
        public double X { get; set; }
        public double Y { get; set; }
    
        public Point()
        {
        }
    
        public Point(double x, double y)
        {
            this.X = x;
            this.Y = y;
        }
    
        public void setXY(double x, double y)
        {
            this.X = x;
            this.Y = y;
        }
    
        public double getX()
        {
            return this.X;
        }
    
        public double getY()
        {
            return this.Y;
        }
    }
    

    相关文章

      网友评论

          本文标题:四参数反算以及百度鹰眼绑定

          本文链接:https://www.haomeiwen.com/subject/mmiuixtx.html