public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler)
        {
            var vector = GetVector(Matrix);

            if (vector != null)
            {
                cancelProgressHandler.Progress("Package_Tool", 10, "Calculating...");
                var dt   = _FeatureSet.DataTable;
                var type = dt.Columns[_SelectedVarIndex].DataType;
                if (vector.Length == dt.Rows.Count)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        dt.Rows[i][ValueField] = Convert.ChangeType((vector[i]), type);
                    }
                }
                cancelProgressHandler.Progress("Package_Tool", 80, "Saving...");
                _FeatureSet.Save();
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// Once the parameters have been configured, the Execute command can be called, it returns true if successful.
        /// </summary>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns>True if executed successfully.</returns>
        public override bool Execute(ICancelProgressHandler cancelProgressHandler)
        {
            // Get the needed input and output parameters
            IFeatureSet inputFeatures  = _inputParam[0].Value as IFeatureSet;
            DoubleParam dp             = _inputParam[1] as DoubleParam;
            double      bufferDistance = 1;

            if (dp != null)
            {
                bufferDistance = dp.Value;
            }

            IFeatureSet outputFeatures = _outputParam[0].Value as IFeatureSet;

            if (Buffer.AddBuffer(inputFeatures, bufferDistance, outputFeatures, cancelProgressHandler))
            {
                if (outputFeatures == null)
                {
                    return(false);
                }
                outputFeatures.Save();
                return(true);
            }

            _outputParam = null;
            return(false);
        }
예제 #3
0
        /// <summary>
        /// Once the Parameter have been configured the Execute command can be called, it returns true if succesful
        /// </summary>
        public override bool Execute(ICancelProgressHandler cancelProgressHandler)
        {
            IFeatureSet self  = _inputParam[0].Value as IFeatureSet;
            IFeatureSet other = _inputParam[1].Value as IFeatureSet;

            if (self != null && other != null)
            {
                self.FillAttributes();
                other.FillAttributes();
            }

            IFeatureSet result = Overlay.EraseFeatures(self, other, cancelProgressHandler);

            if (cancelProgressHandler.Cancel)
            {
                _outputParam = null;
                return(false);
            }
            else
            {
                result.Filename = ((IFeatureSet)_outputParam[0].Value).Filename;
                result.Save();
                _outputParam[0].Value = result;
                return(true);
            }
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <param name="cancelProgressHandler"></param>
        /// <returns></returns>
        public bool Execute(IFeatureSet input, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input == null || output == null)
            {
                return(false);
            }

            // We add all the fields
            foreach (DataColumn inputColumn in input.DataTable.Columns)
            {
                output.DataTable.Columns.Add(new DataColumn(inputColumn.ColumnName, inputColumn.DataType));
            }

            // We add the area field
            bool   addField   = true;
            string fieldCount = string.Empty;
            int    i          = 0;

            while (addField)
            {
                if (output.DataTable.Columns.Contains(TextStrings.Area + fieldCount) == false)
                {
                    output.DataTable.Columns.Add(new DataColumn(TextStrings.Area + fieldCount, typeof(double)));
                    addField = false;
                }
                else
                {
                    fieldCount = i.ToString();
                    i++;
                }
            }

            // we add all the old features to output
            for (int j = 0; j < input.Features.Count; j++)
            {
                Feature newFeature = new Feature(input.Features[j].BasicGeometry, output);
                foreach (DataColumn colSource in input.DataTable.Columns)
                {
                    newFeature.DataRow[colSource.ColumnName] = input.Features[j].DataRow[colSource.ColumnName];
                }

                newFeature.DataRow[TextStrings.Area + fieldCount] =
                    MultiPolygon.FromBasicGeometry(output.Features[j].BasicGeometry).Area;

                // Status updates is done here
                cancelProgressHandler.Progress(
                    string.Empty,
                    Convert.ToInt32((Convert.ToDouble(j) / Convert.ToDouble(input.Features.Count)) * 100),
                    input.Features[j].DataRow[0].ToString());
                if (cancelProgressHandler.Cancel)
                {
                    return(false);
                }
            }

            output.AttributesPopulated = true;
            output.Save();
            return(true);
        }
예제 #5
0
        /// <summary>
        /// Buffer test
        /// </summary>
        /// <param name="input"></param>
        /// <param name="bufferDistance"></param>
        /// <param name="output"></param>
        /// <param name="cancelProgressHandler"></param>
        /// <returns></returns>
        public static bool GetBuffer(
            IFeatureSet input, double bufferDistance, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            int previous = 0;
            int maxNo    = input.Features.Count;

            for (int i = 0; i < maxNo; i++)
            {
                input.Features[i].Buffer(bufferDistance, output);

                // Here we update the progress
                int current = Convert.ToInt32(i * 100 / maxNo);
                if (current > previous)
                {
                    cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted);
                    previous = current;
                }

                if (cancelProgressHandler.Cancel)
                {
                    return(false);
                }
            }

            output.Save();
            return(true);
        }
예제 #6
0
        /// <summary>
        /// Executes the random geometry tool, returning true when it has completed.
        /// </summary>
        /// <param name="cancelProgressHandler"></param>
        /// <returns></returns>
        public override bool Execute(ICancelProgressHandler cancelProgressHandler)
        {
            //Get the needed input and output parameters
            IFeatureSet inputFeatures  = _inputParam[0].Value as IFeatureSet;
            IFeatureSet outputFeatures = _outputParam[0].Value as IFeatureSet;
            IntParam    intInput       = _inputParam[1] as IntParam;

            int numPoints = 1;

            if (intInput != null)
            {
                numPoints = intInput.Value;
            }

            RandomGeometry.RandomPoints(inputFeatures, numPoints, outputFeatures, cancelProgressHandler);

            if (cancelProgressHandler.Cancel)
            {
                //Set output param to null so that ToolManager does not attempt to open file.
                _outputParam = null;
                return(false);
            }
            else
            {
                outputFeatures.Save();
                return(true);
            }
        }
예제 #7
0
 public void shpAreaReCalculate()
 {
     fs.DataTable.Columns.Add(new DataColumn("ShpArea", typeof(double)));
     foreach (IFeature feature in fs.Features)
     {
         feature.DataRow.BeginEdit();
         feature.DataRow["ShpArea"] = feature.Area();
         feature.DataRow.EndEdit();
     }
     fs.Save();
     fs.Dispose();
 }
예제 #8
0
        /// <summary>
        /// Once the Parameter have been configured the Execute command can be called, it returns true if succesful
        /// </summary>
        public override bool Execute(ICancelProgressHandler cancelProgressHandler)
        {
            IFeatureSet input = _inputParam[0].Value as IFeatureSet;

            if (input != null)
            {
                input.FillAttributes();
            }

            IFeatureSet output = _outputParam[0].Value as IFeatureSet;

            DotSpatial.Analysis.Voronoi.VoronoiPolygons(input, output, true);
            output.Save();
            return(true);
        }
예제 #9
0
        static void SaveTest()
        {
            string[] files = Directory.GetFiles("../测试Data",
                                                "*.shp");

            foreach (var shpPath in files)
            {
                Console.WriteLine(Path.GetFileName(shpPath));

                IFeatureSet fs = FeatureSet.Open(shpPath);
                Console.WriteLine(new string('*', 100));

                var newFile = Path.Combine(Path.GetDirectoryName(shpPath), "../saveTest/" + Path.GetFileName(shpPath));

                fs.Save(newFile);
            }
        }
예제 #10
0
        /// <summary>
        /// Executes the DP line simplefy tool programaticaly
        /// Ping Yang Added it for external Testing
        /// </summary>
        /// <param name="input">The input polygon feature set</param>
        /// <param name="tolerance">The tolerance to use when simplefiying</param>
        /// <param name="output">The output polygon feature set</param>
        /// <returns></returns>
        public bool Execute(IFeatureSet input, double tolerance, IFeatureSet output)
        {
            // Validates the input and output data
            if (input == null || output == null)
            {
                return(false);
            }

            // We copy all the fields
            foreach (DataColumn inputColumn in input.DataTable.Columns)
            {
                output.DataTable.Columns.Add(new DataColumn(inputColumn.ColumnName, inputColumn.DataType));
            }

            foreach (IFeature t in input.Features)
            {
                Geometry geom = t.BasicGeometry as Geometry;
                if (geom != null)
                {
                    for (int part = 0; part < geom.NumGeometries; part++)
                    {
                        Geometry geomPart = (Geometry)geom.GetGeometryN(part);

                        // do the simplification
                        IList <Coordinate> oldCoords = geomPart.Coordinates;
                        IList <Coordinate> newCoords = DouglasPeuckerLineSimplifier.Simplify(
                            oldCoords, tolerance);

                        // convert the coordinates back to a geometry
                        Geometry newGeom    = new LineString(newCoords);
                        Feature  newFeature = new Feature(newGeom, output);
                        foreach (DataColumn colSource in input.DataTable.Columns)
                        {
                            newFeature.DataRow[colSource.ColumnName] = t.DataRow[colSource.ColumnName];
                        }
                    }
                }
            }

            output.Save();
            return(true);
        }
예제 #11
0
        /// <summary>
        /// Get Buffer test method
        /// </summary>
        /// <param name="input"></param>
        /// <param name="bufferDistance"></param>
        /// <param name="output"></param>
        /// <returns></returns>
        public bool GetBuffer(IFeatureSet input, double bufferDistance, IFeatureSet output)
        {
            int previous = 0;
            int maxNo    = input.Features.Count;

            for (int i = 0; i < maxNo; i++)
            {
                input.Features[i].Buffer(bufferDistance, output);

                // Here we update the progress
                int current = Convert.ToInt32(i * 100 / maxNo);
                if (current > previous)
                {
                    previous = current;
                }
            }

            output.Save();
            return(true);
        }
예제 #12
0
        public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler)
        {
            var dt = _FeatureSet.DataTable;
            var dv = new DataView(dt);

            dv.Sort = SortingField + " asc";
            //  dt = dv.ToTable();

            string[] fields = new string[] { "Cell_ID", "Row", "Column" };
            double   prg    = 0;

            foreach (var str in fields)
            {
                if (dt.Columns.Contains(str))
                {
                    dt.Columns.Remove(str);
                }
                DataColumn dc = new DataColumn(str, Type.GetType("System.Int64"));
                dt.Columns.Add(dc);
            }

            int index = 0;

            for (int i = 0; i < RowCount; i++)
            {
                for (int j = 0; j < ColumnCount; j++)
                {
                    var dr = dt.Rows[index];
                    dr["Cell_ID"] = index + 1;
                    dr["Row"]     = i + 1;
                    dr["Column"]  = j + 1;
                    index++;
                }
                prg = (i + 1) * 100.0 / RowCount;
                cancelProgressHandler.Progress("Package_Tool", (int)prg, "Processing Row: " + (i + 1));
            }
            _FeatureSet.Save();
            return(true);
        }
예제 #13
0
        /// <summary>
        /// Create polygons from raster.
        /// </summary>
        /// <param name="input">The Polygon Raster(Grid file).</param>
        /// <param name="connectionGrid">Connection Grid.</param>
        /// <param name="output">The Polygon shapefile path.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        public bool Execute(IRaster input, IRaster connectionGrid, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            if (input == null || output == null)
            {
                return false;
            }

            output.DataTable.Columns.Add("Value", typeof(double));

            var featureHash = new Dictionary<double, LineSegmentList>();
            var previous = 0.0;

            var height = input.CellHeight;
            var width = input.CellWidth;

            var xMin = input.Xllcenter - width / 2.0;
            var yMin = input.Yllcenter - height / 2.0;
            var xMax = xMin + width * input.NumColumns;
            var yMax = yMin + height * input.NumRows;

            var numRows = input.NumRows;
            var numColumns = input.NumColumns;

            Func<int, int, double, bool> same = (y, x, value) => y >= 0 && y < numRows &&
                                                                 x >= 0 && x < numColumns &&
                                                                 input.Value[y, x] == value;
            Func<int, int, double> get = (y, x) => y >= 0 && y < numRows && x >= 0 && x < numColumns
                                                       ? input.Value[y, x]
                                                       : input.NoDataValue;
            Func<int, int, int, int, bool> eqValues = (y1, x1, y2, x2) => get(y1, x1) == get(y2, x2);

            var enableCon = connectionGrid != null;
            Func<int, int, int> connection = (y, x) => enableCon ? (int) connectionGrid.Value[y, x] : 0;
            
            for (int y = 0; y < numRows; y++)
            {
                int current = Convert.ToInt32((y * 100.0) / input.NumRows);
                if (current > previous)
                {
                    cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted);
                    previous = current;
                }

                Debug.WriteLine("Row : " + y + " done.");
                for (int x = 0; x < numColumns; x++)
                {
                    var value = input.Value[y, x];
                    if (value == input.NoDataValue)
                    {
                        continue;
                    }

                    LineSegmentList lineList;
                    if (!featureHash.TryGetValue(value, out lineList))
                    {
                        lineList = new LineSegmentList();
                        featureHash.Add(value, lineList);
                    }

                    var curCon = connection(y, x);

                    /*  
                     6 7 8
                     5 0 1
                     4 3 2  
                 current cell (x,y)=0                             
                     */

                    var con_7 = same(y + 1, x, value);
                    var con_5 = same(y, x - 1, value);
                    var con_3 = same(y - 1, x, value);
                    var con_1 = same(y, x + 1, value);

                    var con_8l = enableCon &&
                                same(y + 1, x + 1, value) && !con_7 &&
                                (curCon == 8 || connection(y + 1, x + 1) == 4);   
                    var con_8r = enableCon &&
                                same(y + 1, x + 1, value) && !con_1 &&
                                (curCon == 8 || connection(y + 1, x + 1) == 4);

                    var con_6l = enableCon &&
                                same(y + 1, x - 1, value) && !con_5 &&
                                (curCon == 6 || connection(y + 1, x - 1) == 2);
                    var con_6r = enableCon &&
                                same(y + 1, x - 1, value) && !con_7 &&
                                (curCon == 6 || connection(y + 1, x - 1) == 2);

                    var con_4l = enableCon &&
                                same(y - 1, x - 1, value) && !con_5 &&
                                (curCon == 4 || connection(y - 1, x - 1) == 8);
                    var con_4r = enableCon &&
                                same(y - 1, x - 1, value) && !con_3 &&
                                (curCon == 4 || connection(y - 1, x - 1) == 8);

                    var con_2l = enableCon &&
                                same(y - 1, x + 1, value) && !con_3 &&
                                (curCon == 2 || connection(y - 1, x + 1) == 6);
                    var con_2r = enableCon &&
                                same(y - 1, x + 1, value) && !con_1 &&
                                (curCon == 2 || connection(y - 1, x + 1) == 6);

                    /* Cell points:
                     tl tc tr
                     cl    cr 
                     bl bc br   
                     */
                    var tl = new Coordinate(xMin + x*width, yMax - (y + 1)*height);
                    var tc = new Coordinate(xMin + (x + 0.5)*width, yMax - (y + 1)*height);
                    var tr = new Coordinate(xMin + (x + 1)*width, yMax - (y + 1)*height);
                    var cl = new Coordinate(xMin + x*width, yMax - (y + 0.5)*height);
                    var cr = new Coordinate(xMin + (x + 1)*width, yMax - (y + 0.5)*height);
                    var bl = new Coordinate(xMin + x * width, yMax - y * height);
                    var bc = new Coordinate(xMin + (x + 0.5)*width, yMax - y*height);
                    var br = new Coordinate(xMin + (x + 1)*width, yMax - y*height);

                    /*
                     Cell edges:
                    e_tl   e_tr
                     ----|----
               e_lt  |       | e_rt
                     -       -
               e_lb  |       | e_rb 
                     ----|---- 
                    e_bl   e_br
                     */

                    bool e_tr = false,
                         e_tl = false,
                         e_lt = false,
                         e_lb = false,
                         e_rt = false,
                         e_rb = false,
                         e_br = false,
                         e_bl = false;

                    if (!con_7)
                    {
                        #region Check Cell 7

                        // top: right half
                        if (!con_8l)
                        {
                            var a1 = con_6r && con_1;
                            var a2 = !con_8r && !con_6l && con_4l && !con_2r;
                            e_tr = a1 || a2;
                        }

                        // top: left half
                        if (!con_6r)
                        {
                            var a1 = con_8l && con_5;
                            var a2 = !con_8r && !con_6l && !con_4l && con_2r;
                            e_tl = a1 || a2;
                        }

                        // top: full
                        if (!con_8l && !con_6r && !con_4l && !con_2r)
                        {
                            e_tr = e_tl = true;
                        }
                       
                        #endregion
                    }

                    if (!con_3)
                    {
                        #region Check Cell 3

                        // bottom: left half
                        if (!con_4r)
                        {
                            var a1 = con_2l && con_5;
                            var a2 = !con_2r && !con_4l && !con_6l && con_8r;
                            e_bl = a1 || a2;
                        }

                        // bottom: right half
                        if (!con_2l)
                        {
                            var a1 = con_4r && con_1;
                            var a2 = !con_2r && !con_4l && !con_8r && con_6l;
                            e_br = a1 || a2;
                        }

                        // bottom: full
                        if (!con_4r && !con_2l && !con_8r && !con_6l)
                        {
                            e_bl = e_br = true;
                        }

                        #endregion
                    }

                    if (!con_1)
                    {
                        #region Check Cell 1

                        // right: bottom half
                        if (!con_2r)
                        {
                            var a1 = con_8r && con_3;
                            var a2 = !con_2l && !con_8l && !con_4r && con_6r;
                            e_rb = a1 || a2;
                        }

                        // right: top half
                        if (!con_8r)
                        {
                            var a1 = con_2r && con_7;
                            var a2 = !con_2l && !con_8l && !con_6r && con_4r;
                            e_rt = a1 || a2;
                        }

                        // right: full
                        if (!con_2r && !con_8r && !con_4r && !con_6r)
                        {
                            e_rb = e_rt = true;
                        }
                        
                        #endregion
                    }

                    if (!con_5)
                    {
                        #region Check Cell 5

                        // left: bottom half
                        if (!con_4l)
                        {
                            var a1 = con_3 && con_6l;
                            var a2 = !con_6r && !con_4r && con_8l && !con_2l;
                            e_lb = a1 || a2;
                        }

                        // left: top half
                        if (!con_6l)
                        {
                            var a1 = con_4l && con_7;
                            var a2 = !con_6r && !con_4r && !con_8l && con_2l;
                            e_lt = a1 || a2;
                        }

                        // left: full
                        if (!con_4l && !con_6l && !con_8l && !con_2l)
                        {
                            e_lb = e_lt = true;
                        }

                        #endregion
                    }

                    // Smooth boundaries regarding to outer cells
                    // Right top corner
                    if (e_tr && e_rt)
                    {
                        if (eqValues(y + 1, x, y, x + 1))
                        {
                            var a1 = connection(y + 1, x);
                            var a2 = connection(y, x + 1);
                            if ((a1 == 6 || a1 == 2 || a2 == 6 || a2 == 2) && !(a1 == 6 && a2 == 2))
                            {
                                lineList.AddSegment(tc, cr);
                                e_tr = e_rt = false;
                            }
                        }
                    }

                    // Left top corner
                    if (e_tl && e_lt)
                    {
                        if (eqValues(y, x - 1, y + 1, x))
                        {
                            var a1 = connection(y, x - 1);
                            var a2 = connection(y + 1, x);
                            if ((a1 == 8 || a1 == 4 || a2 == 8 || a2 == 4) && !(a1 == 8 && a2 == 4))
                            {
                                lineList.AddSegment(tc, cl);
                                e_tl = e_lt = false;
                            }
                        }
                    }

                    // Left bottom corner
                    if (e_bl && e_lb)
                    {
                        if (eqValues(y - 1, x, y, x - 1))
                        {
                            var a1 = connection(y - 1, x);
                            var a2 = connection(y, x - 1);
                            if ((a1 == 6 || a1 == 2 || a2 == 6 || a2 == 2) && !(a1 == 6 && a2 == 2))
                            {
                                lineList.AddSegment(cl, bc);
                                e_bl = e_lb = false;
                            }
                        }
                    }

                    // Right bottom corner
                    if (e_br && e_rb)
                    {
                        if (eqValues(y, x + 1, y - 1, x))
                        {
                            var a1 = connection(y, x + 1);
                            var a2 = connection(y - 1, x);
                            if ((a1 == 8 || a1 == 4 || a2 == 8 || a2 == 4) && !(a1 == 8 && a2 == 4))
                            {
                                lineList.AddSegment(bc, cr);
                                e_br = e_rb = false;
                            }
                        }
                    }

                    // Smooth boundaries regarding direction of current cell
                    switch (curCon)
                    {
                        case 2:
                        case 6:
                            if (e_tr && e_rt)
                            {
                                lineList.AddSegment(tc, cr);
                                e_tr = e_rt = false;
                            }
                            if (e_bl && e_lb)
                            {
                                lineList.AddSegment(bc, cl);
                                e_bl = e_lb = false;
                            }
                            break;
                        case 4:
                        case 8:
                            if (e_tl && e_lt)
                            {
                                lineList.AddSegment(cl, tc);
                                e_tl = e_lt = false;
                            }
                            if (e_br && e_rb)
                            {
                                lineList.AddSegment(cr, bc);
                                e_br = e_rb = false;
                            }
                            break;
                    }

                    // Add remaining edges
                    // Top
                    if (e_tl && e_tr)
                    {
                        lineList.AddSegment(tl, tr);
                    }
                    else if (e_tl)
                    {
                        lineList.AddSegment(tl, tc);
                    }
                    else if(e_tr)
                    {
                        lineList.AddSegment(tc, tr);
                    }

                    //Left
                    if (e_lt && e_lb)
                    {
                        lineList.AddSegment(tl, bl);
                    }
                    else if (e_lt)
                    {
                        lineList.AddSegment(tl, cl);
                    }
                    else if (e_lb)
                    {
                        lineList.AddSegment(cl, bl);
                    }

                    // Bottom
                    if (e_bl && e_br)
                    {
                        lineList.AddSegment(bl, br);
                    }
                    else if (e_bl)
                    {
                        lineList.AddSegment(bl, bc);
                    }
                    else if (e_br)
                    {
                        lineList.AddSegment(bc, br);
                    }

                    // Right
                    if (e_rt && e_rb)
                    {
                        lineList.AddSegment(tr, br);
                    }
                    else if (e_rt)
                    {
                        lineList.AddSegment(tr, cr);
                    }
                    else if (e_rb)
                    {
                        lineList.AddSegment(cr, br);
                    }

                    // Right top out diagonals
                    if (con_8l)
                    {
                        lineList.AddSegment(tc, new Coordinate(xMin + (x + 1)*width, yMax - (y + 1 + 0.5)*height));
                    }
                    if (con_8r)
                    {
                        lineList.AddSegment(cr, new Coordinate(xMin + (x + 1 + 0.5) * width, yMax - (y + 1) * height));
                    }

                    // Right in diagonals
                    if (con_4l || con_8l)
                    {
                        if (!con_6r && !con_6l && !con_7 && !con_5)
                        {
                            lineList.AddSegment(tc, cl);
                        }
                    }
                    if (con_4r || con_8r)
                    {
                        if (!con_2r && !con_2l && !con_1 && !con_3)
                        {
                            lineList.AddSegment(cr, bc);
                        }
                    }

                    // Left Top out diagonals
                    if (con_6r)
                    {
                        lineList.AddSegment(tc, new Coordinate(xMin + x*width, yMax - (y + 1 + 0.5)*height));
                    }
                    if (con_6l)
                    {
                        lineList.AddSegment(cl, new Coordinate(xMin + (x - 0.5) * width, yMax - (y + 1) * height));
                    }

                    // Left In diagonals
                    if (con_6r || con_2r)
                    {
                        if (!con_8r && !con_8l && !con_7 && !con_1)
                        {
                            lineList.AddSegment(tc, cr);
                        }
                    }
                    if (con_6l || con_2l)
                    {
                        if (!con_4r && !con_4l && !con_5 && !con_3)
                        {
                            lineList.AddSegment(cl, bc);
                        }
                    }
                    
                    if (cancelProgressHandler.Cancel)
                    {
                        return false;
                    }
                }
            }

            var sw = new Stopwatch();
            foreach (var pair in featureHash)
            {
                sw.Restart();

                var key = pair.Key;
                var lineSegList = pair.Value.List;

                var polyList = new List<Polygon>();
                var ind = 0;
                while (ind != lineSegList.Count)
                {
                    var polyShell = new List<Coordinate>();

                    var start = lineSegList[ind++];
                    polyShell.Add(start.P0);
                    polyShell.Add(start.P1);

                    while (!polyShell[0].Equals2D(polyShell[polyShell.Count - 1]))
                    {
                        var last = polyShell[polyShell.Count - 1];
                        LineSegment segment = null;
                        for (int i = ind; i < lineSegList.Count; i++)
                        {
                            var cur = lineSegList[i];
                            if (cur.P0.Equals2D(last) || cur.P1.Equals2D(last))
                            {
                                segment = cur;
                                if (ind != i)
                                {
                                    var swap = lineSegList[ind];
                                    lineSegList[ind] = cur;
                                    lineSegList[i] = swap;
                                }

                                ind++;
                                break;
                            }
                        }
                        Debug.Assert(segment != null);
                        polyShell.Add(segment.P0.Equals2D(last) ? segment.P1 : segment.P0);
                    }

                    polyList.Add(new Polygon(polyShell));
                }

                var geometry = polyList.Count == 1
                                   ? (IBasicGeometry)polyList[0]
                                   : new MultiPolygon(polyList.ToArray());
                var f = output.AddFeature(geometry);
                f.DataRow["Value"] = key;

                sw.Stop();
                Debug.WriteLine(sw.ElapsedMilliseconds);
            }

            output.AttributesPopulated = true;
            output.Save();
            return true;
        }
예제 #14
0
 /// <summary>
 /// computes voronoi polygons around each of the points,
 /// defining the regions that are closer to that point than any other points
 /// Ping deleted static for external testing 01/2010
 /// </summary>
 /// <param name="input">The input polygon feature set</param>
 /// <param name="output">The output polygon feature set</param>
 /// <param name="cancelProgressHandler">The progress handler</param>
 /// <returns></returns>
 public bool Execute(IFeatureSet input, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
 {
     Analysis.Voronoi.VoronoiPolygons(input, output, true);
     output.Save();
     return(true);
 }
        /// <summary>
        /// Removes portions of the input polygon shapefile that are within the erase polygons.
        /// </summary>
        /// <param name="inputSF">The input polygon shapefile.</param>
        /// <param name="eraseSF">The erase polygon shapefile.</param>
        /// <param name="resultSF">The resulting shapefile, with portions removed.</param>
        /// <returns>False if an error was encountered, true otherwise.</returns>
        public static void ErasePolySFWithPolySF(ref IFeatureSet inputSF, ref IFeatureSet eraseSF, ref IFeatureSet resultSF)
        {
            //Validates the input and resultSF data
            if (inputSF == null || eraseSF == null || resultSF == null)
            {
                return;
            }

            resultSF.CopyTableSchema(inputSF);//Fill the 1st Featureset fields
            IFeatureSet tempSet = inputSF.CombinedFields(eraseSF);
            //go through every feature in 1st featureSet
            for (int i = 0; i < inputSF.Features.Count; i++)
            {

                //go through every feature in 2nd featureSet
                for (int j = 0; j < eraseSF.Features.Count; j++)
                {
                    inputSF.Features[i].Difference(eraseSF.Features[j], tempSet, FieldJoinType.All);

                }
            }
            //Add to the resultSF Feature Set
            for (int a = 0; a < tempSet.Features.Count; a++)
            {
                resultSF.Features.Add(tempSet.Features[a]);

            }

            resultSF.Save();
            return;
        }
예제 #16
0
        /// <summary>
        /// Executes the DP line simplefy tool programmatically
        /// </summary>
        /// <param name="input">The input polygon feature set</param>
        /// <param name="tolerance">The tolerance to use when simplefiying</param>
        /// <param name="output">The output polygon feature set</param>
        /// <param name="cancelProgressHandler">The progress handler</param>
        /// <returns>True, if executed successfully.</returns>
        public bool Execute(IFeatureSet input, double tolerance, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input == null || output == null)
            {
                return(false);
            }

            // We copy all the fields
            foreach (DataColumn inputColumn in input.DataTable.Columns)
            {
                output.DataTable.Columns.Add(new DataColumn(inputColumn.ColumnName, inputColumn.DataType));
            }

            int numTotalOldPoints = 0;
            int numTotalNewPoints = 0;

            for (int j = 0; j < input.Features.Count; j++)
            {
                int numOldPoints = 0;
                int numNewPoints = 0;

                Geometry geom = input.Features[j].Geometry as Geometry;
                if (geom != null)
                {
                    numOldPoints = geom.NumPoints;
                }

                numTotalOldPoints += numOldPoints;
                if (geom != null)
                {
                    for (int part = 0; part < geom.NumGeometries; part++)
                    {
                        Geometry geomPart = (Geometry)geom.GetGeometryN(part);

                        // do the simplification
                        Coordinate[] oldCoords = geomPart.Coordinates;
                        Coordinate[] newCoords = DouglasPeuckerLineSimplifier.Simplify(oldCoords, tolerance);

                        // convert the coordinates back to a geometry
                        Geometry newGeom = new LineString(newCoords);
                        numNewPoints      += newGeom.NumPoints;
                        numTotalNewPoints += numNewPoints;
                        Feature newFeature = new Feature(newGeom, output);
                        foreach (DataColumn colSource in input.DataTable.Columns)
                        {
                            newFeature.DataRow[colSource.ColumnName] = input.Features[j].DataRow[colSource.ColumnName];
                        }
                    }
                }

                // Status updates is done here, shows number of old / new points
                cancelProgressHandler.Progress(Convert.ToInt32((Convert.ToDouble(j) / Convert.ToDouble(input.Features.Count)) * 100), numOldPoints + "-->" + numNewPoints);
                if (cancelProgressHandler.Cancel)
                {
                    return(false);
                }
            }

            cancelProgressHandler.Progress(100, TextStrings.Originalnumberofpoints + numTotalOldPoints + " " + TextStrings.Newnumberofpoints + numTotalNewPoints);

            output.Save();
            return(true);
        }
예제 #17
0
파일: Conflict.cs 프로젝트: giszzt/GeoSOS
        ControlZone _zoneB = new ControlZone(); //管控区B

        public bool ConflictAnalysis()
        {
            IFeatureSet resultSet = null;

            try
            {
                #region 相交分析

                OSGeo.OGR.Layer layerA = null;
                if (_zoneA.FeatureSet != null)
                {
                    layerA = GIS.GDAL.VectorConverter.DS2OrgLayer(_zoneA.FeatureSet);
                }
                else
                {
                    layerA = GIS.GDAL.VectorConverter.GetOgrLayer(_zoneA.Address);
                }

                OSGeo.OGR.Layer layerB = null;
                if (_zoneB.FeatureSet != null)
                {
                    layerB = GIS.GDAL.VectorConverter.DS2OrgLayer(_zoneB.FeatureSet);
                }
                else
                {
                    layerB = GIS.GDAL.VectorConverter.GetOgrLayer(_zoneB.Address);
                }

                OSGeo.OGR.Layer resultLayer = null;
                using (OSGeo.OGR.Driver driver = Ogr.GetDriverByName("ESRI Shapefile"))
                {
                    if (driver == null)
                    {
                        System.Environment.Exit(-1);
                    }
                    string[] resultPath = _address.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
                    string   resultName = resultPath[resultPath.Length - 1];
                    using (var dsResult = driver.CreateDataSource(_address, new string[] { }))
                    {
                        if (dsResult == null)
                        {
                            throw new Exception("Can't get to the datasoure.");
                        }

                        for (int i = 0; i < dsResult.GetLayerCount(); i++)
                        {
                            resultLayer = dsResult.GetLayerByIndex(i);
                            if (resultLayer != null && resultLayer.GetLayerDefn().GetName() == resultName)
                            {
                                dsResult.DeleteLayer(i);
                                break;
                            }
                        }
                        SpatialReference reference  = layerA.GetSpatialRef();
                        FeatureDefn      definition = layerA.GetLayerDefn();
                        wkbGeometryType  type       = definition.GetGeomType();
                        resultLayer = dsResult.CreateLayer("ResultLayer", layerA.GetSpatialRef(), layerA.GetLayerDefn().GetGeomType(), new string[] { });

                        bool intersectSuccess = GIS.GDAL.Overlay.Overlay.OverlayOperate(layerA, layerB, ref resultLayer, OverlayType.Intersects, null);

                        if (!intersectSuccess)
                        {
                            return(false);
                        }
                    }
                }

                #endregion

                resultSet = DotSpatial.Data.DataManager.DefaultDataManager.OpenFile(_address) as IFeatureSet;

                #region 添加转换要素的字段

                DataTable resultTable = resultSet.DataTable;

                DataColumn conflictColumn = new DataColumn();
                conflictColumn.DataType   = typeof(string);
                conflictColumn.ColumnName = "冲突类型";
                conflictColumn.MaxLength  = 100;
                resultTable.Columns.Add(conflictColumn);

                DataColumn conflictColumn2 = new DataColumn();
                conflictColumn2.DataType   = typeof(string);
                conflictColumn2.ColumnName = "处理意见";
                conflictColumn2.MaxLength  = 100;
                resultTable.Columns.Add(conflictColumn2);

                DataColumn conflictColumn3 = new DataColumn();
                conflictColumn3.DataType   = typeof(string);
                conflictColumn3.ColumnName = "备注";
                conflictColumn3.MaxLength  = 50;
                resultTable.Columns.Add(conflictColumn3);

                DataColumn conflictColumn4 = new DataColumn();
                conflictColumn4.DataType   = typeof(string);
                conflictColumn4.ColumnName = "用地类型";
                conflictColumn4.MaxLength  = 50;
                resultTable.Columns.Add(conflictColumn4);

                #endregion

                int index = resultTable.Columns.IndexOf("冲突类型");
                for (int i = 0; i < resultTable.Rows.Count; i++)
                {
                    DataRow dataRow = resultTable.Rows[i];
                    dataRow[index] = _conflictType;
                }

                resultSet.Save();
                if (resultSet.Projection == null)
                {
                }
                GIS.FrameWork.Application.App.Map.Layers.Add(resultSet);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <param name="cancelProgressHandler"></param>
        /// <returns></returns>
        public bool Execute(IFeatureSet input, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input == null || output == null)
            {
                return false;
            }

            // We add all the fields
            foreach (DataColumn inputColumn in input.DataTable.Columns)
            {
                output.DataTable.Columns.Add(new DataColumn(inputColumn.ColumnName, inputColumn.DataType));
            }

            // We add the area field
            bool addField = true;
            string fieldCount = string.Empty;
            int i = 0;
            while (addField)
            {
                if (output.DataTable.Columns.Contains(TextStrings.Area + fieldCount) == false)
                {
                    output.DataTable.Columns.Add(new DataColumn(TextStrings.Area + fieldCount, typeof(double)));
                    addField = false;
                }
                else
                {
                    fieldCount = i.ToString();
                    i++;
                }
            }

            // we add all the old features to output
            for (int j = 0; j < input.Features.Count; j++)
            {
                Feature newFeature = new Feature(input.Features[j].BasicGeometry, output);
                foreach (DataColumn colSource in input.DataTable.Columns)
                {
                    newFeature.DataRow[colSource.ColumnName] = input.Features[j].DataRow[colSource.ColumnName];
                }

                newFeature.DataRow[TextStrings.Area + fieldCount] =
                    MultiPolygon.FromBasicGeometry(output.Features[j].BasicGeometry).Area;

                // Status updates is done here
                cancelProgressHandler.Progress(
                    string.Empty,
                    Convert.ToInt32((Convert.ToDouble(j) / Convert.ToDouble(input.Features.Count)) * 100),
                    input.Features[j].DataRow[0].ToString());
                if (cancelProgressHandler.Cancel)
                {
                    return false;
                }
            }

            output.Save();
            return true;
        }
예제 #19
0
 /// <summary>
 /// computes voronoi polygons around each of the points,
 /// defining the regions that are closer to that point than any other points
 /// Ping deleted static for external testing 01/2010
 /// </summary>
 /// <param name="input">The input polygon feature set</param>
 /// <param name="output">The output polygon feature set</param>
 /// <param name="cancelProgressHandler">The progress handler</param>
 /// <returns></returns>
 public bool Execute(IFeatureSet input,  IFeatureSet output, 
     ICancelProgressHandler cancelProgressHandler)
 {
     Analysis.Voronoi.VoronoiPolygons(input, output, true, cancelProgressHandler);
     output.Save();
     return true;
 }
예제 #20
0
        /// <summary>
        /// Create polygons from raster.
        /// </summary>
        /// <param name="input">The Polygon Raster(Grid file).</param>
        /// <param name="connectionGrid">Connection Grid.</param>
        /// <param name="output">The Polygon shapefile path.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        public bool Execute(IRaster input, IRaster connectionGrid, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            if (input == null || output == null)
            {
                return(false);
            }

            output.DataTable.Columns.Add("Value", typeof(double));

            var featureHash = new Dictionary <double, LineSegmentList>();
            var previous    = 0.0;

            var height = input.CellHeight;
            var width  = input.CellWidth;

            var xMin = input.Xllcenter - width / 2.0;
            var yMin = input.Yllcenter - height / 2.0;
            var xMax = xMin + width * input.NumColumns;
            var yMax = yMin + height * input.NumRows;

            var numRows    = input.NumRows;
            var numColumns = input.NumColumns;

            Func <int, int, double, bool> same = (y, x, value) => y >= 0 && y < numRows &&
                                                 x >= 0 && x < numColumns &&
                                                 input.Value[y, x] == value;
            Func <int, int, double> get = (y, x) => y >= 0 && y < numRows && x >= 0 && x < numColumns
                                                       ? input.Value[y, x]
                                                       : input.NoDataValue;
            Func <int, int, int, int, bool> eqValues = (y1, x1, y2, x2) => get(y1, x1) == get(y2, x2);

            var enableCon = connectionGrid != null;
            Func <int, int, int> connection = (y, x) => enableCon ? (int)connectionGrid.Value[y, x] : 0;

            for (int y = 0; y < numRows; y++)
            {
                int current = Convert.ToInt32((y * 100.0) / input.NumRows);
                if (current > previous)
                {
                    cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted);
                    previous = current;
                }

                Debug.WriteLine("Row : " + y + " done.");
                for (int x = 0; x < numColumns; x++)
                {
                    var value = input.Value[y, x];
                    if (value == input.NoDataValue)
                    {
                        continue;
                    }

                    LineSegmentList lineList;
                    if (!featureHash.TryGetValue(value, out lineList))
                    {
                        lineList = new LineSegmentList();
                        featureHash.Add(value, lineList);
                    }

                    var curCon = connection(y, x);

                    /*
                     * 6 7 8
                     * 5 0 1
                     * 4 3 2
                     * current cell (x,y)=0
                     */

                    var con_7 = same(y + 1, x, value);
                    var con_5 = same(y, x - 1, value);
                    var con_3 = same(y - 1, x, value);
                    var con_1 = same(y, x + 1, value);

                    var con_8l = enableCon &&
                                 same(y + 1, x + 1, value) && !con_7 &&
                                 (curCon == 8 || connection(y + 1, x + 1) == 4);
                    var con_8r = enableCon &&
                                 same(y + 1, x + 1, value) && !con_1 &&
                                 (curCon == 8 || connection(y + 1, x + 1) == 4);

                    var con_6l = enableCon &&
                                 same(y + 1, x - 1, value) && !con_5 &&
                                 (curCon == 6 || connection(y + 1, x - 1) == 2);
                    var con_6r = enableCon &&
                                 same(y + 1, x - 1, value) && !con_7 &&
                                 (curCon == 6 || connection(y + 1, x - 1) == 2);

                    var con_4l = enableCon &&
                                 same(y - 1, x - 1, value) && !con_5 &&
                                 (curCon == 4 || connection(y - 1, x - 1) == 8);
                    var con_4r = enableCon &&
                                 same(y - 1, x - 1, value) && !con_3 &&
                                 (curCon == 4 || connection(y - 1, x - 1) == 8);

                    var con_2l = enableCon &&
                                 same(y - 1, x + 1, value) && !con_3 &&
                                 (curCon == 2 || connection(y - 1, x + 1) == 6);
                    var con_2r = enableCon &&
                                 same(y - 1, x + 1, value) && !con_1 &&
                                 (curCon == 2 || connection(y - 1, x + 1) == 6);

                    /* Cell points:
                     * tl tc tr
                     * cl    cr
                     * bl bc br
                     */
                    var tl = new Coordinate(xMin + x * width, yMax - (y + 1) * height);
                    var tc = new Coordinate(xMin + (x + 0.5) * width, yMax - (y + 1) * height);
                    var tr = new Coordinate(xMin + (x + 1) * width, yMax - (y + 1) * height);
                    var cl = new Coordinate(xMin + x * width, yMax - (y + 0.5) * height);
                    var cr = new Coordinate(xMin + (x + 1) * width, yMax - (y + 0.5) * height);
                    var bl = new Coordinate(xMin + x * width, yMax - y * height);
                    var bc = new Coordinate(xMin + (x + 0.5) * width, yMax - y * height);
                    var br = new Coordinate(xMin + (x + 1) * width, yMax - y * height);

                    /*
                     * Cell edges:
                     * e_tl   e_tr
                     * ----|----
                     * e_lt  |       | e_rt
                     * -       -
                     * e_lb  |       | e_rb
                     * ----|----
                     * e_bl   e_br
                     */

                    bool e_tr = false,
                         e_tl = false,
                         e_lt = false,
                         e_lb = false,
                         e_rt = false,
                         e_rb = false,
                         e_br = false,
                         e_bl = false;

                    if (!con_7)
                    {
                        #region Check Cell 7

                        // top: right half
                        if (!con_8l)
                        {
                            var a1 = con_6r && con_1;
                            var a2 = !con_8r && !con_6l && con_4l && !con_2r;
                            e_tr = a1 || a2;
                        }

                        // top: left half
                        if (!con_6r)
                        {
                            var a1 = con_8l && con_5;
                            var a2 = !con_8r && !con_6l && !con_4l && con_2r;
                            e_tl = a1 || a2;
                        }

                        // top: full
                        if (!con_8l && !con_6r && !con_4l && !con_2r)
                        {
                            e_tr = e_tl = true;
                        }

                        #endregion
                    }

                    if (!con_3)
                    {
                        #region Check Cell 3

                        // bottom: left half
                        if (!con_4r)
                        {
                            var a1 = con_2l && con_5;
                            var a2 = !con_2r && !con_4l && !con_6l && con_8r;
                            e_bl = a1 || a2;
                        }

                        // bottom: right half
                        if (!con_2l)
                        {
                            var a1 = con_4r && con_1;
                            var a2 = !con_2r && !con_4l && !con_8r && con_6l;
                            e_br = a1 || a2;
                        }

                        // bottom: full
                        if (!con_4r && !con_2l && !con_8r && !con_6l)
                        {
                            e_bl = e_br = true;
                        }

                        #endregion
                    }

                    if (!con_1)
                    {
                        #region Check Cell 1

                        // right: bottom half
                        if (!con_2r)
                        {
                            var a1 = con_8r && con_3;
                            var a2 = !con_2l && !con_8l && !con_4r && con_6r;
                            e_rb = a1 || a2;
                        }

                        // right: top half
                        if (!con_8r)
                        {
                            var a1 = con_2r && con_7;
                            var a2 = !con_2l && !con_8l && !con_6r && con_4r;
                            e_rt = a1 || a2;
                        }

                        // right: full
                        if (!con_2r && !con_8r && !con_4r && !con_6r)
                        {
                            e_rb = e_rt = true;
                        }

                        #endregion
                    }

                    if (!con_5)
                    {
                        #region Check Cell 5

                        // left: bottom half
                        if (!con_4l)
                        {
                            var a1 = con_3 && con_6l;
                            var a2 = !con_6r && !con_4r && con_8l && !con_2l;
                            e_lb = a1 || a2;
                        }

                        // left: top half
                        if (!con_6l)
                        {
                            var a1 = con_4l && con_7;
                            var a2 = !con_6r && !con_4r && !con_8l && con_2l;
                            e_lt = a1 || a2;
                        }

                        // left: full
                        if (!con_4l && !con_6l && !con_8l && !con_2l)
                        {
                            e_lb = e_lt = true;
                        }

                        #endregion
                    }

                    // Smooth boundaries regarding to outer cells
                    // Right top corner
                    if (e_tr && e_rt)
                    {
                        if (eqValues(y + 1, x, y, x + 1))
                        {
                            var a1 = connection(y + 1, x);
                            var a2 = connection(y, x + 1);
                            if ((a1 == 6 || a1 == 2 || a2 == 6 || a2 == 2) && !(a1 == 6 && a2 == 2))
                            {
                                lineList.AddSegment(tc, cr);
                                e_tr = e_rt = false;
                            }
                        }
                    }

                    // Left top corner
                    if (e_tl && e_lt)
                    {
                        if (eqValues(y, x - 1, y + 1, x))
                        {
                            var a1 = connection(y, x - 1);
                            var a2 = connection(y + 1, x);
                            if ((a1 == 8 || a1 == 4 || a2 == 8 || a2 == 4) && !(a1 == 8 && a2 == 4))
                            {
                                lineList.AddSegment(tc, cl);
                                e_tl = e_lt = false;
                            }
                        }
                    }

                    // Left bottom corner
                    if (e_bl && e_lb)
                    {
                        if (eqValues(y - 1, x, y, x - 1))
                        {
                            var a1 = connection(y - 1, x);
                            var a2 = connection(y, x - 1);
                            if ((a1 == 6 || a1 == 2 || a2 == 6 || a2 == 2) && !(a1 == 6 && a2 == 2))
                            {
                                lineList.AddSegment(cl, bc);
                                e_bl = e_lb = false;
                            }
                        }
                    }

                    // Right bottom corner
                    if (e_br && e_rb)
                    {
                        if (eqValues(y, x + 1, y - 1, x))
                        {
                            var a1 = connection(y, x + 1);
                            var a2 = connection(y - 1, x);
                            if ((a1 == 8 || a1 == 4 || a2 == 8 || a2 == 4) && !(a1 == 8 && a2 == 4))
                            {
                                lineList.AddSegment(bc, cr);
                                e_br = e_rb = false;
                            }
                        }
                    }

                    // Smooth boundaries regarding direction of current cell
                    switch (curCon)
                    {
                    case 2:
                    case 6:
                        if (e_tr && e_rt)
                        {
                            lineList.AddSegment(tc, cr);
                            e_tr = e_rt = false;
                        }
                        if (e_bl && e_lb)
                        {
                            lineList.AddSegment(bc, cl);
                            e_bl = e_lb = false;
                        }
                        break;

                    case 4:
                    case 8:
                        if (e_tl && e_lt)
                        {
                            lineList.AddSegment(cl, tc);
                            e_tl = e_lt = false;
                        }
                        if (e_br && e_rb)
                        {
                            lineList.AddSegment(cr, bc);
                            e_br = e_rb = false;
                        }
                        break;
                    }

                    // Add remaining edges
                    // Top
                    if (e_tl && e_tr)
                    {
                        lineList.AddSegment(tl, tr);
                    }
                    else if (e_tl)
                    {
                        lineList.AddSegment(tl, tc);
                    }
                    else if (e_tr)
                    {
                        lineList.AddSegment(tc, tr);
                    }

                    //Left
                    if (e_lt && e_lb)
                    {
                        lineList.AddSegment(tl, bl);
                    }
                    else if (e_lt)
                    {
                        lineList.AddSegment(tl, cl);
                    }
                    else if (e_lb)
                    {
                        lineList.AddSegment(cl, bl);
                    }

                    // Bottom
                    if (e_bl && e_br)
                    {
                        lineList.AddSegment(bl, br);
                    }
                    else if (e_bl)
                    {
                        lineList.AddSegment(bl, bc);
                    }
                    else if (e_br)
                    {
                        lineList.AddSegment(bc, br);
                    }

                    // Right
                    if (e_rt && e_rb)
                    {
                        lineList.AddSegment(tr, br);
                    }
                    else if (e_rt)
                    {
                        lineList.AddSegment(tr, cr);
                    }
                    else if (e_rb)
                    {
                        lineList.AddSegment(cr, br);
                    }

                    // Right top out diagonals
                    if (con_8l)
                    {
                        lineList.AddSegment(tc, new Coordinate(xMin + (x + 1) * width, yMax - (y + 1 + 0.5) * height));
                    }
                    if (con_8r)
                    {
                        lineList.AddSegment(cr, new Coordinate(xMin + (x + 1 + 0.5) * width, yMax - (y + 1) * height));
                    }

                    // Right in diagonals
                    if (con_4l || con_8l)
                    {
                        if (!con_6r && !con_6l && !con_7 && !con_5)
                        {
                            lineList.AddSegment(tc, cl);
                        }
                    }
                    if (con_4r || con_8r)
                    {
                        if (!con_2r && !con_2l && !con_1 && !con_3)
                        {
                            lineList.AddSegment(cr, bc);
                        }
                    }

                    // Left Top out diagonals
                    if (con_6r)
                    {
                        lineList.AddSegment(tc, new Coordinate(xMin + x * width, yMax - (y + 1 + 0.5) * height));
                    }
                    if (con_6l)
                    {
                        lineList.AddSegment(cl, new Coordinate(xMin + (x - 0.5) * width, yMax - (y + 1) * height));
                    }

                    // Left In diagonals
                    if (con_6r || con_2r)
                    {
                        if (!con_8r && !con_8l && !con_7 && !con_1)
                        {
                            lineList.AddSegment(tc, cr);
                        }
                    }
                    if (con_6l || con_2l)
                    {
                        if (!con_4r && !con_4l && !con_5 && !con_3)
                        {
                            lineList.AddSegment(cl, bc);
                        }
                    }

                    if (cancelProgressHandler.Cancel)
                    {
                        return(false);
                    }
                }
            }

            foreach (var pair in featureHash)
            {
#if DEBUG
                var sw = new Stopwatch();
                sw.Start();
#endif
                var key         = pair.Key;
                var lineSegList = pair.Value.List;

                var polyList = new List <IPolygon>();
                var ind      = 0;
                while (ind != lineSegList.Count)
                {
                    var polyShell = new List <Coordinate>();

                    var start = lineSegList[ind++];
                    polyShell.Add(start.P0);
                    polyShell.Add(start.P1);

                    while (!polyShell[0].Equals2D(polyShell[polyShell.Count - 1]))
                    {
                        var         last    = polyShell[polyShell.Count - 1];
                        LineSegment segment = null;
                        for (int i = ind; i < lineSegList.Count; i++)
                        {
                            var cur = lineSegList[i];
                            if (cur.P0.Equals2D(last) || cur.P1.Equals2D(last))
                            {
                                segment = cur;
                                if (ind != i)
                                {
                                    var swap = lineSegList[ind];
                                    lineSegList[ind] = cur;
                                    lineSegList[i]   = swap;
                                }

                                ind++;
                                break;
                            }
                        }
                        Debug.Assert(segment != null);
                        polyShell.Add(segment.P0.Equals2D(last) ? segment.P1 : segment.P0);
                    }

                    polyList.Add(new Polygon(new LinearRing(polyShell.ToArray())));
                }

                IGeometry geometry = polyList.Count == 1 ? (IGeometry)polyList[0] : new MultiPolygon(polyList.ToArray());
                var       f        = output.AddFeature(geometry);
                f.DataRow["Value"] = key;

#if DEBUG
                sw.Stop();
                Debug.WriteLine(sw.ElapsedMilliseconds);
#endif
            }

            output.AttributesPopulated = true;
            output.Save();
            return(true);
        }
예제 #21
0
        public static bool GetBuffer(IFeatureSet input, double bufferDistance, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            int previous = 0;
            int maxNo = input.Features.Count;
            for (int i = 0; i < maxNo; i++)
            {
                input.Features[i].Buffer(bufferDistance, output);

                //Here we update the progress
                int current = Convert.ToInt32(i * 100 / maxNo);
                if (current > previous)
                {
                    cancelProgressHandler.Progress("", current, current + TextStrings.progresscompleted);
                    previous = current;
                }

                if (cancelProgressHandler.Cancel)
                    return false;
            }

            output.Save();
            return true;
        }
예제 #22
0
        /// <summary>
        /// Executes the DP line simplefy tool programaticaly
        /// Ping Yang Added it for external Testing
        /// </summary>
        /// <param name="input">The input polygon feature set</param>
        /// <param name="tolerance">The tolerance to use when simplefiying</param>
        /// <param name="output">The output polygon feature set</param>
        /// <returns></returns>
        public bool Execute(IFeatureSet input, double tolerance, IFeatureSet output)
        {
            // Validates the input and output data
            if (input == null || output == null)
            {
                return false;
            }

            // We copy all the fields
            foreach (DataColumn inputColumn in input.DataTable.Columns)
            {
                output.DataTable.Columns.Add(new DataColumn(inputColumn.ColumnName, inputColumn.DataType));
            }

            foreach (IFeature t in input.Features)
            {
                Geometry geom = t.BasicGeometry as Geometry;
                if (geom != null)
                {
                    for (int part = 0; part < geom.NumGeometries; part++)
                    {
                        Geometry geomPart = (Geometry)geom.GetGeometryN(part);

                        // do the simplification
                        IList<Coordinate> oldCoords = geomPart.Coordinates;
                        IList<Coordinate> newCoords = DouglasPeuckerLineSimplifier.Simplify(
                            oldCoords, tolerance);

                        // convert the coordinates back to a geometry
                        Geometry newGeom = new LineString(newCoords);
                        Feature newFeature = new Feature(newGeom, output);
                        foreach (DataColumn colSource in input.DataTable.Columns)
                        {
                            newFeature.DataRow[colSource.ColumnName] = t.DataRow[colSource.ColumnName];
                        }
                    }
                }
            }

            output.Save();
            return true;
        }
예제 #23
0
        //Ping Yang Added it for external testing 01/10
        public bool GetBuffer(IFeatureSet input, double bufferDistance, IFeatureSet output)
        {
            int previous = 0;
            int maxNo = input.Features.Count;
            for (int i = 0; i < maxNo; i++)
            {
                input.Features[i].Buffer(bufferDistance, output);

                //Here we update the progress
                int current = Convert.ToInt32(i * 100 / maxNo);
                if (current > previous)
                {
                    previous = current;
                }
            }

            output.Save();
            return true;
        }
예제 #24
0
        public override bool Execute(ICancelProgressHandler cancelProgressHandler)
        {
            IFeatureSet input  = _inputParam[0].Value as IFeatureSet;
            IFeatureSet output = _outputParam[0].Value as IFeatureSet;

#if DEBUG
            IFeatureSet output1 = _outputParam[1].Value as IFeatureSet;
#endif
            DoubleParam para;
            para = _inputParam[1] as DoubleParam;
            double paraSearchRadius = para != null ? para.Value : 60;
            para = _inputParam[2] as DoubleParam;
            double paraSearchCount = para != null ? para.Value : 3;
            para = _inputParam[3] as DoubleParam;
            double paraToleranceOfConvexHull = para != null ? para.Value : 5;
            string column      = ((StringParam)_inputParam[4]).Value;
            int    columnIndex = -1;

            List <FeatureUnion> myunion = new List <FeatureUnion>();

            if (column != string.Empty)
            {
                columnIndex = input.DataTable.Columns.IndexOf(column);
                if (columnIndex == -1)
                {
                    cancelProgressHandler.Progress(string.Empty, 100, "[Error] Column Not Found.");
                    return(false);
                }
            }

            cancelProgressHandler.Progress(string.Empty, 0, "[Info] Stage 1/2: Cancellable.");

            for (int i = 0; i < input.Features.Count; i++)
            {
                IFeature  feature = input.Features[i];
                IEnvelope envelop = input.Features[i].Envelope;

                // 不闭合
                if (feature.BasicGeometry.Coordinates[feature.BasicGeometry.Coordinates.Count - 1]
                    !=
                    feature.BasicGeometry.Coordinates[0]
                    )
                {
                    continue;
                }

                var c1  = envelop.TopLeft();
                var c2  = envelop.BottomRight();
                var lp  = new Polygon(feature.BasicGeometry.Coordinates);
                var lpf = new Feature(lp);
                var er  = new Polygon(
                    new Coordinate[] {
                    new Coordinate(c1.X, c1.Y),
                    new Coordinate(c1.X, c2.Y),
                    new Coordinate(c2.X, c2.Y),
                    new Coordinate(c2.X, c1.Y),
                    new Coordinate(c1.X, c1.Y)
                });
                var erf = new Feature(er);
                var cop = lpf.Centroid();

                // 无面积
                if (double.IsNaN(cop.Coordinates[0].X) ||
                    double.IsNaN(cop.Coordinates[0].Y)
                    )
                {
                    continue;
                }

                // paraToleranceOfConvexHull
                if (Math.Abs(lpf.ConvexHull().Area() - lpf.Area()) / lpf.Area() > paraToleranceOfConvexHull / 100)
                {
                    continue;
                }

                myunion.Add(new FeatureUnion {
                    OriginalLine      = input.Features[i],
                    LinkedPolygon     = lpf,
                    EnvelopedRect     = erf,
                    CentroidOfPolygon = cop,
                    Visited           = false
                });

#if DEBUG
                output1.Features.Add(myunion[myunion.Count - 1].CentroidOfPolygon.Buffer(paraSearchRadius));
                //output1.Features.Add(myunion[myunion.Count - 1].EnvelopedRect);
#endif

                cancelProgressHandler.Progress(
                    string.Empty,
                    Convert.ToInt32((Convert.ToDouble(i) / Convert.ToDouble(input.Features.Count)) * 100),
                    string.Empty
                    //(myunion[i].LinkedPolygon.Area() / myunion[i].EnvelopedRect.Area()).ToString()
                    );
                if (cancelProgressHandler.Cancel)
                {
                    cancelProgressHandler.Progress(string.Empty, 100, "[Error] Cancelled.");
                    return(false);
                }
            }

            cancelProgressHandler.Progress(string.Empty, 0, "[Info] Stage 2/2: Cancellable.");

            for (int i = 0; i < myunion.Count; i++)
            {
                List <int> coversList = new List <int>();

                for (int j = 0; j < i; j++)
                {
                    if (myunion[i].CentroidOfPolygon.Buffer(paraSearchRadius).Intersects(myunion[j].CentroidOfPolygon.Buffer(paraSearchRadius)) &&
                        !myunion[i].Visited
                        )
                    {
                        coversList.Add(j);
                        myunion[j].Visited = true;
                    }
                }
                for (int j = i + 1; j < myunion.Count; j++)
                {
                    if (myunion[i].CentroidOfPolygon.Buffer(paraSearchRadius).Intersects(myunion[j].CentroidOfPolygon.Buffer(paraSearchRadius)) &&
                        !myunion[i].Visited
                        )
                    {
                        coversList.Add(j);
                        myunion[j].Visited = true;
                    }
                }
                coversList.Add(i);                 // 自己也算一个
                myunion[i].Visited = true;

                // 排序使coversList存储的Index与面积正相关
                coversList.Sort(
                    (a, b) =>
                    myunion[a].LinkedPolygon.Area().CompareTo(
                        myunion[b].LinkedPolygon.Area()
                        )
                    );

                if (coversList.Count >= paraSearchCount)
                {
                    //output.Features.Add(myunion[i].CentroidOfPolygon);
                    bool   flag = true;
                    double max  = 0;

                    // columnIndex of Height
                    if (column != string.Empty
                        &&
                        myunion[coversList[0]].OriginalLine.DataRow[columnIndex] is double
                        )
                    {
                        for (int j = 1; j < coversList.Count; j++)
                        {
                            double current = (double)(myunion[coversList[j]].OriginalLine.DataRow[columnIndex]);
                            if (max < current)
                            {
                                max = current;
                            }
                        }
                        if (
                            (double)(myunion[coversList[0]].OriginalLine.DataRow[columnIndex])
                            >=
                            max
                            )
                        {
                            flag = false;
                        }
                    }

                    if (flag)
                    {
                        output.Features.Add(myunion[coversList[0]].CentroidOfPolygon);
                    }
                }

                cancelProgressHandler.Progress(
                    string.Empty,
                    Convert.ToInt32((Convert.ToDouble(i) / Convert.ToDouble(myunion.Count)) * 100),
                    string.Empty
                    );
                if (cancelProgressHandler.Cancel)
                {
                    cancelProgressHandler.Progress(string.Empty, 100, "[Error] Cancelled.");
                    return(false);
                }
            }

            output.Save();
#if DEBUG
            output1.Save();
#endif
            return(true);
        }
예제 #25
0
        /// <summary>
        /// Finds the average slope in the given polygons.
        /// Ping delete static for external testing
        /// </summary>
        /// <param name="input">The Polygon Raster(Grid file).</param>
        /// <param name="output">The Polygon shapefile path.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        public bool Execute(IRaster input, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            if ((input == null) || (output == null))
            {
                return false;
            }

            output.DataTable.Columns.Add("Value", typeof(double));

            Hashtable featureHash = new Hashtable();
            double previous = 0.0;
            int current;
            double height = input.CellHeight;
            double width = input.CellWidth;
            int numRows = input.NumRows;
            int numColumns = input.NumColumns;
            double xMin = input.Xllcenter - (input.CellWidth / 2.0);
            double yMin = input.Yllcenter - (input.CellHeight / 2.0);
            double xMax = xMin + (height * input.NumColumns);
            double yMax = yMin + (width * input.NumRows);
            for (int y = 0; y < numRows; y++)
            {
                current = Convert.ToInt32((y * 100.0) / input.NumRows);
                if (current > previous)
                {
                    cancelProgressHandler.Progress("", current, current + TextStrings.progresscompleted);
                    previous = current;
                }
                Debug.WriteLine("Row : " + y + " done.");
                for (int x = 0; x < numColumns; x++)
                {
                    double value = input.Value[y, x];
                    List<LineSegment> lineList = new List<LineSegment>();
                    if (!featureHash.Contains(value))
                    {
                        featureHash.Add(value, lineList);
                    }
                    else
                    {
                        lineList = featureHash[value] as List<LineSegment>;
                    }
                    if (y == 0)
                    {
                        lineList.Add(new LineSegment(new Coordinate((x * width) + xMin, yMax), new Coordinate(((x + 1) * width) + xMin, yMax)));
                        if (input.Value[y + 1, x] != value)
                        {
                            lineList.Add(new LineSegment(new Coordinate((x * width) + xMin, yMax - height), new Coordinate(((x + 1) * width) + xMin, yMax - height)));
                        }
                    }
                    else if (y == (numRows - 1))
                    {
                        lineList.Add(new LineSegment(new Coordinate((x * width) + xMin, yMin), new Coordinate(((x + 1) * width) + xMin, yMin)));
                        if (input.Value[y - 1, x] != value)
                        {
                            lineList.Add(new LineSegment(new Coordinate((x * width) + xMin, yMin + height), new Coordinate(((x + 1) * width) + xMin, yMin + height)));
                        }
                    }
                    else
                    {
                        if (input.Value[y + 1, x] != value)
                        {
                            lineList.Add(new LineSegment(new Coordinate((x * width) + xMin, yMax - ((y + 1) * height)), new Coordinate(((x + 1) * width) + xMin, yMax - ((y + 1) * height))));
                        }
                        if (input.Value[y - 1, x] != value)
                        {
                            lineList.Add(new LineSegment(new Coordinate((x * width) + xMin, yMax - (y * height)), new Coordinate(((x + 1) * width) + xMin, yMax - (y * height))));
                        }
                    }
                    if (x == 0)
                    {
                        lineList.Add(new LineSegment(new Coordinate(xMin, yMax - (y * height)), new Coordinate(xMin, yMax - ((y + 1) * height))));
                        if (input.Value[y, x + 1] != value)
                        {
                            lineList.Add(new LineSegment(new Coordinate(xMin + width, yMax - (y * height)), new Coordinate(xMin + width, yMax - ((y + 1) * height))));
                        }
                    }
                    else if (x == (numColumns - 1))
                    {
                        lineList.Add(new LineSegment(new Coordinate(xMax, yMax - (y * height)), new Coordinate(xMax, yMax - ((y + 1) * height))));
                        if (input.Value[y, x - 1] != value)
                        {
                            lineList.Add(new LineSegment(new Coordinate(xMax - width, yMax - (y * height)), new Coordinate(xMax - width, yMax - ((y + 1) * height))));
                        }
                    }
                    else
                    {
                        if (input.Value[y, x + 1] != value)
                        {
                            lineList.Add(new LineSegment(new Coordinate(xMin + ((x + 1) * width), yMax - (y * height)), new Coordinate(xMin + ((x + 1) * width), yMax - ((y + 1) * height))));
                        }
                        if (input.Value[y, x - 1] != value)
                        {
                            lineList.Add(new LineSegment(new Coordinate(xMin + (x * width), yMax - (y * height)), new Coordinate(xMin + (x * width), yMax - ((y + 1) * height))));
                        }
                    }
                    if (cancelProgressHandler.Cancel)
                    {
                        return false;
                    }
                }
            }
            Stopwatch sw = new Stopwatch();
            foreach (double key in featureHash.Keys)
            {
                sw.Reset();
                sw.Start();
                List<LineSegment> lineSegList = featureHash[key] as List<LineSegment>;
                if (lineSegList == null) break;
                List<Polygon> polyList = new List<Polygon>();
                while (lineSegList.Count != 0)
                {
                    List<Coordinate> polyShell = new List<Coordinate>();
                    LineSegment start = lineSegList[0];
                    polyShell.Add(start.P0);
                    polyShell.Add(start.P1);
                    lineSegList.Remove(start);
                    while (!polyShell[0].Equals2D(polyShell[polyShell.Count - 1]))
                    {
                        LineSegment segment = lineSegList.Find(delegate (LineSegment o) {return o.P0.Equals2D(polyShell[polyShell.Count - 1]) || o.P1.Equals2D(polyShell[polyShell.Count - 1]);});
                        if (segment.P0.Equals2D(polyShell[polyShell.Count - 1]))
                        {
                            polyShell.Add(segment.P1);
                        }
                        else
                        {
                            polyShell.Add(segment.P0);
                        }
                        lineSegList.Remove(segment);
                    }
                    polyList.Add(new Polygon(polyShell));
                }
                if (polyList.Count == 1)
                {
                    Feature feat = new Feature(polyList[0], output);
                    feat.DataRow["Value"] = key;
                }
                sw.Stop();
                Debug.WriteLine(sw.ElapsedMilliseconds);
            }
            output.Save();
            return true;
        }
예제 #26
0
        public bool Execute(
            IFeatureSet input, double tolerance, IFeatureSet output,
            ICancelProgressHandler cancelProgressHandler)
        {
            if (input == null || output == null)
            {
                return(false);
            }

            // 复制表
            foreach (DataColumn inputColumn in input.DataTable.Columns)
            {
                output.DataTable.Columns.Add(new DataColumn(inputColumn.ColumnName, inputColumn.DataType));
            }

            int numTotalOldPoints = 0;
            int numTotalNewPoints = 0;

            for (int j = 0; j < input.Features.Count; j++)
            {
                int numOldPoints = 0;
                int numNewPoints = 0;

                Geometry geom = input.Features[j].BasicGeometry as Geometry;
                if (geom != null)
                {
                    numOldPoints = geom.NumPoints;
                }

                numTotalOldPoints += numOldPoints;
                if (geom != null)
                {
                    for (int part = 0; part < geom.NumGeometries; part++)
                    {
                        Geometry geomPart = (Geometry)geom.GetGeometryN(part);

                        // 简化
                        IList <Coordinate> oldCoords = geomPart.Coordinates;
                        IList <Coordinate> newCoords = DouglasPeuckerLineSimplifier.Simplify(
                            oldCoords, tolerance);

                        // coordinates -> geometry
                        Geometry newGeom = new LineString(newCoords);
                        numNewPoints      += newGeom.NumPoints;
                        numTotalNewPoints += numNewPoints;
                        Feature newFeature = new Feature(newGeom, output);
                        foreach (DataColumn colSource in input.DataTable.Columns)
                        {
                            newFeature.DataRow[colSource.ColumnName] = input.Features[j].DataRow[colSource.ColumnName];
                        }
                    }
                }

                cancelProgressHandler.Progress(
                    string.Empty,
                    Convert.ToInt32((Convert.ToDouble(j) / Convert.ToDouble(input.Features.Count)) * 100),
                    numOldPoints + "-->" + numNewPoints);
                if (cancelProgressHandler.Cancel)
                {
                    return(false);
                }
            }

            cancelProgressHandler.Progress(
                string.Empty,
                100,
                "Old / Processed number of points:" + numTotalOldPoints + "/"
                + numTotalNewPoints);

            output.Save();
            return(true);
        }
예제 #27
0
        /// <summary>
        /// Finds the average slope in the given polygons.
        /// Ping delete static for external testing
        /// </summary>
        /// <param name="input">The Polygon Raster(Grid file).</param>
        /// <param name="output">The Polygon shapefile path.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        public bool Execute(IRaster input, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            if ((input == null) || (output == null))
            {
                return(false);
            }

            output.DataTable.Columns.Add("Value", typeof(double));

            Hashtable featureHash = new Hashtable();
            double    previous    = 0.0;
            double    height      = input.CellHeight;
            double    width       = input.CellWidth;
            int       numRows     = input.NumRows;
            int       numColumns  = input.NumColumns;
            double    xMin        = input.Xllcenter - (input.CellWidth / 2.0);
            double    yMin        = input.Yllcenter - (input.CellHeight / 2.0);
            double    xMax        = xMin + (height * input.NumColumns);
            double    yMax        = yMin + (width * input.NumRows);

            for (int y = 0; y < numRows; y++)
            {
                int current = Convert.ToInt32((y * 100.0) / input.NumRows);
                if (current > previous)
                {
                    cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted);
                    previous = current;
                }

                Debug.WriteLine("Row : " + y + " done.");
                for (int x = 0; x < numColumns; x++)
                {
                    double             value    = input.Value[y, x];
                    List <LineSegment> lineList = new List <LineSegment>();
                    if (!featureHash.Contains(value))
                    {
                        featureHash.Add(value, lineList);
                    }
                    else
                    {
                        lineList = featureHash[value] as List <LineSegment>;
                    }

                    if (y == 0)
                    {
                        if (lineList != null)
                        {
                            lineList.Add(
                                new LineSegment(
                                    new Coordinate((x * width) + xMin, yMax),
                                    new Coordinate(((x + 1) * width) + xMin, yMax)));
                            if (input.Value[y + 1, x] != value)
                            {
                                lineList.Add(
                                    new LineSegment(
                                        new Coordinate((x * width) + xMin, yMax - height),
                                        new Coordinate(((x + 1) * width) + xMin, yMax - height)));
                            }
                        }
                    }
                    else if (y == (numRows - 1))
                    {
                        if (lineList != null)
                        {
                            lineList.Add(
                                new LineSegment(
                                    new Coordinate((x * width) + xMin, yMin),
                                    new Coordinate(((x + 1) * width) + xMin, yMin)));
                            if (input.Value[y - 1, x] != value)
                            {
                                lineList.Add(
                                    new LineSegment(
                                        new Coordinate((x * width) + xMin, yMin + height),
                                        new Coordinate(((x + 1) * width) + xMin, yMin + height)));
                            }
                        }
                    }
                    else
                    {
                        if (input.Value[y + 1, x] != value)
                        {
                            if (lineList != null)
                            {
                                lineList.Add(
                                    new LineSegment(
                                        new Coordinate((x * width) + xMin, yMax - ((y + 1) * height)),
                                        new Coordinate(((x + 1) * width) + xMin, yMax - ((y + 1) * height))));
                            }
                        }

                        if (input.Value[y - 1, x] != value)
                        {
                            if (lineList != null)
                            {
                                lineList.Add(
                                    new LineSegment(
                                        new Coordinate((x * width) + xMin, yMax - (y * height)),
                                        new Coordinate(((x + 1) * width) + xMin, yMax - (y * height))));
                            }
                        }
                    }

                    if (x == 0)
                    {
                        if (lineList != null)
                        {
                            lineList.Add(
                                new LineSegment(
                                    new Coordinate(xMin, yMax - (y * height)),
                                    new Coordinate(xMin, yMax - ((y + 1) * height))));
                            if (input.Value[y, x + 1] != value)
                            {
                                lineList.Add(
                                    new LineSegment(
                                        new Coordinate(xMin + width, yMax - (y * height)),
                                        new Coordinate(xMin + width, yMax - ((y + 1) * height))));
                            }
                        }
                    }
                    else if (x == (numColumns - 1))
                    {
                        if (lineList != null)
                        {
                            lineList.Add(
                                new LineSegment(
                                    new Coordinate(xMax, yMax - (y * height)),
                                    new Coordinate(xMax, yMax - ((y + 1) * height))));
                            if (input.Value[y, x - 1] != value)
                            {
                                lineList.Add(
                                    new LineSegment(
                                        new Coordinate(xMax - width, yMax - (y * height)),
                                        new Coordinate(xMax - width, yMax - ((y + 1) * height))));
                            }
                        }
                    }
                    else
                    {
                        if (input.Value[y, x + 1] != value)
                        {
                            if (lineList != null)
                            {
                                lineList.Add(
                                    new LineSegment(
                                        new Coordinate(xMin + ((x + 1) * width), yMax - (y * height)),
                                        new Coordinate(xMin + ((x + 1) * width), yMax - ((y + 1) * height))));
                            }
                        }

                        if (input.Value[y, x - 1] != value)
                        {
                            if (lineList != null)
                            {
                                lineList.Add(
                                    new LineSegment(
                                        new Coordinate(xMin + (x * width), yMax - (y * height)),
                                        new Coordinate(xMin + (x * width), yMax - ((y + 1) * height))));
                            }
                        }
                    }

                    if (cancelProgressHandler.Cancel)
                    {
                        return(false);
                    }
                }
            }

            Stopwatch sw = new Stopwatch();

            foreach (double key in featureHash.Keys)
            {
                sw.Reset();
                sw.Start();
                List <LineSegment> lineSegList = featureHash[key] as List <LineSegment>;
                if (lineSegList == null)
                {
                    break;
                }

                List <Polygon> polyList = new List <Polygon>();
                while (lineSegList.Count != 0)
                {
                    List <Coordinate> polyShell = new List <Coordinate>();
                    LineSegment       start     = lineSegList[0];
                    polyShell.Add(start.P0);
                    polyShell.Add(start.P1);
                    lineSegList.Remove(start);
                    while (!polyShell[0].Equals2D(polyShell[polyShell.Count - 1]))
                    {
                        LineSegment segment =
                            lineSegList.Find(
                                o =>
                                o.P0.Equals2D(polyShell[polyShell.Count - 1]) ||
                                o.P1.Equals2D(polyShell[polyShell.Count - 1]));
                        polyShell.Add(segment.P0.Equals2D(polyShell[polyShell.Count - 1]) ? segment.P1 : segment.P0);
                        lineSegList.Remove(segment);
                    }

                    polyList.Add(new Polygon(polyShell));
                }

                if (polyList.Count == 1)
                {
                    Feature feat = new Feature(polyList[0], output);
                    feat.DataRow["Value"] = key;
                }

                sw.Stop();
                Debug.WriteLine(sw.ElapsedMilliseconds);
            }

            output.Save();
            return(true);
        }
예제 #28
0
        /// <summary>
        /// Removes portions of the input polygon shapefile that are within the erase polygons.
        /// </summary>
        /// <param name="inputShapefile">The input polygon shapefile.</param>
        /// <param name="eraseShapefile">The erase polygon shapefile.</param>
        /// <param name="resultShapefile">The resulting shapefile, with portions removed.</param>
        public static void ErasePolygonShapefileWithPolygonShapefile(
            IFeatureSet inputShapefile, IFeatureSet eraseShapefile, IFeatureSet resultShapefile)
        {
            // Validates the input and resultSF data
            if (inputShapefile == null || eraseShapefile == null || resultShapefile == null)
            {
                return;
            }

            resultShapefile.CopyTableSchema(inputShapefile); // Fill the 1st Featureset fields
            IFeatureSet tempSet = inputShapefile.CombinedFields(eraseShapefile);

            // go through every feature in 1st featureSet
            foreach (IFeature t in inputShapefile.Features)
            {
                // go through every feature in 2nd featureSet
                foreach (IFeature t1 in eraseShapefile.Features)
                {
                    t.Difference(t1, tempSet, FieldJoinType.All);
                }
            }

            // Add to the resultSF Feature Set
            for (int a = 0; a < tempSet.Features.Count; a++)
            {
                resultShapefile.Features.Add(tempSet.Features[a]);
            }

            resultShapefile.Save();
            return;
        }
예제 #29
0
        /// <summary>
        /// Executes the DP line simplefy tool programaticaly
        /// Ping Yang Added it for external Testing
        /// </summary>
        /// <param name="input">The input polygon feature set</param>
        /// <param name="tolerance">The tolerance to use when simplefiying</param>
        /// <param name="output">The output polygon feature set</param>
        /// <returns></returns>
        public bool Execute(IFeatureSet input, double tolerance, IFeatureSet output)
        {
            //Validates the input and output data
            if (input == null || output == null)
                return false;

            //We copy all the fields 
            foreach (DataColumn inputColumn in input.DataTable.Columns)
                output.DataTable.Columns.Add(new DataColumn(inputColumn.ColumnName, inputColumn.DataType));

            int numTotalOldPoints = 0;
            int numTotalNewPoints = 0;

            for (int j = 0; j < input.Features.Count; j++)
            {
                int numOldPoints = 0;
                int numNewPoints = 0;


                Geometry geom = input.Features[j].BasicGeometry as Geometry;
                if (geom != null) numOldPoints = geom.NumPoints;
                numTotalOldPoints += numOldPoints;
                if (geom != null)
                {
                    for (int part = 0; part < geom.NumGeometries; part++)
                    {
                        Geometry geomPart = (Geometry)geom.GetGeometryN(part);
                        //do the simplification
                        IList<Coordinate> oldCoords = geomPart.Coordinates;
                        IList<Coordinate> newCoords =
                            MapWindow.Analysis.Topology.Simplify.DouglasPeuckerLineSimplifier.Simplify(oldCoords, tolerance);

                        //convert the coordinates back to a geometry
                        Geometry newGeom = new LineString(newCoords);
                        numNewPoints += newGeom.NumPoints;
                        numTotalNewPoints += numNewPoints;
                        Feature newFeature = new Feature(newGeom, output);
                        foreach (DataColumn colSource in input.DataTable.Columns)
                            newFeature.DataRow[colSource.ColumnName] = input.Features[j].DataRow[colSource.ColumnName];
                    }
                }
            }

            output.Save();
            return true;
        }
예제 #30
0
        /// <summary>
        /// Executes the DP line simplefy tool programaticaly
        /// </summary>
        /// <param name="input">The input polygon feature set</param>
        /// <param name="tolerance">The tolerance to use when simplefiying</param>
        /// <param name="output">The output polygon feature set</param>
        /// <param name="cancelProgressHandler">The progress handler</param>
        /// <returns></returns>
        public bool Execute(IFeatureSet input, double tolerance, IFeatureSet output, 
            ICancelProgressHandler cancelProgressHandler)
        {
            //Validates the input and output data
            if (input == null || output == null)
                return false;

            //We copy all the fields 
            foreach (DataColumn inputColumn in input.DataTable.Columns)
                output.DataTable.Columns.Add(new DataColumn(inputColumn.ColumnName, inputColumn.DataType));

            int numTotalOldPoints = 0;
                int numTotalNewPoints = 0;

            for (int j = 0; j < input.Features.Count; j++)
            {
                int numOldPoints = 0;
                int numNewPoints = 0;
                
                
                Geometry geom = input.Features[j].BasicGeometry as Geometry;
                if (geom != null) numOldPoints = geom.NumPoints;
                numTotalOldPoints += numOldPoints;
                if (geom != null)
                {
                    for (int part = 0; part < geom.NumGeometries; part++)
                    {
                        Geometry geomPart = (Geometry)geom.GetGeometryN(part);
                        //do the simplification
                        IList<Coordinate> oldCoords = geomPart.Coordinates;
                        IList<Coordinate> newCoords = 
                            MapWindow.Analysis.Topology.Simplify.DouglasPeuckerLineSimplifier.Simplify(oldCoords, tolerance);
                   
                        //convert the coordinates back to a geometry
                        Geometry newGeom = new LineString(newCoords);
                        numNewPoints += newGeom.NumPoints;
                        numTotalNewPoints += numNewPoints;
                        Feature newFeature = new Feature(newGeom, output);
                        foreach (DataColumn colSource in input.DataTable.Columns)
                            newFeature.DataRow[colSource.ColumnName] = input.Features[j].DataRow[colSource.ColumnName];
                    }
                }

                //Status updates is done here, shows number of old / new points
                cancelProgressHandler.Progress("", Convert.ToInt32((Convert.ToDouble(j) / Convert.ToDouble(input.Features.Count)) * 100), 
                    numOldPoints + "-->" + numNewPoints);
                if (cancelProgressHandler.Cancel)
                    return false;
            }
            cancelProgressHandler.Progress("", 100, TextStrings.Originalnumberofpoints + numTotalOldPoints + " " + TextStrings.Newnumberofpoints + numTotalNewPoints);

            output.Save();
            return true;
        }
예제 #31
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(this.CalculateField))
            {
                MessageBox.Show("Please select a calculate field");
                return;
            }
            string        filter = this.txtExpression.Text.Replace(" ", "");
            List <object> Result = new List <object>();
            Dictionary <string, string> DicFields = new Dictionary <string, string>();

            while (filter.Contains("[") && filter.Contains("]"))
            {
                string temp = filter.Substring(filter.IndexOf("["), filter.IndexOf("]") - filter.IndexOf("[") + 1);
                filter = filter.Replace(temp, "");
                DicFields.Add(temp, temp.Replace("[", "").Replace("]", ""));
            }
            foreach (var value in DicFields)
            {
                if (!m_CurrentFeaSet.DataTable.Columns.Contains(value.Value))
                {
                    MessageBox.Show("Fields " + value.Key + " is not exits");
                    return;
                }
            }
            ProgressBox p = new ProgressBox(0, 100, "Field calculate");

            p.ShowPregress();
            p.SetProgressValue(0);
            p.SetProgressDescription("calculate...");
            double pi = Math.Round((double)(1.0 * 100 / m_CurrentFeaSet.Features.Count), 2);

            for (int i = 0; i < m_CurrentFeaSet.Features.Count; i++)
            {
                p.SetProgressValue(pi + pi * i);
                p.SetProgressDescription2(string.Format("{0} feature(s) is(are) calculated, the remaining {1} feature(s) is(are) being calculated", i + 1, m_CurrentFeaSet.Features.Count - i - 1));
                string resultFilter = this.txtExpression.Text.Replace(" ", "");
                foreach (var value in DicFields)
                {
                    string str = m_CurrentFeaSet.Features[i].DataRow[value.Value].ToString();
                    if (resultFilter.Contains(value.Key))
                    {
                        resultFilter = resultFilter.Replace(value.Key, str);
                    }
                }
                try
                {
                    Result.Add(Eval(resultFilter));
                }
                catch
                {
                    p.CloseProgress();
                    MessageBox.Show("Something seems to have gone wrong");
                    return;
                }
            }
            p.SetProgressDescription2("save data to field now,it should take a few seconds");
            if (this.ckxCreate.IsChecked == true)
            {
                if (this.m_FieldType == FieldType.String)
                {
                    m_CurrentFeaSet.DataTable.Columns.Add(this.m_NewFieldName, typeof(String));
                    for (int i = 0; i < m_CurrentFeaSet.Features.Count; i++)
                    {
                        m_CurrentFeaSet.Features[i].DataRow[this.m_NewFieldName] = Result[i].ToString();
                    }
                }
                else if (this.m_FieldType == FieldType.Double)
                {
                    m_CurrentFeaSet.DataTable.Columns.Add(this.m_NewFieldName, typeof(Double));
                    for (int i = 0; i < m_CurrentFeaSet.Features.Count; i++)
                    {
                        m_CurrentFeaSet.Features[i].DataRow[this.m_NewFieldName] = Convert.ToDouble(Result[i]);
                    }
                }
            }
            else
            {
                for (int i = 0; i < m_CurrentFeaSet.Features.Count; i++)
                {
                    m_CurrentFeaSet.Features[i].DataRow[this.CalculateField] = Result[i];
                }
            }
            p.CloseProgress();
            try
            {
                m_CurrentFeaSet.Save();
            }
            catch
            {
                SaveFileDialog f = new SaveFileDialog();
                f.AddExtension = true;
                f.Filter       = "ShapeFile(*.shp)|*.shp";
                f.Title        = "Select Save Path";
                if (f.ShowDialog() == true)
                {
                    m_CurrentFeaSet.SaveAs(f.FileName, true);
                }
            }
            MessageBox.Show("Successfully");
            this.DialogResult = true;
        }