Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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>

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!

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).

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.

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

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:

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

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top