Beispiel #1
0
        /// <summary>
        /// Checking the difference between the two shapes
        /// </summary>
        /// <param name="shp">
        /// The first shape
        /// </param>
        /// <param name="shp2">
        /// The second shape
        /// </param>
        /// <param name="theForm">
        /// The form
        /// </param>
        /// <returns>
        /// True when different
        /// </returns>
        internal static bool AreShapesDifferent(Shape shp, Shape shp2, ICallback theForm)
        {
            theForm.Progress(string.Empty, 100, "Checking the difference between the two shapes");

            if (!shp.IsValid)
            {
                theForm.Error(string.Empty, "The first shape is invalid: " + shp.IsValidReason);
                return(false);
            }

            if (!shp2.IsValid)
            {
                theForm.Error(string.Empty, "The second shape is invalid: " + shp2.IsValidReason);
                return(false);
            }

            var wkt  = shp.ExportToWKT();
            var wkt2 = shp2.ExportToWKT();

            if (wkt != wkt2)
            {
                theForm.Error(string.Empty, "Export to WKT for new shape is different from original one: \n" + wkt + "\n\n" + wkt2);
                return(false);
            }

            if (shp.ShapeType != shp2.ShapeType)
            {
                var msg = string.Format(
                    "The first shape is a {0} and the second shape is a {1}",
                    shp.ShapeType,
                    shp2.ShapeType);
                theForm.Error(string.Empty, msg);
                return(false);
            }

            if (shp.numPoints != shp2.numPoints)
            {
                var msg = string.Format(
                    "The first shape has {0} points and the second shape has {1} points",
                    shp.numPoints,
                    shp2.NumParts);
                theForm.Error(string.Empty, msg);
                return(false);
            }

            if (shp.NumParts != shp2.NumParts)
            {
                var msg = string.Format(
                    "The first shape has {0} points and the second shape has {1} points",
                    shp.NumParts,
                    shp2.NumParts);
                theForm.Error(string.Empty, msg);
                return(false);
            }

            if (shp.ShapeType == ShpfileType.SHP_POLYGON || shp.ShapeType == ShpfileType.SHP_POLYGONM ||
                shp.ShapeType == ShpfileType.SHP_POLYGONZ)
            {
                // Check area:
                if (Math.Abs(shp.Area - shp2.Area) > 0.001)
                {
                    var msg = string.Format(
                        "The first shape has an area of {0} and the second shape has an area of {1}",
                        shp.Area,
                        shp2.Area);
                    theForm.Error(string.Empty, msg);
                    return(false);
                }

                // Check perimeter:
                if (Math.Abs(shp.Perimeter - shp2.Perimeter) > 0.001)
                {
                    var msg =
                        string.Format(
                            "The first shape has a perimeter of {0} and the second shape has a perimeter of {1}",
                            shp.Perimeter,
                            shp2.Perimeter);
                    theForm.Error(string.Empty, msg);
                    return(false);
                }
            }

            if (shp.ShapeType == ShpfileType.SHP_POLYLINE || shp.ShapeType == ShpfileType.SHP_POLYLINEM ||
                shp.ShapeType == ShpfileType.SHP_POLYLINEZ)
            {
                // Check length:
                if (Math.Abs(shp.Length - shp2.Length) > 0.001)
                {
                    var msg =
                        string.Format(
                            "The first shape has a length of {0} and the second shape has a length of {1}",
                            shp.Length,
                            shp2.Length);
                    theForm.Error(string.Empty, msg);
                    return(false);
                }
            }

            if (shp.SerializeToString() != shp2.SerializeToString())
            {
                theForm.Error(string.Empty, "The SerializeToString methods return different values:");
                theForm.Error(string.Empty, shp.SerializeToString());
                theForm.Error(string.Empty, shp2.SerializeToString());
                return(false);
            }

            if (Math.Abs(shp.Extents.xMax - shp2.Extents.xMax) > 0.0001 || Math.Abs(shp.Extents.yMax - shp2.Extents.yMax) > 0.0001 ||
                Math.Abs(shp.Extents.zMax - shp2.Extents.zMax) > 0.0001 || Math.Abs(shp.Extents.mMax - shp2.Extents.mMax) > 0.0001)
            {
                theForm.Error(string.Empty, "The max values of X, Y, Z or M return different values");
            }

            for (var i = 0; i < shp.numPoints; i++)
            {
                if (Math.Abs(shp.Point[i].M - shp2.Point[i].M) > 0.0001)
                {
                    theForm.Error(string.Empty, "M values are different");
                }
            }

            if (Math.Abs(shp.Extents.xMin - shp2.Extents.xMin) > 0.0001 || Math.Abs(shp.Extents.yMin - shp2.Extents.yMin) > 0.0001 ||
                Math.Abs(shp.Extents.zMin - shp2.Extents.zMin) > 0.0001 || Math.Abs(shp.Extents.mMin - shp2.Extents.mMin) > 0.0001)
            {
                theForm.Error(string.Empty, "The min values of X, Y, Z or M return different values");
            }

            if (!shp.Equals(shp2))
            {
                theForm.Error(string.Empty, "Equals returns false");
                return(false);
            }

            return(true);
        }