Beispiel #1
0
def unionSelected(event):  #TODO: support undo better
    layers = getLayersWithSelectedItems()
    if layers.size() == 0:
        warnUser("Nothing Selected")
        return
    for layer in layers:
        if not layer.isEditable():
            warnUser("Noneditable layer(s) selected")
            return
    #get the union of all selected features
    selectedFeatures = getSelectedFeatures()
    unionGeometry = selectedFeatures[0].geometry
    otherFeatures = list(selectedFeatures)[1:]  #[1:] is skip first
    for feature in otherFeatures:
        unionGeometry = unionGeometry.union(feature.geometry)
    #set the geometry of the first feature of the first layer to the union        
    ModGeo = ModifyGeometry("Union Selected Features")
    selectedFeatures = featuresOnLayer(layers[0])
    ModGeo.addChangeGeometryTransaction(layers[0], selectedFeatures[0], unionGeometry)
    #remove all other features leaving only the union
    del selectedFeatures[0] #remove the first feature of the first layer from the list
    ModGeo.addRemoveFeaturesTransaction(layers[0], selectedFeatures)
    del layers[0]
    for layer in layers:
        selectedFeatures = featuresOnLayer(layer)
        ModGeo.addRemoveFeaturesTransaction(layer, selectedFeatures)
    ModGeo.commitTransactions()
    repaint()
    
        
def unionSelected(event):  #TODO: support undo better
    layers = getLayersWithSelectedItems()
    if layers.size() == 0:
        warnUser("Nothing Selected")
        return
    for layer in layers:
        if not layer.isEditable():
            warnUser("Noneditable layer(s) selected")
            return
    #get the union of all selected features
    selectedFeatures = getSelectedFeatures()
    unionGeometry = selectedFeatures[0].geometry
    otherFeatures = list(selectedFeatures)[1:]  #[1:] is skip first
    for feature in otherFeatures:
        unionGeometry = unionGeometry.union(feature.geometry)
    #set the geometry of the first feature of the first layer to the union        
    ModGeo = ModifyGeometry("Union Selected Features")
    selectedFeatures = featuresOnLayer(layers[0])
    ModGeo.addChangeGeometryTransaction(layers[0], selectedFeatures[0], unionGeometry)
    #remove all other features leaving only the union
    del selectedFeatures[0] #remove the first feature of the first layer from the list
    ModGeo.addRemoveFeaturesTransaction(layers[0], selectedFeatures)
    del layers[0]
    for layer in layers:
        selectedFeatures = featuresOnLayer(layer)
        ModGeo.addRemoveFeaturesTransaction(layer, selectedFeatures)
    ModGeo.commitTransactions()
    repaint()
    
        
def distributeSelected():
    global _xDisp, _yDisp
    warnMsg = ""
    
    layers = getLayersWithSelectedItems()
    if layers.size() == 0:
        warnUser("Nothing Selected")
        return
        
    #get the expanded envelope of all selected features
    #also get the sum of all the individual envelopes
    totalEnvelope = Envelope()
    usedWidth = 0
    usedHeight = 0
    featureList = []
    for layer in layers:
        selectedFeatures = featuresOnLayer(layer)
        for feature in selectedFeatures:
            indivEnv = feature.getGeometry().getEnvelopeInternal()
            usedWidth = usedWidth + indivEnv.getWidth()
            usedHeight = usedHeight + indivEnv.getHeight()
            totalEnvelope.expandToInclude(indivEnv)
            featureTuple = (feature, indivEnv, layer)
            featureList.append(featureTuple)
            
    if len(featureList) < 3:
        return
    name = "Distribute Features "
    if _typeDistribution == vertical:
        name = name + "Vertical"
    else: #_typeDistribution == horizontal:
        name = name + "Horizontal"
    distributeGeo = ModifyGeometry(name)
    cf = CoordFilter()
    
    if _typeDistribution == vertical: 
        verticalSpacing = (totalEnvelope.getHeight() - usedHeight) / (len(featureList) - 1)        
        newPos = totalEnvelope.getMinY()
        while len(featureList) > 0:
            #find the bottom most feature
            index = 0
            minPos = totalEnvelope.getMaxY()
        
            for featureTuple in featureList:
                pos = featureTuple[1].getMinY()
                if pos < minPos:
                    currIndex = index
                    minPos = pos
                index = index + 1
            
            currTuple = featureList[currIndex]
            feature = currTuple[0]
            geo = feature.getGeometry().clone()
            _xDisp = 0
            _yDisp = newPos - currTuple[1].getMinY()
            if (not currTuple[2].isEditable()) and (_yDisp <> 0.0):
                warnMsg = "Noneditable layer selected"
            else:
                geo.apply(cf) 
                distributeGeo.addChangeGeometryTransaction(currTuple[2], currTuple[0], geo)
            newPos = newPos + currTuple[1].getHeight() + verticalSpacing
            del featureList[currIndex]
            
    else: #_typeDistribution == horizontal:   
        horizontalSpacing = (totalEnvelope.getWidth() - usedWidth) / (len(featureList) - 1)        
        newPos = totalEnvelope.getMinX()
        while len(featureList) > 0:
            #find the left most feature
            index = 0
            minPos = totalEnvelope.getMaxX()
        
            for featureTuple in featureList:
                pos = featureTuple[1].getMinX()
                if pos < minPos:
                    currIndex = index
                    minPos = pos
                index = index + 1
            
            currTuple = featureList[currIndex]
            feature = currTuple[0]
            geo = feature.getGeometry().clone()
            _xDisp = newPos - currTuple[1].getMinX()
            _yDisp = 0
            if (not currTuple[2].isEditable()) and (_xDisp <> 0.0):
                warnMsg = "Noneditable layer selected"
            else:
                geo.apply(cf) 
                distributeGeo.addChangeGeometryTransaction(currTuple[2], currTuple[0], geo)
            newPos = newPos + currTuple[1].getWidth() + horizontalSpacing
            del featureList[currIndex]
        
    distributeGeo.commitTransactions()
    if len(warnMsg) > 0:
        warnUser(warnMsg)    
    repaint()
def distributeSelected():
    global _xDisp, _yDisp
    warnMsg = ""

    layers = getLayersWithSelectedItems()
    if layers.size() == 0:
        warnUser("Nothing Selected")
        return

    #get the expanded envelope of all selected features
    #also get the sum of all the individual envelopes
    totalEnvelope = Envelope()
    usedWidth = 0
    usedHeight = 0
    featureList = []
    for layer in layers:
        selectedFeatures = featuresOnLayer(layer)
        for feature in selectedFeatures:
            indivEnv = feature.getGeometry().getEnvelopeInternal()
            usedWidth = usedWidth + indivEnv.getWidth()
            usedHeight = usedHeight + indivEnv.getHeight()
            totalEnvelope.expandToInclude(indivEnv)
            featureTuple = (feature, indivEnv, layer)
            featureList.append(featureTuple)

    if len(featureList) < 3:
        return
    name = "Distribute Features "
    if _typeDistribution == vertical:
        name = name + "Vertical"
    else:  #_typeDistribution == horizontal:
        name = name + "Horizontal"
    distributeGeo = ModifyGeometry(name)
    cf = CoordFilter()

    if _typeDistribution == vertical:
        verticalSpacing = (totalEnvelope.getHeight() -
                           usedHeight) / (len(featureList) - 1)
        newPos = totalEnvelope.getMinY()
        while len(featureList) > 0:
            #find the bottom most feature
            index = 0
            minPos = totalEnvelope.getMaxY()

            for featureTuple in featureList:
                pos = featureTuple[1].getMinY()
                if pos < minPos:
                    currIndex = index
                    minPos = pos
                index = index + 1

            currTuple = featureList[currIndex]
            feature = currTuple[0]
            geo = feature.getGeometry().clone()
            _xDisp = 0
            _yDisp = newPos - currTuple[1].getMinY()
            if (not currTuple[2].isEditable()) and (_yDisp <> 0.0):
                warnMsg = "Noneditable layer selected"
            else:
                geo.apply(cf)
                distributeGeo.addChangeGeometryTransaction(
                    currTuple[2], currTuple[0], geo)
            newPos = newPos + currTuple[1].getHeight() + verticalSpacing
            del featureList[currIndex]

    else:  #_typeDistribution == horizontal:
        horizontalSpacing = (totalEnvelope.getWidth() -
                             usedWidth) / (len(featureList) - 1)
        newPos = totalEnvelope.getMinX()
        while len(featureList) > 0:
            #find the left most feature
            index = 0
            minPos = totalEnvelope.getMaxX()

            for featureTuple in featureList:
                pos = featureTuple[1].getMinX()
                if pos < minPos:
                    currIndex = index
                    minPos = pos
                index = index + 1

            currTuple = featureList[currIndex]
            feature = currTuple[0]
            geo = feature.getGeometry().clone()
            _xDisp = newPos - currTuple[1].getMinX()
            _yDisp = 0
            if (not currTuple[2].isEditable()) and (_xDisp <> 0.0):
                warnMsg = "Noneditable layer selected"
            else:
                geo.apply(cf)
                distributeGeo.addChangeGeometryTransaction(
                    currTuple[2], currTuple[0], geo)
            newPos = newPos + currTuple[1].getWidth() + horizontalSpacing
            del featureList[currIndex]

    distributeGeo.commitTransactions()
    if len(warnMsg) > 0:
        warnUser(warnMsg)
    repaint()