readShapefile method
Implementation
Future<void> readShapefile(String path) async {
String shpPath;
String dbfPath;
// Check if the path is a ZIP file
if (p.extension(path).toLowerCase() == '.zip') {
// Extract the ZIP file
final tempDir = await _extractZipFile(path);
// Find the .shp and .dbf files in the extracted directory
shpPath = _findFileInDirectory(tempDir.path, '.shp')!;
dbfPath = _findFileInDirectory(tempDir.path, '.dbf')!;
} else {
// Assume the path is a directory containing .shp and .dbf files
shpPath = _findFileInDirectory(path, '.shp')!;
dbfPath = _findFileInDirectory(path, '.dbf')!;
}
// Read the files
final shpFile = File(shpPath);
final dbfFile = File(dbfPath);
final shpBytes = await shpFile.readAsBytes();
final dbfBytes = await dbfFile.readAsBytes();
final shpGeometries = _parseShpFile(shpBytes);
final dbfAttributes = _parseDbfFile(dbfBytes);
for (int i = 0; i < shpGeometries.length; i++) {
features.add(GeoFeature(
geometry: shpGeometries[i],
properties: dbfAttributes[i],
));
}
}