문제

I'm writing a geography game in Java, and I'd like to have some data on the locations of the borders of countries, but all I can find is shapefiles, and I can't get latitude/longitude data out of them, or else I can only find a single coordinate for each country.

Where can I find

  • a way to extract the longitude/latitude data into usable data in Java or in a text file?
  • a web site with free data on country borders that can be used in a java program?

Edit:

It doesn't need to be exact; for pretty much anything except Russia, China the U.S., and Brazil, 10 coordinates is probably enough. Islands don't really matter either. I just want to know be able to calculate relatively accurately the shortest distance between two countries.

도움이 되었습니까?

해결책

Download the generalized Country borders from here: http://www.baruch.cuny.edu/geoportal/data/esri/esri_intl.htm. These are probably more detailed than you want (Canada has the most vertices at 3316), but is the only free rough border data set I could find online.

To get the coordinates from a shapefile as text, go to MyGeodata Converter

  1. Run Vector Converter
  2. Upload the zip file you just downloaded.
  3. Check available operations
  4. Export to GeoJSON
  5. Download Zip file form MyGeodata Converter
  6. Unzip the file.

Now you have the boundaries in GeoJSON format and can use a GeoJSON parser or a more simple text parser to get the coordinate data.

If that's too much work, you can also parse shapefiles with one of the various Java shapefile frameworks out there. See Does anyone know of a library in Java that can parse ESRI Shapefiles? for some options.

다른 팁

Download the osm file and import into postgresql+postgis(via osm2pgsql tool will do). If you required another database migrate postgresql to your desired database

http://planet.openstreetmap.org/

The MyGeodata converter only throws a 500 error at the moment, so I had to look further and finally stumbled across KML files that roughly describe the outline of each country. I posted the link on this related question, so someone might want to look there.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top