Ejemplo n.º 1
0
        public override bool Run(ITaskHandle task)
        {
            var span = TimeSpan.FromSeconds(SecondsPerStep);

            Log.Info(Name + ": start");

            for (int i = 0; i < 100; i++)
            {
                Thread.Sleep(span);

                int val = i;

                task.CheckPauseAndCancel();

                task.Progress.Update("Running...", val);

                Log.Info("Running: " + i);
            }

            task.Progress.Clear();

            Log.Info(Name + ": end");

            return(true);   // depends on the run in background check
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Runs the tool.
        /// </summary>
        public override bool Run(ITaskHandle task)
        {
            var fs    = Input.Datasource;
            var fsNew = fs.Clone(GeometryType.Point);

            int lastPercent = 0;

            var features = Input.Datasource.GetFeatures(Input.SelectedOnly);

            for (int i = 0; i < features.Count; i++)
            {
                task.CheckPauseAndCancel();
                task.Progress.TryUpdate("Calculating...", i, features.Count, ref lastPercent);

                var gm = features[i].Geometry;

                if (AllParts)
                {
                    var list = gm.Explode();
                    foreach (var gmPart in list)
                    {
                        ProcessGeometry(gmPart, fs, i, fsNew);
                    }
                }
                else
                {
                    ProcessGeometry(gm, fs, i, fsNew);
                }
            }

            task.Progress.Clear();

            Output.Result = fsNew;
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Runs the tool.
        /// </summary>
        /// <returns>True on success, which closes the view</returns>
        public override bool Run(ITaskHandle task)
        {
            Log.Debug("Creating {0} random points", NumPoints);

            var extents = InputLayer.Datasource.Envelope;

            var fs = new FeatureSet(GeometryType.Point);

            fs.Projection.CopyFrom(InputLayer.Datasource.Projection);

            var vector = InputLayer as IVectorInput;

            if (vector != null && vector.SelectedOnly)
            {
                // Get the extent, taking into account selected shapes:
                extents = vector.Datasource.GetSelectedExtents();
            }

            var random      = new Random();
            var lastPercent = 0;

            for (int i = 0; i < NumPoints; i++)
            {
                task.CheckPauseAndCancel();
                var x       = extents.MinX + (extents.Width * random.NextDouble());
                var y       = extents.MinY + (extents.Height * random.NextDouble());
                var feature = new Geometry(GeometryType.Point);
                feature.Points.Add(new Coordinate(x, y));
                fs.Features.EditAdd(feature);

                task.Progress.TryUpdate("Running...", i, NumPoints, ref lastPercent);
            }

            task.Progress.Clear();
            Log.Debug("New feature set has {0} features", fs.NumFeatures);

            OutputLayer.Result = fs;

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Performs the main calculation.
        /// </summary>
        private bool Calcualte(ITaskHandle task)
        {
            var fs = GetWgs84FeatureSet();

            if (fs == null)
            {
                string proj = Input.Datasource.Projection.ExportToProj4();
                Log.Warn("Failed to reproject datasource to WGS84: {0}", null, proj);
                return(false);
            }

            var features = fs.GetFeatures(Input.SelectedOnly);

            int lastPercent = 0;

            var table      = Input.Datasource.Table;
            int fieldIndex = table.Fields.IndexByName(FieldName);

            for (int i = 0; i < features.Count; i++)
            {
                task.CheckPauseAndCancel();
                task.Progress.TryUpdate("Calculating...", i, features.Count, ref lastPercent);

                var ft = features[i];

                double area = GeodesicUtils.GeodesicArea(ft.Geometry);

                area = UnitConversionHelper.Convert(AreaUnits.SquareMeters, Units, area);

                table.EditCellValue(fieldIndex, ft.Index, area);
            }

            if (fs.InternalObject != Input.Datasource.InternalObject)
            {
                // it's a reprojected one
                fs.Dispose();
            }

            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Validates shapes and returns list of errors.
        /// </summary>
        private IEnumerable <ErrorInfo> GetErrors(IFeatureSet fs, ITaskHandle task)
        {
            int lastPercent = 0;

            for (int i = 0; i < fs.NumFeatures; i++)
            {
                task.CheckPauseAndCancel();
                task.Progress.TryUpdate("Calculating...", i, fs.NumFeatures, ref lastPercent);

                var gm = fs.Features[i].Geometry;
                if (!gm.IsValid)
                {
                    var info = ValidationHelper.GetErrorInfo(fs, i, gm.IsValidReason);

                    Log.Info(info.Message);

                    yield return(info);
                }
            }

            task.Progress.Clear();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Runs the tool.
        /// </summary>
        public override bool Run(ITaskHandle task)
        {
            var fs = Input.Datasource;

            var fsNew = fs.Clone(fs.GeometryType);

            if (!TrySaveForAppendMode(Output, fsNew))
            {
                return(false);
            }

            var lastPercent = 0;

            var features = Input.Datasource.GetFeatures(Input.SelectedOnly);

            for (var i = 0; i < features.Count; i++)
            {
                task.CheckPauseAndCancel();
                task.Progress.TryUpdate("Calculating...", i, features.Count, ref lastPercent);

                var ft = features[i];

                var gm         = ft.Geometry.Clone(fs.GeometryType);
                var shapeIndex = fsNew.Features.EditAdd(gm);

                if (shapeIndex != -1)
                {
                    fs.Table.CopyAttributes(ft.Index, fsNew.Table, shapeIndex);
                }
            }

            task.Progress.Clear();

            Output.Result = fsNew;

            return(true);
        }