Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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.

share|improve this answer
    
Thank you, converting it into EPSG:4326 worked! –  LonelyWebCrawler May 11 '13 at 12:51

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

share|improve this answer
    
Thanks, but that's actually exactly what I did. In the .prj file, it even says Google_Maps_Global_Mercator. But still, the coordinates are wacky. –  LonelyWebCrawler May 11 '13 at 12:45
    
Did you have .qpj file. if so remove that and do again –  rashad May 11 '13 at 13:41
    
I did have one, but the solution was to convert the file into EPSG:4326. Thanks for your help! –  LonelyWebCrawler May 11 '13 at 13:42
    
@rashad, 900913 is authority OpenLayers. EPSG's version is 3857. –  mkennedy May 12 '13 at 22:23

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);
share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.