28

I'm trying to convert shapefiles from the State of Texas Senate Districts website into a GeoJSON file for use with Google Maps API.

I'm using QGIS to facilitate but I can't get the projection/coordinates right. So far I've tried Google Mercator (EPSG:900913) and WGS 84 (EPSG:4326) with no luck.

I'm using the OpenLayers to verify results and it keeps placing Texas near the Gulf of Guinea (0 lat, 0 lng).

5 Answers 5

26

It is no problem to load the downloadable shapefile directly into QGIS.

The data is in EPSG:3081, you better leave it that way. Google API expects latlong values, so the target CRS should be EPSG:4326.

Just rightclick on the layer -> Save As... to choose file type GeoJSON, a different file name, and EPSG:4326 as new CRS. You can add the result to the canvas to see that they align (On-the-fly-reprojectionselected).

3
  • any way to "save as" with multiple layers?
    – chrismarx
    Commented Feb 4, 2016 at 21:16
  • No, every file needs a different destination file name. You can use ogr2ogr on the command line for batch processing.
    – AndreJ
    Commented Feb 5, 2016 at 6:37
  • seems like maybe the batch processing support, which supports things like sensible defaults for automatic file naming could be employed to just send the resulting files to a folder
    – chrismarx
    Commented Feb 5, 2016 at 16:02
10

Via Command line:

ogr2ogr -f GeoJSON -t_srs crs:84 output.geojson input.shp

I guess this is what the web client from this answer uses.

1
  • Just tested. Behaves way better than QGIS when it comes to the RAM consumption! Commented Aug 22, 2019 at 10:26
9

Here is the convert tool for shapefile to geojson via web browser without server-side code and supporting non-english encoding, just need to upload the zip file and set the encoding for the correctly text.

https://github.com/gipong/shp2geojson.js

If you use this library with Google Map api v3, you can skip EPSG code field because the ZIP archive(PlanS172.zip) download form the State of Texas Senate Districts website contain the .prj file.

loadshp({
    url: '/shp/PlanS172.zip', // path or your upload file
    encoding: 'big5' // default utf-8
}, function(geojson) {
    // geojson returned
});

enter image description here

1
  • This helped me upload a geojson file to MapBox. I tried using QGIS 2.18.16, but MapBox threw an error about a deprecated EPSGI:4236 tag in the first line.
    – jvangeld
    Commented Jun 28, 2022 at 4:02
2

This should help you if you only need to do a few shapefiles

http://ogre.adc4gis.com/

1
  • thats pretty nice, I was about to send a link with ogr2ogr example
    – geomajor56
    Commented Apr 3, 2014 at 0:00
0

How about trying out this online tool?

https://9revolution9.com/en/tools/geo/shp_geojson/

https://9revolution9.com/en/tools/geo/shp_geojson/

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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