| | |
| | | using Microsoft.ClearScript; |
| | | using Microsoft.ClearScript.V8; |
| | | using Npgsql; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Data.Common; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Web; |
| | | using Turf.Models; |
| | | using static Mono.Security.X509.X520; |
| | | |
| | | namespace Turf.cs |
| | | { |
| | |
| | | |
| | | public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory; |
| | | |
| | | private static string js; |
| | | private static PostgreHelper _dbHelper; |
| | | |
| | | public string TurfJS |
| | | public static PostgreHelper DBHelper |
| | | { |
| | | get |
| | | { |
| | | if (null == js) |
| | | if (null == _dbHelper) |
| | | { |
| | | string jsFile = Path.Combine(BaseDir, "js\\turf.min.6.5.js"); |
| | | if (File.Exists(jsFile)) |
| | | { |
| | | js = File.ReadAllText(jsFile); |
| | | } |
| | | _dbHelper = new PostgreHelper(); |
| | | } |
| | | |
| | | return js; |
| | | return _dbHelper; |
| | | } |
| | | } |
| | | |
| | | public double CalcArea(string code) |
| | | public static string selectCoordinatesByCodeSql = "select ST_X(geom) x, ST_Y(geom) y from bs.s_explorationpoint b where dirid like @code and geom is not null"; |
| | | |
| | | public static string selectCoordinates(string code) |
| | | { |
| | | DbParameter dp = new NpgsqlParameter("@code", code + "%"); |
| | | |
| | | DataTable dt = DBHelper.GetDataTable(selectCoordinatesByCodeSql, dp); |
| | | if (null == dt || 0 == dt.Rows.Count) return null; |
| | | |
| | | List<Coordinate> list = ModelHandler.FillModel<Coordinate>(dt); |
| | | if (null == list || 0 == list.Count) return null; |
| | | |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.Append("["); |
| | | foreach (Coordinate cs in list) |
| | | { |
| | | sb.Append(cs.ToString() + ","); |
| | | } |
| | | sb.Remove(sb.Length - 1, 1); |
| | | sb.Append(']'); |
| | | |
| | | return sb.ToString(); |
| | | } |
| | | |
| | | public static double CalcArea(string code) |
| | | { |
| | | try |
| | | { |
| | |
| | | V8Script script = engine.CompileDocument(jsFile); |
| | | engine.Execute(script); |
| | | |
| | | string cs = "[113.23063216099904,31.21983148200005,113.23061312499972,31.219450768000044,113.23060360699967,31.21910812599997,113.2305679149997,31.218752397000046,113.23055006899986,31.21841570199999,113.230526275,31.218007625000023,113.23050485999988,31.217670932000015,113.23047154600006,31.21738182700004]"; |
| | | |
| | | string cs = selectCoordinates(code); |
| | | object obj = engine.Invoke("pointsToPolygon", cs); |
| | | |
| | | return null == obj ? 0 : Convert.ToDouble(obj); |