管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2024-08-05 b73e6de0b85cd54ad9b6226fb357f89389ff3cb8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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;
 
namespace Turf.cs
{
    public class Tools
    {
        public Tools() { }
 
        private V8Script v8Script;
 
        public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory;
 
        private static PostgreHelper _dbHelper;
 
        public static PostgreHelper DBHelper
        {
            get
            {
                if (null == _dbHelper)
                {
                    _dbHelper = new PostgreHelper();
                }
 
                return _dbHelper;
            }
        }
 
        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)
        {
            using (V8ScriptEngine engine = new V8ScriptEngine())
            {
                engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading;
                engine.DefaultAccess = ScriptAccess.Full;
 
                string jsFile = Path.Combine(BaseDir, "js\\turf.min.6.5.js");
                V8Script script = engine.CompileDocument(jsFile);
                engine.Execute(script);
 
                string cs = selectCoordinates(code);
                if (string.IsNullOrEmpty(cs)) return 0;
 
                object obj = engine.Invoke("pointsToPolygon", cs);
 
                return null == obj ? 0 : Convert.ToDouble(obj);
            }
        }
    }
}