C# GIS 空间分析

Intersection

public bool Intersection(IFeatureSet self, IFeatureSet other, IFeatureSet output)
        {            
            int maxFeature = self.ShapeIndices.Count;
            int privious = 0;
            output.CopyTableSchema(FeatureSetExt.CombinedFields(self, other));
            FeatureAttributesSet.AddFeatureAttributes(output.DataTable.Columns);

            for (int i = 0; i < self.ShapeIndices.Count; i++)
            {
                IFeature iTF, iSF, f;
                iTF = self.GetFeature(i);
                for (int j = 0; j < other.ShapeIndices.Count; j++)
                {
                    iSF = other.GetFeature(j);
                    if (iSF.Geometry.Envelope.Intersects(iTF.Geometry.Envelope)) 
                    {
                        f = iTF.Intersection(iSF.Geometry);

                        if (f != null && f.FeatureType == FeatureType.Polygon) 
                        {
                            IFeature feature = new Feature(f.Geometry);
                            output.Features.Add(feature);
                            feature.CopyAttributes(self.GetFeature(i));
                            feature.CopyAttributes(other.GetFeature(j));
                            FeatureAttributesSet.SetFeatureAttributes(output.DataTable.Rows[output.DataTable.Rows.Count - 1], f.Geometry);
                        }
                    }
                }                
            }
           
            return true;
        }

Difference

private bool DifferentFeatures(IFeatureSet targetFeatures, IFeatureSet sourceFeatures, IFeatureSet featureSet)
        {            
            bool bResult = true;
            int privious = 0;

            featureSet.CopyTableSchema(targetFeatures);

            FeatureAttributesSet.AddFeatureAttributes(featureSet.DataTable.Columns);

            for (int i = 0; i < targetFeatures.ShapeIndices.Count; i++)
            {
                var tf = targetFeatures.GetFeature(i);
                for (int j = 0; j < sourceFeatures.ShapeIndices.Count; j++)
                {
                    var sf = sourceFeatures.GetFeature(j);

                    if (sf.Geometry.Envelope.Intersects(tf.Geometry.Envelope))
                    {
                        tf = tf.Difference(sf.Geometry);
                    }

                    if (tf == null) break;
                }

                if (tf != null)
                {
                    featureSet.AddFeature(tf.Geometry).CopyAttributes(targetFeatures.GetFeature(i));
                    FeatureAttributesSet.SetFeatureAttributes(featureSet.DataTable.Rows[featureSet.DataTable.Rows.Count - 1], tf.Geometry);
                }                
            }
            
            return bResult;
        }  

.

C# GIS 空间分析

上一篇:WPF 键盘事件


下一篇:自定义WPF Popup控件