I had a bit of play with this last night and came up with this script: layer = iface.activeLayer() #active layer should be your CSV file newname = layer.name() + '_Map' otype = "Point" # could be "Polygon" or "LineString" resultlayer = QgsVectorLayer(otype, newname, "memory") resultlayer.startEditing() dp=resultlayer.dataProvider() dp.addAttributes(list(layer.dataProvider().fields())) resultlayer.updateFields() dp.addFeatures(list(layer.dataProvider().getFeatures())) QgsMapLayerRegistry.instance().addMapLayer(resultlayer)
You can paste the script into the python console editor 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) You can then select individual rows in the attribute table and use the “Add Part” tool to digitise them. From: Qgis-user [mailto:[email protected]] On Behalf Of Matthias Kuhn Sent: Tuesday, 17 November 2015 6:59 AM To: DelazJ Cc: [email protected] Subject: Re: [Qgis-user] Creating Geometries for tabular data I use the process on a postgis DB, but Shapefiles are also capable of having tabular data without geometries attached. However I do not know how you would create such a file (easily) from an existing geometry-less layer. Maybe something like this: http://gis.stackexchange.com/questions/327/how-can-i-convert-an-excel-file-with-x-y-columns-to-a-shapefile Or try with adding a dummy geometry column in a csv so it loads as points and then save as shapefile. Best, Matthias On 11/16/2015 03:00 PM, DelazJ wrote: Hi, Matthias, what kind of format can this file be? 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. I thought I could save the csv into shapefile (even empty) and proceed with the "add part" tool but "saving as" failed. It would be nice if we could find a way to address this "issue"... 2015-11-16 7:22 GMT+01:00 Matthias Kuhn <[email protected]<mailto:[email protected]>>: Hi, IIRC you can use the "add part" tool to create geometries for existing objects. Just use the attribute table to select the proper object and then digitize with the add part tool. Of course the selected layer has to be capable of saving geomtries in the format you like (i.e. you cannot geometrizise an excel table). Cheers, Matthias _______________________________________________ Qgis-user mailing list [email protected]<mailto:[email protected]> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user -- Matthias Kuhn OPENGIS.ch - https://www.opengis.ch Spatial • (Q)GIS • PostGIS • Open Source 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.
_______________________________________________ Qgis-user mailing list [email protected] List info: http://lists.osgeo.org/mailman/listinfo/qgis-user Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
