25

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

24

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
    Feb 4 '16 at 21:16
  • No, every file needs a different destination file name. You can use ogr2ogr on the command line for batch processing.
    – AndreJ
    Feb 5 '16 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
    Feb 5 '16 at 16:02
8

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

7

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! Aug 22 '19 at 10:26
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
    Apr 3 '14 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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