Skip to content
Permalink
Browse files
import vector layer: allow to create single-part geometries from shap…
…efile (follow 08e844f)
  • Loading branch information
brushtyler committed Dec 5, 2012
1 parent 98dc557 commit e1697359d1ecd30e0b3483553041bf5218bc7b30
Showing with 38 additions and 38 deletions.
  1. +4 −1 python/plugins/db_manager/dlg_import_vector.py
  2. +0 −9 python/plugins/db_manager/ui/DlgImportVector.ui
  3. +34 −28 src/core/qgsvectorlayerimport.cpp
@@ -88,10 +88,11 @@ def checkSupports(self):
""" update options available for the current input layer """
allowSpatial = self.db.connector.hasSpatialSupport()
hasGeomType = self.inLayer and self.inLayer.hasGeometryType()
isShapefile = self.inLayer and self.inLayer.providerType() == "ogr" and self.inLayer.storageType() == "ESRI Shapefile"
self.chkGeomColumn.setEnabled(allowSpatial and hasGeomType)
self.chkSourceSrid.setEnabled(allowSpatial and hasGeomType)
self.chkTargetSrid.setEnabled(allowSpatial and hasGeomType)
#self.chkSinglePart.setEnabled(allowSpatial and hasGeomType)
self.chkSinglePart.setEnabled(allowSpatial and hasGeomType and isShapefile)
self.chkSpatialIndex.setEnabled(allowSpatial and hasGeomType)


@@ -269,6 +270,8 @@ def accept(self):
options['overwrite'] = True
elif self.radAppend.isChecked():
options['append'] = True
if self.chkSinglePart.isEnabled() and self.chkSinglePart.isChecked():
options['forceSinglePartGeometryType'] = True

outCrs = None
if self.chkTargetSrid.isEnabled() and self.chkTargetSrid.isChecked():
@@ -138,11 +138,6 @@
<zorder>label_2</zorder>
<zorder>cboSchema</zorder>
<zorder>label_3</zorder>
<zorder>widget_3</zorder>
<zorder>cboTable</zorder>
<zorder>label_2</zorder>
<zorder>cboSchema</zorder>
<zorder>label_3</zorder>
</widget>
</item>
<item>
@@ -302,9 +297,6 @@
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="chkSinglePart">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Create single-part geometries instead of multi-part</string>
</property>
@@ -334,7 +326,6 @@
<zorder>groupBox</zorder>
<zorder>groupBox_2</zorder>
<zorder>buttonBox</zorder>
<zorder>widget</zorder>
<zorder>groupBox_3</zorder>
<zorder>wdgInput</zorder>
</widget>
@@ -204,6 +204,15 @@ QgsVectorLayerImport::importLayer( QgsVectorLayer* layer,
outputCRS = &layer->crs();
}


bool overwrite = false;
bool forceSinglePartGeom = false;
if ( options )
{
overwrite = options->take( "overwrite" ).toBool();
forceSinglePartGeom = options->take( "forceSinglePartGeometryType" ).toBool();
}

QgsFieldMap fields = skipAttributeCreation ? QgsFieldMap() : layer->pendingFields();
QGis::WkbType wkbType = layer->wkbType();

@@ -216,38 +225,35 @@ QgsVectorLayerImport::importLayer( QgsVectorLayer* layer,
fldIt.value().setName( fldIt.value().name().toLower() );
}

// convert wkbtype to multipart (see #5547)
switch ( wkbType )
if ( !forceSinglePartGeom )
{
case QGis::WKBPoint:
wkbType = QGis::WKBMultiPoint;
break;
case QGis::WKBLineString:
wkbType = QGis::WKBMultiLineString;
break;
case QGis::WKBPolygon:
wkbType = QGis::WKBMultiPolygon;
break;
case QGis::WKBPoint25D:
wkbType = QGis::WKBMultiPoint25D;
break;
case QGis::WKBLineString25D:
wkbType = QGis::WKBMultiLineString25D;
break;
case QGis::WKBPolygon25D:
wkbType = QGis::WKBMultiPolygon25D;
break;
default:
break;
// convert wkbtype to multipart (see #5547)
switch ( wkbType )
{
case QGis::WKBPoint:
wkbType = QGis::WKBMultiPoint;
break;
case QGis::WKBLineString:
wkbType = QGis::WKBMultiLineString;
break;
case QGis::WKBPolygon:
wkbType = QGis::WKBMultiPolygon;
break;
case QGis::WKBPoint25D:
wkbType = QGis::WKBMultiPoint25D;
break;
case QGis::WKBLineString25D:
wkbType = QGis::WKBMultiLineString25D;
break;
case QGis::WKBPolygon25D:
wkbType = QGis::WKBMultiPolygon25D;
break;
default:
break;
}
}
}

bool overwrite = false;
if ( options )
{
overwrite = options->take( "overwrite" ).toBool();
}

QgsVectorLayerImport * writer =
new QgsVectorLayerImport( uri, providerKey, fields, wkbType, outputCRS, overwrite, options );

0 comments on commit e169735

Please sign in to comment.