Skip to content

Commit

Permalink
import vector layer: pass empty geometry column importing non-spatial…
Browse files Browse the repository at this point in the history
… table, do not deference null pointer (fix #6728)
  • Loading branch information
brushtyler committed Nov 30, 2012
1 parent 5b41187 commit 85faeb3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
21 changes: 13 additions & 8 deletions python/plugins/db_manager/dlg_import_vector.py
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions src/core/qgsvectorlayerimport.cpp
Expand Up @@ -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() ) )
{
Expand Down

0 comments on commit 85faeb3

Please sign in to comment.