-
Notifications
You must be signed in to change notification settings - Fork 4
/
GeometricNetworkInfo.cs
141 lines (127 loc) · 5 KB
/
GeometricNetworkInfo.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//-----------------------------------------------------------------------
// <copyright file="GeometricNetworkInfo.cs" company="Studio A&T s.r.l.">
// Copyright (c) Studio A&T s.r.l. All rights reserved.
// </copyright>
// <author>Nicogis</author>
//-----------------------------------------------------------------------
namespace Studioat.ArcGis.Soe.Rest
{
using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SOESupport;
/// <summary>
/// class of GeometricNetworkInfo
/// </summary>
internal class GeometricNetworkInfo
{
/// <summary>
/// Initializes a new instance of the <see cref="GeometricNetworkInfo"/> class
/// </summary>
/// <param name="id">id of layer</param>
/// <param name="name">name of layer</param>
/// <param name="geometricNetwork">object IGeometricNetwork</param>
public GeometricNetworkInfo(int id, string name, ESRI.ArcGIS.Geodatabase.IGeometricNetwork geometricNetwork)
{
this.Name = name;
this.ID = id;
IGeoDataset geodataset = geometricNetwork as IGeoDataset;
this.SpatialReference = geodataset.SpatialReference;
this.Extent = geodataset.Extent;
this.GeometricNetwork = geometricNetwork;
}
/// <summary>
/// Gets or sets extent
/// </summary>
public IEnvelope Extent
{
get;
set;
}
/// <summary>
/// Gets or sets id
/// </summary>
public int ID
{
get;
set;
}
/// <summary>
/// Gets or sets name
/// </summary>
public string Name
{
get;
set;
}
/// <summary>
/// Gets or sets geometricNetwork
/// </summary>
public ESRI.ArcGIS.Geodatabase.IGeometricNetwork GeometricNetwork
{
get;
set;
}
/// <summary>
/// Gets or sets spatialReference
/// </summary>
public ISpatialReference SpatialReference
{
get;
set;
}
/// <summary>
/// convert the current instance in JsonObject
/// </summary>
/// <returns>object JsonObject</returns>
public JsonObject ToJsonObject()
{
byte[] bytes = Conversion.ToJson(this.Extent);
JsonObject jo = new JsonObject(Encoding.UTF8.GetString(bytes));
if (!jo.Exists("spatialReference"))
{
if (this.SpatialReference.FactoryCode == 0)
{
jo.AddString("spatialReference", this.SpatialReference.Name);
}
else
{
jo.AddLong("spatialReference", (long)this.SpatialReference.FactoryCode);
}
}
JsonObject jsonObjectGeometricNetworkInfo = new JsonObject();
jsonObjectGeometricNetworkInfo.AddString("name", this.Name);
jsonObjectGeometricNetworkInfo.AddLong("id", (long)this.ID);
jsonObjectGeometricNetworkInfo.AddJsonObject("extent", jo);
INetSchema netSchema = (INetSchema)this.GeometricNetwork.Network;
INetWeight netWeight;
List<JsonObject> weights = new List<JsonObject>();
for (int i = 0; i < netSchema.WeightCount; i++)
{
netWeight = netSchema.get_Weight(i);
JsonObject weight = new JsonObject();
weight.AddLong("id", (long)netWeight.WeightID);
weight.AddString("name", netWeight.WeightName);
weight.AddString("type", Enum.GetName(typeof(esriWeightType), netWeight.WeightType));
weight.AddLong("bitGateSize", (long)netWeight.BitGateSize);
List<JsonObject> weightAssociation = new List<JsonObject>();
IEnumNetWeightAssociation enumNetWeightAssociation = netSchema.get_WeightAssociations(netWeight.WeightID);
INetWeightAssociation netWeightAssociation = enumNetWeightAssociation.Next();
while (netWeightAssociation != null)
{
JsonObject jsonObjectNetWeightAssociation = new JsonObject();
jsonObjectNetWeightAssociation.AddString("fieldName", netWeightAssociation.FieldName);
jsonObjectNetWeightAssociation.AddString("tableName", netWeightAssociation.TableName);
weightAssociation.Add(jsonObjectNetWeightAssociation);
netWeightAssociation = enumNetWeightAssociation.Next();
}
weight.AddArray("weightAssociation", weightAssociation.ToArray());
weights.Add(weight);
}
jsonObjectGeometricNetworkInfo.AddArray("weights", weights.ToArray());
return jsonObjectGeometricNetworkInfo;
}
}
}