Opened 16 years ago

Closed 15 years ago

#1290 closed patch (fixed)

Shapefile attribute tables do not show lines with null geometry

Reported by: gabrimonfa Owned by: mhugent
Priority: minor: annoyance Milestone: Version 1.2.0
Component: Data Provider Version: Trunk
Keywords: shapefile, null geometry Cc: pcav
Must Fix for Release: No Platform: All
Platform Version: Awaiting user input: no

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.

Attachments (3)

example.tar.gz (299 bytes ) - added by gabrimonfa 15 years ago.
It contains a shapefile with 3 null-geometries. dbf has two fields, one char(16) and one number(16)
example2.tar.gz (394 bytes ) - added by gabrimonfa 15 years ago.
It contains a shapefile with 3 null-geometries and 1 non-null geometry. dbf has two fields, one char(16) and one number(16)
display_attributes_of_a_null_geometry.patch (1.2 KB ) - added by gabrimonfa 15 years ago.
crude patch to solve the problem

Download all attachments as: .zip

Change History (15)

comment:1 by lutra, 15 years ago

Hi,

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

by gabrimonfa, 15 years ago

Attachment: example.tar.gz added

It contains a shapefile with 3 null-geometries. dbf has two fields, one char(16) and one number(16)

comment:2 by gabrimonfa, 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

comment:3 by pcav, 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

by gabrimonfa, 15 years ago

Attachment: example2.tar.gz added

It contains a shapefile with 3 null-geometries and 1 non-null geometry. dbf has two fields, one char(16) and one number(16)

comment:4 by pcav, 15 years ago

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

comment:5 by lutra, 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?

comment:6 by gabrimonfa, 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.

comment:7 by pcav, 15 years ago

Priority: major: does not work as expectedminor: annoyance

comment:8 by pcav, 15 years ago

Component: OGR Layer supportData Provider

by gabrimonfa, 15 years ago

crude patch to solve the problem

comment:9 by gabrimonfa, 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.

comment:10 by lutra, 15 years ago

Cc: pcav added
Milestone: Version 1.0.3Version 1.2.0
Owner: changed from nobody to mhugent
Type: bugpatch

Thanks!

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

comment:11 by lutra, 15 years ago

Platform: UnixAll

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.

comment:12 by mhugent, 15 years ago

Resolution: fixed
Status: newclosed

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

Note: See TracTickets for help on using tickets.