QGIS
VBA
Scripts
Копировать в буфер обмена
из текстового поля слева
AFFINE Афинные преобразования
# -*- coding: utf-8 -*- canvas = qgis.utils.iface.mapCanvas() j = 0 for layer in canvas.layers(): # layer = qgis.utils.iface.activeLayer() layer.removeSelection() layer.invertSelection() featids = layer.selectedFeaturesIds() layer.startEditing() canvas.refresh() result = {} features = {} j += 1 for fid in featids: features[fid] = QgsFeature() if not layer.getFeatures( QgsFeatureRequest().setFilterFid(fid) ).nextFeature( features[fid] ): continue; result[fid] = features[fid].geometry() i = 0 vertex = result[fid].vertexAt(i) while (vertex != QgsPoint(0,0)): # x' = a*x + b*y + tx # y' = c*x + d*y + ty newx = 1*vertex.x() + 0*vertex.y() + (39.893648824575 - 39.891595) # Вологда newy = 0*vertex.x() + 1*vertex.y() + (59.2302972492193 - 59.230433) layer.moveVertex(newx,newy,fid,i) i += 1 vertex = result[fid].vertexAt(i) if fid % (len(featids) / 10) == 0: print (str(j) + ") layer '" + layer.name() + " - " + str(100 * fid / len(featids)) + "%") layer.invertSelection() layer.commitChanges() print (str(j) + ") layer '" + layer.name() + "' is ready") print ("Complete") canvas.refresh()
AFFINE Афинные преобразования (поворот)
# -*- coding: utf-8 -*- import math theta = 45 x0 = 40.935985 y0 = 60.045773 theta_radians = 2 * math.pi * theta / 360 a = math.cos(theta_radians) b = -math.sin(theta_radians) tx = (x0 - math.cos(theta_radians) * x0 + math.sin(theta_radians) * y0) c = math.sin(theta_radians) d = math.cos(theta_radians) ty = (y0 - math.sin(theta_radians) * x0 - math.cos(theta_radians) * y0) canvas = qgis.utils.iface.mapCanvas() j = 0 for layer in canvas.layers(): # layer = qgis.utils.iface.activeLayer() layer.removeSelection() layer.invertSelection() featids = layer.selectedFeaturesIds() layer.startEditing() canvas.refresh() result = {} features = {} for fid in featids: features[fid] = QgsFeature() if not layer.getFeatures( QgsFeatureRequest().setFilterFid(fid) ).nextFeature( features[fid] ): continue; result[fid] = features[fid].geometry() i = 0 vertex = result[fid].vertexAt(i) while (vertex != QgsPoint(0,0)): # x' = a*x + b*y + tx # y' = c*x + d*y + ty newx = a*vertex.x() + b*vertex.y() + tx newy = c*vertex.x() + d*vertex.y() + ty layer.moveVertex(newx,newy,fid,i) i += 1 vertex = result[fid].vertexAt(i) layer.invertSelection() layer.commitChanges() j += 1 print (str(j) + ") layer '" + layer.name() + "' is ready") print ("Complete") canvas.refresh()
MERGE Объединение слоёв St
# -*- coding: utf-8 -*- import glob, processing, os for j in ["08","09","21","24"]: path = "c:/Users/User/Desktop/data/" + j + "/" files = glob.glob(path + "*.shp") if not os.path.isdir(path + "merged/"): os.makedirs(path + "merged/") output = path + "merged/merged.shp" processing.runandload("saga:mergelayers", files, True, True, output) print (str(j) + ") layer is ready") print ("Complete")
MERGE Объединение слоёв
# -*- coding: utf-8 -*- from qgis.core import * import os # Set the directory where the input files are stored directory = "d:/!DATA/RU-VLG-725d99-20180721-ru/data/" # Get the list of input files fileList = os.listdir(directory) # Copy the features from all the files in a new list feats = [] for file in fileList: if file.endswith('.shp'): layer = QgsVectorLayer(directory + file, file, 'ogr') for feat in layer.getFeatures(): geom = feat.geometry() attrs = feat.attributes() feature = QgsFeature() feature.setGeometry(geom) feature.setAttributes(attrs) feats.append(feature) # Get the Coordinate Reference System and the list of fields from the last input file crs = layer.crs().toWkt() field_list = layer.dataProvider().fields().toList() # Create the merged layer by checking the geometry type of the input files (for other types, please see the API documentation) if layer.wkbType() == QGis.WKBPoint: v_layer = QgsVectorLayer('Point?crs=' + crs, 'Merged', "memory") if layer.wkbType() == QGis.WKBLineString: v_layer = QgsVectorLayer('LineString?crs=' + crs, 'Merged', "memory") if layer.wkbType() == QGis.WKBPolygon: v_layer = QgsVectorLayer('Polygon?crs=' + crs, 'Merged', "memory") # Add the features to the merged layer prov = v_layer.dataProvider() prov.addAttributes(field_list) v_layer.updateFields() v_layer.startEditing() prov.addFeatures(feats) v_layer.commitChanges() QgsMapLayerRegistry.instance().addMapLayer(v_layer)
SPLIT Деление на слои по атрибутам
# -*- coding: utf-8 -*- import processing # utilize the Processing Framework import os # the standard Python os library input = u'c:/Users/User/Desktop/4/5.shp' field = 'GeomType' operator = 0 # enumerator for equals (=) output = u'c:/Users/User/Desktop/4/' # obtain dictionary object that contains unique values from specified field unique = processing.runalg('qgis:listuniquevalues', input, field, None) values = unique['UNIQUE_VALUES'].split(';') # loop through the unique values array for value in values: # build the output layer path layer_path = os.path.join(output , value + '.shp') # run the extract by attribute tool processing.runalg('qgis:extractbyattribute', input, field, operator, value, layer_path)
SPLIT Деление (экспорт слоя) по атрибуту
# -*- coding: utf-8 -*- import processing input = u'c:/Users/User/Desktop/4/5.shp' field = 'GeomType' operator = 0 # enumerator for equals (=) value = u'Parcel' output = u'c:/Users/User/Desktop/4/Parcel.shp' processing.runalg('qgis:extractbyattribute', input, field, operator, value, output)
Связи
shp = iface.activeLayer() csv = iface.mapCanvas().layers()[0] shpField = 'NAME' csvField = 'NAME' joinObject = QgsVectorJoinInfo() joinObject.joinLayerId = shp.id() joinObject.joinFieldName = shpField joinObject.targetFieldName = csvField joinObject.setJoinFieldNamesSubset(['OSM_ID', 'ADMIN_L4']) joinObject.prefix = '' csv.addJoin(joinObject)
Топологическое объединение
# -*- coding: utf-8 -*- import processing # utilize the Processing Framework layers = QgsMapLayerRegistry.instance().mapLayers().values() [ qgis.utils.iface.legendInterface().setLayerVisible(l, False) for l in layers ] name = u'Административные границы' layer = QgsMapLayerRegistry.instance().mapLayersByName( name )[0] qgis.utils.iface.legendInterface().setLayerVisible(layer, True) it = layer.getFeatures( QgsFeatureRequest().setFilterExpression ( u'"ADMIN_LVL" = \'6\'' ) ) layer.setSelectedFeatures( [ f.id() for f in it ] ) name = u'Здания' layerA = QgsMapLayerRegistry.instance().mapLayersByName( name )[0] qgis.utils.iface.legendInterface().setLayerVisible(layerA, True) processing.runalg("qgis:joinattributesbylocation",layerA,layer,['within'],0,0,"sum,mean,min,max,median",0,"d:/output.shp")
UPDATE Обновление колонки, замена
layer = iface.activeLayer() fieldindex = layer.fieldNameIndex("Tasks") layer.startEditing() for feat in layer.getFeatures(): if feat[fieldindex]: fields = feat[fieldindex].split('.') for i in range(1, len(fields)): feat[fieldindex + i] = fields[i - 1] layer.updateFeature(feat) else: continue layer.commitChanges() #e = QgsExpression('concat("NAME", ", ", "NAME")') #feat[1] = e.evaluate() # -*- coding: utf-8 -*- layer = iface.activeLayer() fieldindex = layer.fieldNameIndex("A_STRT") layer.startEditing() cou = layer.featureCount() for feat in layer.getFeatures(): if feat.id() % (cou / 10) == 0: print (str(100 * feat.id() / cou + 1) + "%") if feat[fieldindex]: fields = u'улица,переулок,проспект,проезд,площадь,шоссе,тракт,набережная'.split(',') for i in range(0, len(fields)): feat[fieldindex] = feat[fieldindex].replace(fields[i] + ' ','').replace(' ' + fields[i],'') layer.updateFeature(feat) else: continue layer.commitChanges() print ("Complete")
UPDATE Объединение колонок
# -*- coding: utf-8 -*- layer = iface.activeLayer() #fieldindex = layer.fieldNameIndex("NAME") layer.startEditing() cou = layer.featureCount() for feat in layer.getFeatures(): if feat.id() % (cou / 10) == 0: print (str(100 * feat.id() / cou + 1) + "%") if feat[1]: txt = [feat[1]] if feat[2]: txt.append(', ' + feat[2]) if feat[4]: txt.append(', ' + feat[4]) layer.changeAttributeValue(feat.id(), 0, ''.join(txt)) else: continue layer.commitChanges() print ("Complete") txt = [feat[1]] if feat[2]: txt.append(', ' + feat[2]) if feat[4]: txt.append(', ' + feat[4]) feat[0] = ''.join(txt) layer.updateFeature(feat)
UPDATE Создание колонок с XY
# -*- coding: utf-8 -*- from PyQt4.QtCore import QVariant layer = iface.activeLayer() provider = layer.dataProvider() provider.addAttributes([QgsField('X', QVariant.Double), QgsField('Y', QVariant.Double)]) layer.updateFields() fX = layer.fieldNameIndex("X") fY = layer.fieldNameIndex("Y") layer.startEditing() cou = layer.featureCount() for feat in layer.getFeatures(): if feat.id() % (cou / 10) == 0: print (str(100 * feat.id() / cou) + "%") k = feat.geometry().centroid().asPoint() feat[fX] = k.x() feat[fY] = k.y() layer.updateFeature(feat) layer.commitChanges() print ("Complete") # -*- coding: utf-8 -*- from PyQt4.QtCore import QVariant layer = iface.activeLayer() provider = layer.dataProvider() provider.addAttributes([QgsField('X', QVariant.Double), QgsField('Y', QVariant.Double)]) layer.updateFields() fX = layer.fieldNameIndex("X") fY = layer.fieldNameIndex("Y") layer.startEditing() cou = layer.featureCount() for feat in layer.getFeatures(): if feat.id() % (cou / 10) == 0: print (str(100 * feat.id() / cou) + "%") if feat[0]: k = feat.geometry().centroid().asPoint() feat[fX] = k.x() feat[fY] = k.y() layer.updateFeature(feat) else: continue layer.commitChanges() print ("Complete")
Координаты центра выделенного объекта
layer = qgis.utils.iface.activeLayer() selected_features = layer.selectedFeatures() for feat in selected_features: k = feat.geometry().centroid().asPoint() print (k.x()) print (k.y())
Площадь выделенных объектов
from qgis.core import QGis area = QgsDistanceArea() area.setEllipsoid('WGS84') area.setEllipsoidalMode(True) wb = iface.activeLayer() a = 0 for feat in wb.selectedFeatures(): multiPart = feat.geometry().isMultipart() if (multiPart is False): pol = feat.geometry().asPolygon() s = area.measurePolygon(pol[0]) / 1e6 # print ("area is %.2f km2" % (s)) a += s else: pol = feat.geometry().asMultiPolygon() print ("There are %d polygons" % len(pol)) i = 1 for geom in pol: s = area.measurePolygon(geom[0]) / 1e6 # print ("area%d is %.2f km2" % (i, s)) i += 1 a += s print ("Area is %.3f km2" % (a))
DELETE Удаление колонок
canvas = qgis.utils.iface.mapCanvas() j = 0 for layer in canvas.layers(): provider = layer.dataProvider() fieldnames = [ layer.fieldNameIndex(li) for li in ["Block_Area","Block_KN","Color"] ] fields_to_delete = [fid for fid in range(len(provider.fields())) if fid not in fieldnames] provider.deleteAttributes(fields_to_delete) layer.updateFields() j += 1 print (str(j) + ") layer '" + layer.name() + "' is ready") print ("Complete") canvas.refresh()
DELETE Удаление объектов по значению в колонке
canvas = qgis.utils.iface.mapCanvas() j = 0 for layer in canvas.layers(): layer.removeSelection() layer.startEditing() it = layer.getFeatures( QgsFeatureRequest( QgsExpression("\"Color\" IS NONE") ) ) layer.deleteFeatures( [i.id() for i in it] ) layer.commitChanges() j += 1 print (str(j) + ") layer '" + layer.name() + "' is ready") print ("Complete") canvas.refresh()
GeoJSON с атрибутами объекта
from PyQt4.QtGui import QDockWidget consoleWidget = iface.mainWindow().findChild( QDockWidget, 'PythonConsole' ) consoleWidget.console.shellOut.clearConsole() layer = qgis.utils.iface.activeLayer() selected_features = layer.selectedFeatures() for i in selected_features: attrs = i.__geo_interface__ print (attrs)
STYLE Цвет точек и полигонов по названию
# -*- coding: utf-8 -*- from PyQt4.QtGui import * layer = qgis.utils.iface.activeLayer() layer.setLayerTransparency(35) # define some rules: label, expression, color name, (min scale, max scale) minm = 0 road_rules = ( (u'Акация', u'"Название" = '+u"'Акация'", 'mediumpurple', (0, minm,)), (u'Барбарис', u'"Название" = '+u"'Барбарис'", 'maroon', (0, minm,)), (u'Берёза', u'"Название" = '+u"'Берёза'", 'lime', (0, minm,)), (u'Вяз', u'"Название" = '+u"'Вяз'", 'green', (0, minm,)), (u'Дерен_Белый', u'"Название" = '+u"'Дерен_Белый'", 'lavender', (0, minm,)), (u'Дуб', u'"Название" = '+u"'Дуб'", 'white', (0, minm,)), (u'Ива', u'"Название" = '+u"'Ива'", 'pink', (0, minm,)), (u'Калина', u'"Название" = '+u"'Калина'", 'firebrick', (0, minm,)), (u'Каштан', u'"Название" = '+u"'Каштан'", 'tan', (0, minm,)), (u'Кедр', u'"Название" = '+u"'Кедр'", 'darkolivegreen', (0, minm,)), (u'Клён', u'"Название" = '+u"'Клён'", 'brown', (0, minm,)), (u'Лапчатка', u'"Название" = '+u"'Лапчатка'", 'teal', (0, minm,)), (u'Липа', u'"Название" = '+u"'Липа'", 'yellow', (0, minm,)), (u'Лиственница', u'"Название" = '+u"'Лиственница'", 'olive', (0, minm,)), (u'Ольха', u'"Название" = '+u"'Ольха'", 'magenta', (0, minm,)), (u'Осина', u'"Название" = '+u"'Осина'", 'purple', (0, minm,)), (u'Рябина', u'"Название" = '+u"'Рябина'", 'red', (0, minm,)), (u'Сирень', u'"Название" = '+u"'Сирень'", 'mediumvioletred', (0, minm,)), (u'Сосна', u'"Название" = '+u"'Сосна'", 'darkkhaki', (0, minm,)), (u'Спирея', u'"Название" = '+u"'Спирея'", 'darkseagreen', (0, minm,)), (u'Тополь', u'"Название" = '+u"'Тополь'", 'cyan', (0, minm,)), (u'Туя', u'"Название" = '+u"'Туя'", 'sienna', (0, minm,)), (u'Яблоня', u'"Название" = '+u"'Яблоня'", 'orange', (0, minm,)), (u'Ясень', u'"Название" = '+u"'Ясень'", 'blue', (0, minm,)), (u'Другие', u'"Название" = '+u"'Другие'", 'gray', (0, minm,)) ) road_rules = ( (u'Acacia', u'"Name" = '+u"'Acacia'", 'mediumpurple', (0, minm,)), (u'Barberry', u'"Name" = '+u"'Barberry'", 'maroon', (0, minm,)), (u'Birch', u'"Name" = '+u"'Birch'", 'lime', (0, minm,)), (u'Elm', u'"Name" = '+u"'Elm'", 'green', (0, minm,)), (u'Oak', u'"Name" = '+u"'Oak'", 'white', (0, minm,)), (u'Willow', u'"Name" = '+u"'Willow'", 'pink', (0, minm,)), (u'Maple', u'"Name" = '+u"'Maple'", 'brown', (0, minm,)), (u'Cinquefoil', u'"Name" = '+u"'Cinquefoil'", 'teal', (0, minm,)), (u'Linden', u'"Name" = '+u"'Linden'", 'yellow', (0, minm,)), (u'Larch', u'"Name" = '+u"'Larch'", 'olive', (0, minm,)), (u'Alder', u'"Name" = '+u"'Alder'", 'magenta', (0, minm,)), (u'Aspen', u'"Name" = '+u"'Aspen'", 'purple', (0, minm,)), (u'Rowan', u'"Name" = '+u"'Rowan'", 'red', (0, minm,)), (u'Poplar', u'"Name" = '+u"'Poplar'", 'cyan', (0, minm,)), (u'Appletree', u'"Name" = '+u"'Appletree'", 'orange', (0, minm,)), (u'Ash', u'"Name" = '+u"'Ash'", 'blue', (0, minm,)), (u'Other', u'"Name" = '+u"'Other'", 'gray', (0, minm,)) ) # create a new rule-based renderer symbol = QgsSymbolV2.defaultSymbol(layer.geometryType()) # symbol = QgsFillSymbolV2.createSimple({'style':'solid', 'color':'255,0,0,255', 'style_border':'solid'}) renderer = QgsRuleBasedRendererV2(symbol) # get the "root" rule root_rule = renderer.rootRule() for label, expression, color_name, scale in road_rules: # create a clone (i.e. a copy) of the default rule rule = root_rule.children()[0].clone() # set the label, expression and color rule.setLabel(label) rule.setFilterExpression(expression) rule.symbol().setColor(QColor(color_name)) # set the scale limits if they have been specified if scale is not None: rule.setScaleMinDenom(scale[0]) rule.setScaleMaxDenom(scale[1]) # append the rule to the list of rules root_rule.appendChild(rule) # delete the default rule root_rule.removeChildAt(0) # apply the renderer to the layer layer.setRendererV2(renderer)
STYLE Цвет по диапазону
# -*- coding: utf-8 -*- from PyQt4.QtGui import * layer = qgis.utils.iface.activeLayer() layer.setLayerTransparency(35) # define ranges: label, lower value, upper value, color name coffee_prices = ( ('Free', 0, 3000, 'green'), ('Cheap', 3000, 10000, 'yellow'), ('Average', 10000, 20000, 'orange'), ('Expensive', 20000, 100000, 'red'), ) # create a category for each item in animals ranges = [] for label, lower, upper, color in coffee_prices: symbol = QgsSymbolV2.defaultSymbol(layer.geometryType()) symbol.setColor(QColor(color)) rng = QgsRendererRangeV2(lower, upper, symbol, label) ranges.append(rng) # create the renderer and assign it to a layer expression = u'Площадь' # field name renderer = QgsGraduatedSymbolRendererV2(expression, ranges) layer.setRendererV2(renderer)
Копирование объекта на центроид
from PyQt4.QtCore import * from PyQt4.QtGui import * from qgis.core import * from qgis.gui import * registry = QgsMapLayerRegistry.instance() n = registry.count() layers = registry.mapLayers().values() layers_names = [ layers[i].name() for i in range(n) ] name1 = 'building1' name2 = 'building2' idx1 = layers_names.index(name1) idx2 = layers_names.index(name2) #features feat1 = layers[idx1].getFeatures().next() feat2 = layers[idx2].getFeatures().next() #polygons geometry pol1 = feat1.geometry().asPolygon() #polygon1 pol2 = feat2.geometry().asPolygon() #polygon2 #centroid coordinates c1 = feat1.geometry().centroid().asPoint() #centroid1 c2 = feat2.geometry().centroid().asPoint() #centroid2 pol_t = pol1 n = len(pol_t[0]) #calculating displacement based in centroids px = c2.x() - c1.x() py = c2.y() - c1.y() #translation as an affine transformation for i in range(n): pol_t[0][i].setX(pol1[0][i].x() + px) pol_t[0][i].setY(pol1[0][i].y() + py) #creating a memory layer for displaced polygon (building1) crs = layers[1].crs() epsg = crs.postgisSrid() uri = "Polygon?crs=epsg:" + str(epsg) + "&field=id:integer""&index=yes" mem_layer = QgsVectorLayer(uri, "building1_displaced", "memory") QgsMapLayerRegistry.instance().addMapLayer(mem_layer) mem_layer.startEditing() feat = QgsFeature() #Set geometry feat.setGeometry(QgsGeometry.fromPolygon(pol_t)) #set attributes values feat.setAttributes([1]) mem_layer.addFeature(feat, True) mem_layer.commitChanges()
Сдвижка растра
from osgeo import gdal gdal.AllRegister() rast_src = gdal.Open('5.tif', 1) gt = rast_src.GetGeoTransform() gtl = list(gt) gtl[0] -= (4439275.37495471 - 4439268.6905) gtl[3] -= (8227990.30819916 - 8227987.4296) rast_src.SetGeoTransform(tuple(gtl)) rast_src = None
Открытие shp из zip
# -*- coding: utf-8 -*- zip_uri = '/vsizip/d:/Scripts QGIS/55555.zip' shp = QgsVectorLayer(zip_uri, u'Слой', 'ogr') QgsMapLayerRegistry.instance().addMapLayer(shp)
Сохранение в форматы
from qgis.core import * import os pathToFile = "d:\\Scripts QGIS\\5\\" trs = QgsCoordinateReferenceSystem() trs.createFromId(4326) layers = iface.legendInterface().layers() for layer in layers: newName = layer.name() + ".geojson" ret = QgsVectorFileWriter.writeAsVectorFormat(layer, pathToFile + newName,'utf-8', trs,'GeoJSON') if ret == QgsVectorFileWriter.NoError: print (newName + " saved to " + pathToFile + "!") QObject::tr( "GeoJSON" ) QStringLiteral( "*.geojson" ) QObject::tr( "ESRI Shapefile" ) QStringLiteral( "*.shp" ) QObject::tr( "Mapinfo TAB" ) QStringLiteral( "*.tab" ) QObject::tr( "Mapinfo MIF" ) QStringLiteral( "*.mif" ) QObject::tr( "AutoCAD DXF" ) QStringLiteral( "*.dxf" ) QObject::tr( "MS Office Open XML spreadsheet [XLSX]" ) QStringLiteral( "*.xlsx" ) QObject::tr( "Comma Separated Value [CSV]" ) QStringLiteral( "*.csv" ) QObject::tr( "Atlas BNA" ) QStringLiteral( "*.bna" ) from qgis.core import * import os pathToFile = "c:\\Users\\User\\Desktop\\5\\" crs = QgsCoordinateReferenceSystem() crs.createFromProj4("+proj=tmerc +lat_0=0 +lon_0=35.55 +k=1 +x_0=1250000 +y_0=-6214743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs") layers = iface.legendInterface().layers() for layer in layers: newName = layer.name() + ".shp" ret = QgsVectorFileWriter.writeAsVectorFormat(layer,pathToFile + newName,'utf-8',crs,'ESRI Shapefile') if ret == QgsVectorFileWriter.NoError: print (newName + " saved to " + pathToFile) from qgis.core import * import os pathToFile = "c:\\Users\\User\\Desktop\\5\\" crs = QgsCoordinateReferenceSystem() crs.createFromProj4("+proj=tmerc +lat_0=0 +lon_0=35.55 +k=1 +x_0=1250000 +y_0=-6214743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs") layers = iface.legendInterface().layers() for layer in layers: newName = layer.name() + ".dxf" ret = QgsVectorFileWriter.writeAsVectorFormat(layer,pathToFile + newName,'utf-8',crs,'AutoCAD DXF') if ret == QgsVectorFileWriter.NoError: print (newName + " saved to " + pathToFile)
ГСК-WM
import math from PyQt4.QtGui import QDockWidget consoleWidget = iface.mainWindow().findChild(QDockWidget, 'PythonConsole') consoleWidget.console.shellOut.clearConsole() def ogz_s(x1, x2, y1, y2): return math.sqrt( math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) ) def ogz_ur(x1, x2, y1, y2): return math.atan((y2 - y1) / (x2 - x1)) def SKtoSK(XY): t1 = [-669.13, -120.89, 4438420.07994637, 8228726.23003649] t2 = [4976.50, -16.970, 4449424.78508004, 8228923.442037] m = ogz_s(t1[2], t2[2], t1[3], t2[3]) / ogz_s(t1[0], t2[0], t1[1], t2[1]); U = ogz_ur(t1[2], t2[2], t1[3], t2[3]) - ogz_ur(t1[0], t2[0], t1[1], t2[1]); K = [m * math.cos(U), m * math.sin(U)]; X = t1[2] + (XY[0] - t1[0]) * K[0] - (XY[1] - t1[1]) * K[1] Y = t1[3] + (XY[1] - t1[1]) * K[0] + (XY[0] - t1[0]) * K[1] return [X, Y] canvas = qgis.utils.iface.mapCanvas() j = 0 for layer in canvas.layers(): # layer = qgis.utils.iface.activeLayer() layer.removeSelection() layer.invertSelection() featids = layer.selectedFeaturesIds() layer.startEditing() canvas.refresh() result = {} features = {} for fid in featids: features[fid] = QgsFeature() if not layer.getFeatures( QgsFeatureRequest().setFilterFid(fid) ).nextFeature(features[fid]): continue; result[fid] = features[fid].geometry() i = 0 vertex = result[fid].vertexAt(i) while (vertex != QgsPoint(0,0)): XY = [vertex.x(), vertex.y()] layer.moveVertex(SKtoSK(XY)[0], SKtoSK(XY)[1], fid, i) i += 1 vertex = result[fid].vertexAt(i) layer.invertSelection() layer.commitChanges() j += 1 print (str(j) + ") layer '" + layer.name() + "' is ready") print ("Complete") canvas.refresh()
Проекции
def CRS(name, s): crs = QgsCoordinateReferenceSystem() crs.createFromProj4(s) crs.saveAsUserCrs(name) CRS('МСК-35 зона 1', '+proj=tmerc +lat_0=0 +lon_0=35.55 +k=1 +x_0=1250000 +y_0=-6214743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('МСК-35 зона 2', '+proj=tmerc +lat_0=0 +lon_0=38.55 +k=1 +x_0=2250000 +y_0=-6214743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('МСК-35 зона 3', '+proj=tmerc +lat_0=0 +lon_0=41.55 +k=1 +x_0=3250000 +y_0=-6214743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('МСК-35 зона 4', '+proj=tmerc +lat_0=0 +lon_0=44.55 +k=1 +x_0=4250000 +y_0=-6214743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('МСК-35 зона 5', '+proj=tmerc +lat_0=0 +lon_0=47.55 +k=1 +x_0=5250000 +y_0=-6214743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('МСК-44 зона 1', '+proj=tmerc +lat_0=0 +lon_0=41.55 +k=1 +x_0=1250000 +y_0=-6114743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('МСК-44 зона 2', '+proj=tmerc +lat_0=0 +lon_0=44.55 +k=1 +x_0=2250000 +y_0=-6114743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('МСК-44 зона 3', '+proj=tmerc +lat_0=0 +lon_0=47.55 +k=1 +x_0=3250000 +y_0=-6114743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('СК-1963 район C зона 1', '+proj=tmerc +lat_0=0 +lon_0=24.95 +k=1 +x_0=1250000 +y_0=-11057.628 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('СК-1963 район C зона 2', '+proj=tmerc +lat_0=0 +lon_0=27.95 +k=1 +x_0=2250000 +y_0=-11057.628 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('СК-1963 район C зона 3', '+proj=tmerc +lat_0=0 +lon_0=30.95 +k=1 +x_0=3250000 +y_0=-11057.628 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('СК-1963 район C зона 4', '+proj=tmerc +lat_0=0 +lon_0=33.95 +k=1 +x_0=4250000 +y_0=-11057.628 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('СК-1963 район C зона 5', '+proj=tmerc +lat_0=0 +lon_0=36.95 +k=1 +x_0=5250000 +y_0=-11057.628 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('СК-1963 район D зона 1', '+proj=tmerc +lat_0=0 +lon_0=38.55 +k=1 +x_0=1250000 +y_0=-14743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('СК-1963 район D зона 2', '+proj=tmerc +lat_0=0 +lon_0=41.55 +k=1 +x_0=2250000 +y_0=-14743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('СК-1963 район D зона 3', '+proj=tmerc +lat_0=0 +lon_0=44.55 +k=1 +x_0=3250000 +y_0=-14743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('СК-1963 район D зона 4', '+proj=tmerc +lat_0=0 +lon_0=47.55 +k=1 +x_0=4250000 +y_0=-14743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('СК-1963 район P зона 1', '+proj=tmerc +lat_0=0 +lon_0=32.48333333333 +k=1 +x_0=1250000 +y_0=-12900.566 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS('СК-1963 район P зона 2', '+proj=tmerc +lat_0=0 +lon_0=35.48333333333 +k=1 +x_0=2250000 +y_0=-12900.566 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') # -*- coding: utf-8 -*- def CRS(name, s): crs = QgsCoordinateReferenceSystem() crs.createFromProj4(s) crs.saveAsUserCRS(name) CRS(u'МСК-35 зона 1', u'+proj=tmerc +lat_0=0 +lon_0=35.55 +k=1 +x_0=1250000 +y_0=-6214743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'МСК-35 зона 2', u'+proj=tmerc +lat_0=0 +lon_0=38.55 +k=1 +x_0=2250000 +y_0=-6214743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'МСК-35 зона 3', u'+proj=tmerc +lat_0=0 +lon_0=41.55 +k=1 +x_0=3250000 +y_0=-6214743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'МСК-35 зона 4', u'+proj=tmerc +lat_0=0 +lon_0=44.55 +k=1 +x_0=4250000 +y_0=-6214743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'МСК-35 зона 5', u'+proj=tmerc +lat_0=0 +lon_0=47.55 +k=1 +x_0=5250000 +y_0=-6214743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'МСК-44 зона 1', u'+proj=tmerc +lat_0=0 +lon_0=41.55 +k=1 +x_0=1250000 +y_0=-6114743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'МСК-44 зона 2', u'+proj=tmerc +lat_0=0 +lon_0=44.55 +k=1 +x_0=2250000 +y_0=-6114743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'МСК-44 зона 3', u'+proj=tmerc +lat_0=0 +lon_0=47.55 +k=1 +x_0=3250000 +y_0=-6114743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'СК-1963 район C зона 1', u'+proj=tmerc +lat_0=0 +lon_0=24.95 +k=1 +x_0=1250000 +y_0=-11057.628 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'СК-1963 район C зона 2', u'+proj=tmerc +lat_0=0 +lon_0=27.95 +k=1 +x_0=2250000 +y_0=-11057.628 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'СК-1963 район C зона 3', u'+proj=tmerc +lat_0=0 +lon_0=30.95 +k=1 +x_0=3250000 +y_0=-11057.628 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'СК-1963 район C зона 4', u'+proj=tmerc +lat_0=0 +lon_0=33.95 +k=1 +x_0=4250000 +y_0=-11057.628 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'СК-1963 район C зона 5', u'+proj=tmerc +lat_0=0 +lon_0=36.95 +k=1 +x_0=5250000 +y_0=-11057.628 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'СК-1963 район D зона 1', u'+proj=tmerc +lat_0=0 +lon_0=38.55 +k=1 +x_0=1250000 +y_0=-14743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'СК-1963 район D зона 2', u'+proj=tmerc +lat_0=0 +lon_0=41.55 +k=1 +x_0=2250000 +y_0=-14743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'СК-1963 район D зона 3', u'+proj=tmerc +lat_0=0 +lon_0=44.55 +k=1 +x_0=3250000 +y_0=-14743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'СК-1963 район D зона 4', u'+proj=tmerc +lat_0=0 +lon_0=47.55 +k=1 +x_0=4250000 +y_0=-14743.504 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'СК-1963 район P зона 1', u'+proj=tmerc +lat_0=0 +lon_0=32.48333333333 +k=1 +x_0=1250000 +y_0=-12900.566 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') CRS(u'СК-1963 район P зона 2', u'+proj=tmerc +lat_0=0 +lon_0=35.48333333333 +k=1 +x_0=2250000 +y_0=-12900.566 +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs') MAPINFOW.PRJ "--- МСК-35 Вологодская область ---" "МСК-35 зона 1", 8, 1001, 7, 35.55, 0, 1, 1250000, -6214743.504 "МСК-35 зона 2", 8, 1001, 7, 38.55, 0, 1, 2250000, -6214743.504 "МСК-35 зона 3", 8, 1001, 7, 41.55, 0, 1, 3250000, -6214743.504 "МСК-35 зона 4", 8, 1001, 7, 44.55, 0, 1, 4250000, -6214743.504 "МСК-35 зона 5", 8, 1001, 7, 47.55, 0, 1, 5250000, -6214743.504 "--- МСК-35 Вологодская область ГОСТ 51794-2008 ---" "МСК-35 зона 1", 8, 9999, 3, 23.57, -140.95, -79.8, 0, -0.35, -0.79, -0.22, 0, 7, 35.55, 0, 1, 1250000, -6214743.504 "МСК-35 зона 2", 8, 9999, 3, 23.57, -140.95, -79.8, 0, -0.35, -0.79, -0.22, 0, 7, 38.55, 0, 1, 2250000, -6214743.504 "МСК-35 зона 3", 8, 9999, 3, 23.57, -140.95, -79.8, 0, -0.35, -0.79, -0.22, 0, 7, 41.55, 0, 1, 3250000, -6214743.504 "МСК-35 зона 4", 8, 9999, 3, 23.57, -140.95, -79.8, 0, -0.35, -0.79, -0.22, 0, 7, 44.55, 0, 1, 4250000, -6214743.504 "МСК-35 зона 5", 8, 9999, 3, 23.57, -140.95, -79.8, 0, -0.35, -0.79, -0.22, 0, 7, 47.55, 0, 1, 5250000, -6214743.504
Excel Change border thickness if line
Sub Borders() Application.ScreenUpdating = False For Each cell In Selection If cell.Borders(xlEdgeLeft).LineStyle <> -4142 Then cell.Borders(xlEdgeLeft).Weight = xlThin End If If cell.Borders(xlEdgeRight).LineStyle <> -4142 Then cell.Borders(xlEdgeRight).Weight = xlThin End If If cell.Borders(xlEdgeTop).LineStyle <> -4142 Then cell.Borders(xlEdgeTop).Weight = xlThin End If If cell.Borders(xlEdgeBottom).LineStyle <> -4142 Then cell.Borders(xlEdgeBottom).Weight = xlThin End If Next Application.ScreenUpdating = True End Sub
Excel Clear Spaces
Sub Clear() Dim c As Range For Each c In Selection c.Value = Application.WorksheetFunction.Trim(Replace(c.Value, "", " ")) Next End Sub ' replace(replace("AVERAGE_DE" ,' ','') ,',','.')