Bug report #5293

fTools doesn't work properly on MultiPoint geometry

Added by Paolo Cavallini almost 12 years ago. Updated almost 7 years ago.

Status:Closed
Priority:High
Assignee:-
Category:Processing/QGIS
Affected QGIS version:master Regression?:
Operating System: Easy fix?:
Pull Request or Patch supplied:No Resolution:fixed
Crashes QGIS or corrupts data:No Copied to github as #:15006

Description

Add geometry columns command does not work, as it returns two columns filled with 0s. See attached sample.

Test_xy_shp.zip (1.64 KB) Paolo Cavallini, 2012-04-03 08:48 AM

Test_xy_3DPoint.zip (958 Bytes) Salvatore Larosa, 2012-04-10 05:10 AM


Related issues

Related to QGIS Application - Bug report #5497: add geometry column error Closed 2012-04-25

History

#1 Updated by Alexander Bruy almost 12 years ago

Field Calculator also can't create columns with X and Y for this dataset

#2 Updated by Paolo Cavallini almost 12 years ago

Apparently, the error occurs when the SHP is 3D MultiPoint.
If you convert SHP geometries from 3DMultiPoint to Point, the calculation of the coordinates works fine!
Thanks Salvatore for noticing.

#3 Updated by Paolo Cavallini almost 12 years ago

  • Priority changed from High to Normal

The file comes from a geoMedia export, so this may be the root of the problem.

#4 Updated by Giovanni Manghi almost 12 years ago

  • Subject changed from Add geometry columns broken to Many ftools tools broken (like "Add geometry columns broken" or "points in polygon") when a input a 3d shapefile

#5 Updated by Alexander Bruy almost 12 years ago

Not sure that this is fTools problem. As I said before, Field Calculator (core functionality) also don't work with such files.

#6 Updated by Giovanni Manghi almost 12 years ago

Alexander Bruy wrote:

Not sure that this is fTools problem. As I said before, Field Calculator (core functionality) also don't work with such files.

sorry you are right. Maybe would be better to change the category of the ticket and the title.

#7 Updated by Paolo Cavallini almost 12 years ago

  • Category set to Data Provider

Probably the problem lies in the vector provider

#8 Updated by Salvatore Larosa almost 12 years ago

Even I guess this is an error in the vector provider.
I tested the operation in other GIS software and the result is this:

  • QGIS(master version): loads and displays the layer, but add geometry column command doesn't work;
  • gvSIG(1.11.0 final): loads but does not display the layer, I get the layer is not supported message;
  • ArcGIS 9.x: loads and displays the layer, but add geometry column command doesn't work;
  • ArcGIS 10.x: everything works.

It seems that the 3D MultiPoint (MultiPointZM) geometries has some problems in general!

#9 Updated by Paolo Cavallini almost 12 years ago

Also the count is broken here, possibly because of the same issue (it always returns 0).

#10 Updated by Giovanni Manghi almost 12 years ago

Paolo Cavallini wrote:

Also the count is broken here, possibly because of the same issue (it always returns 0).

if the issue is a higher level we should change the title of the ticket

#11 Updated by Salvatore Larosa almost 12 years ago

Giovanni Manghi wrote:

if the issue is a higher level we should change the title of the ticket

IMHO, it does not depend on ftools. I agree with Alexander!
I am increasingly convinced that depends on the type of shapefile.

I did a similar operation using the Filed Calculator:
I created two fields and then I applied the functions $x and $y (Geometry tag)!
The result is 0 for both!

#12 Updated by Giovanni Manghi almost 12 years ago

Salvatore Larosa wrote:

Giovanni Manghi wrote:

if the issue is a higher level we should change the title of the ticket

IMHO, it does not depend on ftools. I agree with Alexander!
I am increasingly convinced that depends on the type of shapefile.

I did a similar operation using the Filed Calculator:
I created two fields and then I applied the functions $x and $y (Geometry tag)!
The result is 0 for both!

please then change the title/details accordingly

#13 Updated by Salvatore Larosa almost 12 years ago

Giovanni Manghi wrote:

please then change the title/details accordingly

Giovanni, I can not edit the ticket, unfortunately!
Have I not rights to do that?

#14 Updated by Giovanni Manghi almost 12 years ago

Have I not rights to do that?

try now (logout and login again)

#15 Updated by Salvatore Larosa almost 12 years ago

  • File Test_xy_3DPoint.zip added
  • Subject changed from Many ftools tools broken (like "Add geometry columns broken" or "points in polygon") when a input a 3d shapefile to Field calculator doesn't work on MULTI-geometry for the calculation of the coordinates X and Y (consequently also ftools commands is affect)

I noticed that 3D Shapefile works fine, the issue occur when input file is of type MULTI-geometry!

the attached sample here is 3D Point and everything works!

#16 Updated by Giovanni Manghi almost 12 years ago

Salvatore Larosa wrote:

I noticed that 3D Shapefile works fine, the issue occur when input file is of type MULTI-geometry!

the attached sample here is 3D Point and everything works!

see also #5497

#17 Updated by Salvatore Larosa almost 12 years ago

Also from PostGIS Provider with a MultiPoint geometry doesn't work!
Instead, in MultiPolygon and MultiLinestring ones everything works fine!

Seems that ESRI Shapefile MultiPolygon type [1] does not exist, only MultiPatch!

[1] - http://urlin.it/2ecd8

#18 Updated by Giovanni Manghi almost 12 years ago

  • Priority changed from Normal to High

#19 Updated by Salvatore Larosa almost 12 years ago

Probably a problem of API?

I ran the following test:
in ftools plugin adding (+) to doGeometry.py:

def simpleMeasure( self, inGeom, calcType, ellips, crs ):
    if inGeom.wkbType() in ( QGis.WKBPoint, QGis.WKBPoint25D ):
      pt = QgsPoint()
      pt = inGeom.asPoint()
      attr1 = pt.x()
      attr2 = pt.y()
+    elif inGeom.wkbType() in ( QGis.WKBMultiPoint, QGis.WKBMultiPoint25D ):
+      pt = QgsMultiPoint()
+      pt = inGeom.asMultiPoint()
+      attr1 = pt.x()
+      attr2 = pt.y()
    else:
      measure = QgsDistanceArea()

then run the Export tool / add geometry column and
if SHP is Point/3DPoint geometry type (QgsPoint) it is successfully,
instead if SHP is MultiPoint/3DMultiPoint geometry type (QgsMultiPoint) not working! QGIS crashes!

and backtrace:

Program received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffbdc4c700 (LWP 25528)]
0x00007ffff07c1475 in raise () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0  0x00007ffff07c1475 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007ffff07c46f0 in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x00007ffff07ba621 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6
#3  0x00007fffeed8be19 in ?? () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#4  0x00007fffeed8cf5c in _XReply () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#5  0x00007fffeed89edd in XTranslateCoordinates () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#6  0x00007ffff269dfa9 in QWidgetPrivate::mapFromGlobal(QPoint const&) const () from /usr/lib/libQtGui.so.4
#7  0x00007ffff269e006 in QWidgetPrivate::mapFromGlobal(QPoint const&) const () from /usr/lib/libQtGui.so.4
#8  0x00007ffff269e006 in QWidgetPrivate::mapFromGlobal(QPoint const&) const () from /usr/lib/libQtGui.so.4
#9  0x00007ffff269e04d in QWidget::mapFromGlobal(QPoint const&) const () from /usr/lib/libQtGui.so.4
#10 0x00007ffff260c41e in QApplicationPrivate::dispatchEnterLeave(QWidget*, QWidget*) ()
   from /usr/lib/libQtGui.so.4
#11 0x00007ffff267baee in QApplicationPrivate::enterModal_sys(QWidget*) () from /usr/lib/libQtGui.so.4
#12 0x00007ffff2610595 in QApplicationPrivate::enterModal(QWidget*) () from /usr/lib/libQtGui.so.4
#13 0x00007ffff26600d2 in QWidgetPrivate::show_helper() () from /usr/lib/libQtGui.so.4
#14 0x00007ffff2660312 in QWidget::setVisible(bool) () from /usr/lib/libQtGui.so.4
#15 0x00007ffff2abfc3c in QDialog::setVisible(bool) () from /usr/lib/libQtGui.so.4
#16 0x00007ffff2abe9e0 in QDialog::exec() () from /usr/lib/libQtGui.so.4
#17 0x00007ffff4356fc9 in QgsMessageViewer::showMessage(bool) () from /usr/local/lib/libqgis_gui.so.1.9.90
#18 0x00007fffd2bf7a0c in meth_QgsMessageOutput_showMessage () from /usr/local/share/qgis/python/qgis/core.so
#19 0x00007fffd40073d5 in call_function (oparg=<optimized out>, pp_stack=0x7fffbdc4b9d0)
    at ../Python/ceval.c:4021
#20 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:2666
#21 0x00007fffd400817b in fast_function (nk=<optimized out>, na=4, n=<optimized out>, pp_stack=0x7fffbdc4bb30, 
    func=<function at remote 0x17a0848>) at ../Python/ceval.c:4107
#22 call_function (oparg=<optimized out>, pp_stack=0x7fffbdc4bb30) at ../Python/ceval.c:4042
#23 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:2666
#24 0x00007fffd4009025 in PyEval_EvalCodeEx (co=<optimized out>, globals=<optimized out>, 
    locals=<optimized out>, args=<optimized out>, argcount=3, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=
    0x0) at ../Python/ceval.c:3253
#25 0x00007fffd3f8be7c in function_call (func=<function at remote 0x17a2578>, arg=
    (<type at remote 0x7fffd43977c0>, exceptions.NameError("global name 'QgsMultiPoint' is not defined", <traceback at remote 0x420db48>), kw=0x0) at ../Objects/funcobject.c:526
#26 0x00007fffd3f63833 in PyObject_Call (func=<function at remote 0x17a2578>, arg=<optimized out>, 
    kw=<optimized out>) at ../Objects/abstract.c:2529
#27 0x00007fffd4001a47 in PyEval_CallObjectWithKeywords (func=<function at remote 0x17a2578>, arg=
    (<type at remote 0x7fffd43977c0>, exceptions.NameError("global name 'QgsMultiPoint' is not defined",), <traceback at remote 0x420db48>), kw=<optimized out>) at ../Python/ceval.c:3890
#28 0x00007fffd402bc6e in PyErr_PrintEx (set_sys_last_vars=<optimized out>) at ../Python/pythonrun.c:1155
#29 0x00007fffd394509d in ?? () from /usr/lib/python2.7/dist-packages/PyQt4/QtCore.so
#30 0x00007fffd3977bb1 in ?? () from /usr/lib/python2.7/dist-packages/PyQt4/QtCore.so
#31 0x00007ffff3155ec5 in ?? () from /usr/lib/libQtCore.so.4
#32 0x00007ffff0579b50 in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0
#33 0x00007ffff086790d in clone () from /lib/x86_64-linux-gnu/libc.so.6
#34 0x0000000000000000 in ?? ()

throws two exceptions in 25, 27:
exceptions.NameError("global name 'QgsMultiPoint' is not defined" 

Could be a problem in qgis.core library?
Why QgsMultiPoint is not defined?

#20 Updated by Salvatore Larosa almost 12 years ago

Worth to file a new ticket for?

#21 Updated by Giovanni Manghi almost 12 years ago

Salvatore Larosa wrote:

Worth to file a new ticket for?

I added Jurgen as watcher (hi Jurgen). Let's see if he can leave feedback about this issue.

#22 Updated by Salvatore Larosa almost 12 years ago

  • % Done changed from 0 to 50

We almost reached the end!
I found the solution, thinking that it was also easy!

Rightly, to represent a MultiPoint geometry type need a list!

[(3.4), (5.6)]

in the console so if I create a multi-geometry type:

>>> geomMulti = QgsGeometry.fromWkt = ("MULTIPOINT (3 4)")

the following command throws:

>>> geomMulti.asMultiPoint () 
[(3.4)]
>>> geomMulti.isMultipart()
True

in order to recover the x coordinate I type:

>>> pt = geomMulti.asMultiPoint()
>>> getX = pt.x()

but get the error:

Traceback (most recent call last):
   File "<input>", line 1, in <module>
AttributeError: 'list' object has no attribute 'x'

while if I consider pt as a list:

>>> pt[0].x()
3.0
>>> pt[0].y()
4.0

returns the correct values!

Now, the problem is solved in fTools, but remains to solve the Field Calculator issue!

Tonight to party with python!

#23 Updated by Salvatore Larosa almost 12 years ago

  • % Done changed from 50 to 100
  • Subject changed from Field calculator doesn't work on MULTI-geometry for the calculation of the coordinates X and Y (consequently also ftools commands is affect) to fTools doesn't work properly on MultiPoint geometry
  • Category changed from Data Provider to 44

I changed the subject and category for this ticket and I will open a new ticket for Field Calculator.
I guess it is more appropriate in order to fix!

I hope Carson can do it as soon as possible!

#24 Updated by Giovanni Manghi almost 12 years ago

Salvatore Larosa wrote:

I changed the subject and category for this ticket and I will open a new ticket for Field Calculator.
I guess it is more appropriate in order to fix!

I hope Carson can do it as soon as possible!

I don't think Carson will have a look at this. Lately the person who worked on ftools was Alexander.

#25 Updated by Alexander Bruy almost 12 years ago

  • Resolution set to fixed
  • Status changed from Open to Closed

Fixed in d3a50e8bcb

#26 Updated by Giovanni Manghi almost 7 years ago

The "ftools" category is being removed from the tracker, changing the category of this ticket to "Processing/QGIS" to not leave the category orphaned.

Also available in: Atom PDF