81

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.

0

5 Answers 5

91

Current answer

Try "QuickWKT" Plugin.

Old answer

Try "QuickWKT" plugin. You have to allow experimental plugins to be able to install it.

enter image description here

4
  • @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 3, 2011 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, 2013 at 13:05
  • Try clydedacruz.github.io/osm-wkt Mar 6, 2018 at 7:32
  • 1
    It does not appear to be "experimental" anymore.
    – jpmc26
    Oct 4, 2018 at 22:47
25

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

4
  • 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 9, 2011 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. Aug 9, 2011 at 13:55
  • 4
    No need. QuickWKT already exists. We're approaching an ideal world ;)
    – underdark
    Aug 9, 2011 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, 2012 at 16:20
10

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:

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

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

QgsProject.instance().addMapLayer(result)

References:

6

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

4
  • 1
    Amazing approach. Quick and straightforward
    – Taras
    Aug 10, 2021 at 9:00
  • This is far and away the best approach these days. So simple.
    – Nick K9
    Oct 30, 2021 at 20:53
  • I was 30 minutes on different solutions to visualize the WKT - this is ingenious!
    – arapEST
    Nov 23, 2021 at 6:34
  • @arapEST indeed, one of the highly appreciated hidden features. And best of all, we can use it to directly copy&paste polylines from AutoCAD to QGIS with the help of a little AutoLISP program.
    – christoph
    Nov 23, 2021 at 10:41
5

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 see also the geometry as text.

Probably there are more elegant alternatives.

3
  • My goal is to visualise the string as geometry in a layer.
    – Chau
    Aug 9, 2011 at 12:13
  • Even if this does not solve the question, it is still very useful! So thanks for the information!
    – til_b
    Sep 18, 2014 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 !!! Jan 14, 2017 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.