[mapserver-dev] Error accessing Shape files w/no attributes

Jim Klassen Jim.Klassen at ci.stpaul.mn.us
Mon Sep 28 15:38:42 EDT 2009


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);
   }


James Klassen
Office of Technology and Communications
15 West Kellogg Blvd
Saint Paul, MN 55102
P: 651-329-8741
USNG: 15TVK92577674
( http://www.stpaul.gov/ )
Making Saint Paul the Most Livable City in America


More information about the mapserver-dev mailing list