[GIS] Creating lines from points in QGIS, python error ( ‘NoneType’ object has no attribute ‘asPoint’ )

errorpoints-to-linepythonqgis

I'm new to Qgis, and i'm stuck with a simple task, I have a csv file with points coordinates and i would like to connect those points in a path, I'm working with wildlife movement data.
i've tried with the qgis algorithm and several plugins like Points2one, PointsToPath, and Point Connector but every time I get the same python error.
This is the log:

Traceback (most recent call last):
              File "/home/gabriele/.qgis2/python/plugins/pointstopaths_v02/pointstopathsdialog.py", line 89, in accept
                points = processor.generatePointDict()
              File "/home/gabriele/.qgis2/python/plugins/pointstopaths_v02/processfeatures.py", line 52, in generatePointDict
                self.coords = self.geom.asPoint()
AttributeError: 'NoneType' object has no attribute 'asPoint'

Since I've zero knowledge of python code, what I'm doing wrong?

Best Answer

This can happen if you import data with missing geometries. I was able to reproduce this error in Points2One with the following CSV... note the 'woot' entry which is missing data.

Place,x,y
Fibble,1.0,2.0
Flubble,-13.0,29.9
Ploot,45.2,-14.0
Woot,,
Flurb,55.5,45.5

QGIS will happily load this without warnings.

Calling Point2One on this throws a similar exception:-

File "/home/steven/.qgis2/python/plugins/points2one/p2o_engine.py", line 121, in iter_points
geom = feature.geometry().asPoint()
AttributeError: 'NoneType' object has no attribute 'asPoint'

I suspect the same thing will be happening with the other plugins.

You should make sure you :-

  • import with geometry (make sure you don't have the 'No geometry (attribute only)' selected)
  • have geometry values for ALL rows : either an x and y field, or a WKT field, and none of these fields are blank

If you're using Excel (or similar) you can use sort/filter to export a new copy of your csv with all such rows excluded, and see if that works.

Related Question