views:

498

answers:

9

So I'm writing a Javascript library that takes x,y coordinates and uses them to draw a map of the US. To do this, I need to find the coordinate data necessary to draw each state. This map on Wikipedia is a great example of what I need, because the SVG file contains the shapes that make up each state nicely labeled: http://upload.wikimedia.org/wikipedia/commons/3/32/Blank_US_Map.svg

I also have a set of sites which I need to place on this map. Since I know the latitude and longitude of each site, I can use that to draw each site in its appropriate place on the map. Unfortunately, for this to work my map needs to use the Mercator projection, so that there can be an easy mapping of lat,long to x,y pixel coordinates.

The Wikipedia map I mentioned above uses some other projection, so I can't use it for this purpose. Does anyone know where I can find this type of map data in the Mercator projection? Any data format is fine, so long as I can programmatically get at the coordinates which are used to draw each state and identify which shapes comprise each state.

+1  A: 

Have you looked at NIMA products? http://egsc.usgs.gov/nimamaps/ and https://www1.nga.mil/ProductsServices/Pages/default.aspx They have a variety of maps, formats, etc. and all paid for by us taxpayers, so much is available to the public. Good first stop for maps.

DarenW
Thanks for the links, but I can't seem to find a download-able set of coordinates that can be used to render maps. I'll keep these in mind in the future, but I can't find anything close to what I need now on those websites.
Eli Courtwright
+1  A: 

I've never done the sort of work you're asking about, but it looks to me like these data from the US Army Corps of Engineers will be useful for you:

http://crunch.tec.army.mil/software/corpscon/corpscon.html

Lord Torgamus
Perhaps I'm just dense, but that utility and its files seem mostly useful for converting between several different formats, none of which is what I really need. So while those data files look like they might have the info I need, I have no idea how to get it out in any sort of way which is useful to me, since I don't see a file format spec anywhere, and even if I had one then I'd still have to write a program to parse through a binary file to extract the data I need.
Eli Courtwright
+1  A: 

visokio.com has downloadable collections of vector maps here: http://www.visokio.com/maps most of them support decimal latitude/longitude coordinates.

however it looks like all are in a propetiary format viewable only with their own software. a trial software is available, tho.

hth.

edit: come across these when browsing around wikipedia:

widyakumara
Thanks for the suggestion - this does look like a nice software package, and the map data does indeed have what I need (US Mercator projection with state lines). However, there doesn't seem to be any way to export the coordinates they use to actually draw the map. You can import/export extra things that you draw onto their existing maps, but not the map data itself. And since their format is both binary and proprietary, I'd have to reverse-engineer it, which would be technically difficult and dubiously legal.
Eli Courtwright
+2  A: 

Here: http://www.nws.noaa.gov/geodata/catalog/national/html/us_state.htm
you can download a shp file with the data. The shape format includes a dbf with some attributes, including coordinates for each state.

Also, you can use shp2text to extract all the information.

Edit: Data in the map is in North American Datum of 1983, but you can use the Spreadsheet and formulas here to convert to Mercator (UTM).

Carlos Gutiérrez
+4  A: 

This is a GIS question and would not be solved easily unless you're using the proper tools.

  • Use QGIS to open the US Shapefile data

    EDIT In the case the shapefiles I linked to are not exactly the ones you were looking for then Google for "US shapefiles". Shapefiles are actually a group of geospatial (and not just one file).

  • Reproject your layer to the specified projection

    EDIT this can be a hassle, but just in case, it doesn't ogr (see below) can reproject. EPSG are obtained from spatial reference

  • Use ogr2ogr (cheatsheet) or the converter plugin to convert your data to KML. This will output your data in a Google maps/earth/human readable format that will have the coordinates in them

EDIT 2 What are you using to display the online maps? have you considered openlayers or Google maps API or mapserver

EDIT 3 I tested my method on some data I have and it works, here's a sample output for one polygon using "State and Equivalent (Current)" layer:

<Placemark>
      <name>American Samoa</name>
      <styleUrl>#PolyStyle00</styleUrl>
      <Snippet></Snippet>
      <MultiGeometry>
        <Polygon>
          <tessellate>1</tessellate>
          <extrude>0</extrude>
          <altitudeMode>clampToGround</altitudeMode>
          <outerBoundaryIs><LinearRing><coordinates> -0.001536,-0.000099,0.000000 -0.001536,-0.000099,0.000000 -0.001536,-0.000100,0.000000 -0.001536,-0.000100,0.000000 -0.001536,-0.000100,0.000000 -0.001536,-0.000100,0.000000 -0.001537,-0.000100,0.000000 -0.001537,-0.000100,0.000000 -0.001537,-0.000100,0.000000 -0.001537,-0.000100,0.000000 -0.001537,-0.000100,0.000000 -0.001537,-0.000100,0.000000 -0.001537,-0.000100,0.000000 -0.001537,-0.000100,0.000000 -0.001537,-0.000100,0.000000 -0.001537,-0.000100,0.000000 -0.001537,-0.000100,0.000000 -0.001537,-0.000100,0.000000 -0.001537,-0.000100,0.000000 -0.001537,-0.000100,0.000000 -0.001537,-0.000099,0.000000 -0.001537,-0.000099,0.000000 -0.001537,-0.000099,0.000000 -0.001537,-0.000099,0.000000 -0.001537,-0.000099,0.000000 -0.001537,-0.000099,0.000000 -0.001537,-0.000099,0.000000 -0.001537,-0.000099,0.000000 -0.001537,-0.000099,0.000000 -0.001537,-0.000099,0.000000 -0.001537,-0.000099,0.000000 -0.001537,-0.000099,0.000000 -0.001537,-0.000099,0.000000 -0.001537,-0.000099,0.000000 -0.001537,-0.000099,0.000000 -0.001536,-0.000099,0.000000 -0.001536,-0.000099,0.000000 -0.001536,-0.000099,0.000000 -0.001536,-0.000099,0.000000 -0.001536,-0.000099,0.000000 -0.001536,-0.000099,0.000000 -0.001536,-0.000099,0.000000 -0.001536,-0.000099,0.000000</coordinates>
            </LinearRing>
          </outerBoundaryIs>
        </Polygon>
dassouki
+1  A: 

Indieprojector should be able to generate the files you need. It's a free online tool that reprojects any shapefile and exports it again to .svg. They even have US States included online so you won't need to mess with the Shapefile.

Jelly
+2  A: 

Kevin McCurley has created some maps of the United States, including a map of all 50 states, in the Mercator projection. If you look at the source of that final link, it consists of (latitude, longitude) pairs for the outlines of the states, which are then transformed into (x, y) pairs for display in the svg format. His allowed usage is

Feel free to use these files in your own fun, but I would appreciate receiving credit for having created them. Enjoy...

I don't know if that's good enough for you.

A. Rex
That was EXACTLY what I needed, thanks. I'll definitely look into the shape file ideas presented in the other answers in the future, especially when a file like this isn't available.
Eli Courtwright
+1  A: 

Here is a stackoverflow response with the JS math from lat long to mercator

http://stackoverflow.com/questions/1019997/in-javascript-convert-lat-longs-to-x-y-co-ordinates

download one of those shapefiles listed above and then use OGR to do ogr2ogr for converting to CSV

get OGR here

http://www.gdal.org/ogr/index.html

Here is the doc for OGR

http://www.gdal.org/ogr2ogr.html

Here is the name of the output formats

http://www.gdal.org/ogr/ogr_formats.html

Given your reputation I know you can handle it once you get it to CSV

TheSteve0
+1  A: 

A new map from scratch

It's easy to create a map from the free shapefile which is provided in pretty high resolution by the USGS. Actually, some guy has already created a shapefile->svg translation script that does just that for you but note that the project has been moved to GitHub.

Unfortunately the shapefile is in the NAD83 projection so it needs to be reprojected to Mercator before you run the script. Again, this is an already solved problem and a very common thing to do in GIS's and only needs to be done once. For this I'm going to suggest MapWindow because it's trivial to do in that.

To reproject the shapefiles to Mercator you need to download and install MapWindow. When you run the program you can see a Plug-ins menu in the main window and you're going to need to enable the GIS Tools plugin. Then you click the green "plus" symbol to add the shapefile into MapWindow and it should render the USA on the screen.

When you've imported the shapefile into MapWindow you're going to reproject it. To do that you click on the GIS Tools -> Vector -> Reproject a Shapefile and it should open up a dialog box.

The first dialog you see asks about what projection you want:

  • Category: Projected Coordinate Systems
  • Group: World
  • Name: Mercator (world)

The second might not show up but if it does it's asking about the current projection:

  • Category: Geographic Coordinate Systems
  • Group: North America
  • Name: North American Datum 1983

This process should create a new shapefile called *statesp020_reprojected* or something like that.

You now need to translate the shpaefile to SVG using the script above. I'm not going to bother with writing instructions on that because I haven't tried it before, but I'm sure you can figure it out!

Hannson