From 81f67d9cf9632cc35ec5026655623a7263b74182 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 29 二月 2024 16:49:01 +0800 Subject: [PATCH] 添加V8引擎的调用 --- Turf/cs/Tools.cs | 49 +++++++++++++++++++++++++++++++++++++------------ 1 files changed, 37 insertions(+), 12 deletions(-) diff --git a/Turf/cs/Tools.cs b/Turf/cs/Tools.cs index 9f05439..5617c3b 100644 --- a/Turf/cs/Tools.cs +++ b/Turf/cs/Tools.cs @@ -1,10 +1,16 @@ 锘縰sing 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 { @@ -16,26 +22,46 @@ 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 { @@ -48,8 +74,7 @@ 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); -- Gitblit v1.9.3