87

Is there a simple tool in QGIS to graphically visualise geometry formatted as text?

Example geometry:

POLYGON((571178 6337246,571178 6402217,598061 6402217,598061 6337246,571178 6337246))

Result:

A layer in QGIS showing the polygon from above.

result

The intention is to do quick and dirty visualisation for debugging purposes - I feel it is easier to relate to a graphical representation than a coordinate list.

Taras
  • 32,823
  • 4
  • 66
  • 137
Chau
  • 4,480
  • 4
  • 39
  • 57

6 Answers6

94

Try the "QuickWKT" Plugin (see the official page: https://plugins.qgis.org/plugins/QuickWKT/).

enter image description here

Taras
  • 32,823
  • 4
  • 66
  • 137
underdark
  • 84,148
  • 21
  • 231
  • 413
  • @underdark, will QuickWKT render multiple WKT features in the same "paste"? That is, given your screenshot, can you input multiple features using some sort of delimiter? I tried comma, semicolon, and linebreaks but none of those worked. Any thoughts? – elrobis Dec 03 '11 at 17:51
  • 1
    @elrobis You can add multiple geometries by splitting them with an linebreak, so that every geom is on a single line. No comma's or other delimiters needed. – RickyA Jul 10 '13 at 13:05
  • Try https://clydedacruz.github.io/osm-wkt/ – Clyde D'Cruz Mar 06 '18 at 07:32
  • 1
    It does not appear to be "experimental" anymore. – jpmc26 Oct 04 '18 at 22:47
28

Indeed there is! Look here for how to achieve it with the Add Delimited Text Layer plugin.

Essentially you create a CSV file (although you should use a delimiter other than comma), where one column is the WKT representation of your geometry. Then when you select that file in the plugin, it picks up that there is a WKT column, and does the right thing.

I can't vouch for its robustness, but the sample you gave works fine:

id|wkt
1|POLYGON((571178 6337246,571178 6402217,598061 6402217,598061 6337246,571178 6337246))

enter image description here

MerseyViking
  • 14,543
  • 1
  • 41
  • 75
  • 1
    In an ideal world, I would imagine a window with a textbox where I could input my string. But apart from my imagination, your solution comes close :) Thanks a lot, I will try it out. – Chau Aug 09 '11 at 12:46
  • 1
    An option would be to develop a plugin yourself, which would be a fairly simple bit of Python, or sponsor a developer to do it for you. – MerseyViking Aug 09 '11 at 13:55
  • 5
    No need. QuickWKT already exists. We're approaching an ideal world ;) – underdark Aug 09 '11 at 15:22
  • In case anyone else didn't know how to change the delimiter, in Windows go to the control panel > Regional and Language Options > Additonal Settings/Customize > List Separator and type in | instead of , – coelacanth Dec 11 '12 at 16:20
17

No Plugin required

In QGIS deploy a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer....

In the Query window simply paste the following expression:

SELECT ST_GeomFromText('POLYGON((571178 6337246,571178 6402217,598061 6402217,598061 6337246,571178 6337246))')

or with an SRID code

SELECT ST_GeomFromText('POLYGON((571178 6337246,571178 6402217,598061 6402217,598061 6337246,571178 6337246))', 4326)

The result might look like this

Result

One can also achieve the same result by means of PyQGIS:

from qgis.core import QgsVectorLayer, QgsProject

wkt_string = 'POLYGON((571178 6337246,571178 6402217,598061 6402217,598061 6337246,571178 6337246))'

layer = QgsVectorLayer(f"?query=SELECT ST_GeomFromText('{wkt_string}')", "result", "virtual")

if layer.isValid(): QgsProject.instance().addMapLayer(layer)


References:

Taras
  • 32,823
  • 4
  • 66
  • 137
13

In QGIS >=3.18.3 we can copy one or multiple WKT strings into clipboard and paste them using Edit > Paste Feature As > Temporary Scratch Layer... into map canvas. CRS needs to be adjusted afterwards.

christoph
  • 5,605
  • 1
  • 20
  • 34
6

Quick and dirty: select the record in the table of attributes, Ctrl-C and then paste with Ctrl-V in a text editor. Along with attributes, you will also see the geometry as text.

Probably there are more elegant alternatives.

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
Giovanni Manghi
  • 3,907
  • 16
  • 24
  • My goal is to visualise the string as geometry in a layer. – Chau Aug 09 '11 at 12:13
  • 1
    Even if this does not solve the question, it is still very useful! So thanks for the information! – til_b Sep 18 '14 at 13:56
  • It is not the answer that the author seeks, but it is as if you had given me that simple tool that you will always use. ¡¡¡ Thanks, thanks, very much !!! – Juanma Font Jan 14 '17 at 11:24
0

Use a virtual field

  1. Go to "Layer properties" > "Fields"
  2. Activate edit mode
  3. Open "Field calculator"
  4. Add a virtual field, using the expression geom_from_wkt($geometry)

Done

laconbass
  • 111
  • 3
  • 1
    The question asks to do it the other way round: They have a WKT from somewhere else and want do display the geometry in qgis. – til_b Jul 14 '23 at 07:38
  • @til_b oops! should read from instead of to ^^U – laconbass Jul 14 '23 at 10:53
  • 1
    geom_from_wkt takes a wkt string as input, not $geometry, and you don't need to add a virtual field but replace the feature geometry (it's in the "available fields" dropdown) with the results of geom_from_wkt. – til_b Jul 14 '23 at 11:13