GeoSharp icon indicating copy to clipboard operation
GeoSharp copied to clipboard

Not work with new data format

Open Radzhab opened this issue 8 years ago • 2 comments

I download allcountries.txt. run code but its rise error image

Radzhab avatar Jan 28 '17 10:01 Radzhab

The format hasn't changed and it works fine, as you see in the screenshot The Value is 42.64991 - which should be easily parsed by double.Parse ... but it doesn't: the Problem is probably your Russian setting.

Does Russian use "," to seperate the decimal?

Compile in a neutral culture or explicitly set the culture to a culture which uses a period for the decimal separator.

FreeApophis avatar Sep 07 '18 08:09 FreeApophis

Compile in a neutral culture

I'm not sure how one would do that?

or explicitly set the culture to a culture which uses a period for the decimal separator.

Indeed. You can do either:

this.Latitude = double.Parse(Fields[4], CultureInfo.InvariantCulture);
this.Longitude = double.Parse(Fields[5], CultureInfo.InvariantCulture);

Or, alternatively, use this as one of the first lines in your program:

Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

Not that the latter changes the culture for the entire application, you might not want that.

Finally, you may want to take a look at NGeoNames (full disclosure: I'm the author) which handles all of the parsing for you.

RobThree avatar Sep 07 '18 08:09 RobThree