Skip to content
Permalink
Browse files
import vector layer: pass empty geometry column importing non-spatial…
… table, do not deference null pointer (fix #6728)
  • Loading branch information
brushtyler committed Nov 30, 2012
1 parent 5b41187 commit 85faeb37a066692eb6e5c4a5aeac4c53f77f402e
Showing with 16 additions and 10 deletions.
  1. +13 −8 python/plugins/db_manager/dlg_import_vector.py
  2. +3 −2 src/core/qgsvectorlayerimport.cpp
@@ -63,8 +63,9 @@ def __init__(self, inLayer, outDb, outUri, parent=None):

pk = self.outUri.keyColumn()
self.editPrimaryKey.setText(pk if pk != "" else self.default_pk)
geom = self.outUri.geometryColumn()
self.editGeomColumn.setText(geom if geom != "" else self.default_geom)
if self.inLayer.hasGeometryType():
geom = self.outUri.geometryColumn()
self.editGeomColumn.setText(geom if geom != "" else self.default_geom)

inCrs = self.inLayer.crs()
srid = inCrs.postgisSrid() if inCrs.isValid() else 4236
@@ -76,10 +77,11 @@ def __init__(self, inLayer, outDb, outUri, parent=None):

def checkSupports(self):
allowSpatial = self.db.connector.hasSpatialSupport()
self.chkGeomColumn.setEnabled(allowSpatial and self.inLayer.hasGeometryType())
self.chkSourceSrid.setEnabled(allowSpatial)
self.chkTargetSrid.setEnabled(allowSpatial)
self.chkSpatialIndex.setEnabled(allowSpatial)
hasGeomType = self.inLayer.hasGeometryType()
self.chkGeomColumn.setEnabled(allowSpatial and hasGeomType)
self.chkSourceSrid.setEnabled(allowSpatial and hasGeomType)
self.chkTargetSrid.setEnabled(allowSpatial and hasGeomType)
self.chkSpatialIndex.setEnabled(allowSpatial and hasGeomType)


def populateSchemas(self):
@@ -174,8 +176,11 @@ def importLayer(self):
# get pk and geom field names from the source layer or use the
# ones defined by the user
pk = self.outUri.keyColumn() if not self.chkPrimaryKey.isChecked() else self.editPrimaryKey.text()
geom = self.outUri.geometryColumn() if not self.chkGeomColumn.isChecked() else self.editGeomColumn.text()
geom = geom if geom != "" else self.default_geom
if self.inLayer.hasGeometryType():
geom = self.outUri.geometryColumn() if not self.chkGeomColumn.isChecked() else self.editGeomColumn.text()
geom = geom if geom != "" else self.default_geom
else:
geom = QString()

self.outUri.setDataSource( schema, table, geom, QString(), pk )
uri = self.outUri.uri()
@@ -121,11 +121,12 @@ bool QgsVectorLayerImport::addFeature( QgsFeature& feat )
const QgsAttributeMap &attrs = feat.attributeMap();

QgsFeature newFeat;
newFeat.setGeometry( *feat.geometry() );
if ( feat.geometry() )
newFeat.setGeometry( *feat.geometry() );

for ( QgsAttributeMap::const_iterator it = attrs.begin(); it != attrs.end(); it++ )
{
// add only mapped attributes (un-mapped ones are not present in the
// add only mapped attributes (un-mapped ones will not be present in the
// destination layer)
if ( mOldToNewAttrIdx.contains( it.key() ) )
{

0 comments on commit 85faeb3

Please sign in to comment.