def _geomAttrbUpdate(self, fids): """Update geometry atrributes of currently selected features :param fid: list feature id """ mapLayer = self.parent.toolbars["vdigit"].GetLayer() vectorName = mapLayer.GetName() if self.tree: item = self.tree.FindItemByData("maplayer", mapLayer) vdigit = self.tree.GetLayerInfo(item, key="vdigit") else: item = vdigit = None if not vdigit or "geomAttr" not in vdigit: return dbInfo = gselect.VectorDBInfo(vectorName) sqlfile = tempfile.NamedTemporaryFile(mode="w") for fid in fids: for layer, cats in six.iteritems(self.digit.GetLineCats(fid)): table = dbInfo.GetTable(layer) for attrb, item in six.iteritems(vdigit["geomAttr"]): val = -1 if attrb == "length": val = self.digit.GetLineLength(fid) type = attrb elif attrb == "area": val = self.digit.GetAreaSize(fid) type = attrb elif attrb == "perimeter": val = self.digit.GetAreaPerimeter(fid) type = "length" if val < 0: continue val = UnitsConvertValue(val, type, item["units"]) for cat in cats: sqlfile.write( "UPDATE %s SET %s = %f WHERE %s = %d;\n" % ( table, item["column"], val, dbInfo.GetKeyColumn(layer), cat, )) sqlfile.file.flush() RunCommand("db.execute", parent=True, quiet=True, input=sqlfile.name)
def _geomAttrbUpdate(self, fids): """Update geometry atrributes of currently selected features :param fid: list feature id """ mapLayer = self.parent.toolbars['vdigit'].GetLayer() vectorName = mapLayer.GetName() if self.tree: item = self.tree.FindItemByData('maplayer', mapLayer) vdigit = self.tree.GetLayerInfo(item, key='vdigit') else: item = vdigit = None if not vdigit or 'geomAttr' not in vdigit: return dbInfo = gselect.VectorDBInfo(vectorName) sqlfile = tempfile.NamedTemporaryFile(mode="w") for fid in fids: for layer, cats in self.digit.GetLineCats(fid).iteritems(): table = dbInfo.GetTable(layer) for attrb, item in vdigit['geomAttr'].iteritems(): val = -1 if attrb == 'length': val = self.digit.GetLineLength(fid) type = attrb elif attrb == 'area': val = self.digit.GetAreaSize(fid) type = attrb elif attrb == 'perimeter': val = self.digit.GetAreaPerimeter(fid) type = 'length' if val < 0: continue val = UnitsConvertValue(val, type, item['units']) for cat in cats: sqlfile.write( 'UPDATE %s SET %s = %f WHERE %s = %d;\n' % (table, item['column'], val, dbInfo.GetKeyColumn(layer), cat)) sqlfile.file.flush() RunCommand('db.execute', parent=True, quiet=True, input=sqlfile.name)