2

I'm trying to write a simple Python script to load data stored in MSSQL to PostGIS. Idea is to load processing in QGIS and then run "importintopostgis" geoalgorithm : "Import into Postgis" from python, since layers in MSSQL don't change:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import processing

processing.runalg("qgis:importintopostgis"....
processing.runalg("qgis:importintopostgis"...

For some of the layers it actually works ok, till i stumble to one of the layers that returns:

Error importing to PostGIS Feature write errors: Creation error for features from #0 to #0. Provider errors was: PostGIS error while adding features: ERROR: Geometry type (MultiLineString) does not match column type (LineString) Only 88794 of 88994 features written.

I'm assuming that plugin assumes that geometry is Linestring when reading few lines, creates table with linestring geo feature and then stumbles on multilinestring.

Can't find a way to correct that any idea ?

The other possibility I found was to use OGR import from python with:

processing.runalg("gdalogr:importvectorintopostgisdatabaseavailableconnections",1,"dbname=

This one crashes with message:

'NoneType' object has no attribute 'groups' See log for more details

I can't find error log in "History and log" window.

I think now I'm stuck. Any Idea how to solve this problem ? ETL tool, some other script etc.

  • did you try to convert the data with only ogr2ogr? It seems a bit of detour to do this with QGIS and python scripting. There is also this thread on doing it with saving layers from QGIS: gis.stackexchange.com/questions/104081/… – tilt Jul 3 '17 at 11:35
  • I have around 200 layers that should be updated in PostGIS so method described in link is not appropriate for me even though it works OK. That's why I use scripting in the first place. Using ogr2ogr directly is option, problem is that this script should run on click of a button or when opening project. Tnx for commenting :) – Greg Jul 3 '17 at 11:43
  • I found out that MSSQL was storing different kind of geometries polyline, point etc. ESRI apparently doesn't have problems with that but qgis does. Not sure what kind of table should I open in postgis to make it compatible for loading.... – Greg Nov 6 '17 at 11:14

Your Answer

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

Browse other questions tagged or ask your own question.