Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#3147 closed defect (fixed)

Shape file w/no attributes failed

Reported by: jimk Owned by: sdlime
Priority: normal Milestone: 5.6 release
Component: MapServer C Library Version: unspecified
Severity: normal Keywords:
Cc:

Description

When I try to access a layer that points to a shape file with no attributes I get the following error...

msDrawMap(): Image handling error. Failed to draw layer named 'CITYOUTLINE'. msGetDBFItems(): DBASE file error. File contains no data.

It looks like this is related to a change introduced with the improved algorithm in msLayerWhichItems() in maplayer.c. The problem seems to be how lines 385 and 386 are interacting with msDBFGetItems/msShapeFileLayerGetItems in that msShapeFileLayerGetItems is returning MS_FAILURE because msDBFGetItems found no items and thus calls msSetError and returns NULL. The line maplayer.c:386 then causes msLayerWhichItems to fail before line 388 can say this is an expected condition.

385  rv = msLayerGetItems(layer);
386  if(rv != MS_SUCCESS) return rv;
387
388  if(layer->numitems == 0) return MS_SUCCESS; /* nothing to do but not an error */

The following are the changes I made to mapshape.c (to return MS_SUCCESS) and to mapxbase.c to not set an error that isn't an error. The change to mapxbase.c may cause issues with tileindexed layers with no attributes in the tileindex shapefile failing without an error message. This depends on what the correct behavior is in another place in msTiledSHPLayerGetItems. I think this is for the tileindex not the actual data shapes, and the tileindex does require at least one attribute. If this is true and the mapxbase.c change is kept, an error probably needs to be set in msTiledSHPLayerGetItems if there are no items.

Index: mapshape.c
===================================================================
--- mapshape.c  (revision 9354)
+++ mapshape.c  (working copy)
@@ -2579,6 +2579,7 @@

  layer->numitems = msDBFGetFieldCount(shpfile->hDBF);
  layer->items = msDBFGetItems(shpfile->hDBF);    
+  if(layer->numitems == 0) return MS_SUCCESS; /* No items is a valid case */
  if(!layer->items) return MS_FAILURE;

  return msLayerInitItemInfo(layer);
Index: mapxbase.c
===================================================================
--- mapxbase.c  (revision 9354)
+++ mapxbase.c  (working copy)
@@ -824,7 +824,7 @@
  char fName[32];

  if((nFields = msDBFGetFieldCount(dbffile)) == 0) {
-    msSetError(MS_DBFERR, "File contains no data.", "msGetDBFItems()");
+    /*msSetError(MS_DBFERR, "File contains no data.", "msGetDBFItems()");*/
    return(NULL);
  }

Attachments (1)

CITY_OUTLINE.zip (1.9 KB ) - added by jimk 15 years ago.
Test case shape file.

Download all attachments as: .zip

Change History (4)

comment:1 by sdlime, 15 years ago

Milestone: 5.6 release
Status: newassigned

comment:2 by sdlime, 15 years ago

Resolution: fixed
Status: assignedclosed

Jim: I did add this to beta 4, but only the mapshape.c change. Please verify that your test base works if you would.

Steve

by jimk, 15 years ago

Attachment: CITY_OUTLINE.zip added

Test case shape file.

comment:3 by jimk, 15 years ago

Thanks. It looks like it was committed in r9480. I tested against r9494 and it is working.

Note: See TracTickets for help on using tickets.