<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Consolas","serif";
        color:black;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor="white" lang="EN-AU" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I had a bit of play with this last night and came up with this script:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">layer = iface.activeLayer()  #active layer should be your CSV file<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">newname = layer.name() + '_Map'<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">otype = "Point"  # could be "Polygon" or "LineString"<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">resultlayer = QgsVectorLayer(otype, newname, "memory")<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">resultlayer.startEditing()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">dp=resultlayer.dataProvider()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">dp.addAttributes(list(layer.dataProvider().fields()))<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">resultlayer.updateFields()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">dp.addFeatures(list(layer.dataProvider().getFeatures()))<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">QgsMapLayerRegistry.instance().addMapLayer(resultlayer)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">You can paste the script into the python console editor<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">If you open a CSV file with no geometry and run the script it will create a copy of the CSV in a Memory layer with the specified object type (Point, LineString
 or Polygon)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">You can then select individual rows in the attribute table and use the “Add Part” tool to digitise them.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext"> Qgis-user [mailto:qgis-user-bounces@lists.osgeo.org]
<b>On Behalf Of </b>Matthias Kuhn<br>
<b>Sent:</b> Tuesday, 17 November 2015 6:59 AM<br>
<b>To:</b> DelazJ<br>
<b>Cc:</b> qgis-user@lists.osgeo.org<br>
<b>Subject:</b> Re: [Qgis-user] Creating Geometries for tabular data<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt">I use the process on a postgis DB, but Shapefiles are also capable of having tabular data without geometries attached.<br>
However I do not know how you would create such a file (easily) from an existing geometry-less layer.<br>
<br>
Maybe something like this:<br>
<a href="http://gis.stackexchange.com/questions/327/how-can-i-convert-an-excel-file-with-x-y-columns-to-a-shapefile">http://gis.stackexchange.com/questions/327/how-can-i-convert-an-excel-file-with-x-y-columns-to-a-shapefile</a><br>
<br>
Or try with adding a dummy geometry column in a csv so it loads as points and then save as shapefile.<br>
<br>
Best,<br>
Matthias<o:p></o:p></p>
<div>
<p class="MsoNormal">On 11/16/2015 03:00 PM, DelazJ wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">Hi,<o:p></o:p></p>
</div>
<p class="MsoNormal">Matthias, what kind of format can this file be?<o:p></o:p></p>
</div>
<p class="MsoNormal">This is not the first time I see MapInfo user asking about this feature. I personnaly had last week to add geometries to features that were in a tabular file (csv) and couldn't find how to do this except giving an unique ID to the table
 data, and in another shapefile digitizing, filling ID after each drawing and, at the end joining layers. It was possible because there was not so many features but it's unfriendly.<o:p></o:p></p>
</div>
<p class="MsoNormal">I thought I could save the csv into shapefile (even empty)  and proceed with the "add part" tool but "saving as" failed.<o:p></o:p></p>
</div>
<p class="MsoNormal">It would be nice if we could find a way to address this "issue"...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">2015-11-16 7:22 GMT+01:00 Matthias Kuhn <<a href="mailto:matthias@opengis.ch" target="_blank">matthias@opengis.ch</a>>:<o:p></o:p></p>
<p class="MsoNormal">Hi,<br>
<br>
IIRC you can use the "add part" tool to create geometries for existing<br>
objects. Just use the attribute table to select the proper object and<br>
then digitize with the add part tool. Of course the selected layer has<br>
to be capable of saving geomtries in the format you like (i.e. you<br>
cannot geometrizise an excel table).<br>
<br>
Cheers,<br>
Matthias<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">_______________________________________________<br>
Qgis-user mailing list<br>
<a href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a><br>
List info: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">
http://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
Unsubscribe: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">
http://lists.osgeo.org/mailman/listinfo/qgis-user</a><o:p></o:p></p>
</div>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</blockquote>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<pre>-- <o:p></o:p></pre>
<pre>Matthias Kuhn<o:p></o:p></pre>
<pre>OPENGIS.ch - <a href="https://www.opengis.ch">https://www.opengis.ch</a><o:p></o:p></pre>
<pre>Spatial • (Q)GIS • PostGIS • Open Source<o:p></o:p></pre>
</div>
<br clear="both">
This email is intended for the named recipient only.  The information it contains may be confidential.  If you are not the intended recipient you must not reproduce or distribute any part of this email, disclose its contents to any other party or take any action in reliance on it.  If you have received this email in error, please contact the sender immediately and delete the message.<BR>
</body>
</html>