Geo::GDAL  2.4
Reading a vector dataset

The code here does not have any warranty. It is recommended that before using any of this code, you look into it and try to understand what it does, what input it needs, etc. Do not blindly execute anything!

The script below reads the sizes of the bounding boxes of features into a hash, which is indexed by the value of a field in the attribute data of the feature.

use Geo::GDAL;
# information that we need:
$dsname = "./"; # name of the datasource (in this case a directory)
$lname = "borders"; # name of the layer
$field = "country"; # name of the field whose value we need
$datasource = Geo::GDAL::OpenEx($dsname);
$layer = $datasource->Layer($lname);
$layer->ResetReading();
while ($feature = $layer->GetNextFeature()) {
my $geom = $feature->GetGeometry();
my $value = $feature->GetField($field);
my $extent = $geom->GetEnvelope();
$data{$value}{width} = $extent->[1] - $extent->[0];
$data{$value}{height} = $extent->[3] - $extent->[2];
}