MapPoint Forums

MapForums

Community of MapPoint and Bing Maps Users and Developers




Importing LatLongs and postcodes from excel

This is a discussion on Importing LatLongs and postcodes from excel within the Development forums, part of the MapPoint Desktop Discussion category; I am using c# to write an application to import postcodes and latlongs from excel and access and then create ...


Go Back   MapPoint Forums > Map Forums > MapPoint Desktop Discussion > Development

Today's Posts Twitter Feed Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-01-2008
Junior Member
White Belt
 
Join Date: Nov 2007
Posts: 5
Importing LatLongs and postcodes from excel

I am using c# to write an application to import postcodes and latlongs from excel and access and then create a route and calculate directions. The code works fine as long as the import file only includes either latlongs or postcodes. If i try to use a mixture then the code fails. The import file layout is always in the same format,

Stop Number, Postcode, Latitude, Longitude.

The stop number is mandatory. Each record will have either the postcode or the lat longs but not both.

I use the following code to process the data

Code:
 
DataSet ds = new DataSet();
OleDbDataAdapter adapter = new OleDbDataAdapter(commandText, conn);
adapter.Fill(ds);
conn.Close(); 
DataTable dt = ds.Tables[0];
 
foreach (DataRow dr in dt.Rows)
{
MapPoint.Location loc = null;
string postCode = (dr["Postcode"].ToString());
string lat = (dr["Latitude"].ToString());
string lon = (dr["Longitude"].ToString());
object result = new object();
if (postCode.Equals(""))
{
double dblLat = System.Convert.ToDouble(lat);
double dblLon = System.Convert.ToDouble(lon);
result = axMappointControl1.ActiveMap.GetLocation(dblLat, dblLon, 1);
}
if (lat.Equals(""))
{
result = axMappointControl1.ActiveMap.ShowFindDialog(postCode, MapPoint.GeoFindState.geoFindDefault, 0, true);
}
 
if (result is MapPoint.Location)
{
loc = result as MapPoint.Location;
if (loc != null)
{
MapPoint.Pushpin pushpin = axMappointControl1.ActiveMap.AddPushpin(loc, loc.Name);
}
}
else if (result is MapPoint.Pushpin)
{
MapPoint.Pushpin found = result as MapPoint.Pushpin;
loc = found.Location;
}
else
{
MessageBox.Show("No location found");
}
I want the code to look to see if there is an entry in the postcode field, if there is use this to find the location. If there isnt then use the latlongs to find the location.

This is ok if the whole import file only contains either latlongs or postcodes.

If it contains both, i have seen it work through the data table of postcodes and when it finds a blank postcode it is not passing a the latitude or longitude into the variable.

Im a noob at C# so i must be doing something wrong.

Any help would be much appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 07-03-2008
Senior Member
Black Belt
 
Join Date: Nov 2004
Location: Belgium
Posts: 2,410
Re: Importing LatLongs and postcodes from excel

Hi,

Quote:
If i try to use a mixture then the code fails
You don't tell what the problem is. Anyway you do a lot of conversion from double to string and so. At a certain place you check if (lat.Equals("")). Are you sure this string can be a null string? Did you check with the debugger if this all is oke?

You also tell that if data does not contain a mixture then it works. Did you tried this with exactly the same data as the mixture one?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 07-03-2008
Junior Member
White Belt
 
Join Date: Nov 2007
Posts: 5
Re: Importing LatLongs and postcodes from excel

Hi

I will try to explain better.

I have been trying to post an example of my in HTML but i cant so i will try and describe it better.

The table has four columns,
1. Stop Number
2. Postcode
3. Latitude
4. Longitude

The stop number column is manadatory, this is like the primary key.

Each stop number will have either a postcode or latitude and longitude. It will not have both.

The code looks to see if the Stop number has a postcode, if it doesnt have a postcode it should look at the latitude and longitude.

If i am importing the table from Access everything works fine.

The issue is if im importing from excel. For example,

Stop number = 1, Postcode = B65 4RT, lat = "", long = "" outcome = stop added to route.
stop number = 2, Postcode = B67 6YH, lat = "", long = "" outcome = stop added to route.
Stop number = 3, Postcode = "", Latitude = 52.6666, Longitude = -2.6777. outcome = stop not found.

When you look at the code in debugging mode it shows that string lat and string lon have not been assigned the value from the column.

It seems to be that if the last data that was processed was from the postcode column, it is not picking up the data from the latitude and longitude columns for the next data row if the postcode = "".

Not sure if this is any clearer but hope it provides a better explanation. It would be easeier if i could post html.

Thanks for your help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 07-04-2008
Senior Member
Black Belt
 
Join Date: Nov 2004
Location: Belgium
Posts: 2,410
Re: Importing LatLongs and postcodes from excel

Hi,

thanks for clarify. So it is an Excel problem. I see nothing wrong at your code at first sight, but I never done something in Excel. Hope someone with more Excel insight drops in here.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
excel, importing, latlongs, postcodes


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
sorting stops when importing from excel? zb61 MapPoint Desktop Discussion 3 11-01-2007 08:48 AM
Mappoint importing with excel error Raian MapPoint Desktop Discussion 1 10-23-2007 08:48 AM
importing data from excel to mappoint Layne MapPoint Desktop Discussion 0 05-09-2003 12:40 PM
importing excel file into mappoint misterb83 MapPoint Desktop Discussion 2 04-14-2003 01:56 AM
When importing from MS Excel .csv files into MapPo.... Anonymous MapPoint Desktop Discussion 1 08-08-2001 07:35 AM


All times are GMT -5. The time now is 03:16 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.0 RC3
MP2K Magazine
Visitor Map



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70