using System; using System.Collections.Generic; using System.Drawing; using System.Globalization; using System.IO; using System.Linq; using InABox.Core; namespace Comal.Classes { public class GeoJSONCrsProperties { public string Name { get; set; } } public class GeoJSONCrs { public string Type { get; set; } public GeoJSONCrsProperties Properties { get; set; } } public class GeoJSONFeatureGeometry { public string Type { get; set; } public List>>> Coordinates { get; set; } public List Points() { var result = new List(); var list = Coordinates?.FirstOrDefault()?.FirstOrDefault() ?? new List>(); foreach (var item in list) { if (item.Count == 2) result.Add(new PointF(item[0], item[1])); } return result; } public Tuple Bounds() { float minX = float.MaxValue, minY = float.MaxValue, maxX = float.MinValue, maxY = float.MinValue; var points = Points(); foreach (var point in points) { if (point.X < minX) minX = point.X; if (point.X > maxX) maxX = point.X; if (point.Y < minY) minY = point.Y; if (point.Y > maxY) maxY = point.Y; } return new Tuple(new PointF(minX, minY), new PointF(maxX, maxY)); } } public class GeoJSONFeatureProperties { public int? Land_ID { get; set; } public string? Road_Number_type { get; set; } public string? Road_Number_1 { get; set; } public string? Road_Number_2 { get; set; } public string? Lot_Number { get; set; } public string? Road_Name { get; set; } public string? Road_Type { get; set; } public string? Road_Suffix { get; set; } public string? Locality { get; set; } public string? View_Scale { get; set; } public double? ST_Area_Shape_ { get; set; } public double? ST_Perimeter_Shape_ { get; set; } public string ID() => Land_ID?.ToString() ?? ""; public string FullAddress() => $"{Street()} {Suburb()} {State()} {Country()}".Trim().ToUpper(); public String Street() { List result = new List(); if (string.IsNullOrWhiteSpace(Lot_Number)) { if (!string.IsNullOrWhiteSpace(Road_Number_2)) result.Add($"{Road_Number_1 ?? ""}/{Road_Number_2 ?? ""}"); else result.Add(Road_Number_1 ?? ""); } else result.Add($"LOT {Lot_Number ?? ""}"); result.Add(Road_Name ?? ""); result.Add(Road_Type ?? ""); return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(string.Join(" ", result).ToLower()); } public String Suburb() => CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Locality?.ToLower() ?? ""); public String State() => ""; public String Postcode() => ""; public String Country() => ""; } public class GeoJSONFeature { public string? Type { get; set; } public GeoJSONFeatureProperties? Properties { get; set; } public GeoJSONFeatureGeometry? Geometry { get; set; } } public class GeoJSONFile { public string? Type { get; set; } public string? Name { get; set; } public GeoJSONCrs? Crs { get; set; } public List? Features { get; set; } public static GeoJSONFile? Load(string filename) { var fs = new FileStream(filename, FileMode.Open); var geojson = Serialization.Deserialize(fs); return geojson; } } public class GeoFence : Entity, IRemotable, IPersistent { public String Street { get; set; } public String City { get; set; } public String State { get; set; } public String Country { get; set; } public String PostCode { get; set; } public string FullAddress { get; set; } public double MinX { get; set; } public double MinY { get; set; } public double MaxX { get; set; } public double MaxY { get; set; } public string Geometry { get; set; } } }