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()
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()
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
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 __init__(self, kenvelope=None): '''kenvelope es un envelope de JTS''' if kenvelope: self.kenvelope = kenvelope else: self.kenvelope = Envelope()
class PKEnvelope: def __init__(self, kenvelope=None): '''kenvelope es un envelope de JTS''' if kenvelope: self.kenvelope = kenvelope else: self.kenvelope = Envelope() def bottom(self): return self.kenvelope.getMinY() def top(self): return self.kenvelope.getMaxY() def left(self): return self.kenvelope.getMinX() def right(self): return self.kenvelope.getMaxX() def is_null_envelope(self): return self.kenvelope.isNull() def set_to_null(self): '''Hace que este envelope se corresponda con el de una geometria vacia''' self.kenvelope.setToNull() def width(self): return self.kenvelope.getWidth() def height(self): return self.kenvelope.getHeight() def expand_by(self, xfactor, yfactor=None): '''Aumenta este envelope en las direcciones x e y la cantidad indicada. Si yfactor no se indica, se usara xfactor en las dos direcciones. Siempre devuelve None''' if yfactor == None: yfactor = xfactor self.kenvelope.expandBy(xfactor, yfactor) def expand_to_include_point(self, x, y): '''Aumenta este envelope para que incluya el punto x, y. Siempre devuelve None''' self.kenvelope.expandToInclude(x, y) def expand_to_include_envelope(self, pkenvelope): '''Aumenta este envelope para incluir pkenvelope (que es un PKEnvelope). Siempre devuelve None''' self.kenvelope.expandToInclude(pkenvelope.kenvelope) def contains_point(self, x, y): return self.kenvelope.contains(x, y) def contains_envelope(self, pkenvelope): '''Devuelve True si pkenvelope esta completamente dentro de este envelope''' return self.kenvelope.contains(pkenvelope.kenvelope) def intersection(self, pkenvelope): return PKEnvelope(self.kenvelope.intersection(pkenvelope.kenvelope)) def clone(self): '''Devuelve un PKEnvelope identido (pero sin relacion alguna) a este''' return PKEnvelope(self.kenvelope.clone()) def __getitem__(self, key): if key == 'bottom' or key == 'ymin' or key == 'miny' or key == 1: return self.bottom() #min_y elif key == 'top' or key == 'ymax' or key == 'maxy' or key == 3: return self.top() #max_y elif key == 'left' or key == 'xmin' or key == 'minx' or key == 0: return self.left() #min_x elif key == 'right' or key == 'xmax' or key == 'maxx' or key == 2: return self.right() #max_x def __str__(self): '''Devuelve una cadena como "PKEnvelope[xmin, ymin, xmax, ymax]"''' return 'PKEnvelope[' \ + self.left() + ', ' \ + self.bottom() + ', ' \ + self.right() + ', ' \ + self.top() + ']' def __eq__(self, other): return type(self) == type(other) and self.kenvelope.equals( other.kenvelope) # la comprobacion de tipo tambien comprueba que other no sea None (self nunca lo es) #end class PKEnvelope
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()