export country border coordinates into kml from GE

1,752 views
Skip to first unread message

larryx71

unread,
Mar 7, 2006, 5:53:59 PM3/7/06
to KML Discussions
Hi everyone, i am new to GE, but one of the things I am interested in doing is to get all of the coordinates of a country border(say france) and export that to a kml file that can be used outside of GE. Is that possible? or has there already been an topic that's like mine? Thanks in advance.

BTW, i think GE looks great.


Forkboy2

unread,
Mar 7, 2006, 10:22:56 PM3/7/06
to KML Discussions
You can find SHP files of world country boundaries here

http://www.bluemarblegeo.com/products/worldmapdata.php?op=download

But don't think there is anyway to export them from GE.

Matt

Terry_Pinnell

unread,
Mar 8, 2006, 6:11:00 AM3/8/06
to KML Discussions
After some research and testing, I can get you some way along the road on this. (I tried your link, Matt, but I don't know how to get from SHP to text.)

Here are the key steps I took, using UK as an example, starting at this web page:

http://www.maproom.psu.edu/cgi-bin/dcw/dcwcountry0.cgi

"This will allow you to download a file containing a list of lat/long points for the outline of United Kingdom."
http://www.maproom.psu.edu/cgi-bin/ian/points/point10.cgi?country=United_Kingdom

That got me to an explanatory page, including:

DCW Polygon Point Generation
The polygon-point generation program is running for: United_Kingdom
Opening united_kingdom2pts.txt. Note that the filename consists of the country name before "2pts.txt": united_kingdom2pts.txt.


I then received the data in my browser and saved it to HD. It has over 24,000 lines, and after stripping blanks its format is like this:

united_kingdom
1
-6.349643 49.893982
-6.350727 49.899216
-6.344689 49.898914
-6.340974 49.890331
-6.345302 49.885883
-6.348185 49.886723
-6.349583 49.892166
-6.358377 49.891254
-6.352918 49.900299
-6.350727 49.899216
END
2
-5.533409 54.677719
-5.522974 54.674538
etc

With some text editing using Regex it wasn't too difficult to convert that to a KLM file. You could alternatively probably use other methods, such as manipulation in Excel, possibly with the aid of macros.

I don't know much about KLM. But to get it to display a plain boundary line it seemed reasonable to try using the LineString tag. My automated editing with Regex got me a KML file like this:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Folder>
<name>TEST UK Boundary</name>

<Placemark><Name>1</Name>
<LineString><tessellate>1</tessellate><coordinates>
-6.349643, 49.893982, 0
-6.350727, 49.899216, 0
-6.344689, 49.898914, 0
-6.340974, 49.890331, 0
-6.345302, 49.885883, 0
-6.348185, 49.886723, 0
-6.349583, 49.892166, 0
-6.358377, 49.891254, 0
-6.352918, 49.900299, 0
-6.350727, 49.899216, 0
</coordinates></LineString></Placemark>
<Placemark><Name>2</Name>
<LineString><tessellate>1</tessellate><coordinates>
-5.533409, 54.677719, 0
etc

Either I haven't got it quite right (very likely!) or the data is incomplete, but on loading that in GE Plus I got something that seemed to follow the boundaries of Wales, Northern Ireland, and some Scottish islands quite well, but clearly didn't get England right!




--
Terry, West Sussex, UK

tekgergedan

unread,
Mar 8, 2006, 6:45:31 AM3/8/06
to KML Discussions
Terry, for a 50% probability, the vagrant points/lines (especially those in, say, Africa) are the result of the absent spaces. Because you put ENTER between the point infos in the KML, you cant see; be sure after each "...,0" there is a space (ie "...,0 "). The reason is that, in original KML, they are seperated by a SPACE character not by an ENTER character.

PhilbD

unread,
Mar 8, 2006, 9:23:07 AM3/8/06
to KML Discussions
I'd rather say that
-each of the "valid" polygons has one coordinate at its very barycenter ("why?" is another question, most certainly related to the format itself). Maybe you should erase it from each <placemark>, should that impose you another copy-replace routine.

-the mainland polygon is purely missing from the datafile (haven't been able to download it, though)

-the line that points from the Hebrides to the equator (true?) is a lone number in the coordinates list that's been converted by GE as a full coordinate :
("45" became "45,0,0")

It's fun you mention your method here because I'm now familiar with anorther copy-paste-replace method for drawing geometry stored in MIF files, and it is quite similar. Maybe you should post your file here, so that we could take a peek.

tekgergedan

unread,
Mar 8, 2006, 9:36:23 AM3/8/06
to KML Discussions
A bit far from the original topic...

Here is Terry's part of the code:

<coordinates>
-6.349643, 49.893982, 0
-6.350727, 49.899216, 0
-6.344689, 49.898914, 0
-6.340974, 49.890331, 0
-6.345302, 49.885883, 0
-6.348185, 49.886723, 0
-6.349583, 49.892166, 0
-6.358377, 49.891254, 0
-6.352918, 49.900299, 0
-6.350727, 49.899216, 0
</coordinates>

The original KML (ie when we create a polygon/path) is like this:
<coordinates>
-6.349643,49.893982,0 -6.350727,49.899216,0 -6.344689,49.898914,0 -6.340974,49.890331,0 -6.345302,49.885883,0 -6.348185,49.886723,0 -6.349583,49.892166,0 -6.358377,49.891254,0 -6.352918,49.900299,0 -6.350727,49.899216,0
</coordinates>

If this is complicated to view/investigate, we can type like this:
<coordinates>
-6.349643,49.893982,0
-6.350727,49.899216,0
-6.344689,49.898914,0
-6.340974,49.890331,0
-6.345302,49.885883,0
-6.348185,49.886723,0
-6.349583,49.892166,0
-6.358377,49.891254,0
-6.352918,49.900299,0
-6.350727,49.899216,0
</coordinates>
Here, a SPACE character must exist after each '...,0'. Select by dragging this post to see the difference.

PhilbD

unread,
Mar 8, 2006, 10:10:10 AM3/8/06
to KML Discussions
Whether there's a space or not before each return-chariot, I don't see a difference in GE There shouldn't be any, anyway, since this is just XML.

(Off off-topic : at least it's confirmed that the first coordinate is the barycenter)

Terry_Pinnell

unread,
Mar 8, 2006, 10:45:12 AM3/8/06
to KML Discussions
tekgergedan: I don't think that makes any difference. I wouldn't have expected it to, because presumably KML ignores blanks at the end of a line. But I tried it anyway, globally changing all '0[return]' to '0 [return]'. When I loaded the revised KML file in GE, it looked just the same as before.

tekgergedan

unread,
Mar 8, 2006, 11:05:36 AM3/8/06
to KML Discussions
Maybe... I said 50% probability.
I had that problem in my first tryouts and I realized that this first quote below was interpreted as the second:

Quote:


6.349643, 49.893982, 0
6.350727, 49.899216, 0





Quote:


6.349643, 49.893982,06.350727, 49.899216,0





Because there is no space. Anyway I think your problem is not necessarily this.
Maybe I was wrong as PhilbD tells. I must rethink about my past problems.

Terry_Pinnell

unread,
Mar 8, 2006, 11:08:37 AM3/8/06
to KML Discussions
I'm a bit out of my depth here, as a newcomer to KML, and I'm not sure what a barycenter is. Hopefully though it will allow the OP to make some practical progress if he's really keen.

I've uploaded the 868 KB text file here, where it will remain for a maximum of 7 days: http://s60.yousendit.com/d.aspx?id=0E1FZF9O4OP192ZH1SXIR8SBOR

I'd appreciate a copy of the final correct KML please, so I can see where I went wrong.

I can post my rough KML file too if that's of interest, but it's all in the format I showed in my previous post.

Come to think, it might be better to use a much smaller country, like Cyprus. That's only 17 KB, and I've posted it here:
http://s60.yousendit.com/d.aspx?id=3TNYHEG8NRLVL3V4AH30W8RA3

Finally, here is another link, from where data for all European countries can be downloaded:
http://www.maproom.psu.edu/cgi-bin/dcw/dcwarea.cgi?Europe

Terry_Pinnell

unread,
Mar 8, 2006, 11:38:39 AM3/8/06
to KML Discussions
While I'm still curious about this, I decided to take a look at that Cyprus file myself. Starting with the downloaded Cypus text file I linked in my last post, I revised it in my text editor to look like this:
33.419300, 35.218689
32.307491, 35.000000
32.302181, 35.007801
etc

Then I used this handy facility I've just discovered, from Ink_Polaroid modified by McShea98:
http://www.mcshea98.com/Keyhole/line.htm

to convert it to a KML path.

But on opening it in GE I got this:



I'd be interested to see what others get.

larryx71

unread,
Mar 8, 2006, 2:08:44 PM3/8/06
to KML Discussions
thanks for the help, I will look into that, just wanted to do some research about what I could do with GE in my application.

PriceCollins

unread,
Mar 9, 2006, 7:20:40 AM3/9/06
to KML Discussions
I suspect you got the latitude / longitude switched. In the "Fly To" box one puts latitude then longitude. It's reversed in <coordinates>

I thought there was a secret way to download the coastlines and borders. Has that been turned off in the latest GE version?

Terry_Pinnell

unread,
Mar 9, 2006, 9:11:45 AM3/9/06
to KML Discussions
Well-spotted! (Bad luck I should choose a country where the Long & Lat are so similar.)

Here's the revised result:



What about that spurious straight line?

mcshea98

unread,
Mar 9, 2006, 2:01:33 PM3/9/06
to KML Discussions
Terry_Pinnell,

If you post your KML, I will look at it and let you know how to get rid of the extra line (that goes near the center of the geometry).

Also, Valery35 put together a great compliation of data that you might find useful. Here is the link to the post.

Let me know if you were looking for something else.

tekgergedan

unread,
Mar 9, 2006, 3:02:35 PM3/9/06
to KML Discussions
This is what I've achieved:



EDIT: The reason of the lines is the starting coordinates. Removing the first lines in each section corrects the poligon. However, Terry's long line towards SE is a conversion error done by the script.

I used Excel and Word to convert the list to KML.

Terry_Pinnell

unread,
Mar 9, 2006, 3:19:56 PM3/9/06
to KML Discussions
That's more like it - well done!

I see you have a couple of straight lines too, as I do in my Cyprus example.

I'll attach my KML file in my reply to mcshea98.

Terry_Pinnell

unread,
Mar 9, 2006, 3:21:27 PM3/9/06
to KML Discussions
Thanks, useful link. (But note that I wasn't the OP.)

My Cyprus KML is attached.
343009-Cyprus3a.kml

tekgergedan

unread,
Mar 9, 2006, 3:23:40 PM3/9/06
to KML Discussions
Sorry, I posted the wrong jpg. I reposted it. See...

tekgergedan

unread,
Mar 9, 2006, 3:26:23 PM3/9/06
to KML Discussions
I know your Cyprus. Because it is only one island, and, therefore, one polygon, it is easy. Delete the first line. It will be OK. I think, that dot in the center has been created for something else.

BTW, as mcshea98 told, val is working on country and level1 administrative borders. Why are you working on this?

mcshea98

unread,
Mar 9, 2006, 3:31:25 PM3/9/06
to KML Discussions
Quite Right Terry,

I should have scrolled all the way to the top.

Terry_Pinnell

unread,
Mar 10, 2006, 1:25:22 AM3/10/06
to KML Discussions
Quote:

I know your Cyprus. Because it is only one island, and, therefore, one polygon, it is easy. Delete the first line. It will be OK. I think, that dot in the center has been created for something else.

BTW, as mcshea98 told, val is working on country and level1 administrative borders. Why are you working on this?




Well, initially to try to help the OP, larryx71, and then curiosity and wanting to learn how to do this sort of stuff
Reply all
Reply to author
Forward
0 new messages