Skip to content

Commit

Permalink
import vector layer: allow to create single-part geometries from shap…
Browse files Browse the repository at this point in the history
…efile (follow 08e844f)
  • Loading branch information
brushtyler committed Dec 5, 2012
1 parent 98dc557 commit e169735
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
5 changes: 4 additions & 1 deletion python/plugins/db_manager/dlg_import_vector.py
Expand Up @@ -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)


Expand Down Expand Up @@ -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():
Expand Down
9 changes: 0 additions & 9 deletions python/plugins/db_manager/ui/DlgImportVector.ui
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
62 changes: 34 additions & 28 deletions src/core/qgsvectorlayerimport.cpp
Expand Up @@ -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();

Expand All @@ -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 );

Expand Down

0 comments on commit e169735

Please sign in to comment.