I am trying to create a shapefile and a geojson using geopandas and fiona.

import fiona
import fiona.crs


geometry = [Point(xy) for xy in zip(df['longitude'],df['latitude'])]
crs = {'init': 'epsg:4326'}
gdf = GeoDataFrame(df, crs=crs, geometry=geometry)

some more stuffs and finally:

gdf.to_file('localization/shapefiles/localizaciones.shp', driver='ESRI Shapefile')

but the .prj file is in blank. Then the projection is wrong.

I am writing the content of the the .prj file after the file is created in blank, but the crs problems still in progress either in geojson file or gpx files. No crs is created

  • What versions of GeoPandas and Fiona do you have? – joris Nov 16 '18 at 7:05
  • GPX is always EPSG:4326 and so is GeoJSON by the current specification tools.ietf.org/html/rfc7946 so there is no crs problem with them. – user30184 Nov 16 '18 at 7:11
  • Why do you mention GPX? As for the question, it seems clear from the code that a shapefile is written. Then a prj file is needed – atlefren Nov 16 '18 at 9:02
  • About gpx and the geojson is my mistake. Nothing have to do – kamome Nov 16 '18 at 13:36
  • fiona version 1.7.13 Pandas version 0.23.0 Geopandas 0.4.0 – kamome Nov 16 '18 at 13:39

Found two solutions to have coordinate reference system defined in the output shapefile: Proj4 style mappings and WKT strings (source: Fiona). The OGC WKT strings can be found on spatialreference.

import geopandas as gpd
from shapely.geometry import Point

lat_point_list = [50.854457, 52.518172, 50.072651, 48.853033, 50.854457]
lon_point_list = [4.377184, 13.407759, 14.435935, 2.349553, 4.377184]

geometry = [Point(xy) for xy in zip(lon_point_list, lat_point_list)]
#crs1 = {'init': 'epsg:4326'}         # Does NOT work
crs2 = {'proj': 'longlat', 'ellps': 'WGS84', 'datum': 'WGS84', 'no_defs': True}     # Works
#crs3 = 'EPSG:4326'       # Does NOT work
crs4 = 'GEOGCS["WGS 84",DATUM["WGS_1984",' \
       'SPHEROID["WGS 84",6378137,298.257223563,' \
       'AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],' \
       'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],' \
       'UNIT["degree",0.01745329251994328,' \
       'AUTHORITY["EPSG","9122"]],' \
       'AUTHORITY["EPSG","4326"]]'     # Works

points = gpd.GeoDataFrame(index=[0, 1, 2, 3, 4], crs=crs4, geometry=geometry)
points.to_file(filename='points.shp', driver="ESRI Shapefile")
  • Previous solution was on Windows 7 OS using geopandas installation from conda. On Ubuntu 18.04 OS there was no problem creating the projection text in the output shapefile with { 'init': 'epsg:4326'} or 'EPSG:4326'. It worked with both the geopandas installation of conda and conda-forge. – Davma Jan 2 '19 at 23:13
  • EPSG Geodetic Parameter Registry should be used wherever possible (as they are authority that define EPSG codes...) ~ epsg-registry.org/export.htm?wkt=urn:ogc:def:crs:EPSG::4326 – nmtoken Oct 4 '19 at 13:15

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.