Plotting Technical Descriptions

Topics: Algorithms, SharpMap v0.9 / v1.x, WinForms Controls
Jun 12, 2008 at 10:31 AM
Hi guys!

Has anyone tried plotting technical descriptions using SharpMap?


Coordinator
Jun 12, 2008 at 7:49 PM
What is a "technical description?"

Are you talking about a CAD diagram? If so, it should be possible, given the OGR provider which can read DXF files.
Jun 13, 2008 at 11:09 AM
I have a table that looks like this:

frm    to        H    B    Deg    Min    Dist
============================
1        2        N    W    45    0    100
2        3        N    E     45    0    100
3        4        S     E    45     0    100
4        5        S    W    45    0    100

and I wanted to plot it using a known starting point.
From where I am, they call this technical description.

With some research, I was able to come up with this function:

 SharpMap.Geometries.Point NextPoint(double startX, double startY, string heading, string bearing, int degree, int minute, double distance)
{
            double DEG2RAD = 4 * Math.Atan(1) / 180;
            double azimuth = degree + (minute / 60);

            string hb = heading + bearing;

            switch(hb){
                case "NE":
                    // do nothing
                    break;
                case "NW":
                    azimuth = 0 - azimuth;
                    break;
                case "SE":
                    azimuth = 180 - azimuth;
                    break;
                case "SW":
                    azimuth = -180 + azimuth;
                    break;
                default:
                    azimuth = 0;
                    break;
            }

            azimuth = azimuth * DEG2RAD;

            double endX = startX + Math.Sin(azimuth) * distance;
            double endY = startY + Math.Cos(azimuth) * distance;

            return new SharpMap.Geometries.Point(endX, endY);
}


Coordinator
Jun 13, 2008 at 6:33 PM
Edited Jun 13, 2008 at 6:34 PM

Nice. Thanks for sharing. If I come across this question again, I can point them to your post!

Just a note, though, you can use a constant for DEG2RAD, and this will speed things up a bit:

    private const Double DEG2RAD = 0.0174532925199432958;
 
4 * Math.Atan(1) / 180 simplifies to: (4 * pi/4) / 180, or (pi / 180), which equals the above constant, to the limit of precision of a double floating point.

Jun 17, 2008 at 6:00 AM
Noted! Thanks!