10

I am trying to map a Shapefile (download) onto a Google Map using the Javascript API. The Shapefile describes the boundaries of NYC School Districts.

The file's projection was Lambert Conformal Conic, and so I tried to convert it to Google Mercator using QGIS. However, the coordinates still don't make sense. When I map the polygons, they cover all of Earth.

For example, one of the impossible points that I get is -8240484.27362, 4961069.9502.

How can I properly convert my Shapefile to an acceptable format?

LonelyWebCrawler
  • 203
  • 1
  • 2
  • 6

3 Answers3

12

It's true that Google uses Google Mercator (EPSG:3857 or EPSG:900913) for displaying, but I think you/the Javascript API want lat/lon coordinates for input.

So convert the data into EPSG:4326, and look if it fits.

You can load the shapefile into QGIS, and use Openlayers plugin with Google or Openstreetmap background to check if the transformation is correct.

AndreJ
  • 76,698
  • 5
  • 86
  • 162
6

Google uses Google Mercator projection. EPSG:900913. For proj4 settings see here.

To display your data in Google Mercator: On QGIS status bar click on the grey globe icon to open the Project Properties page. Check Enable 'on the fly' CRS transformation and select Google Mercator -EPSG 900913 and click Apply.

To save data in Google Mercator: Right click on shapefile and select Save As.. Select Custom CRS instead of Layer CRS and click Browse to open Coordinate Reference System Selector select Google Mercator EPSG:900913 there and click OK

rkm
  • 1,751
  • 12
  • 22
4

Load the shapefile 'as is' into QGIS and Save as KML will do the conversion and will show correctly in Google Earth.

See: http://pvanb.wordpress.com/2012/07/31/exporting-vector-layer-as-kml-in-qgis/

enter image description here

for Google Maps you need to upload the kml to a public facing webserver.

Example Layer in Google Maps API v3

https://google-developers.appspot.com/maps/documentation/javascript/examples/full/layer-kml

Example Code:

  var ctaLayer = new google.maps.KmlLayer({
    url: 'http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml'
  });
  ctaLayer.setMap(map);
Mapperz
  • 49,701
  • 9
  • 73
  • 132
  • Thanks, but I was considering to use a Shapefile because it seems easier to draw Polygons for each shape rather than import it from KML, because I would have more control over color, etc. – LonelyWebCrawler May 11 '13 at 12:48