| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 | 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<List<List<List<float>>>> Coordinates { get; set; }        public List<PointF> Points()        {            var result = new List<PointF>();            var list = Coordinates?.FirstOrDefault()?.FirstOrDefault() ?? new List<List<float>>();            foreach (var item in list)            {                if (item.Count == 2)                    result.Add(new PointF(item[0], item[1]));            }            return result;        }                public Tuple<PointF,PointF> 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<PointF,PointF>(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<String> result = new List<string>();            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<GeoJSONFeature>? Features { get; set; }        public static GeoJSONFile? Load(string filename)        {            var fs = new FileStream(filename, FileMode.Open);            var geojson = Serialization.Deserialize<GeoJSONFile>(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; }    }    }
 |