// Copyright (c) 2022 - schick Informatik // bsmd.AIS2Service [MonitorZone.cs]: %UserDisplayName% // Description: Represents a geographical area that should be checked against // ship positions using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; namespace bsmd.AIS2Service { #region class MonitorZone internal class MonitorZone { #region fields private int _id; // PK from database private List _vertices = new List(); private List _assignments = new List(); private string _name; #endregion #region Construction public MonitorZone(int id, string name) { _id = id; _name = name; } #endregion #region Properties public int Id { get { return _id; } } public string Name { get { return _name; } } public List Vertices { get { return _vertices; } } public List Assignments { get { return _assignments; } } public bool Active { get; set; } #endregion #region public methods public bool IsPointInPolygon4(GeoPoint testPoint) { bool result = false; int j = _vertices.Count() - 1; for (int i = 0; i < _vertices.Count(); i++) { if (_vertices[i].Lat < testPoint.Lat && _vertices[j].Lat >= testPoint.Lat || _vertices[j].Lat < testPoint.Lat && _vertices[i].Lat >= testPoint.Lat) { if (_vertices[i].Lon + (testPoint.Lat - _vertices[i].Lat) / (_vertices[j].Lat - _vertices[i].Lat) * (_vertices[j].Lon - _vertices[i].Lon) < testPoint.Lon) { result = !result; } } j = i; } return result; } #endregion } #endregion #region class GeoPoint internal class GeoPoint { private int _id; public GeoPoint(int id) { _id = id; } public int Id { get { return _id; } } public double Lat { get; set; } public double Lon { get; set; } } #endregion #region class MonitorAssignment internal class MonitorAssignment { private int _id; public MonitorAssignment(int id) { _id = id; } public enum ZoneMonitorType { INACTIVE, ENTER, EXIT, PASSTHROUGH, // outside - enter - inside - exit - outside LEAVE_AND_RETURN // inside - exit - outside - enter - insider } public int Id { get { return _id; } } public int MMSI { get; set; } public ZoneMonitorType MonitorType { get; set; } = ZoneMonitorType.INACTIVE; } #endregion }