Пример #1
0
 def get_by_envelope(self, bbox):
     '''bbox es un PKEnvelope o una tupla (xmin, ymin, xmax, ymax) -> lista de PKFeature
     cuyos envelopes intersectan con bbox'''
     kenvelope = None
     if type(bbox) == type(()):
         kenvelope = Envelope(bbox[0], bbox[2], bbox[1],
                              bbox[3])  #  Envelope(xmin, xmax, ymin, ymax)
     else:
         kenvelope = bbox.kenvelope
     kfeatures = self.klayer.getUltimateFeatureCollectionWrapper().query(
         kenvelope)
     pkfeatures = [
         PKFeature(self.klayer, kfeature) for kfeature in kfeatures
     ]
     return pkfeatures
Пример #2
0
def alignSelected():
    global _leftAlign, _rightAlign, _topAlign, _bottomAlign, _verticalAlign, _horizontalAlign, _layerEditable, _warnMsg

    #get the expanded envelope of all selected features
    layers = getLayersWithSelectedItems()
    if layers.size() == 0:
        warnUser("Nothing Selected")
        return
    envelope = Envelope()
    for layer in layers:
        selectedFeatures = featuresOnLayer(layer)
        for feature in selectedFeatures:
            envelope.expandToInclude(
                feature.getGeometry().getEnvelopeInternal())

    _leftAlign = envelope.getMinX()
    _rightAlign = envelope.getMaxX()
    _topAlign = envelope.getMaxY()
    _bottomAlign = envelope.getMinY()
    _verticalAlign = envelope.centre().x
    _horizontalAlign = envelope.centre().y
    name = "Align Features "

    if _typeAlignment == left:
        name = name + "Left"
    elif _typeAlignment == top:
        name = name + "Top"
    elif _typeAlignment == right:
        name = name + "Right"
    elif _typeAlignment == bottom:
        name = name + "Bottom"
    elif _typeAlignment == vertical:
        name = name + "Vertical"
    else:  #_typeAlignment == horizontal:
        name = name + "Horizontal"
    alignGeo = AlignGeometry(name)

    # loop through each layer and align selected geometries
    _warnMsg = ""

    for layer in layers:
        _layerEditable = layer.isEditable()
        alignGeo.addTransactionOnSelection(layer)
    if len(_warnMsg) > 0:
        warnUser(_warnMsg)
    alignGeo.commitTransactions()
    repaint()
Пример #3
0
 def __init__(self, kenvelope=None):
     '''kenvelope es un envelope de JTS'''
     if kenvelope:
         self.kenvelope = kenvelope
     else:
         self.kenvelope = Envelope()
Пример #4
0
 def setEnvelope(self, env):
     from com.vividsolutions.jts.geom import Envelope
     bounds = env.bounds
     jenv = Envelope(bounds[0], bounds[2], bounds[1], bounds[3])
     self.jobj.setEnvelope(jenv)
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()