Getting the correct number of records from a shapefile

Last Published: April 25, 2020


After a record is deleted from a shape file using ' recNum)' method and 'getNumRecs()' method is called on the same object, the total number of records will remain same.

In MapObjects Java 2.0, Shapefile class is within com.esri.mo2.file.shp package.


Shapefile.delRecord(int rec) only flags the record as deleted but does not remove it permanently from the file. Shapefile.getNumRecs() method will return the number of records stored in the header of the shape file, which only stores the total number of records, including those flagged as deleted.

Solution or Workaround

Use for-loop to go through all the records in the shapefile and count only those that return the status as OK as shown in the following example:

int rec=0;
for(int i=0;i<shapefile.getNumRecs();i++){
int isOK=shapefile.getRecord();
if (isOK==Shapefile.OK)rec++;
//total # of records = rec

Article ID:000005619

  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic