Feature request #1290

Shapefile attribute tables do not show lines with null geometry

Added by Gabriele Monfardini about 16 years ago. Updated over 15 years ago.

Status:Closed
Priority:Low
Assignee:Marco Hugentobler
Category:Data Provider
Pull Request or Patch supplied: Resolution:fixed
Easy fix?:No Copied to github as #:11350

Description

I've seen Changeset 2020. Qgis do not crash anymore viewing shapefiles with records with null geometry.
But... this records are not shown.
Since null geometries are allowed by shapefile format and these records may carry useful data, they should be shown.

example.tar.gz - It contains a shapefile with 3 null-geometries. dbf has two fields, one char(16) and one number(16) (299 Bytes) Gabriele Monfardini, 2009-07-16 08:37 AM

example2.tar.gz - It contains a shapefile with 3 null-geometries and 1 non-null geometry. dbf has two fields, one char(16) and one number(16) (394 Bytes) Gabriele Monfardini, 2009-07-16 09:12 AM

display_attributes_of_a_null_geometry.patch Magnifier - crude patch to solve the problem (1.2 KB) Gabriele Monfardini, 2009-07-18 07:06 AM

History

#1 Updated by Giovanni Manghi over 15 years ago

Hi,

can you please attach here a shapefile so we can do further tests? Thanks!

#2 Updated by Gabriele Monfardini over 15 years ago

I've attached a shapefile with 3 empty geometries.
The attribute table is like that

Value | Number
aa | 1
bb | 2
cc | 0

I'm using qgis 1.2.0-Unstable Trunk at revision 11034.
The behavior is different from my first submission. Now the three rows are shown in the attribute table, but instead of the values they show the string "ERROR":

Value | Number
ERROR | ERROR
ERROR | ERROR
ERROR | ERROR

I don't know if the shapefile is exactly coherent with the shapefile format, I've created it with ArcView GIS 3.2a

#3 Updated by Paolo Cavallini over 15 years ago

Confirmed. However, I do not see a real use case for what is essentially a non-spatial table: can you help us understanding?
Thanks

#4 Updated by Paolo Cavallini over 15 years ago

The non-null geom is visualized, and the record shown, the others not. Do you know of other software behaving differently?

#5 Updated by Giovanni Manghi over 15 years ago

Hi,

I had the chance to try both the shapes you posted also on arcview 3.x and arcgis 9.x

On arcview 3.x they load fine and attribute tables show the records correctly. Arcgis 9.x works differently: in the first case it gives first a "general function failure" and then, when you open the table, a "error getting a list of OIDs from the table" and shows nothing. In the second case Arcgis 3.x gives directly a "error loading feature class" and do not load the shape.

On the other hand gvSIG seems to open correctly the table.

In what situations do you use such shapefiles? Maybe do you digitize at a later time a vector and then attach it to the table?

#6 Updated by Gabriele Monfardini over 15 years ago

Sometimes it happens to receive shapefiles with null features, but valid scalar data.
Sometimes the geometry is null by mistake and this, for example, may cause errors manipulating such features (i.e. importing or visualizing them).

So it would be useful to be able to inspect this features with qgis and see if the problem is caused by incorrect scalar data in the dbf or something else (corrupted uploaded file for example).

IMHO it is not an oddities to have a null geometry, it is not a "non-geometric" data.
AFAIK it is explicitly allowed by shapefile format to have null-geometries.
A null geometry is a perfectly legal geometry. Why this should prevent to inspect scalar data?

I think that the fact that dbf values related to null geometries are not shown is yet a bug, even if a minor one.

#7 Updated by Gabriele Monfardini over 15 years ago

I've added a crude patch to try to solve the problem.
(Is this the correct way to provide a possible patch?)

The idea is simple, to fetch only the attributes of the null-geometry row and to mark the feature as not valid to prevent problem with rasterization.

Obviously I don't know if setting mFetchFeaturesWithoutGeom( TRUE ) in qgsvectordataprovider.cpp is a good idea, maybe better solutions are possible that affects only the ogr provider.

The patch works with my test shapefiles.

#8 Updated by Giovanni Manghi over 15 years ago

Thanks!

I changed the owner of the ticket, so Marco will have a look to your patch when he'll be back.

#9 Updated by Giovanni Manghi over 15 years ago

The patch works.

The second part of the patch seems to have been already implemented somehow. It remains to apply the first part "mFetchFeaturesWithoutGeom( TRUE )", if obviously the developers think it is a good idea.

#10 Updated by Marco Hugentobler over 15 years ago

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

Applied in with modifications (kept QgsOGRProvider::featureAtId consistent with QgsOGRProvider::nextFeature).
Thanks for the contribution!

Also available in: Atom PDF