4字节 经纬度_以一个经纬度为中心计算出四个顶点

public const double EARTH_RADIUS = 6378137.0;//地球半径(m)

///

/// 以一个经纬度为中心计算出四个顶点

///

/// 半径(米)

///

public static Degree[] GetDegreeCoordinates(Degree Degree1, double distance)

{

double dlng = 2 * Math.Asin(Math.Sin(distance / (2 * EARTH_RADIUS)) / Math.Cos(Degree1.X));

dlng = degrees(dlng);//一定转换成角度数 原PHP文章这个地方说的不清楚根本不正确 后来lz又查了很多资料终于搞定了

double dlat = distance / EARTH_RADIUS;

dlat = degrees(dlat);//一定转换成角度数

return new Degree[] { new Degree(Math.Round(Degree1.X + dlat,6), Math.Round(Degree1.Y - dlng,6)),//left-top

new Degree(Math.Round(Degree1.X - dlat,6), Math.Round(Degree1.Y - dlng,6)),//left-bottom

new Degree(Math.Round(Degree1.X + dlat,6), Math.Round(Degree1.Y + dlng,6)),//right-top

new Degree(Math.Round(Degree1.X - dlat,6), Math.Round(Degree1.Y + dlng,6)) //right-bottom

};

}

///

/// 角度数转换为弧度公式

///

///

///

private static double radians(double d)

{

return d * Math.PI / 180.0;

}

///

/// 弧度转换为角度数公式

///

///

///

private static double degrees(double d)

{

return d * (180 / Math.PI);

}

///

/// 代表经度, 纬度

///

public class Poin

{

/// 纬度 X

/// 经度 Y

public Poin(double lat, double lng)

{

this.lat = lat;

this.lng = lng;

}

// 纬度 X

private double lat;

// 经度 Y

private double lng;

///

/// 代表纬度 X轴

///

public double Lat { set; get; }

///

/// 代表经度 Y轴

///

public double Lng { get; set; }

public double RadLat { get { return lat * Math.PI / 180; } }

public double RadLng { get { return lng * Math.PI / 180; } }

}

///

/// 经纬度坐标

///

public class Degree

{

public Degree(double x, double y)

{

X = x;

Y = y;

}

private double x;

public double X

{

get { return x; }

set { x = value; }

}

private double y;

public double Y

{

get { return y; }

set { y = value; }

}

}

///

/// 计算坐标点的距离

///

public void GetDistance()

{

//x经度 y纬度

string enbid = "";

double distance = 0;

double x1 = ConverToRadian(31.499605);

double x2 = ConverToRadian(31.4996);

double y1 = ConverToRadian(104.73775);

double y2 = ConverToRadian(104.73783);

double d = 0;

if (Math.Sin(x1) * Math.Sin(x2) + Math.Cos(x1) * Math.Cos(x2) * Math.Cos(y1 - y2) > 1)

d = EARTH_RADIUS * Math.Acos(1);

else if (Math.Sin(x1) * Math.Sin(x2) + Math.Cos(x1) * Math.Cos(x2) * Math.Cos(y1 - y2) < -1)

d = EARTH_RADIUS * Math.Acos(-1);

else

d = EARTH_RADIUS * Math.Acos(Math.Sin(x1) * Math.Sin(x2) + Math.Cos(x1) * Math.Cos(x2) * Math.Cos(y1 - y2));

}

public void Polygon_Trans4(IFeatureClass pFeatureCls, string strPath, string strFilename, ProgressBar pBar) { if (pFeatureCls == null || strPath == "" || strFilename == "") return; createNewShape(strPath, strFilename, pFeatureCls); IFeatureCursor pFeatCursor = pFeatureCls.Search(null, false); IFeature pFeature = pFeatCursor.NextFeature(); //打开目标图层 IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass(); IWorkspace pWS = pWSF.OpenFromFile(strPath, 0); IFeatureWorkspace pFWS = (IFeatureWorkspace)pWS; IFeatureClass pTargetFClass = pFWS.OpenFeatureClass(strFilename); IWorkspaceEdit pWSEdit = pWS as IWorkspaceEdit; pWSEdit.StartEditOperation(); pWSEdit.StartEditing(false); ITable pTble = (ITable)pFeatureCls; int lCunt = pTble.RowCount(null); pBar.Visible = true; pBar.Minimum = 0; pBar.Maximum = lCunt; pBar.Step = 1; IFeature pNewFeature; IPolygon pOutPolygon; IGeometryCollection pOutGeos; IPolygon pInPolygon; IGeometryCollection pInGeos; IPoint pOutPnt = new PointClass(); IPointCollection pOutPnts; while (pFeature != null) { pBar.PerformStep(); pNewFeature = pTargetFClass.CreateFeature(); pOutPolygon = new PolygonClass(); pOutGeos = pOutPolygon as IGeometryCollection; //获取原图形 pInPolygon = pFeature.Shape as IPolygon; pInGeos = pInPolygon as IGeometryCollection; for (int m = 0; m < pInGeos.GeometryCount; m++) { IGeometry pInGeo = pInGeos.get_Geometry(m); IPointCollection pInPnts = pInGeo as IPointCollection; pOutPnts = new PolygonClass(); object missing = Type.Missing; for (int n = 0; n < pInPnts.PointCount; n++) { IPoint pInPnt = pInPnts.get_Point(n); //转换点坐标 pOutPnt.X = ClsParas4.m_OffY + pInPnt.Y * ClsParas4.m_vb + pInPnt.X * ClsParas4.m_va; pOutPnt.Y = ClsParas4.m_OffX + pInPnt.Y * ClsParas4.m_va - pInPnt.X * ClsParas4.m_vb; pOutPnts.AddPoint(pOutPnt, ref missing, ref missing); } ISegmentCollection pSegmentCols = new RingClass(); pSegmentCols.AddSegmentCollection(pOutPnts as ISegmentCollection); pOutGeos.AddGeometry(pSegmentCols as IGeometry, ref missing, ref missing); } for (int i = 0; i < pFeature.Fields.FieldCount; i++) { if (pNewFeature.Fields.get_Field(i).Name.ToString().Equals("FID", StringComparison.CurrentCultureIgnoreCase) || pNewFeature.Fields.get_Field(i).Name.ToString().Equals("SHAPE", StringComparison.CurrentCultureIgnoreCase)) continue; pNewFeature.set_Value(i, pFeature.get_Value(i)); } pNewFeature.Shape = pOutPolygon as IGeometry; pNewFeature.Store(); pFeature = pFeatCursor.NextFeature(); } pBar.Visible = false; pWSEdit.StopEditOperation(); pWSEdit.StopEditing(true); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值