ShapefileFeatureReader constructor

ShapefileFeatureReader(
  1. File shpFile, {
  2. Charset? charset,
})

Implementation

ShapefileFeatureReader(File shpFile, {Charset? charset}) {
  String nameNoExt = FileUtilities.nameFromFile(shpFile.path, false);

  String parentFolder = FileUtilities.parentFolderFromFile(shpFile.path);

  String dbfName = nameNoExt + ".dbf";
  String shxName = nameNoExt + ".shx";

  String dbfPath = FileUtilities.joinPaths(parentFolder, dbfName);
  String shxPath = FileUtilities.joinPaths(parentFolder, shxName);

  File shxFile = File(shxPath);
  var shxReader;
  if (shxFile.existsSync()) {
    shxReader = FileReaderRandom(shxFile);
  }

  charset ??= Charset();
  shp = ShapefileReader(FileReaderRandom(shpFile), shxReader);

  var file = File(dbfPath);
  if (file.existsSync()) {
    dbf = DbaseFileReader(FileReaderRandom(file), charset);
  }
}