这是我寻求帮助的第一篇文章。在开发 shapefile 读取软件时,我遇到了以下错误:
不能将属性或索引器“ShapeRange.Parts”分配给——它是只读的
我的代码片段,错误如下。
var shx = new DSShapeRange(featureType) { Extent = geometry.EnvelopeInternal.ToDotSpatial() };
shx.Parts = new List<DSPartRange>();
该行所在的功能是:
private static DSShapeRange ShapeRangeFromGeometry(IGeometry geometry, double[] vertices, int offset)
{
var featureType = geometry.OgcGeometryType.ToDotSpatial();
var shx = new DSShapeRange(featureType) { Extent = geometry.EnvelopeInternal.ToDotSpatial() };
shx.Parts = new List<DSPartRange>();
var vIndex = offset / 2;
var shapeStart = vIndex;
for (var part = 0; part < geometry.NumGeometries; part++)
{
var prtx = new DSPartRange(vertices, shapeStart, vIndex - shapeStart, featureType);
var bp = geometry.GetGeometryN(part) as IPolygon;
if (bp != null)
{
// Account for the Shell
prtx.NumVertices = bp.Shell.NumPoints;
vIndex += bp.Shell.NumPoints;
// The part range should be adjusted to no longer include the holes
foreach (var hole in bp.Holes)
{
var holex = new DSPartRange(vertices, shapeStart, vIndex - shapeStart, featureType)
{
NumVertices = hole.NumPoints
};
shx.Parts.Add(holex);
vIndex += hole.NumPoints;
}
}
else
{
int numPoints = geometry.GetGeometryN(part).NumPoints;
// This is not a polygon, so just add the number of points.
vIndex += numPoints;
prtx.NumVertices = numPoints;
}
shx.Parts.Add(prtx);
}
return shx;
}