-
Notifications
You must be signed in to change notification settings - Fork 16
/
GeometryTest.cs
86 lines (67 loc) · 2.69 KB
/
GeometryTest.cs
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
84
85
86
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.Geometry;
namespace EngineApplication
{
class GeometryTest
{
/// <summary>
/// 获取点
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
private IPoint ConstructPoint(double x, double y)
{
IPoint pPoint = new PointClass();
pPoint.PutCoords(x, y);
return pPoint;
}
private object pMissing = Type.Missing;
public IGeometry GetMultipointGeometry()
{
const double MultipointPointCount = 25;
IPointCollection pPointCollection = new MultipointClass();
for (int i = 0; i < MultipointPointCount; i++)
{
pPointCollection.AddPoint(GetPoint(), ref pMissing, ref pMissing);
}
return pPointCollection as IGeometry;
}
private IPoint GetPoint()
{
const double Min = -10;
const double Max = 10;
Random pRandom = new Random();
double x = Min + (Max - Min) * pRandom.NextDouble();
double y = Min + (Max - Min) * pRandom.NextDouble();
return ConstructPoint(x, y);
}
private IPolygon FlatBuffer(IPolyline pLline1, double pBufferDis)
{
object o = System.Type.Missing;
//分别对输入的线平移两次(正方向和负方向)
IConstructCurve pCurve1 = new PolylineClass();
pCurve1.ConstructOffset(pLline1, pBufferDis, ref o, ref o);
IPointCollection pCol = pCurve1 as IPointCollection;
IConstructCurve pCurve2 = new PolylineClass();
pCurve2.ConstructOffset(pLline1, -1 * pBufferDis, ref o, ref o);
//把第二次平移的线的所有节点翻转
IPolyline pline2 = pCurve2 as IPolyline;
pline2.ReverseOrientation();
//把第二条的所有节点放到第一条线的IPointCollection里面
IPointCollection pCol2 = pline2 as IPointCollection;
pCol.AddPointCollection(pCol2);
//用面去初始化一个IPointCollection
IPointCollection pPointCol = new PolygonClass();
pPointCol.AddPointCollection(pCol);
//把IPointCollection转换为面
IPolygon pPolygon = pPointCol as IPolygon;
//简化节点次序
pPolygon.SimplifyPreserveFromTo();
return pPolygon;
}
}
}