Example #1
0
        public bool SaveObservationPoint(ObservationPoint observPoint)
        {
            bool result = true;

            try
            {
                var bdObservPoint = context.VisiblilityObservPoints.FirstOrDefault(p => p.OBJECTID == observPoint.Objectid);
                if (bdObservPoint != null)
                {
                    bdObservPoint.Update(observPoint);
                    if (Submit())
                    {
                        log.InfoEx($"Observation Point Row with ObjectId '{observPoint.Objectid}' was saved");
                    }
                }
            }
            catch (MilSpaceDataException ex)
            {
                log.WarnEx(ex.Message);
                if (ex.InnerException != null)
                {
                    log.WarnEx(ex.InnerException.Message);
                }

                result = false;
            }
            catch (Exception ex)
            {
                log.WarnEx($"Unexpected exception:{ex.Message}");
                result = false;
            }
            return(result);
        }
Example #2
0
        public void AddObservPoint(IPoint point, ObservationPoint pointArgs, IFeatureClass featureClass)
        {
            IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)calcWorkspace;

            workspaceEdit.StartEditing(true);
            workspaceEdit.StartEditOperation();


            var pointFeature = featureClass.CreateFeature();

            pointFeature.Shape = point;

            pointFeature.set_Value(featureClass.FindField("TitleOP"), pointArgs.Title);
            pointFeature.set_Value(featureClass.FindField("TypeOP"), pointArgs.Type.ToString());
            pointFeature.set_Value(featureClass.FindField("saffiliation"), pointArgs.Affiliation.ToString());
            pointFeature.set_Value(featureClass.FindField("XWGS"), pointArgs.X);
            pointFeature.set_Value(featureClass.FindField("YWGS"), pointArgs.Y);
            pointFeature.set_Value(featureClass.FindField("HRel"), pointArgs.RelativeHeight);
            pointFeature.set_Value(featureClass.FindField("AvailableHeightLover"), pointArgs.AvailableHeightLover);
            pointFeature.set_Value(featureClass.FindField("AvailableHeightUpper"), pointArgs.AvailableHeightUpper);
            pointFeature.set_Value(featureClass.FindField("AzimuthB"), pointArgs.AzimuthStart);
            pointFeature.set_Value(featureClass.FindField("AzimuthE"), pointArgs.AzimuthEnd);
            pointFeature.set_Value(featureClass.FindField("AzimuthMainAxis"), pointArgs.AzimuthMainAxis);
            pointFeature.set_Value(featureClass.FindField("AnglCameraRotationH"), pointArgs.AngelCameraRotationH);
            pointFeature.set_Value(featureClass.FindField("AnglCameraRotationV"), pointArgs.AngelCameraRotationV);
            pointFeature.set_Value(featureClass.FindField("AnglMinH"), pointArgs.AngelMinH);
            pointFeature.set_Value(featureClass.FindField("AnglMaxH"), pointArgs.AngelMaxH);
            pointFeature.set_Value(featureClass.FindField("dto"), pointArgs.Dto);
            pointFeature.set_Value(featureClass.FindField("soper"), pointArgs.Operator);

            pointFeature.Store();
        }
Example #3
0
        public PayloadParserTests()
        {
            var observationPoint    = new ObservationPoint(35.89167m, 14.5075M);
            var parserConfiguration = new ParserConfiguration(observationPoint, 12345);

            _sut = new PacketFactory(parserConfiguration);
        }
Example #4
0
 public static bool SaveObservationPoint(ObservationPoint observPoint)
 {
     using (var accessor = new VisibilityDataAccess())
     {
         var res = accessor.SaveObservationPoint(observPoint);
         return(res);
     }
 }
Example #5
0
        public override int GetHashCode()
        {
            var hashCode = ObservationPoint.GetHashCode();

            hashCode = (hashCode * 397) ^ EstimatedValue.GetHashCode();
            hashCode = (hashCode * 397) ^ ObservationTime.GetHashCode();

            return(hashCode);
        }
Example #6
0
        public void AddPoint(ObservationPoint point, string featureName, IActiveView activeView)
        {
            var pointGeometry = new PointClass {
                X = (double)point.X, Y = (double)point.Y, SpatialReference = EsriTools.Wgs84Spatialreference
            };

            pointGeometry.Z      = (double)point.RelativeHeight;
            pointGeometry.ZAware = true;

            var featureClass = GetFeatureClass(featureName, activeView);

            GdbAccess.Instance.AddObservPoint(pointGeometry, point, featureClass);
            UpdateObservationPointsList();
        }
        private double GetActualPointMeasurementDepth(ObservationPoint point)
        {
            if (!double.TryParse(point.ObsLocationIndicator, out double indicatorValue))
            {
                indicatorValue = 6;
            }

            if (point.ObsLocationIndicator == "B")
            {
                indicatorValue = 10;
            }

            return(point.Depth * (indicatorValue / 10));
        }
Example #8
0
        public static void Main(string[] args)
        {
            var points = ObservationPoint.LoadFromMpk("ShindoObsPoints.mpk.lz4", true);

            //誤差が蓄積しないタイマーのインスタンスを作成(デフォルトは間隔1000ms+精度1ms↓)
            var timer = new NtpTimer()
            {
                Offset = TimeSpan.FromSeconds(1.1),
            };

            //適当にイベント設定
            timer.Elapsed += time =>
            {
                Console.WriteLine($"\nsys: {DateTime.Now.ToString("HH:mm:ss.fff")} ntp:{time.ToString("HH:mm:ss.fff")}");
                try
                {
                    //画像を取得して結果を計算 (良い子のみんなはawaitを使おうね!)
                    var result = points.ParseIntensityFromParameterAsync(time, false).Result;

                    //現在の最大震度
                    Console.WriteLine($"MaxInt: raw:{result.Max(r => r.AnalysisResult)} jma:{result.Max(r => r.AnalysisResult).ToJmaIntensity().ToLongString()}");
                }
                catch (AggregateException ex)
                {
                    var ex2 = ex.InnerException;
                    if (!ex2.Message.Contains("404"))
                    {
                        return;
                    }
                    timer.Offset += TimeSpan.FromMilliseconds(100);
                    Console.WriteLine($"404のためオフセット調整 to:{timer.Offset.TotalSeconds}s");
                }
            };

            //タイマー開始
            timer.Start().Wait();

            Console.WriteLine("Enterキー入力で終了");

            //改行入力待ち
            Console.ReadLine();

            //タイマー終了
            timer.Stop();
        }
        public MainWindow()
        {
            InitializeComponent();

            map.Map            = MessagePackSerializer.Deserialize <TopologyMap>(Properties.Resources.WorldMap, MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4BlockArray));
            map.Zoom           = 5;
            map.CenterLocation = new Location(36.474f, 135.264f);

            //TODO: 設定ファイルからデフォルトの値読み込み
            //SetPoints(ObservationPoint.LoadFromMpk("ShindoObsPoints.mpk.lz4", true));
            gridView.ItemDoubleClicked += () =>
            {
                var point = gridView.SelectedPoint;
                if (point == null)
                {
                    return;
                }
                map.Navigate(new Rect(point.Location.AsPoint() - new Vector(.4, .4), point.Location.AsPoint() + new Vector(.4, .4)), new Duration(TimeSpan.FromSeconds(.25)));
            };
            gridView.SelectedPointChanged += e =>
            {
                if (e.oldValue != null && map.RenderObjects.Cast <RenderObjects.ObservationPointRenderObject>().FirstOrDefault(r => r.ObservationPoint == e.oldValue) is RenderObjects.ObservationPointRenderObject ro)
                {
                    ro.IsSelected = false;
                }
                if (e.newValue != null && map.RenderObjects.Cast <RenderObjects.ObservationPointRenderObject>().FirstOrDefault(r => r.ObservationPoint == e.newValue) is RenderObjects.ObservationPointRenderObject rn)
                {
                    rn.IsSelected = true;
                }
                imageMap.SelectedPoint = e.newValue;
                map.InvalidateChildVisual();
            };
            imageMap.PointClicked += e =>
            {
                switch (e.button)
                {
                case MouseButton.Middle:                         // 選択
                {
                    var point = imageMap.Points?.FirstOrDefault(p => p.Point == e.location && p != gridView.SelectedPoint);
                    gridView.SelectedPoint = point;
                }
                break;

                case MouseButton.Left:                         // 移動
                {
                    if (gridView.SelectedPoint == null)
                    {
                        break;
                    }
                    gridView.SelectedPoint.Point = e.location;
                    gridView.InvalidateVisual();
                    imageMap.InvalidateVisual();
                    map.InvalidateChildVisual();
                }
                break;

                case MouseButton.Right:                         // 削除
                {
                    if (gridView.SelectedPoint?.Point != e.location)
                    {
                        break;
                    }
                    if (MessageBox.Show("登録された座標を削除しますか?", "確認", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        gridView.SelectedPoint.Point = null;
                        gridView.InvalidateVisual();
                        imageMap.InvalidateVisual();
                        map.InvalidateChildVisual();
                    }
                }
                break;
                }
            };
            linkcheckMenuItem.Click += async(s, e) =>
            {
                if (gridView.Points == null)
                {
                    return;
                }
                linkcheckMenuItem.IsEnabled = false;
                try
                {
                    var data = await new AppApi(gridView.Points).GetLinkedRealtimeData(DateTime.Now.AddMinutes(-1), RealtimeDataType.Shindo);
                    if (data.Data == null)
                    {
                        MessageBox.Show($"APIの震度情報の取得に失敗しました ({data.StatusCode})");
                        return;
                    }
                    foreach (var datum in data.Data)
                    {
                        var lp = datum.ObservationPoint;
                        if (lp.Point != null)
                        {
                            var ro = map.RenderObjects.Cast <RenderObjects.ObservationPointRenderObject>().FirstOrDefault(r => r.ObservationPoint == lp.Point);
                            ro.IsLinked = true;
                        }
                    }
                }
                finally
                {
                    Dispatcher.Invoke(() =>
                    {
                        linkcheckMenuItem.IsEnabled = true;
                        map.InvalidateChildVisual();
                    });
                }
            };

            loadMenuItem.Click += (s, e) =>
            {
                var dialog = new OpenFileDialog
                {
                    Filter           = "MessagePack(LZ4)|*.mpk.lz4|MessagePack(未圧縮)|*.mpk|CSV|*.csv|Json|*.json|EqWatch互換|*.dat",
                    FilterIndex      = 1,
                    RestoreDirectory = true
                };
                if (dialog.ShowDialog() == true)
                {
                    var filename = dialog.FileName;
                    SetPoints(dialog.FilterIndex switch
                    {
                        1 => ObservationPoint.LoadFromMpk(filename, true),
                        2 => ObservationPoint.LoadFromMpk(filename, false),
                        3 => ObservationPoint.LoadFromCsv(filename).points,
                        4 => ObservationPoint.LoadFromJson(filename),
                        5 => ImportEqWatchData(filename),
                        _ => null
                    });
                }
 public PacketFactory(ParserConfiguration parserConfiguration)
 {
     _parserConfiguration = parserConfiguration;
     _observationPoint    = _parserConfiguration.ObservationPoint;
     _distanceCalculator  = new DistanceCalculator();
 }
Example #11
0
 public override string ToString()
 {
     return($"FlashObservation: ObservationPoint = {ObservationPoint.ToString()}, Intensity = {Intensity.ToString()}, " +
            $"Duration(ms) = {DurationMs.ToString()}, ObservationTime = {ObservationTime.ToString()}, EstimatedValue = {EstimatedValue.ToString()}");
 }
Example #12
0
 /// <summary>
 /// ObservationPointを元にImageAnalysisResultを初期化します。
 /// </summary>
 /// <param name="point">元にするObservationPoint</param>
 public ImageAnalysisResult(ObservationPoint point)
 {
     ObservationPoint = point;
 }
Example #13
0
 public ParserConfiguration(ObservationPoint observationPoint, int listenOnPort)
 {
     ObservationPoint = observationPoint;
     ListenOnPort     = listenOnPort;
 }
 private void CreateNewPoint(ObservationPoint point)
 {
     controller.AddPoint(point, cmbObservPointsLayers.SelectedItem.ToString(), ActiveView);
 }
Example #15
0
        public static IFeatureClass CreateOPFeatureClass(WizardResult calcResult, IFeatureClass observatioPointsFeatureClass,
                                                         IActiveView activeView, IRaster raster)
        {
            var calcObservPointsFeatureClass = VisibilityCalcResults.GetResultName(VisibilityCalculationResultsEnum.ObservationPoints, calcResult.TaskName);

            var observPointTemporaryFeatureClass =
                GdbAccess.Instance.GenerateTemporaryFeatureClassWithRequitedFields(observatioPointsFeatureClass.Fields, calcObservPointsFeatureClass);

            bool   isCircle;
            double maxAzimuth  = 0;
            double minAzimuth  = 360;
            double maxDistance = 0;

            calcResult.ObservationStation.Project(activeView.FocusMap.SpatialReference);

            var observationStationPolygon   = calcResult.ObservationStation as IPolygon;
            var observStationEnvelope       = observationStationPolygon.Envelope;
            var observStationEnvelopePoints = new IPoint[] { observStationEnvelope.LowerLeft, observStationEnvelope.LowerRight,
                                                             observStationEnvelope.UpperRight, observStationEnvelope.UpperLeft };

            var observerPointGeometry = new PointClass
            {
                X = calcResult.ObservationPoint.X.Value,
                Y = calcResult.ObservationPoint.Y.Value,
                SpatialReference = EsriTools.Wgs84Spatialreference
            };

            observerPointGeometry.Project(activeView.FocusMap.SpatialReference);

            observerPointGeometry.AddZCoordinate(raster);
            observerPointGeometry.ZAware = true;

            if (double.IsNaN(observerPointGeometry.Z))
            {
                throw new MilSpacePointOutOfRatserException(calcResult.ObservationPoint.Objectid, calcResult.RasterLayerName);
            }

            var minDistance = FindMinDistance(observStationEnvelopePoints, observerPointGeometry);


            // ---- Get min and max azimuths ----

            var points = EsriTools.GetPointsFromGeometries(new IGeometry[] { calcResult.ObservationStation },
                                                           observerPointGeometry.SpatialReference,
                                                           out isCircle).ToArray();

            bool isPointInside = EsriTools.IsPointOnExtent(observStationEnvelope, observerPointGeometry);

            // Set azimuth for circle polygon
            if (isCircle && !isPointInside)
            {
                for (int i = 0; i < observStationEnvelopePoints.Length; i++)
                {
                    var line = new Line()
                    {
                        FromPoint        = observerPointGeometry,
                        ToPoint          = observStationEnvelopePoints[i],
                        SpatialReference = observerPointGeometry.SpatialReference
                    };

                    if (i == 0)
                    {
                        maxDistance = line.Length;
                    }
                    else if (maxDistance < line.Length)
                    {
                        maxDistance = line.Length;
                    }

                    if (minAzimuth > line.PosAzimuth())
                    {
                        minAzimuth = line.PosAzimuth();
                    }

                    if (maxAzimuth < line.PosAzimuth())
                    {
                        maxAzimuth = line.PosAzimuth();
                    }
                }
            }
            else
            {
                EsriTools.CreateDefaultPolylinesForFun(observerPointGeometry, points, new IGeometry[] { calcResult.ObservationStation },
                                                       isCircle, isPointInside, -1, out minAzimuth, out maxAzimuth, out maxDistance).ToList();
            }
            // ---- End. Get min and max azimuths ----

            // observerPointGeometry.Project(activeView.FocusMap.SpatialReference);
            var pointCopy = observerPointGeometry.CloneWithProjecting();

            (pointCopy as PointClass).ZAware = true;

            int idObserPooint = 0;

            for (var currentHeight = calcResult.FromHeight; currentHeight <= calcResult.ToHeight; currentHeight += calcResult.Step)
            {
                double maxTiltAngle = -90;
                double minTiltAngle = 90;

                var height = currentHeight;

                // Set parameters for case if point located into the polygon
                if (isCircle && isPointInside)
                {
                    minTiltAngle = -90;
                    minDistance  = 0;
                }

                for (int i = 0; i < observStationEnvelopePoints.Length; i++)
                {
                    var currentTitleAngle = EsriTools.FindAngleByDistanceAndHeight(height, observerPointGeometry, observStationEnvelopePoints[i], raster);

                    if (minTiltAngle > currentTitleAngle)
                    {
                        minTiltAngle = currentTitleAngle;
                    }

                    if (maxTiltAngle < currentTitleAngle)
                    {
                        maxTiltAngle = currentTitleAngle;
                    }
                }

                // Create observation point copy with changing height, distance and angles values
                ObservationPoint currentObservationPoint = calcResult.ObservationPoint.ShallowCopy();
                currentObservationPoint.RelativeHeight  = currentHeight;
                currentObservationPoint.AngelMinH       = minTiltAngle;
                currentObservationPoint.AngelMaxH       = maxTiltAngle;
                currentObservationPoint.AzimuthStart    = minAzimuth;
                currentObservationPoint.AzimuthEnd      = maxAzimuth;
                currentObservationPoint.InnerRadius     = minDistance;
                currentObservationPoint.OuterRadius     = maxDistance;
                currentObservationPoint.AzimuthMainAxis = calcResult.ObservationPoint.AzimuthMainAxis;
                currentObservationPoint.Id = idObserPooint.ToString();

                GdbAccess.Instance.AddObservPoint(pointCopy, currentObservationPoint, observPointTemporaryFeatureClass);
                idObserPooint++;
            }

            return(observPointTemporaryFeatureClass);
        }
Example #16
0
 public ObservationPointRenderObject(ObservationPoint point)
 {
     ObservationPoint = point;
 }
Example #17
0
        public static async Task Main(string[] args)
        {
            var points = ObservationPoint.LoadFromMpk("ShindoObsPoints.mpk.lz4", true);

            using (var appApi = new AppApi(points))
                using (var webApi = new WebApi())
                {
                    //タイマーのインスタンスを作成
                    var timer = new SecondBasedTimer()
                    {
                        Offset = TimeSpan.FromSeconds(3.1),                //1.1
                    };

                    //適当にイベント設定
                    timer.Elapsed += async time =>
                    {
                        Console.WriteLine($"\nsys: {DateTime.Now.ToString("HH:mm:ss.fff")} ntp:{time.ToString("HH:mm:ss.fff")}");
                        try
                        {
                            try
                            {
                                {
                                    //APIから結果を計算 (良い子のみんなはawaitを使おうね!)
                                    var result = await appApi.GetLinkedRealTimeData(time, RealTimeDataType.Shindo, false);

                                    //現在の最大震度
                                    Console.WriteLine($"*API* 最大震度: 生:{result.Max(r => r.Value)} jma:{result.Max(r => r.Value).ToJmaIntensity().ToLongString()} {result.Count(r => r.Point.point != null)},{result.Count(r => r.Point.point == null)}");
                                    //最大震度観測点(の1つ)
                                    //var maxPoint = result.OrderByDescending(r => r.Value).First();
                                    //Console.WriteLine($"最大観測点 {maxPoint.Point.site.Prefefecture.GetLongName()} {maxPoint.Point.point.Name} 震度:{maxPoint.Value}({maxPoint.Value.ToJmaIntensity().ToLongString()})");
                                }
                            }
                            catch (KyoshinMonitorException ex1)
                            {
                                Console.WriteLine($"API HTTPエラー発生 {ex1.StatusCode}({(int)ex1.StatusCode})");
                            }
                            try
                            {
                                //APIから結果を計算 (良い子のみんなはawaitを使おうね!)
                                var result = await webApi.ParseIntensityFromParameterAsync(points, time);

                                //現在の最大震度
                                Console.WriteLine($"*WEB* 最大震度: 生:{result.Max(r => r.AnalysisResult)} jma:{result.Max(r => r.AnalysisResult).ToJmaIntensity().ToLongString()}");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine($"*WEB* 取得失敗 " + ex.Message);
                            }
                        }
                        catch (KyoshinMonitorException ex)
                        {
                            Console.WriteLine($"HTTPエラー発生 {ex.StatusCode}({(int)ex.StatusCode})");
                            if (ex.StatusCode != HttpStatusCode.NotFound)
                            {
                                return;
                            }
                            timer.Offset += TimeSpan.FromMilliseconds(100);
                            Console.WriteLine($"404のためオフセット調整 to:{timer.Offset.TotalSeconds}s");
                        }
                    };

                    //タイマー開始
                    timer.Start((await NtpAssistance.GetNetworkTimeWithNtp()) ?? throw new Exception());

                    Console.WriteLine("Enterキー入力で終了");

                    //改行入力待ち
                    Console.ReadLine();

                    //タイマー終了
                    timer.Stop();
                }
        }