public override void UpdateView()
        {
            bool ready = Model.Points.Count(p => p.Selected) >= 3;

            pointPairGrid1.AdjustColumnWidths();

            btnApply.Enabled       = ready && Model.Points.All(p => p.Complete);
            btnRemovePoint.Enabled = pointPairGrid1.Adapter.SelectedItem != null;
            btnZoomToPoint.Enabled = pointPairGrid1.Adapter.SelectedItem != null;
            btnClearPoints.Enabled = Model.Points.Any();

            statusPointCount.Text = "Number of points: " + Model.ActivePoints.Count();

            double value = UnitConversionHelper.Convert(_context.Map.MapUnits, LengthUnits.Meters, Model.StdError);

            statusError.Text = "Error: " + value.ToString("0.00 m");

            UpdateStatusMessage();

            if (Model.Registered)
            {
                btnApply.SendToBack();
            }
            else
            {
                btnCancel.SendToBack();
            }
        }
        /// <summary>
        /// Runs the tool.
        /// </summary>
        public override bool Run(ITaskHandle task)
        {
            var units     = Input.Datasource.GetLengthUnits();
            var tolerance = UnitConversionHelper.Convert(Tolerance.Units, units, Tolerance.Value);

            Log.Info("Tolerance in datasource units: {0} {1}", tolerance, units.EnumToString());

            var fs = Input.Datasource.SimplifyLines(tolerance, Input.SelectedOnly);

            Output.Result = fs;

            return(true);
        }
        private void OnZoomToPointClick(object sender, EventArgs e)
        {
            var point = pointPairGrid1.Adapter.SelectedItem;

            if (point == null)
            {
                return;
            }

            int index = Model.Points.IndexOf(point);

            double pad = UnitConversionHelper.Convert(_context.Map.MapUnits, LengthUnits.Meters, 1000.0);

            ZoomToPoint(_fs1, index, pad, mapControl1);

            ZoomToPoint(_fs2, index, 100.0, mapControl2);
        }
Beispiel #4
0
        public async Task ConvertUnit(IDialogContext context, LuisResult result)
        {
            string[] measure = result.Entities.Where(x => x.Type == "Measure").FirstOrDefault().Entity.Split(' ');

            string[] unit = result.Entities.Where(x => x.Type == "ToMeasure").FirstOrDefault().Entity.Split(' ');

            var fromAmount = measure[0];

            var massType = measure[1];

            string returnMessage = UnitConversionHelper.Convert(Convert.ToDouble(fromAmount), massType, unit[1]);

            var entities = new List <EntityRecommendation>(result.Entities);

            await context.PostAsync(returnMessage);

            context.Wait(MessageReceived);
        }
Beispiel #5
0
        /// <summary>
        /// Provide execution logic for the tool.
        /// </summary>
        public override bool Run(ITaskHandle task)
        {
            var units = Input.Datasource.GetLengthUnits();

            var bufferDistance = UnitConversionHelper.Convert(BufferDistance.Units, units, BufferDistance.Value);

            var success = false;

            if (Output.MemoryLayer)
            {
                Output.Result = Input.Datasource.BufferByDistance(bufferDistance, NumSegments, Input.SelectedOnly,
                                                                  MergeResults);
            }
            else
            {
                success = GisUtils.Instance.BufferByDistance(Input.Datasource, Input.SelectedOnly, bufferDistance,
                                                             NumSegments, MergeResults, Output.Filename, Output.Overwrite);
            }

            return(Output.Result != null || success);
        }
        /// <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);
        }
        private void Calculate()
        {
            var map   = _context.Map;
            var table = Model.Table;

            const string msg = "Updating measurements";

            GlobalListeners.ReportProgress(string.Empty, 0, msg);
            int featureCount = Model.Features.Count;

            foreach (var ft in Model.Features)
            {
                GlobalListeners.ReportProgress(string.Empty, Convert.ToInt32((ft.Index + 1) * 100.0 / featureCount), msg);

                var g = ft.Geometry;

                if (_lengthInfo.Active)
                {
                    double length = map.GeodesicLength(g);

                    length = UnitConversionHelper.Convert(LengthUnits.Meters, View.LengthUnits, length);

                    table.EditCellValue(_lengthInfo.FieldIndex, ft.Index, length);
                }

                if (_areaInfo.Active)
                {
                    double area = map.GeodesicArea(g);

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

                    table.EditCellValue(_areaInfo.FieldIndex, ft.Index, area);
                }
            }

            GlobalListeners.ClearProgress();
        }