{"id":1074,"date":"2018-09-18T13:44:27","date_gmt":"2018-09-18T11:44:27","guid":{"rendered":"http:\/\/hannes.enjoys.it\/blog\/?p=1074"},"modified":"2018-09-18T17:07:38","modified_gmt":"2018-09-18T15:07:38","slug":"writing-one-wkt-file-per-feature-in-qgis","status":"publish","type":"post","link":"https:\/\/hannes.enjoys.it\/blog\/2018\/09\/writing-one-wkt-file-per-feature-in-qgis\/","title":{"rendered":"Writing one WKT file per feature in QGIS"},"content":{"rendered":"<p>Someone in #qgis just asked about this so here is a minimal pyqgis (for QGIS 3) example how you can write a separate WKT file for each feature of the currently selected layer. Careful with too many features, filesystems do not like ten thousands of files in the same directory. I am writing them to <code>\/tmp\/<\/code> with <code>$fid.wkt<\/code> as filename, adjust the path to your liking.<\/p>\n<pre>layer = iface.activeLayer()\r\nfeatures = layer.getFeatures()\r\n\r\nfor feature in features:\r\n  geometry = feature.geometry()\r\n  wkt = geometry.asWkt()\r\n  \r\n  fid = feature.attribute(\"fid\")\r\n  filename = \"\/tmp\/{n}.wkt\".format(n=fid)\r\n  \r\n  with open(filename, \"w\") as output:\r\n    output.write(wkt)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Someone in #qgis just asked about this so here is a minimal pyqgis (for QGIS 3) example how you can write a separate WKT file for each feature of the currently selected layer. Careful with too many features, filesystems do not like ten thousands of files in the same directory. I am writing them to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,43,31,40],"tags":[],"class_list":["post-1074","post","type-post","status-publish","format-standard","hentry","category-gis","category-python","category-qgis","category-small-things"],"_links":{"self":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/1074","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/comments?post=1074"}],"version-history":[{"count":3,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/1074\/revisions"}],"predecessor-version":[{"id":1077,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/1074\/revisions\/1077"}],"wp:attachment":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/media?parent=1074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/categories?post=1074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/tags?post=1074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}