123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- 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<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> 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<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 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 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 serializer = new Newtonsoft.Json.JsonSerializer();
- using var sr = new StreamReader(filename);
- using var jtr = new Newtonsoft.Json.JsonTextReader(sr);
- var geojson = serializer.Deserialize<GeoJSONFile>(jtr);
- return geojson;
- }
- }
|