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

Taras
  • 32,823
  • 4
  • 66
  • 137
user28781
  • 281
  • 1
  • 3
  • 3

5 Answers5

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

AndreJ
  • 76,698
  • 5
  • 86
  • 162
  • any way to "save as" with multiple layers? – chrismarx Feb 04 '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 05 '16 at 06: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 05 '16 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.

Martin Thoma
  • 287
  • 1
  • 3
  • 9
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

Gipong
  • 196
  • 1
  • 4
  • 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 Jun 28 '22 at 04:02
2

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

http://ogre.adc4gis.com/

RustyShackleford
  • 717
  • 1
  • 6
  • 19
0

How about trying out this online tool?

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

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