Using a Class in a C# console application [modified]
-
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; // MemoryStreampublic 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
-
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; // MemoryStreampublic 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
Don't bother converting it. Leave it in VB.NET as a class library, and add that as a reference to any application that needs it. The whole point of .NET is supposed to be language neutrality.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
Don't bother converting it. Leave it in VB.NET as a class library, and add that as a reference to any application that needs it. The whole point of .NET is supposed to be language neutrality.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
I Agree, but if you want to see how it can be done in c#, create a new WinfowdFormsApplication and take a look at it's Program.cs
-
I Agree, but if you want to see how it can be done in c#, create a new WinfowdFormsApplication and take a look at it's Program.cs
Why would I want to do this? The OP doesn't get replies to posts sent to me, so you might want to address it to him instead.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
Why would I want to do this? The OP doesn't get replies to posts sent to me, so you might want to address it to him instead.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
Pete O'Hanlon wrote:
The OP doesn't get replies to posts sent to me, so you might want to address it to him instead.
Ooops, didn't know that, 'cause That's the most common way in other forums
-
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; // MemoryStreampublic 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
When I ran it through the converter found here: http://www.developerfusion.com/tools/convert/csharp-to-vb/[^] I got this:
Public Function QuadKeyToBBox(quadKey As String) As String
Dim TILE_HEIGHT As Integer = 256
Dim TILE_WIDTH As Integer = 256
Dim zoom As Integer = quadKey.Length
Dim x As Integer = 0
Dim y As Integer = 0For i As Integer = zoom To 1 Step -1 Dim mask As Integer = 1 << (i - 1) Select Case quadKey(zoom - i) Case "0"C Exit Select Case "1"C x = x Or mask Exit Select Case "2"C y = y Or mask Exit Select Case "3"C x = x Or mask y = y Or mask Exit Select Case Else Throw New ArgumentException("Invalid QuadKey digit sequence.") End Select Next Dim W As Double = CSng(x \* TILE\_WIDTH) \* 360 / CSng(TILE\_WIDTH \* Math.Pow(2, zoom)) - 180 Dim N As Double = CSng(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 / CSng(Math.PI) Dim E As Double = CSng((x + 1) \* TILE\_WIDTH) \* 360 / CSng(TILE\_WIDTH \* Math.Pow(2, zoom)) - 180 Dim S\_\_1 As Double = CSng(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 / CSng(Math.PI) Dim bounds As Double() = New Double() {W, S\_\_1, E, N} Return String.Join(",", Array.ConvertAll(bounds, Function(s\_\_2) s\_\_2.ToString()))
End Function
I have no idea how this is going to work because I just converted it and pasted it here (with some corrections where the converter incorrectly inserted backslashes in the converted code).
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why do -
When I ran it through the converter found here: http://www.developerfusion.com/tools/convert/csharp-to-vb/[^] I got this:
Public Function QuadKeyToBBox(quadKey As String) As String
Dim TILE_HEIGHT As Integer = 256
Dim TILE_WIDTH As Integer = 256
Dim zoom As Integer = quadKey.Length
Dim x As Integer = 0
Dim y As Integer = 0For i As Integer = zoom To 1 Step -1 Dim mask As Integer = 1 << (i - 1) Select Case quadKey(zoom - i) Case "0"C Exit Select Case "1"C x = x Or mask Exit Select Case "2"C y = y Or mask Exit Select Case "3"C x = x Or mask y = y Or mask Exit Select Case Else Throw New ArgumentException("Invalid QuadKey digit sequence.") End Select Next Dim W As Double = CSng(x \* TILE\_WIDTH) \* 360 / CSng(TILE\_WIDTH \* Math.Pow(2, zoom)) - 180 Dim N As Double = CSng(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 / CSng(Math.PI) Dim E As Double = CSng((x + 1) \* TILE\_WIDTH) \* 360 / CSng(TILE\_WIDTH \* Math.Pow(2, zoom)) - 180 Dim S\_\_1 As Double = CSng(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 / CSng(Math.PI) Dim bounds As Double() = New Double() {W, S\_\_1, E, N} Return String.Join(",", Array.ConvertAll(bounds, Function(s\_\_2) s\_\_2.ToString()))
End Function
I have no idea how this is going to work because I just converted it and pasted it here (with some corrections where the converter incorrectly inserted backslashes in the converted code).
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why doThanks, I just tried it again myself and got another error message"-- line 3 col 8: invalid TypeDecl" That is the converter that I was using yesterday. Anyway the conversion that you posted is something that I can work with. Thanks again.