예제 #1
0
        /// <summary>
        /// Check the given shapefile location
        /// </summary>
        /// <param name="shapefilename">
        /// The shapefilename.
        /// </param>
        /// <param name="theForm">
        /// The the form.
        /// </param>
        /// <returns>
        /// True when no errors else false
        /// </returns>
        internal static bool CheckShapefileLocation(string shapefilename, ICallback theForm)
        {
            if (shapefilename == string.Empty)
            {
                theForm.Error(string.Empty, "Input parameters are wrong");
                return(false);
            }

            var folder = Path.GetDirectoryName(shapefilename);

            if (folder == null)
            {
                theForm.Error(string.Empty, "Input parameters are wrong");
                return(false);
            }

            if (!Directory.Exists(folder))
            {
                theForm.Error(string.Empty, "Output folder doesn't exists: " + folder);
                return(false);
            }

            if (!File.Exists(shapefilename))
            {
                theForm.Error(string.Empty, "Input shapefile doesn't exists");
                return(false);
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Check if the resulting shapefile is correct
        /// </summary>
        /// <param name="inputSf">
        /// The input sf.
        /// </param>
        /// <param name="resultingSf">
        /// The resulting sf.
        /// </param>
        /// <param name="gdalLastErrorMsg">
        /// The gdal last error msg.
        /// </param>
        /// <param name="theForm">
        /// The the form.
        /// </param>
        /// <returns>
        /// True when no errors else false
        /// </returns>
        internal static bool CheckShapefile(
            IShapefile inputSf,
            IShapefile resultingSf,
            string gdalLastErrorMsg,
            ICallback theForm)
        {
            if (resultingSf == null)
            {
                var msg = "The resulting shapefile was not created: " + inputSf.ErrorMsg[inputSf.LastErrorCode];
                if (gdalLastErrorMsg != string.Empty)
                {
                    msg += Environment.NewLine + "GdalLastErrorMsg: " + gdalLastErrorMsg;
                }

                theForm.Error(string.Empty, msg);
                return(false);
            }

            if (resultingSf.NumShapes < -1)
            {
                theForm.Error(string.Empty, "Resulting shapefile has no shapes");
                return(false);
            }

            if (resultingSf.HasInvalidShapes())
            {
                theForm.Error(string.Empty, "Resulting shapefile has invalid shapes");
                return(false);
            }

            if (resultingSf.NumFields < -1)
            {
                theForm.Error(string.Empty, "Resulting shapefile has no fields");
                return(false);
            }

            if (resultingSf.NumShapes != resultingSf.Table.NumRows)
            {
                var msg = string.Format(
                    "The resulting shapefile has {0} shapes and {1} rows. This should be equal!",
                    resultingSf.NumShapes,
                    resultingSf.Table.NumRows);
                theForm.Error(string.Empty, msg);
                return(false);
            }

            return(true);
        }
예제 #3
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);
        }
예제 #4
0
 public Callback <TResult> OnError(ICallback other) => OnError(err => other.Error(err));