[mapserver-dev] Error accessing Shape files w/noattributes

Steve Lime Steve.Lime at dnr.state.mn.us
Fri Oct 2 15:56:39 EDT 2009


I'll take care of it. Just to confirm, a shapefile with no attributes is valid according to the ESRI spec. correct?

Steve

>>> On 10/2/2009 at 1:53 PM, in message <4AC605C70200004F000144EC at jeckle>, "Jim
Klassen" <Jim.Klassen at ci.stpaul.mn.us> wrote:
> Sorry for the delay. I didn't see your response until now... anyway #3147
> 
>>>> "Steve Lime" <Steve.Lime at dnr.state.mn.us> 09/29/09 10:10 AM >>>
> Jim: Create a quick ticket and I'll take care of applying your patch tonite.
> 
> Steve
> 
>>>> On 9/28/2009 at 2:38 PM, in message <4AC0CA720200004F000142A1 at jeckle>, "Jim
> Klassen" <Jim.Klassen at ci.stpaul.mn.us> wrote:
>> 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
>> _______________________________________________
>> mapserver-dev mailing list
>> mapserver-dev at lists.osgeo.org 
>> http://lists.osgeo.org/mailman/listinfo/mapserver-dev



More information about the mapserver-dev mailing list