using System; using System.Collections.Generic; using System.Drawing; using System.Globalization; using System.IO; using System.Linq; using InABox.Core; namespace PRSServer.Engines.GPS; 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 BoundingBox() { 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 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 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 serializer = new Newtonsoft.Json.JsonSerializer(); using var sr = new StreamReader(filename); using var jtr = new Newtonsoft.Json.JsonTextReader(sr); var geojson = serializer.Deserialize(jtr); return geojson; } }