コード例 #1
0
ファイル: ActicityBase.cs プロジェクト: jugstalt/gViewGisOS
        override public List <IActivityData> Process()
        {
            IDatasetElement sElement = base.SourceDatasetElement;
            IFeatureClass   sFc      = base.SourceFeatureClass;

            TargetDatasetElement tElement = base.TargetDatasetElement;
            IDataset             tDs      = base.TargetDataset;
            //IFeatureDatabase tDatabase = base.TargetFeatureDatabase;

            IFeatureClass    tFc       = base.CreateTargetFeatureclass(sFc, sFc.Fields);
            IFeatureDatabase tDatabase = FeatureDatabase(tFc);

            Report.featureMax = sFc.CountFeatures;
            Report.featurePos = 0;
            ReportProgess("Query Filter: " + SourceData.FilterClause);

            using (IFeatureCursor cursor = SourceData.GetFeatures(String.Empty))
            {
                IFeature        feature;
                List <IFeature> features = new List <IFeature>();

                ReportProgess("Read/Write Features...");
                while ((feature = cursor.NextFeature) != null)
                {
                    features.Add(feature);

                    Report.featurePos++;
                    if (!CancelTracker.Continue)
                    {
                        break;
                    }

                    if (features.Count > 100)
                    {
                        ReportProgess();
                        if (!tDatabase.Insert(tFc, features))
                        {
                            throw new Exception(tDatabase.lastErrorMsg);
                        }
                        features.Clear();
                    }
                }

                if (features.Count > 0)
                {
                    ReportProgess();
                    if (!tDatabase.Insert(tFc, features))
                    {
                        throw new Exception(tDatabase.lastErrorMsg);
                    }
                }

                ReportProgess("Flush Features");
                base.FlushFeatureClass(tFc);

                return(base.ToProcessResult(tFc));
            }
        }
コード例 #2
0
ファイル: ActicityBase.cs プロジェクト: jugstalt/gViewGisOS
        override public List <IActivityData> Process()
        {
            IDatasetElement sElement = base.SourceDatasetElement;
            IFeatureClass   sFc      = base.SourceFeatureClass;

            TargetDatasetElement tElement = base.TargetDatasetElement;
            IDataset             tDs      = base.TargetDataset;
            //IFeatureDatabase tDatabase = base.TargetFeatureDatabase;

            GeometryDef geomDef = new GeometryDef(
                geometryType.Polygon,
                null,
                false);

            IFeatureClass    tFc       = base.CreateTargetFeatureclass(geomDef, sFc.Fields);
            IFeatureDatabase tDatabase = FeatureDatabase(tFc);

            Report.featureMax = sFc.CountFeatures;
            Report.featurePos = 0;
            ReportProgess("Query Filter: " + SourceData.FilterClause);

            using (IFeatureCursor cursor = SourceData.GetFeatures(String.Empty))
            {
                IFeature        feature;
                List <IFeature> features = new List <IFeature>();

                ReportProgess("Read/Write Features...");
                while ((feature = cursor.NextFeature) != null)
                {
                    if (feature.Shape is ITopologicalOperation)
                    {
                        feature.Shape = ((ITopologicalOperation)feature.Shape).Buffer(_bufferDistance);
                    }
                    else
                    {
                        continue;
                    }

                    if (feature.Shape == null)
                    {
                        continue;
                    }

                    features.Add(feature);

                    Report.featurePos++;
                    ReportProgess();
                    if (!CancelTracker.Continue)
                    {
                        break;
                    }

                    if (features.Count > 100)
                    {
                        if (!tDatabase.Insert(tFc, features))
                        {
                            throw new Exception(tDatabase.lastErrorMsg);
                        }
                        features.Clear();
                    }
                }

                if (features.Count > 0)
                {
                    ReportProgess();
                    if (!tDatabase.Insert(tFc, features))
                    {
                        throw new Exception(tDatabase.lastErrorMsg);
                    }
                }

                ReportProgess("Flush Features");
                base.FlushFeatureClass(tFc);

                return(base.ToProcessResult(tFc));
            }
        }
コード例 #3
0
ファイル: ActicityBase.cs プロジェクト: jugstalt/gViewGisOS
        override public List <IActivityData> Process()
        {
            #region Where Clauses
            List <string> whereClauses = new List <string>();
            if (_mergeField == null)
            {
                whereClauses.Add(String.Empty);
            }
            else
            {
                foreach (object val in _values)
                {
                    if (val == null)
                    {
                        continue;
                    }
                    switch (_mergeField.type)
                    {
                    case FieldType.smallinteger:
                    case FieldType.integer:
                    case FieldType.biginteger:
                        whereClauses.Add(_mergeField.name + "=" + val.ToString());
                        break;

                    case FieldType.Float:
                    case FieldType.Double:
                        whereClauses.Add(_mergeField.name + "=" + Convert.ToDouble(val).ToString(_nhi));
                        break;

                    case FieldType.boolean:
                        whereClauses.Add(_mergeField.name + "=" + val.ToString());
                        break;

                    case FieldType.String:
                        whereClauses.Add(_mergeField.name + "='" + val.ToString() + "'");
                        break;

                    default:
                        throw new Exception("Can't merge this fieldtype: " + _mergeField.type.ToString());
                    }
                }
            }
            #endregion

            IDatasetElement sElement = base.SourceDatasetElement;
            IFeatureClass   sFc      = base.SourceFeatureClass;

            TargetDatasetElement tElement = base.TargetDatasetElement;
            IDataset             tDs      = base.TargetDataset;
            //IFeatureDatabase tDatabase = base.TargetFeatureDatabase;

            Fields fields = new Fields();
            if (_mergeField != null)
            {
                fields.Add(_mergeField);
            }
            IFeatureClass    tFc       = base.CreateTargetFeatureclass(sFc, fields);
            IFeatureDatabase tDatabase = FeatureDatabase(tFc);

            Report.featureMax = sFc.CountFeatures;
            Report.featurePos = 0;

            bool isPolygonFc = (sFc.GeometryType == geometryType.Polygon);
            foreach (string whereClause in whereClauses)
            {
                ReportProgess("Query Filter: " + SourceData.FilterClause + (String.IsNullOrEmpty(whereClause) ? " AND " + whereClause : String.Empty));

                Feature mergeFeature   = null;;
                bool    attributeAdded = false;
                using (IFeatureCursor cursor = SourceData.GetFeatures(whereClause))
                {
                    IFeature feature;

                    List <IPolygon> polygons = new List <IPolygon>();
                    while ((feature = cursor.NextFeature) != null)
                    {
                        if (mergeFeature == null)
                        {
                            mergeFeature = new Feature();
                        }

                        Report.featurePos++;
                        if (!CancelTracker.Continue)
                        {
                            break;
                        }

                        if (_mergeField != null && attributeAdded == false)
                        {
                            mergeFeature.Fields.Add(new FieldValue(_mergeField.name, feature[_mergeField.name]));
                            attributeAdded = true;
                        }

                        if (isPolygonFc)
                        {
                            if (feature.Shape != null)
                            {
                                if (!(feature.Shape is IPolygon))
                                {
                                    throw new Exception("Wrong argument type :" + feature.Shape.GeometryType.ToString());
                                }
                                polygons.Add(feature.Shape as IPolygon);
                            }
                        }
                        else
                        {
                            if (mergeFeature.Shape == null)
                            {
                                mergeFeature.Shape = feature.Shape;
                            }
                            else
                            {
                                mergeFeature.Shape = Algorithm.Merge(mergeFeature.Shape, feature.Shape, false);
                            }
                        }
                        ReportProgess();
                    }
                    if (isPolygonFc && mergeFeature != null)
                    {
                        ProgressReporterEvent r = new ProgressReporterEvent(MergePolygonReport);
                        mergeFeature.Shape = Algorithm.FastMergePolygon(polygons, CancelTracker, r);
                    }
                }
                if (mergeFeature != null)
                {
                    if (!tDatabase.Insert(tFc, mergeFeature))
                    {
                        throw new Exception(tDatabase.lastErrorMsg);
                    }
                }
                if (!CancelTracker.Continue)
                {
                    break;
                }
            }

            ReportProgess("Flush Features");
            base.FlushFeatureClass(tFc);

            return(base.ToProcessResult(tFc));
        }
コード例 #4
0
ファイル: ActicityBase.cs プロジェクト: jugstalt/gViewGisOS
        public override List <IActivityData> Process()
        {
            IDatasetElement sElement = base.SourceDatasetElement;
            IFeatureClass   sFc      = base.SourceFeatureClass;

            TargetDatasetElement tElement = base.TargetDatasetElement;
            IDataset             tDs      = base.TargetDataset;
            //IFeatureDatabase tDatabase = base.TargetFeatureDatabase;

            IFeatureClass    tFc       = base.CreateTargetFeatureclass(sFc, sFc.Fields);
            IFeatureDatabase tDatabase = FeatureDatabase(tFc);

            Report.featureMax = sFc.CountFeatures;
            Report.featurePos = 0;
            ReportProgess("Query Filter: " + SourceData.FilterClause);

            using (IFeatureCursor cursor = SourceData.GetFeatures(String.Empty))
            {
                IFeature        feature;
                List <IFeature> features = new List <IFeature>();

                ReportProgess("Read/Write Features...");
                while ((feature = cursor.NextFeature) != null)
                {
                    if (feature.Shape == null)
                    {
                        continue;
                    }

                    List <IGeometry> geometries = new List <IGeometry>();
                    #region Dissolve
                    if (feature.Shape is IPolygon)
                    {
                        foreach (IPolygon polygon in Algorithm.SplitPolygonToDonutsAndPolygons((IPolygon)feature.Shape))
                        {
                            geometries.Add(polygon);
                        }
                    }
                    else if (feature.Shape is IPolyline)
                    {
                        foreach (IPath path in Algorithm.GeometryPaths((IPolyline)feature.Shape))
                        {
                            Polyline pLine = new Polyline();
                            pLine.AddPath(path);
                            geometries.Add(pLine);
                        }
                    }
                    else if (feature.Shape is IMultiPoint)
                    {
                        for (int i = 0; i < ((IMultiPoint)feature.Shape).PointCount; i++)
                        {
                            IPoint p = ((IMultiPoint)feature.Shape)[i];
                            if (p != null)
                            {
                                geometries.Add(p);
                            }
                        }
                    }
                    #endregion

                    if (geometries.Count > 0)
                    {
                        foreach (IGeometry geometry in geometries)
                        {
                            Feature f = new Feature(feature);
                            f.Shape = geometry;
                            if (!tDatabase.Insert(tFc, f))
                            {
                                throw new Exception(tDatabase.lastErrorMsg);
                            }
                        }
                    }
                }
            }

            ReportProgess("Flush Features");
            base.FlushFeatureClass(tFc);

            return(base.ToProcessResult(tFc));
        }
コード例 #5
0
ファイル: Triangulation.cs プロジェクト: jugstalt/gViewGisOS
        public override List <IActivityData> Process()
        {
            IDatasetElement sElement = base.SourceDatasetElement;
            IFeatureClass   sFc      = base.SourceFeatureClass;

            ActivityBase.TargetDatasetElement tElement = base.TargetDatasetElement;
            IDataset tDs = base.TargetDataset;
            //IFeatureDatabase tDatabase = base.TargetFeatureDatabase;

            GeometryDef geomDef = new GeometryDef(
                geometryType.Polyline,
                null,
                false);

            IFeatureClass    tFc       = base.CreateTargetFeatureclass(geomDef, sFc.Fields);
            IFeatureDatabase tDatabase = FeatureDatabase(tFc);

            Report.featureMax = sFc.CountFeatures;
            Report.featurePos = 0;
            ReportProgess("Query Filter: " + SourceData.FilterClause);

            Nodes nodes = new Nodes();

            using (IFeatureCursor cursor = SourceData.GetFeatures(String.Empty))
            {
                if (cursor == null)
                {
                    return(null);
                }

                IFeature feature;
                while ((feature = cursor.NextFeature) != null)
                {
                    if (Report.featurePos++ % 100 == 0)
                    {
                        ReportProgess();
                    }

                    if (feature.Shape is IPoint)
                    {
                        nodes.Add((IPoint)feature.Shape);
                    }
                }
            }

            VoronoiGraph voronoi = new VoronoiGraph();

            voronoi.ProgressMessage += new VoronoiGraph.ProgressMessageEventHandler(voronoi_ProgressMessage);
            voronoi.Progress        += new VoronoiGraph.ProgressEventHandler(voronoi_Progress);
            voronoi.Calc(nodes);
            List <IPoint> vertices = voronoi.Nodes;
            Edges         edges    = voronoi.Edges;

            ReportProgess("Write Lines");
            Report.featurePos = 0;
            List <IFeature> features = new List <IFeature>();

            foreach (Edge edge in edges)
            {
                Polyline pLine = new Polyline();
                Path     path  = new Path();
                path.AddPoint(vertices[edge.p1]);
                path.AddPoint(vertices[edge.p2]);
                pLine.AddPath(path);

                Feature feature = new Feature();
                feature.Shape = pLine;

                features.Add(feature);
                Report.featurePos++;
                if (features.Count >= 100)
                {
                    if (!tDatabase.Insert(tFc, features))
                    {
                        throw new Exception(tDatabase.lastErrorMsg);
                    }
                    features.Clear();
                    ReportProgess();
                }
            }

            if (features.Count > 0)
            {
                ReportProgess();
                if (!tDatabase.Insert(tFc, features))
                {
                    throw new Exception(tDatabase.lastErrorMsg);
                }
            }

            ReportProgess("Flush Features");
            base.FlushFeatureClass(tFc);

            return(base.ToProcessResult(tFc));
        }