calculate how many meters in one degree at a point - CSharp System

CSharp examples for System:Math Geometry

Description

calculate how many meters in one degree at a point

Demo Code


using System.Windows;
using Microsoft.SqlServer.Types;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from w  ww .  ja  v a 2 s .c om*/

public class Main{
        /// <summary>
        /// calculate how many meters in one degree at a point
        /// </summary>
        /// <param name="sg"></param>
        /// <returns></returns>
        /// <remarks>by Alex Feb.2013</remarks>
        public static double MetersPerDegree(double X, double Y, int SRID)
        {
            SqlGeography h1 = Point2SqlGeography(X - 0.5, Y, SRID), h2 = Point2SqlGeography(X + 0.5, Y, SRID),
                v1 = Point2SqlGeography(X, Y - 0.5, SRID), v2 = Point2SqlGeography(X, Y + 0.5, SRID);
            double hr = h1.STDistance(h2).Value, hv = v1.STDistance(v2).Value;
            return (hr + hv) / 2;
        }
}

Related Tutorials