vl_pointonsurface_qgis_2x.py
1 |
#!/usr/bin/env python
|
---|---|
2 |
# -*- coding: utf-8 -*-
|
3 |
|
4 |
# ----- define interface -----
|
5 |
##Virtual Layers (QGIS 2.x)=group
|
6 |
##Create point on surface=name
|
7 |
##Input_layer=vector
|
8 |
##Output_layer=string vl_
|
9 |
##Unique_identifier_column=string gid
|
10 |
##Geometry_column=string geom
|
11 |
|
12 |
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry |
13 |
|
14 |
otptlyr = Output_layer |
15 |
uic = Unique_identifier_column |
16 |
gmc = Geometry_column |
17 |
|
18 |
inptlyr = processing.getObject(Input_layer) |
19 |
crs = inptlyr.crs().authid() |
20 |
crs = crs[5:]
|
21 |
|
22 |
query = """SELECT
|
23 |
rowid AS '{0}' /*:int*/,
|
24 |
ST_PointOnSurface(geometry) AS '{1}' /*:point:{2}*/
|
25 |
FROM '{3}';
|
26 |
""".format( uic, gmc, crs, inptlyr.name() )
|
27 |
|
28 |
vlayer = QgsVectorLayer( "?query={}".format(query), otptlyr, "virtual" ) |
29 |
QgsMapLayerRegistry.instance().addMapLayer(vlayer) |