1

Currently, I am trying to transform a shapefile to GeoJSON, I have the .shp, .shx, .dbf and .prj files.

In order to do this I have the following code:

import json
import geopandas as gpd
import shapefile

SHP_FILE = '00ent.shp'
DBF_FILE = '00ent.dbf'
JSON_FILE = "mexico.geojson"

geodf = gpd.read_file(DBF_FILE)
geodf.plot()

enter image description here

The problem is that these points in the geometry, are not a lat, long points, and I want to convert to lat, lang in order to convert the file in a geoJson with the lat long coordinates.

Data:

CVEGEO  CVE_ENT NOMGEO  geometry
0   01  01  Aguascalientes  POLYGON ((2470517.824 1155028.588, 2470552.248...
1   02  02  Baja California MULTIPOLYGON (((1493197.166 1849625.247, 14934...
2   03  03  Baja California Sur MULTIPOLYGON (((1694656.344 1227647.637, 16946...
3   04  04  Campeche    MULTIPOLYGON (((3544897.199 946994.621, 354491...
4   05  05  Coahuila de Zaragoza    POLYGON ((2469954.193 1978522.993, 2469982.807...
5   06  06  Colima  MULTIPOLYGON (((1157633.318 768573.525,

How can I translate this to lat long?

I can use another Python library if is necessary.

  • You can use QGIS (qgis.org) to change the coordinate system of your data and then export your data to GeoJson . If you need to get a point that represents your polygon you can calculate the centroid. The conversion can also be done in QGIS – Leo Cardona Apr 9 at 21:00
  • The problem is that I need can do this without online tool or other software only with a python library. – Tlaloc-ES Apr 9 at 21:05
1

You should be able to do this with only geopandas:

import geopandas as gpd

shp_file = "00ent.shp"
json_file = "mexico.geojson"

# Read in data
gdf = gpd.read_file(shp_file)
# Reproject to Lat/Long: http://epsg.io/4326
gdf_4326 = gdf.to_crs(epsg='4326')
# Write to file
gdf_4326.to_file(json_file, driver="GeoJSON")
| improve this answer | |
  • is epsg.io/4326 a standard?, what projection was using the current file? Thanks – Tlaloc-ES Apr 9 at 21:45
  • EPSG:4326 is World Geodetic System 1984, used in GPS. – Leo Cardona Apr 9 at 21:57
  • 1
    @Tlaloc-ES, you can see the the projection used in the original file with gdf.crs. That should print the EPSG string that you can use with epsg.io to get more info. – Ryan Apr 10 at 16:20

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.