Esempio n. 1
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (this.cboLayer.Text == "")
            {
                MessageBox.Show("Please select a polyline layer");
                return;
            }
            IFeatureLayer layer  = m_Layers[this.cboLayer.SelectedIndex];
            IFeatureSet   feaset = (layer as FeatureLayer).FeatureSet;
            ProgressBox   p      = new ProgressBox(0, 100, "Self intersection check progress");

            p.ShowPregress();
            p.SetProgressValue(0);
            p.SetProgressDescription("Checking Self intersection...");
            double     pi      = Math.Round((double)(1.0 * 100 / feaset.Features.Count), 2);
            List <int> FidList = new List <int>();

            //DateTime dt = DateTime.Now;
            for (int i = 0; i < feaset.Features.Count; i++)
            {
                p.SetProgressValue(i * pi + pi);
                p.SetProgressDescription2(string.Format("{0} feature(s) is(are) checked, the remaining {1} feature(s) is(are) being queried", i + 1, feaset.Features.Count - i - 1));
                var LineList = GetLinesFromGeometry(feaset.Features[i].Geometry);
                //var LineList = GetAllLine(feaset.Features[i].Geometry);
                bool IsCrossed = false;
                for (int j = 0; j < LineList.Count; j++)
                {
                    for (int k = j + 1; k < LineList.Count; k++)
                    {
                        if (LineList[j].Crosses(LineList[k]))
                        {
                            FidList.Add(feaset.Features[i].Fid);
                            IsCrossed = true;
                            break;
                        }
                    }
                    if (IsCrossed)
                    {
                        break;
                    }
                }
            }
            //DateTime dt2 = DateTime.Now;
            //var span = dt2 - dt;
            //MessageBox.Show(span.ToString());
            p.CloseProgress();
            if (FidList.Count == 0)
            {
                MessageBox.Show(string.Format("{0} has no Self intersection.", layer.LegendText));
            }
            else
            {
                layer.UnSelectAll();
                MainWindow.m_DotMap.Refresh();
                layer.Select(FidList);
                MessageBox.Show(string.Format("{0} has {1} Self intersection", layer.LegendText, FidList.Count.ToString()));
            }
            this.Close();
        }
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (this.cboLayer.Text == "")
            {
                MessageBox.Show("Please select a polygon layer");
                return;
            }
            IFeatureLayer layer  = m_Layers[this.cboLayer.SelectedIndex];
            IFeatureSet   feaset = (layer as FeatureLayer).FeatureSet;
            ProgressBox   p      = new ProgressBox(0, 100, "Faying surface check progress");

            p.ShowPregress();
            p.SetProgressValue(0);
            p.SetProgressDescription("Checking faying surface...");
            double     pi      = Math.Round((double)(1.0 * 100 / feaset.Features.Count));
            List <int> FidList = new List <int>();

            for (int i = 0; i < feaset.Features.Count; i++)
            {
                p.SetProgressValue(i * pi + pi);
                p.SetProgressDescription2(string.Format("{0} feature(s) is(are) checked, the remaining {1} feature(s) is(are) being queried", i + 1, feaset.Features.Count - i - 1));
                for (int j = i + 1; j < feaset.Features.Count; j++)
                {
                    if (feaset.Features[i].Geometry.Overlaps(feaset.Features[j].Geometry))
                    {
                        if (!FidList.Contains(i))
                        {
                            FidList.Add(i);
                        }
                        if (!FidList.Contains(j))
                        {
                            FidList.Add(j);
                        }
                    }
                }
            }
            p.CloseProgress();
            if (FidList.Count == 0)
            {
                MessageBox.Show(string.Format("{0} has no faying surface.", layer.LegendText));
            }
            else
            {
                layer.UnSelectAll();
                MainWindow.m_DotMap.Refresh();
                layer.Select(FidList);
                MessageBox.Show(string.Format("{0} has {1} faying surfaces.", layer.LegendText, FidList.Count.ToString()));
            }
            this.Close();
        }
Esempio n. 3
0
        private FeatureSet IntersectFeatures(IFeatureSet targetFeatures, IFeatureSet sourceFeatures)
        {
            if (targetFeatures == null || sourceFeatures == null)
            {
                return(null);
            }
            FeatureSet resultFeatures = new FeatureSet();   // the resulting featureset

            resultFeatures.CopyTableSchema(targetFeatures); // set up the data table in the new feature set

            ProgressBox p = new ProgressBox(0, 100, "Self intersection check progress");

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

            for (int i = 0; i < targetFeatures.Features.Count; i++)
            {
                p.SetProgressValue(i * pi + pi);
                p.SetProgressDescription2(string.Format("{0} feature(s) is(are) checked, the remaining {1} feature(s) is(are) being queried", i + 1, targetFeatures.Features.Count - i - 1));
                var tf = targetFeatures.GetFeature(i); // get the full undifferenced feature
                for (int j = 0; j < sourceFeatures.Features.Count; j++)
                {
                    var sf = sourceFeatures.GetFeature(j);
                    if (sf.Geometry.Intersects(tf.Geometry))
                    {
                        tf = tf.Intersection(sf.Geometry); // clip off any pieces of SF that overlap FR
                    }
                    if (tf == null)
                    {
                        break;
                    }
                }
                if (tf != null)
                {
                    resultFeatures.AddFeature(tf.Geometry).CopyAttributes(targetFeatures.GetFeature(i));
                }
            }
            p.CloseProgress();
            return(resultFeatures);
        }
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (this.cboLayer.Text == "")
            {
                MessageBox.Show("Please select a polyline layer");
                return;
            }
            IFeatureLayer layer  = m_Layers[this.cboLayer.SelectedIndex];
            IFeatureSet   feaset = (layer as FeatureLayer).FeatureSet;
            ProgressBox   p      = new ProgressBox(0, 100, "Suspension point check progress");

            p.ShowPregress();
            p.SetProgressValue(0);
            p.SetProgressDescription("Checking suspension point...");
            Dictionary <int, List <GeoAPI.Geometries.IPoint> > AllPoints = new Dictionary <int, List <GeoAPI.Geometries.IPoint> >();//线图层所有端点

            for (int i = 0; i < feaset.Features.Count; i++)
            {
                IFeature pFea = feaset.Features[i];
                if (pFea.Geometry.GeometryType == "LineString")
                {
                    GeoAPI.Geometries.Coordinate coord1  = pFea.Geometry.Coordinates[0];
                    GeoAPI.Geometries.IPoint     pPoint1 = new NetTopologySuite.Geometries.Point(coord1);
                    int count = pFea.Geometry.Coordinates.Count() - 1;
                    GeoAPI.Geometries.Coordinate coord2  = pFea.Geometry.Coordinates[count];
                    GeoAPI.Geometries.IPoint     pPoint2 = new NetTopologySuite.Geometries.Point(coord2);
                    AllPoints.Add(pFea.Fid, new List <GeoAPI.Geometries.IPoint>()
                    {
                        pPoint1, pPoint2
                    });
                }
                else//多线
                {
                    for (int j = 0; j < pFea.Geometry.NumGeometries; j++)
                    {
                        var geometry = pFea.Geometry.GetGeometryN(j);
                        GeoAPI.Geometries.Coordinate coord1  = geometry.Coordinates[0];
                        GeoAPI.Geometries.IPoint     pPoint1 = new NetTopologySuite.Geometries.Point(coord1);
                        int count = geometry.Coordinates.Count() - 1;
                        GeoAPI.Geometries.Coordinate coord2  = geometry.Coordinates[count];
                        GeoAPI.Geometries.IPoint     pPoint2 = new NetTopologySuite.Geometries.Point(coord2);
                        if (AllPoints.ContainsKey(pFea.Fid))
                        {
                            if (!AllPoints[pFea.Fid].Contains(pPoint1))
                            {
                                AllPoints[pFea.Fid].Add(pPoint1);
                            }
                            if (!AllPoints[pFea.Fid].Contains(pPoint2))
                            {
                                AllPoints[pFea.Fid].Add(pPoint2);
                            }
                        }
                        else
                        {
                            AllPoints.Add(pFea.Fid, new List <GeoAPI.Geometries.IPoint>()
                            {
                                pPoint1, pPoint2
                            });
                        }
                    }
                }
            }
            List <GeoAPI.Geometries.IPoint> resultPoint = new List <GeoAPI.Geometries.IPoint>();
            double pi     = Math.Round((double)(1.0 * 100 / feaset.Features.Count), 2);
            int    number = 1;

            foreach (var value in AllPoints)
            {
                p.SetProgressValue(number * pi);
                p.SetProgressDescription2(string.Format("{0} feature(s) is(are) checked, the remaining {1} feature(s) is(are) being queried", number, feaset.Features.Count - number));
                number++;
                foreach (var point in value.Value)
                {
                    bool IsSuspension = true;
                    foreach (var fea in feaset.Features)
                    {
                        if (fea.Fid == value.Key)
                        {
                            continue;
                        }
                        //一旦相交,必不是悬点
                        if (fea.Geometry.Intersects(point))
                        {
                            IsSuspension = false;
                            break;
                        }
                    }
                    if (IsSuspension && !resultPoint.Contains(point))
                    {
                        resultPoint.Add(point);
                    }
                }
            }
            AllPoints.Clear();
            p.CloseProgress();
            if (resultPoint.Count == 0)
            {
                MessageBox.Show(string.Format("{0} has no suspension point.", layer.LegendText));
            }
            else
            {
                IFeatureSet pSet   = new FeatureSet(FeatureType.Point);
                string[]    Fields = new string[3] {
                    "ID", "X", "Y"
                };
                foreach (string field in Fields)
                {
                    pSet.DataTable.Columns.Add(field);
                }
                int s = 0;
                foreach (var point in resultPoint)
                {
                    IFeature pFea = pSet.AddFeature(point);
                    pFea.DataRow[0] = s;
                    pFea.DataRow[1] = point.X;
                    pFea.DataRow[2] = point.Y;
                    s++;
                }
                pSet.Projection = MainWindow.m_DotMap.Projection;
                pSet.Name       = m_Layers[this.cboLayer.SelectedIndex].LegendText + "_suspenion points";
                var             feaLayer = MainWindow.m_DotMap.Layers.Add(pSet);
                PointSymbolizer symbol   = new PointSymbolizer(System.Drawing.Color.Red, DotSpatial.Symbology.PointShape.Ellipse, 5);
                feaLayer.Symbolizer = symbol;
                MessageBox.Show(string.Format("{0} has {1} suspension point.", layer.LegendText, resultPoint.Count.ToString()));
            }
            this.Close();
        }
        private void btnApply_Click(object sender, RoutedEventArgs e)
        {
            if (hasQueried)
            {
                return;
            }
            var TargetLayerList = (from u in TargetLayers
                                   where u.IsChecked
                                   select u).ToList();

            if (TargetLayerList.Count == 0)
            {
                MessageBox.Show("Please select at least one target layer");
                return;
            }
            if (SelectedSourceLayer == null)
            {
                MessageBox.Show("Please select a source layer");
                return;
            }
            ProgressBox p = new ProgressBox(0, 100, "Location query progress");

            p.ShowPregress();
            p.SetProgressValue(0);
            IFeatureSet srcFeaset;

            if (this.UsingSelectedFeas)
            {
                srcFeaset = SelectedSourceLayer.Layer.Selection.ToFeatureSet();
            }
            else
            {
                srcFeaset = SelectedSourceLayer.Layer.FeatureSet;
            }
            Dictionary <IFeatureLayer, List <int> > DicFidList = new Dictionary <IFeatureLayer, List <int> >();

            switch (m_SpatialMethod)
            {
            case SpatialMethod.Intersect:
                foreach (var layer in TargetLayerList)
                {
                    List <int> FidList    = new List <int>();
                    var        tarFeaList = GetTargetFeaList(layer.Layer);
                    int        tarCount   = tarFeaList.Count;
                    double     pi         = Math.Round((double)(100 * 1.0 / tarCount), 2);
                    p.SetProgressDescription("Querying " + layer.Layer.LegendText);
                    for (int i = 0; i < tarCount; i++)
                    {
                        p.SetProgressValue(pi * (i + 1));
                        p.SetProgressDescription2(string.Format("{0} feature(s) is(are) queried, the remaining {1} feature(s) is(are) being queried", i + 1, tarCount - i - 1));
                        foreach (var fea in srcFeaset.Features)
                        {
                            if (tarFeaList[i].Geometry.Intersects(fea.Geometry))
                            {
                                FidList.Add(tarFeaList[i].Fid);
                                break;
                            }
                        }
                    }
                    DicFidList.Add(layer.Layer, FidList);
                }
                break;

            case SpatialMethod.Contains:
                foreach (var layer in TargetLayerList)
                {
                    List <int> FidList    = new List <int>();
                    var        tarFeaList = GetTargetFeaList(layer.Layer);
                    int        tarCount   = tarFeaList.Count;
                    double     pi         = Math.Round((double)(100 * 1.0 / tarCount), 2);
                    p.SetProgressDescription("Querying " + layer.Layer.LegendText);
                    for (int i = 0; i < tarCount; i++)
                    {
                        p.SetProgressValue(pi * (i + 1));
                        p.SetProgressDescription2(string.Format("{0} feature(s) is(are) queried, the remaining {1} feature(s) is(are) being queried", i + 1, tarCount - i - 1));
                        foreach (var fea in srcFeaset.Features)
                        {
                            if (tarFeaList[i].Geometry.Contains(fea.Geometry))
                            {
                                FidList.Add(tarFeaList[i].Fid);
                                break;
                            }
                        }
                    }
                    DicFidList.Add(layer.Layer, FidList);
                }
                break;

            case SpatialMethod.Within:
                foreach (var layer in TargetLayerList)
                {
                    List <int> FidList    = new List <int>();
                    var        tarFeaList = GetTargetFeaList(layer.Layer);
                    int        tarCount   = tarFeaList.Count;
                    double     pi         = Math.Round((double)(100 * 1.0 / tarCount), 2);
                    p.SetProgressDescription("Querying " + layer.Layer.LegendText);
                    for (int i = 0; i < tarCount; i++)
                    {
                        p.SetProgressValue(pi * (i + 1));
                        p.SetProgressDescription2(string.Format("{0} feature(s) is(are) queried, the remaining {1} feature(s) is(are) being queried", i + 1, tarCount - i - 1));
                        foreach (var fea in srcFeaset.Features)
                        {
                            if (tarFeaList[i].Geometry.Within(fea.Geometry))
                            {
                                FidList.Add(tarFeaList[i].Fid);
                                break;
                            }
                        }
                    }
                    DicFidList.Add(layer.Layer, FidList);
                }
                break;
            }
            //select features
            foreach (var value in DicFidList)
            {
                if (value.Value.Count > 0)
                {
                    switch (m_SelectionMethod)
                    {
                    case SelectionMethod.Add:
                        value.Key.Select(value.Value);
                        break;

                    case SelectionMethod.RemoveFromSelected:
                        value.Key.UnSelect(value.Value);
                        break;

                    case SelectionMethod.SelectFromSelected:
                    case SelectionMethod.Select:
                        value.Key.UnSelectAll();
                        value.Key.Select(value.Value);
                        break;
                    }
                    MainWindow.m_DotMap.Refresh();
                }
            }
            p.CloseProgress();
            hasQueried = true;
        }
Esempio n. 6
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;
        }