108 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			108 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C#
		
	
	
	
| 
								 | 
							
								using LY.App.Common;
							 | 
						|||
| 
								 | 
							
								using NetTopologySuite.Algorithm;
							 | 
						|||
| 
								 | 
							
								using NetTopologySuite.Geometries;
							 | 
						|||
| 
								 | 
							
								using Newtonsoft.Json;
							 | 
						|||
| 
								 | 
							
								using Pipelines.Sockets.Unofficial.Arenas;
							 | 
						|||
| 
								 | 
							
								using SqlSugar;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace LY.App.Model
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    /// <summary>
							 | 
						|||
| 
								 | 
							
								    /// 多边形实体
							 | 
						|||
| 
								 | 
							
								    /// </summary>
							 | 
						|||
| 
								 | 
							
								    public class MultPolygonEntity : BaseEntity
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 空间位置点数据
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        [SugarColumn(QuerySql = "st_astext(location)", ColumnDataType = "point", ColumnName = "location",
							 | 
						|||
| 
								 | 
							
								            UpdateSql = "ST_GeomFromText(@location)",
							 | 
						|||
| 
								 | 
							
								            InsertSql = "ST_GeomFromText(@location)", IsNullable = true, ColumnDescription = "空间位置点数据")]
							 | 
						|||
| 
								 | 
							
								        [JsonIgnore]
							 | 
						|||
| 
								 | 
							
								        public string? Location { get; set; } //   Geometry 
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 空间面数据
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        [SugarColumn(QuerySql = "st_astext(region)", ColumnDataType = "multipolygon", ColumnName = "region",
							 | 
						|||
| 
								 | 
							
								            UpdateSql = "ST_GeomFromText(@region)",
							 | 
						|||
| 
								 | 
							
								            InsertSql = "ST_GeomFromText(@region)", IsNullable = true, ColumnDescription = "空间面数据")]
							 | 
						|||
| 
								 | 
							
								        [JsonIgnore]
							 | 
						|||
| 
								 | 
							
								        public string? Region { get; set; } //MultiPolygon  Geometry
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        [SugarColumn(IsIgnore = true)]
							 | 
						|||
| 
								 | 
							
								        public string RegionJson { get; set; }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 空间位置点经度
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        public double Lon { get; set; }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 空间位置点纬度
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        public double Lat { get; set; }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 空间位置点Json数据
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        public void SetRegionJson()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            RegionJson = "";
							 | 
						|||
| 
								 | 
							
								            if (!string.IsNullOrWhiteSpace(Region))
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                var geo = GeoJsonHelper.FromWKT(Region);
							 | 
						|||
| 
								 | 
							
								                if (geo != null)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    RegionJson = GeoJsonHelper.GetGeoJson(geo);
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 设置空间位置点
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="region"></param>
							 | 
						|||
| 
								 | 
							
								        public void SetRegion(MultiPolygon region)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            if (region != null)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                Region = region.AsText();
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 设置空间位置点
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="lon"></param>
							 | 
						|||
| 
								 | 
							
								        /// <param name="lat"></param>
							 | 
						|||
| 
								 | 
							
								        public void SetLocation(double lon, double lat)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            Lon = lon;
							 | 
						|||
| 
								 | 
							
								            Lat = lat;
							 | 
						|||
| 
								 | 
							
								            SetLocation();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 设置空间位置点
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="region"></param>
							 | 
						|||
| 
								 | 
							
								        public void SetRegionJson(string region)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            RegionJson = "";
							 | 
						|||
| 
								 | 
							
								            if (!string.IsNullOrWhiteSpace(region))
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                var geo = GeoJsonHelper.FromWKT(region);
							 | 
						|||
| 
								 | 
							
								                if (geo != null)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    RegionJson = GeoJsonHelper.GetGeoJson(geo);
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 设置空间位置点
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        public void SetLocation()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            Location = $"POINT({Lon} {Lat})";
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |