Click here to Skip to main content
15,882,017 members
Home / Discussions / C#
   

C#

 
GeneralRe: Wierd exceptions when calling WCF more than once from a static class Pin
Ravi Bhavnani17-Jan-11 12:22
professionalRavi Bhavnani17-Jan-11 12:22 
GeneralRe: Wierd exceptions when calling WCF more than once from a static class Pin
Michael900017-Jan-11 12:48
Michael900017-Jan-11 12:48 
GeneralRe: Wierd exceptions when calling WCF more than once from a static class Pin
Michael900018-Jan-11 5:02
Michael900018-Jan-11 5:02 
GeneralRe: Wierd exceptions when calling WCF more than once from a static class Pin
Ravi Bhavnani18-Jan-11 5:57
professionalRavi Bhavnani18-Jan-11 5:57 
AnswerRe: Wierd exceptions when calling WCF more than once from a static class Pin
Ravi Bhavnani17-Jan-11 11:56
professionalRavi Bhavnani17-Jan-11 11:56 
GeneralRe: Wierd exceptions when calling WCF more than once from a static class [modified] Pin
Michael900017-Jan-11 12:27
Michael900017-Jan-11 12:27 
QuestionAnyone work with Microsoft Dynamics Great Plains? Pin
DeepToot17-Jan-11 5:53
DeepToot17-Jan-11 5:53 
QuestionUsing a Class in a C# console application [modified] Pin
B Don Davis17-Jan-11 4:46
B Don Davis17-Jan-11 4:46 
Thanks, but I finally figured it out.
I am fairly new to VB.net but I am getting by. I am almost clueless about C# though. I have managed to find a C# function that does what I need
and have converted it with the online code converter. It runs in VB and works but two of the four calculations are not working. (I had hoped to get it
working in C# to test the formulas.) It takes a string (a mapping Tile Quadkey, 02311102221333130 for example) and calculates the bounding box for that
map tile(Lat/Lon) corner positions coordinates of the four corners). The calculated values W (West Longitude) N (North Latitude) E (East Longitude) and
S (South Latitude). I have set up a new C# project, a console app. I have used the code at bottom and created a new class in that program. On the form Program.cs
I don't have a clue about how to make use of that class. The test value would be Quadkey = "02311102221333130" 
It appears that it returns a string of the array bounds, values separated by commas.
If someone wanted to convert this to working VB.net that would really great, but I hardly expect that.

The corrected, working calling procedure. I guess that I knew even less than I thought.
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // Instance of OutputClass
            WMSHandler outCl = new WMSHandler();
            double N = 0;
            // Call Output class' method
            string MyString = outCl.QuadKeyToBBox("02311102221333130");
            Console.WriteLine(MyString);
            Console.ReadLine();
        }
    }
}


But that is not working. Any help would be appreciated.

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // to do
        }
    }
}



using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    using System;
    using System.Math;
    using System.IO; // MemoryStream

    public class WMSHandler
    {
        // Bing Maps tiles are always 256px x 256px
        public const int TILE_HEIGHT = 256, TILE_WIDTH = 256;
        // Returns the bounding box coordinates for a given tile quadkey
        public string QuadKeyToBBox(string quadKey)
        {
            int zoom = quadKey.Length;
            int x = 0, y = 0;
            // Work out the x and y position of this tile
            for (int i = zoom; i > 0; i--)
            {
                int mask = 1 << (i - 1);
                switch (quadKey[zoom - i])
                {
                    case '0':
                        break;
                    case '1':
                        x |= mask;
                        break;
                    case '2':
                        y |= mask;
                        break;
                    case '3':
                        x |= mask;
                        y |= mask;
                        break;
                    default:
                        throw new ArgumentException("Invalid QuadKey digit sequence.");
                }
            }
            // From the grid position and zoom, work out the min and max Latitude / Longitude values of this tile
            double W = (float)(x * TILE_WIDTH) * 360 / (float)(TILE_WIDTH * Math.Pow(2, zoom)) - 180;
            double N = (float)Math.Asin((Math.Exp((0.5 - (y * TILE_HEIGHT) / (TILE_HEIGHT) / Math.Pow(2, zoom)) * 4 * Math.PI) - 1) / (Math.Exp((0.5 - (y * TILE_HEIGHT) / 256 / Math.Pow(2, zoom)) * 4 * Math.PI) + 1)) * 180 / (float)Math.PI;
            double E = (float)((x + 1) * TILE_WIDTH) * 360 / (float)(TILE_WIDTH * Math.Pow(2, zoom)) - 180;
            double S = (float)Math.Asin((Math.Exp((0.5 - ((y + 1) * TILE_HEIGHT) / (TILE_HEIGHT) / Math.Pow(2, zoom)) * 4 * Math.PI) - 1) / (Math.Exp((0.5 - ((y + 1) * TILE_HEIGHT) / 256 / Math.Pow(2, zoom)) * 4 * Math.PI) + 1)) * 180 / (float)Math.PI;
            double[] bounds = new double[] { W, S, E, N };
            // Return a comma-separated string of the bounding coordinates
            return string.Join(",", Array.ConvertAll(bounds, s => s.ToString()));
        } // public string
    } // class
}// namespace


modified on Monday, January 17, 2011 11:18 AM

AnswerRe: Using a Class in a C# console application PinPopular
Pete O'Hanlon17-Jan-11 5:16
mvePete O'Hanlon17-Jan-11 5:16 
GeneralRe: Using a Class in a C# console application Pin
Michael900017-Jan-11 8:40
Michael900017-Jan-11 8:40 
GeneralRe: Using a Class in a C# console application Pin
Pete O'Hanlon17-Jan-11 9:09
mvePete O'Hanlon17-Jan-11 9:09 
GeneralRe: Using a Class in a C# console application Pin
Michael900017-Jan-11 11:59
Michael900017-Jan-11 11:59 
AnswerRe: Using a Class in a C# console application Pin
#realJSOP18-Jan-11 4:45
mve#realJSOP18-Jan-11 4:45 
GeneralRe: Using a Class in a C# console application Pin
B Don Davis18-Jan-11 14:08
B Don Davis18-Jan-11 14:08 
Questionsql server express Pin
arkiboys17-Jan-11 3:25
arkiboys17-Jan-11 3:25 
AnswerRe: sql server express Pin
Dan Mos17-Jan-11 3:45
Dan Mos17-Jan-11 3:45 
GeneralRe: sql server express Pin
arkiboys17-Jan-11 3:53
arkiboys17-Jan-11 3:53 
GeneralRe: sql server express Pin
Dan Mos17-Jan-11 3:59
Dan Mos17-Jan-11 3:59 
JokeRe: sql server express Pin
Henry Minute17-Jan-11 6:01
Henry Minute17-Jan-11 6:01 
GeneralRe: sql server express Pin
Dan Mos17-Jan-11 9:10
Dan Mos17-Jan-11 9:10 
GeneralRe: sql server express Pin
Henry Minute17-Jan-11 9:20
Henry Minute17-Jan-11 9:20 
GeneralRe: sql server express Pin
Bernhard Hiller17-Jan-11 21:05
Bernhard Hiller17-Jan-11 21:05 
AnswerRe: sql server express Pin
Ravi Sant17-Jan-11 3:51
Ravi Sant17-Jan-11 3:51 
GeneralRe: sql server express Pin
arkiboys17-Jan-11 4:08
arkiboys17-Jan-11 4:08 
GeneralRe: sql server express Pin
Henry Minute17-Jan-11 6:23
Henry Minute17-Jan-11 6:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.