More

Import shapefile to PostGIS using Python and OGR?

Import shapefile to PostGIS using Python and OGR?


I am not able to import a shapefile to PostGIS using the same library (OGR). I am using below link but it gives me error. Import shp to Postgis using Python and ogr

Error:

Traceback (most recent call last):

File "C:/Users/n/.qgis2/python/pluginsImporttoolImport_tool.py", line 223, in select_output_file_5

layer = shapefile.GetLayer(0)

AttributeError: 'NoneType' object has no attribute 'GetLayer'


the problem is this line…

srcFile = os.path.join("DISTAL-data", "TM_WORLD_BORDERS-0.3","C:Users
DownloadsTM_WORLD_BORDERS-0.3TM_WORLD_BORDE‌​RS-0.3.shp")

os.path.join() will create this file path (under windows)

DISTAL-dataTM_WORLD_BORDERS-0.3C:Users DownloadsTM_WORLD_BORDERS-0.3TM_WORLD_BORDERS-0.3.shp

which probably isn't a valid path. Just replace it with

srcFile = 'C:Users
DownloadsTM_WORLD_BORDERS-0.3TM_WORLD_BORDERS-0.3.shp'

and it should work.


Watch the video: Tutorial2: How to import shapefile to PostGIS with QGIS? updated