[gdal-dev] How to delete shapefile

Clay, Bruce bclay at ball.com
Tue Jun 16 16:40:25 EDT 2009


I am trying to delete a temporary shapefile after running a process with
the following code.

 

int GdalWrapper::DeleteDataset(const char *datasetName)

{

      int status = -1;

 

      if (datasetName != NULL)

      {

            OGRDataSource *dataSrc = OpenDatasetFile(datasetName);

            if (dataSrc != NULL)

            {

                  try

                  {

                        int refCnt = dataSrc->GetSummaryRefCount();

                        if (refCnt > 0)

                        {

                              dataSrc->Release();

                        }

                        int deleteOk =
dataSrc->TestCapability(ODsCDeleteLayer);

                        if (deleteOk == TRUE)

                        {

                              dataSrc->DeleteLayer(0);

                              status = 0;

                        }

                        else

                        {

                              mLastErrorMsg = "Can not delete requested
dataset";

                        }

                  }

                  catch(...)

                  {

                        mLastErrorMsg = "Could not delete layer: ";

                        mLastErrorMsg += datasetName;

                  }

 

            }

 

      }

 

      return(status);

}

 

The TestCapability always returns FALSE.  If I call DeleteLayer anyway I
get an unsupported operation error messege.

I am using GDAL 1.5.3 with Visual Studio 2005.

 

Is there an error in my code or a different way to delete a shapefile
using GDAL or do I have to go to the operating system and find all of
the files that make up the shapefile and delete them that way?

 

Bruce

 

 




This message and any enclosures are intended only for the addressee.  Please  
notify the sender by email if you are not the intended recipient.  If you are  
not the intended recipient, you may not use, copy, disclose, or distribute this  
message or its contents or enclosures to any other person and any such actions  
may be unlawful.  Ball reserves the right to monitor and review all messages  
and enclosures sent to or from this email address.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090616/a4093b2e/attachment-0001.html


More information about the gdal-dev mailing list