[Qgis-user] How to transform a selected multipart feature into singlepart features during a edit session in QGIS? [SOLVED]

vinayan vinayan123 at gmail.com
Mon Dec 31 18:59:04 PST 2012


that is really cool! I have also felt(coming from ArcGis background :-) 
) that this should be somewhere in the advanced editing 
toolbar..although there is a delete part tool in Qgis, exploding 
selected features this way are much easier for users..



On Monday 31 December 2012 10:50 PM, Alexandre Neto wrote:
>
> Inspired by this question & answer 
> <http://gis.stackexchange.com/questions/9261/switch-line-direction-in-qgis> as 
> an example of how "easily" can one make its own solutions when using 
> Open Source, I have tried to create my own code to selectively 
> "explode" multipart features during an editing session.
>
> I have explored the QGIS 1.8 API <http://qgis.org/api/1.8/> for the 
> first time, and came out with this piece of code that seams to do the job:
>
> |layer=  qgis.utils.iface.mapCanvas().currentLayer()
> remove_list=  []
>
> for  featurein  layer.selectedFeatures():
>      geom=  feature.geometry()
>      # check if feature geometry is multipart
>      if  geom.isMultipart():
>          remove_list.append(feature.id())
>          new_features=  []
>          temp_feature=  QgsFeature(feature)
>          # create a new feature using the geometry of each part
>          for  partin  geom.asGeometryCollection():
>              temp_feature.setGeometry(part)
>              new_features.append(QgsFeature(temp_feature))
>          # add new features to layer
>          layer.addFeatures(new_features,  False)
>
> # remove the original (multipart) features from layer
> if  len(remove_list)  >  0:
>      for  idin  remove_list:
>          layer.deleteFeature(id)     |
>
> I'm not an experienced programmer, so the code might not be the most 
> efficient one.
>
> Next steep will be to make a plugin out of it... Or at least, try to!
>
>
> Alexandre Neto
>
>
> On Thu, Dec 27, 2012 at 12:36 PM, Alexandre Neto 
> <senhor.neto at gmail.com <mailto:senhor.neto at gmail.com>> wrote:
>
>     There are several questions and respective answers for how to make
>     a multipart features Layer into a singlepart features one using QGIS:
>
>       * How to break a single polygon into multiple polys?
>         <http://gis.stackexchange.com/questions/27825/how-to-break-a-single-polygon-into-multiple-polys>
>       * How to split non-contiguous feature in QGIS?
>         <http://gis.stackexchange.com/questions/23377/how-to-split-non-contiguous-feature-in-qgis>
>
>     But all the solutions I saw, creates a entirely new layer and
>     would transform ALL the multipart geometries into single ones.
>
>     So the questions is, how could one, during an edit session,
>     *selectively* transform a multipart feature into a singlepart
>     feature, without the need to create a new layer?
>
>     I saw a ticket <http://trac.osgeo.org/qgis/ticket/3278>for this
>     but it seems to have been misunderstood.
>
>     It would be the opposite to the "merge selected features" tool,
>     and similar to explode
>     <http://webhelp.esri.com/arcgisdesktop/9.2/index.cfm?TopicName=Merging_and_separating_features> in
>     ArcGIS.
>
>     Is there any plugin doing this? How could this be done using the
>     python console?
>
>
>     Alexandre Neto
>
>
>     PS: I have posted the same question
>     <http://gis.stackexchange.com/questions/44799/how-to-transform-a-selected-multipart-feature-into-singlepart-features-during-a>in
>     gis.stackexchange.com <http://gis.stackexchange.com> In case
>     anyone wants to answer there.
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20130101/ecbddc47/attachment.html>


More information about the Qgis-user mailing list