1

Closed

delete 3d point fails

description

  • Open a 3d point featureset.
  • call RemoveShapesAt()
  • call Save();
_m contains 0 "M" values. and this will cause outof range exception at this line

PointShapeFile.SaveAs()
{
...
if (M != null) shpStream.WriteLe(M[shp]);
...}

Everywhere else it seems t otbe the rule that ifa file has z then it must have M also.

So this code in

FeatureSet.RemoveShapeAt() fails to copy and remove the M values
if (CoordinateType == CoordinateType.M)
{
double[] mShape = new double[sr.NumPoints];
Array.Copy(_m, sr.StartIndex, mShape, 0, sr.NumPoints);
m.AddRange(mShape);
}

is I adjust as follows it SEEMS to work

// remove the z values if necessary
if (CoordinateType == CoordinateType.Z)
{
double[] zShape = new double[sr.NumPoints];
Array.Copy(_z, sr.StartIndex, zShape, 0, sr.NumPoints);
z.AddRange(zShape);
            double[] mShape = new double[sr.NumPoints];
            Array.Copy(_m, sr.StartIndex, mShape, 0, sr.NumPoints);
            m.AddRange(mShape);
}

Who can verify that this is the correct fix?
            }



    foreach (int index in remaining)
        {
            if (index < 0 || index >= _shapeIndices.Count) continue;
            ShapeRange sr = _shapeIndices[index];
            double[] xyShape = new double[sr.NumPoints * 2];
            Array.Copy(_vertices, sr.StartIndex*2, xyShape, 0, sr.NumPoints * 2);
            vertex.AddRange(xyShape);

            // remove the m values if necessary
            if (CoordinateType == CoordinateType.M)
            {
                double[] mShape = new double[sr.NumPoints];
                Array.Copy(_m, sr.StartIndex, mShape, 0, sr.NumPoints);
                m.AddRange(mShape);
            }

            // remove the z values if necessary
            if (CoordinateType == CoordinateType.Z)
            {
                double[] zShape = new double[sr.NumPoints];
                Array.Copy(_z, sr.StartIndex, zShape, 0, sr.NumPoints);
                z.AddRange(zShape);
                double[] mShape = new double[sr.NumPoints];
                Array.Copy(_m, sr.StartIndex, mShape, 0, sr.NumPoints);
                m.AddRange(mShape);
            }
            sr.StartIndex = pointTotal;
            pointTotal += sr.NumPoints;
            ProgressMeter.Next();
        }
Closed Feb 28 at 8:04 AM by jany_
This issue list is no longer active. This issue has been copied to our issue list on github (https://github.com/DotSpatial/DotSpatial/issues)

Please check there to find out whether this issue was fixed.

comments

Shade1974 wrote Nov 30, 2010 at 2:33 AM

Good catch keenedge. Yes, the smart way to check is testing the CoordinateType. The null check that is there now predates the coordinate test used in the other shapefile classes and may just be poorly tested since I personally don't have a lot of sample data for M or Z lying around. In theory, if the coordinate type is correct, the array should be dimensioned and sized appropriately. This makes me realize, however, that the saving code is not very fault tolerant to people meddling with the size and dimensionality of the arrays. A robust method would pad the XY, M and Z arrays if they are found to be shorter than the expected dimensionality when saving because the values are required in the output format, whether your array has the values or not. I will post that idea as an issue, but at least in the meantime, your fix should solve the short term crisis ok.

Ted