Starting point is that I select a geometry with the following query in QGIS DB Manager:
SELECT 1 AS myid, st_buffer(st_union(wkb_geometry), 5)
FROM ax_strassenverkehr
WHERE unverschluesselt ILIKE '%ßen Ma%'
GROUP BY unverschluesselt
... and add the query result as a new layer, which looks like this:
... that's fine.
In a QGIS plugin, I do a similar query (with appropriate parameters) like
res = self.execSQL("""SELECT ST_AsText(ST_Buffer(ST_Union(wkb_geometry), %(h_buf)s))
FROM ax_strassenverkehr
WHERE unverschluesselt = '%(str)s'
GROUP BY unverschluesselt""" % params)[0][0]
where self.execSQL(thesqlquerystring)
takes the query string, establishes a psycopg2
connection, executes the query and delivers the result (res
), which in the example referred to above is structured as follows:
POLYGON((ExteriorRing), (InteriorRing), (InteriorRing))
explicitly:
POLYGON((4423986.83175955 5495829.42418485,4423972.33611678 5495831.8800263,4423959.58980503 5495834.0325163,4423958.4686183 5495834.17427554,4423957.51681004 5495834.09657691,4423956.66851016 5495834.09952945,4423955.83291851 5495834.24584413,4423955.03408746 5495834.53130928,4423953.86974287 5495835.06268802,4423948.48324897 5495836.64197419,4423947.53120533 5495837.03136213,4423946.67898683 5495837.6073254,4423945.9626597 5495838.345489,4423945.41253919 5495839.21461356,4423945.05190662 5495840.17791736,4423944.89602412 5495841.194633,4423944.95148868 5495842.22173268,4423947.25148868 5495856.75173268,4423947.26712799 5495856.84483213,4423948.95712799 5495866.35483213,4423948.98051101 5495866.47750074,4423951.02051101 5495876.49750074,4423951.04728722 5495876.62101301,4423954.53728722 5495891.79101301,4423954.57025097 5495891.92571865,4423956.01025097 5495897.47571865,4423956.05968242 5495897.65277966,4423957.71968242 5495903.20277965,4423957.76769268 5495903.35446247,4423959.19769268 5495907.63446247,4423959.24772832 5495907.77701664,4423960.83772832 5495912.09701664,4423960.90751744 5495912.27595251,4423964.38751744 5495920.71595251,4423964.47963038 5495920.92559711,4423967.44963038 5495927.28559711,4423967.55274412 5495927.49366206,4423971.14274412 5495934.33366206,4423971.24286856 5495934.51518134,4423974.43286856 5495940.02518134,4423974.53527089 5495940.19425952,4423978.98527089 5495947.22425952,4423979.1200482 5495947.42615963,4423983.4800482 5495953.62615963,4423983.64915654 5495953.85273855,4423988.76915654 5495960.32273855,4423988.91074102 5495960.49371371,4423994.22074102 5495966.62371372,4423994.30509164 5495966.71862764,4423998.12509164 5495970.90862764,4423998.24020171 5495971.03070826,4424001.41582609 5495974.28738106,4424001.26401122 5495975.31975972,4424001.33363906 5495976.37496665,4424001.6236348 5495977.39192888,4424002.12102622 5495978.32515526,4424002.80356382 5495979.13290034,4424005.29354592 5495981.51504857,4424018.66023265 5495995.0311394,4424019.7403913 5495996.12915191,4424021.12451919 5495997.7531953,4424019.27908955 5496000.03980638,4424018.72733387 5496000.88593858,4424018.35690544 5496001.8257028,4424018.18292328 5496002.82074261,4424018.21248846 5496003.8304455,4424018.44439427 5496004.81360048,4424018.8691755 5496005.73008012,4424019.46949471 5496006.54247834,4424021.35949471 5496008.62247834,4424022.09401488 5496009.2852866,4424022.94466341 5496009.79049125,4424023.87813453 5496010.11831183,4424024.85787968 5496010.25591305,4424025.84553853 5496010.19790736,4424026.80244089 5496009.94656586,4424027.69112078 5496009.51172944,4424028.47678338 5496008.91042342,4424029.12866735 5496008.16619095,4424041.07866735 5495991.43619095,4424041.57529947 5495990.56912741,4424041.88960401 5495989.6206258,4424042.00902835 5495988.6285671,4424041.92880297 5495987.63257185,4424041.65213188 5495986.67241782,4424041.1900647 5495985.78645136,4424040.56105532 5495985.01005594,4424039.79022494 5495984.37423901,4424038.90835875 5495983.90439364,4424037.95067646 5495983.61928438,4424036.95542572 5495983.53029783,4424035.96235455 5495983.64098792,4424034.45124591 5495983.96479691,4424033.3912961 5495983.87458841,4424033.05858888 5495983.77030704,4424032.83644149 5495983.6473326,4424032.18800852 5495983.08682274,4424021.50770859 5495972.39670637,4424020.8004624 5495971.62990259,4424020.5810855 5495971.33637013,4424020.40561017 5495970.94155063,4424020.25905859 5495970.40012398,4424020.22323782 5495970.01260833,4424020.25496413 5495969.45966403,4424020.30587356 5495969.17117726,4424020.43348171 5495968.82570155,4424020.69273654 5495968.35106578,4424020.94807185 5495968.03475487,4424027.49152946 5495961.19786867,4424036.12085847 5495952.1885692,4424042.66104602 5495945.35837342,4424055.10503033 5495932.36748789,4424055.66576034 5495932.84309503,4424055.77079824 5495932.92975592,4424059.92079824 5495936.25975592,4424060.02902593 5495936.34418318,4424063.66902593 5495939.10418317,4424063.756002 5495939.16866097,4424066.91032154 5495941.45454443,4424067.97465283 5495942.23041211,4424068.01380903 5495942.25866735,4424068.36380903 5495942.50866735,4424069.21638344 5495942.99880016,4424070.14840105 5495943.31257793,4424071.12380719 5495943.43786229,4424072.10486873 5495943.36980669,4424073.05363376 5495943.11104383,4424073.93339976 5495942.67158381,4424074.71013338 5495942.06842696,4424075.35378705 5495941.3249061,4424084.47378705 5495928.4149061,4424084.95596471 5495927.5676374,4424085.26457004 5495926.64290918,4424085.3878716 5495925.6758744,4424085.32118217 5495924.70329429,4424085.0670369 5495923.76214089,4424084.63509696 5495922.88819156,4424084.04178229 5495922.11466895,4424083.30964736 5495921.47097803,4424081.02964736 5495919.83097803,4424081.02533254 5495919.82787786,4424078.1570789 5495917.7693693,4424074.20638158 5495914.71699679,4424070.99226052 5495912.04852884,4424071.74056739 5495911.10308737,4424072.25072074 5495910.31704846,4424072.60524705 5495909.44962428,4424072.79169373 5495908.53128271,4424072.80351194 5495907.59428007,4424072.64028656 5495906.67152816,4424072.30775081 5495905.79543822,4424071.81758486 5495904.99678251,4424071.18700556 5495904.30361344,4424068.15700556 5495901.54361344,4424067.40169162 5495900.97630829,4424066.5531576 5495900.56118868,4424065.64169055 5495900.31307161,4424064.69982378 5495900.24081323,4424063.76117571 5495900.34699267,4424062.85924985 5495900.62782004,4424062.02623896 5495901.07327165,4424061.29187603 5495901.66744785,4424060.39880397 5495902.54191424,4424059.97854849 5495902.1470008,4424055.54446075 5495897.67401756,4424054.80288737 5495896.86987967,4424055.68901298 5495895.99197797,4424056.29590172 5495895.2643468,4424056.75462751 5495894.43529208,4424057.04871729 5495893.53458554,4424057.16761017 5495892.59457195,4424057.10703666 5495891.64900762,4424056.86917198 5495890.73184817,4424056.46255795 5495889.8760292,4424055.90179627 5495889.11228357,4424053.10179627 5495885.97228356,4424052.4224938 5495885.33991393,4424051.63802154 5495884.84398402,4424050.77540748 5495884.50158047,4424049.86437189 5495884.32450037,4424048.93630335 5495884.31884477,4424048.02317728 5495884.48480855,4424047.15645427 5495884.81667362,4424046.36599616 5495885.30300599,4424045.41600225 5495886.01698889,4424043.10033344 5495883.06575464,4424039.35091687 5495877.90787848,4424037.92445828 5495875.77782883,4424037.91813846 5495875.76841491,4424035.4675673 5495872.12700395,4424031.95756896 5495866.57925657,4424028.14064817 5495859.98994318,4424025.88704224 5495855.76322305,4424024.96626414 5495853.90515066,4424026.05820247 5495853.32428873,4424026.84317062 5495852.80656794,4424027.51732356 5495852.1510318,4424028.05681759 5495851.38086557,4424028.44257167 5495850.5233088,4424028.66094229 5495849.60869189,4424028.70420604 5495848.66936337,4424028.57083274 5495847.73854577,4424028.26553961 5495846.84916064,4424026.55553961 5495843.06916064,4424026.08201729 5495842.24259029,4424025.46032723 5495841.5208262,4424024.71303533 5495840.93006674,4424023.86726655 5495840.4917551,4424022.95372033 5495840.22180098,4424022.00555628 5495840.13000307,4424021.05719055 5495840.21969344,4424020.14304661 5495840.48761653,4424019.17008495 5495840.8768012,4424016.18297425 5495833.38462882,4424017.08984186 5495833.021227,4424017.95655841 5495832.57116679,4424018.71925656 5495831.96121327,4424019.34883933 5495831.21463621,4424019.82128808 5495830.35991757,4424020.11857887 5495829.42966494,4424020.22937003 5495828.45936752,4424020.14943487 5495827.48604222,4424019.88182292 5495826.54682147,4424018.15182292 5495822.15682148,4424017.7040169 5495821.28329685,4424017.09417536 5495820.51409674,4424016.34580345 5495819.87886843,4424015.48774569 5495819.40209556,4424014.55307419 5495819.10215438,4424013.57781404 5495818.99060553,4424012.5995547 5495819.07174844,4424011.65600124 5495819.34245562,4424010.72575489 5495819.71154798,4424008.86156289 5495815.03600717,4424010.2684485 5495814.47974267,4424011.14181608 5495814.03072058,4424011.91057354 5495813.41965287,4424012.54506553 5495812.67011188,4424013.02081611 5495811.81101168,4424013.31947288 5495810.87549262,4424013.42951495 5495809.89964299,4424013.34669738 5495808.92110682,4424013.07421491 5495807.97763182,4424011.83942366 5495804.88179156,4424011.88902213 5495804.25111768,4424011.77349388 5495803.27692615,4424011.46997145 5495802.3440435,4424010.33997145 5495799.76404349,4424009.87336698 5495798.92742861,4424009.25577822 5495798.1951525,4424008.50987424 5495797.5940939,4424007.66303401 5495797.14631514,4424006.74634146 5495796.86825229,4424005.79344449 5495796.77011184,4424004.83931991 5495796.85549613,4424003.9189896 5495797.12127105,4423997.37999696 5495799.71087211,4423982.64100771 5495805.54047233,4423981.76610985 5495805.99061904,4423980.99630232 5495806.60337894,4423980.36139448 5495807.35502403,4423979.88597195 5495808.21644828,4423979.58844457 5495809.15429463,4423979.48033355 5495810.13224674,4423979.56582527 5495811.11243524,4423979.84160923 5495812.05690415,4423986.83175955 5495829.42418485),(4423993.75590379 5495942.94514364,4423993.68262292 5495941.96376743,4423993.40443135 5495940.98817456,4423992.93504302 5495940.08881556,4423990.70316381 5495936.70184098,4423985.77305065 5495928.61840791,4423981.84064261 5495921.25601252,4423979.53234238 5495916.2345982,4423979.44170901 5495915.57599575,4423979.53976905 5495915.03289402,4423979.83453926 5495914.51158745,4423980.47632279 5495913.90229929,4423986.58822116 5495910.22401395,4423996.06978358 5495904.51307326,4424005.47886054 5495898.84362952,4424012.12639837 5495894.84511052,4424014.1555827 5495893.62560073,4424014.9434165 5495893.0396526,4424015.60155462 5495892.3110433,4424016.10461882 5495891.46786852,4424016.19255098 5495891.22027497,4424016.92734739 5495890.77618928,4424018.84029611 5495893.57878445,4424018.93951408 5495893.71891589,4424023.21951408 5495899.54891589,4424023.34826455 5495899.71673319,4424028.02826455 5495905.55673319,4424028.13113976 5495905.68094768,4424030.80113976 5495908.80094768,4424030.88904244 5495908.90093927,4424035.72904244 5495914.26093927,4424035.86850213 5495914.40920032,4424040.70850213 5495919.34920032,4424040.83625268 5495919.47499715,4424042.39865462 5495920.959279,4424037.70711309 5495925.86354975,4424006.86457932 5495958.09934154,4424006.22990278 5495957.84892495,4424005.82877581 5495957.61493422,4424005.39292181 5495957.21326484,4424001.13207148 5495952.41270681,4423996.90356551 5495947.20690311,4423993.75590379 5495942.94514364),(4423966.20268172 5495876.82783068,4423966.26960121 5495876.70292564,4423966.55612362 5495875.75433962,4423966.64995105 5495874.76787778,4423966.5473983 5495873.78228483,4423964.49317283 5495863.79894751,4423962.62204171 5495853.00396029,4423962.59580007 5495851.58691208,4423962.7709375 5495851.08789038,4423963.08493294 5495850.67090443,4423963.5264334 5495850.35849767,4423964.30414407 5495850.11047102,4423966.54742252 5495849.72937353,4423966.55826803 5495849.72751877,4423975.67705401 5495848.15772776,4423993.13889604 5495845.16054592,4423997.15182807 5495855.12744776,4423997.21315865 5495855.27308799,4423999.44315865 5495860.34308799,4423999.49992564 5495860.46750503,4424001.06992564 5495863.78750503,4424001.12572353 5495863.90171837,4424003.42572353 5495868.46171837,4424003.49936543 5495868.60213881,4424005.86936543 5495872.95213881,4424005.92857711 5495873.05775414,4424008.44857711 5495877.42775414,4424008.48734371 5495877.49380614,4424009.05899693 5495878.450942,4423975.70163391 5495898.58446198,4423974.45256022 5495899.01383106,4423973.51903809 5495899.0069416,4423972.55874075 5495898.63210434,4423971.78195486 5495897.9203517,4423971.13319369 5495896.61776091,4423969.0357128 5495888.96428617,4423966.76330424 5495879.34112993,4423966.20268172 5495876.82783068))
Now I would like to pass this WKT Geometry to a QgsRubberBand.Geometry
with the following code:
self.blinkRubber(QgsGeometry.fromWkt(res))
With blinkRubber(self, geom)
defined as follows (self.rubberCoordTemp
is a list of [rubber bands...]):
def blinkRubber(self, qgeom):
self.rubberCoordTemp.append(QgsRubberBand(self.canvas, True))
self.rubberCoordTemp[-1].setBorderColor(QColor(255, 255, 255, 0))
self.rubberCoordTemp[-1].setFillColor(QtGui.QColor(0, 0, 255, 128))
self.rubberCoordTemp[-1].setWidth(0)
self.rubberCoordTemp[-1].setToGeometry(qgeom, None)
# rubber erzeugen
QTimer.singleShot(3000, self.removeRubberCoordTemp)
def removeRubberCoordTemp(self):
for r in self.rubberCoordTemp:
iface.mapCanvas().scene().removeItem(r)
self.rubberCoordTemp = []
The result looks like this:
Obviously the interior rings are missing. Why is that so? Since the query and the resulting WKT polygon seems to be correct, is there something I am missing with QgsGeometry.fromWkt()
or QgsRubberBand.setToGeomtry()
?