Hello, I edited an empty shapefile using ShapefileFeatureTable.
However, when I checked the shapefile in QGIS, no geometry was displayed, even though the shapefile actually contains a polygon.
It looks like ShapefileFeatureTable does not update the extent of the shapefile, is that correct?
Here is the output of ogrinfo:
$ ogrinfo -al -so test.shp
INFO: Open of `test.shp'
using driver `ESRI Shapefile' successful.
Layer name: test
Metadata:
DBF_DATE_LAST_UPDATE=2025-12-17
Geometry: Polygon
Feature Count: 1
Extent: (0.000000, 0.000000) - (0.000000, 0.000000)
...
$ ogrinfo -al test.shp
INFO: Open of `test.shp'
using driver `ESRI Shapefile' successful.
Layer name: test
Metadata:
DBF_DATE_LAST_UPDATE=2025-12-17
Geometry: Polygon
Feature Count: 1
Extent: (0.000000, 0.000000) - (0.000000, 0.000000)
...
OGRFeature(test):0
level (Integer64) = 3
POLYGON ((139.757125 35.671236,139.757125 35.691236,
139.777125 35.691236,139.777125 35.671236,
139.757125 35.671236))
Solved! Go to Solution.
Thanks for your help, @AndreaGiudiceandrea . Your comment on Stack Exchange was also very helpful.
The issue was caused by the extent stored in the .shx file.
By updating the .shx file directly, QGIS and ogrinfo are now able to display the shapefile extent correctly.
static void WriteShxExtent(string shxPath,
double xmin, double ymin,
double xmax, double ymax)
{
using var fs = new FileStream(shxPath, FileMode.Open, FileAccess.Write);
using var bw = new BinaryWriter(fs);
fs.Seek(36, SeekOrigin.Begin);
// little-endian double
bw.Write(xmin);
bw.Write(ymin);
bw.Write(xmax);
bw.Write(ymax);
}
I hope this issue with not updating the .shx extent header will be fixed in a future release.
@TaroShibata, thanks for sharing the workaround!
@RossMcguyer , do you know when this issue will be fixed and how and where the fixing procedure could be tracked online?
I found another related issue.
The extent of a ShapefileFeatureTable instance is updated after adding a polygon, but the Xmin and Ymin values remain unchanged.
This seems inconsistent with the expected behavior. It should be same with the extent of the polygon.
Below are the print messages from the console.
table's extent before adding a polygon:Envelope[XMin=0, YMin=0, XMax=0, YMax=0, Wkid=4326]
polygon's extent $Envelope[XMin=139.757125, YMin=35.671236, XMax=139.77712499999998, YMax=35.691235999999996, Wkid=4326]
table's extent after adding the polygon:Envelope[XMin=0, YMin=0, XMax=139.77712499999998, YMax=35.691235999999996, Wkid=4326]