This is my list of code snippets useful when writing (geo)graphical applications in C#. Of course there are many powerful .NET libraries which handle these problems. But sometimes it is easier to just include some lines of code.
I've written the code to run directly in the browser using JSIL. You can extract the essential lines in your project. It should work for .NET, Mono, Silverlight, WinRT and Windows Phone. I've included the base types needed (Point, Rect) into the snippet. You can replace them with the appropriate type of the framework you are using.
For example: If you use the line simplification for WPF lines, you can take the System.Windows.Point. If you use it for WCF Spatial Library, you can take the System.Spatial.GeometryPoint.
You can use this snippet for geo-fencing or for UI-hit-testing. For a given polyline you can check if the distance of a point to the line string is not greater than a certain value.
You can use this snippet for geo-fencing or UI-hit-testing. Works for all polygons, even for OGC-invalid ones, corresponding to the "fill mode" alternate.
Simplifies a line string for a given precision. Based on the well known Douglas-Peucker algorithm
Clips a line string against a given rectangle. Based on the well known Cohen-Sutherland algorithm
Calcluate the airline distance based on mercator distance. This approximation formula is sufficiently accurate for our needs for distances of up to 600 km and 80° latitude (the error is never more than 5% even for extreme values).
This snippet contains methods to transform between geographic (WGS84) coordinates and projected (Mercator) coordinates. Also contains methods to transform between the various representations of these formats used by PTV components.