Hi Alexander,
I moved to new version 26.5 and here my results:
Test data(input/output/QGIS)
shapefile8.7z (7.5 MB)
Error:
[ShapefileTest] Testing Shapefile → Shapefile
Args: input=‘D:\GisConverter\Tests\Shapefile\Input\shapefile8.7z’, format=‘Shapefile’, output=‘D:\GisConverter\Tests\Shapefile\Output\2026-06-04_18-00-48\ShapefileTest\Shapefile’, temp=‘D:\GisConverter\Tests\Shapefile\Temp\2026-06-04_18-00-48\ShapefileTest\Shapefile’, logPath=‘D:\GisConverter\Tests\Shapefile\Log\2026-06-04_18-00-48\shapefiletest_shapefile_log.txt’, logLevel=‘’
Conversion failed.
2026-06-04T18:00:55.8626418+03:00 (Local) | 2026-06-04T15:00:55.8626418Z (UTC)
Unexpected error: Length of the value exceeds length of the field.
Result: ConversionFailed
Thanks,
Hi Dani,
Thank you for providing the test data and the exact error message.
The “Length of the value exceeds length of the field” exception is raised by the Shapefile writer when a string attribute is longer than the length defined in the .dbf field schema. In version 26.5 the writer validates this strictly, so any field that contains a value longer than the declared width will cause the whole conversion to fail.
What you can do
- Inspect the source schema – find the maximum length of each string field.
- Trim or truncate values that exceed the allowed length before writing the feature to the destination Shapefile.
- (Optional) Increase the field width in the destination schema, then write the features.
Below is a minimal example that implements the first two steps with the latest Aspose.GIS 26.x API:
using Aspose.Gis;
using Aspose.Gis.Formats.Shapefile;
using System;
using System.Collections.Generic;
// Input and output paths
string inputPath = @"D:\GisConverter\Tests\Shapefile\Input\shapefile8\input.shp";
string outputPath = @"D:\GisConverter\Tests\Shapefile\Output\ShapefileTest\output.shp";
// Open source shapefile
using (var src = ShapefileReader.Open(inputPath))
{
// Read source schema (field names & lengths)
var srcSchema = src.GetFeatureSchema();
// Create a new schema for the destination shapefile
var dstSchema = new FeatureSchema();
foreach (var field in srcSchema)
{
// Preserve numeric/date fields as‑is
if (field.Type != AttributeDataType.String)
{
dstSchema.Add(field);
continue;
}
// For string fields increase length a bit (optional)
int newLength = Math.Max(field.Size, 255); // 255 is the classic Shapefile max
dstSchema.Add(new Field(field.Name, AttributeDataType.String, newLength));
}
// Create writer with the new schema
using (var dst = ShapefileWriter.Create(outputPath, src.GetFeatureType()))
{
dst.SetFeatureSchema(dstSchema);
// Copy features while truncating oversized strings
foreach (var srcFeature in src)
{
var dstFeature = dst.CreateFeature();
foreach (var field in srcSchema)
{
var value = srcFeature.Attributes[field.Name];
if (field.Type == AttributeDataType.String && value != null)
{
string str = value.ToString();
// Truncate to the destination field length
int maxLen = dstSchema[field.Name].Size;
if (str.Length > maxLen)
str = str.Substring(0, maxLen);
dstFeature.Attributes[field.Name] = str;
}
else
{
dstFeature.Attributes[field.Name] = value;
}
}
// Copy geometry
dstFeature.Geometry = srcFeature.Geometry.Clone();
// Write the feature
dst.Write(dstFeature);
}
}
}
Key points in the code
FeatureSchema is rebuilt so you can optionally enlarge string columns (newLength).
- Each string attribute is checked against the destination column size and truncated if necessary.
- Geometry is copied unchanged (
Clone()).
Additional resources
Next steps
- Run the snippet on the provided
shapefile8.7z archive. The conversion should complete without the “Length of the value exceeds length of the field” error.
- If you prefer to keep the original field widths, you can simply truncate the offending values as shown.
- Should you need the original values preserved, consider increasing the field width in the destination schema (e.g., to 255) as demonstrated.
- If the problem persists after applying the truncation logic, please let us know which attribute(s) cause the overflow – you can obtain that information by printing
field.Name and field.Size from the source schema.
Feel free to share the updated log or any further details, and we’ll be glad to assist you further.
Waiting to your answer-
Thank you very much.
Hi, @danies8
I need to explore your request. I’ll be back with an answer in a couple of days.