# （转载）一种根据纠偏数据对火星坐标进行完美拟合的方法

## 一种根据纠偏数据对火星坐标进行完美拟合的方法

(2011-02-15 13:30:27)

### it

（原创：小牙,QQ328959，转载请注明出处）

marsOffset.lat=m0.lat*coef0+m1.lat*coef1+m2.lat*coef2+m3.lat*coef3;

marsOffset.lng=m0.lng*coef0+m1.lng*coef1+m2.lng*coef2+m3.lng*coef3;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

using System.ComponentModel.Composition;

using System.Globalization;

using System.Windows;

using Microsoft.Practices.Prism.Commands;

using Microsoft.Practices.Prism.Regions;

using Microsoft.Practices.ServiceLocation;

using Microsoft.Practices.Prism.Events;

using SmartClient.Infrastructure;

using SmartClient.Infrastructure.Models;

using SmartClient.Modules.GPS.Comm;

using System.Windows.Resources;

namespace SmartClient.Modules.GPS

{

[Export(typeof(IRegulateService))]

[PartCreationPolicy(CreationPolicy.Shared)]

class RegulateService : IRegulateService

{

private const int REGULATE_ZOOM_COEF = 1000000; //经纬度放大系数，为了将校正数据的小数点部分换算成整数。0.1精度时为1000000

private int _stepNum = 1; //经纬度校正表，精度系数（0.1精度时） = 0.1 *  MapRegBig * ExpLong

private int _expLong = 10; //经纬度放大系数，为了将校正表格点的小数点部分换算成整数。0.1精度时为10

private int _minX = 0;

private int _maxX = 0;

private int _minY = 0;

private int _maxY = 0;

[ImportingConstructor]

public RegulateService()

{

StreamResourceInfo resourceInfo = Application.GetResourceStream(new Uri("/data/Regulate.dat", UriKind.Relative));

Byte[] regulateByte = null;

{

}

MemoryStream stream = new MemoryStream(regulateByte);

resourceInfo.Stream.Close();

_minX = ********;//此处涉及boboking的纠偏数据索引方法，不便提供

_maxX = ********;

_minY = ********;

_maxY = ********;

}

public MarsOffset getMarsOffset(Position position)

{

double latConvert = position.Latitude.DecimalDegrees * _expLong;

double lngConvert = position.Longitude.DecimalDegrees * _expLong;

//计算该真实坐标点四周的纠偏点坐标（上取整，下取整）

int x0 = (int)Math.Floor(latConvert),   y0 = (int)Math.Floor(lngConvert);

int x1 = (int)Math.Floor(latConvert),   y1 = (int)Math.Ceiling(lngConvert);

int x2 = (int)Math.Ceiling(latConvert), y2 = (int)Math.Ceiling(lngConvert);

int x3 = (int)Math.Ceiling(latConvert), y3 = (int)Math.Floor(lngConvert);

if(x0 < _minX || x1 > _maxX || y0 < _minY || y1 > _maxY)

return new MarsOffset(0.0, 0.0);

//根据四个周边点的取整（已放大），读取纠偏数据

MarsOffset mo0 = getRegulateData(x0, y0);

MarsOffset mo1 = getRegulateData(x1, y1);

MarsOffset mo2 = getRegulateData(x2, y2);

MarsOffset mo3 = getRegulateData(x3, y3);

//计算纠偏点影响系数

double coef0 = (x2 - latConvert) * (y2 - lngConvert);

double coef1 = (x3 - latConvert) * (lngConvert - y3);

double coef2 = (latConvert - x0) * (lngConvert - y0);

double coef3 = (latConvert - x1) * (y1 - lngConvert);

MarsOffset marsOffset = new MarsOffset();

marsOffset.latOffset = mo0.latOffset * coef0 + mo1.latOffset * coef1 + mo2.latOffset * coef2 + mo3.latOffset * coef3;

marsOffset.lngOffset = mo0.lngOffset * coef0 + mo1.lngOffset * coef1 + mo2.lngOffset * coef2 + mo3.lngOffset * coef3;

return marsOffset;

}

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace SmartClient.Infrastructure.Models

{

public struct MarsOffset

{

public double latOffset;

public double lngOffset;

public MarsOffset(double lat, double lng)

{

this.latOffset = lat;

this.lngOffset = lng;

}

}

}

（声明：本人无意破解任何算法，只是为美化显示效果做了以上工作，如您采用以上算法涉及任何法律问题，本人不承担相关责任。）

posted @ 2013-10-19 13:40  阿牛  阅读(1200)  评论(0编辑  收藏  举报