-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLayerInfo.cs
315 lines (293 loc) · 9.35 KB
/
LayerInfo.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
* Erstellt mit SharpDevelop.
* Benutzer: mri0
* Datum: 09.10.2009
* Zeit: 10:32
*
* Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
*/
using System;
using System.Collections.Generic;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;
namespace MXDReader
{
/// <summary>
/// Description of LayerInfo.
/// </summary>
public class LayerInfo
{
private IMapDocument mxd;
private string mxdname = "";
private string username = "";
private string server = "";
private string instance = "";
private string version = "";
private string name = "";
private string owner = "";
private string tablename = "";
private string type = "";
private string defquery = "";
private string joininfo = "";
private string minscale = "";
private string maxscale = "";
private string symbfields = "";
private string parent = "";
private string label = "";
private string relateinfo = "";
List<ILayer> groupLayerList;
public LayerInfo(IMapDocument mapDoc)
{
/* Diese Eigenschaften sind für jeden Layer identisch */
mxd = mapDoc;
mxdname = mxd.DocumentFilename;
UID pID = new UIDClass();
pID.Value = "{EDAD6644-1810-11D1-86AE-0000F8751720}";
groupLayerList = getLayerList(pID);
}
private void fillLayerProps(ILayer lyr)
{
name = lyr.Name;
minscale = lyr.MinimumScale.ToString();
maxscale = lyr.MaximumScale.ToString();
getParentLayerNames(lyr);
this.parent = this.parent.TrimStart('/');
}
private void getParentLayerNames(ILayer lyr)
{
foreach (ILayer grpLyr in groupLayerList)
{
// Zuerst Cast nach GroupLayer, erst dann nach ICompositeLayer
IGroupLayer grpLyr2 = (IGroupLayer)grpLyr;
ICompositeLayer cmpLyr = (ICompositeLayer)grpLyr2;
for (int cmpLyrIndex=0; cmpLyrIndex < cmpLyr.Count; cmpLyrIndex++)
{
ILayer childLyr = cmpLyr.get_Layer(cmpLyrIndex);
if (childLyr.Equals(lyr))
{
this.parent = "/" + grpLyr.Name + this.parent;
getParentLayerNames(grpLyr);
}
}
}
}
private void fillDatalayerProps(ILayer lyr)
{
IDataLayer dlyr = lyr as IDataLayer;
IDatasetName dataName = dlyr.DataSourceName as IDatasetName;
// nur für SDE-Layer werden die Connection-Infos ausgegeben
// bei übrigen Layern wird nur der Pfad ausgegeben
if (dataName.WorkspaceName.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace)
{
IPropertySet props = dataName.WorkspaceName.ConnectionProperties;
username = props.GetProperty("user").ToString();
server = props.GetProperty("server").ToString();
instance = props.GetProperty("instance").ToString();
version = props.GetProperty("version").ToString();
string[] s = dataName.Name.Split('.');
owner = s[0];
tablename = s[1];
} else {
tablename = dataName.Name;
server = dataName.WorkspaceName.PathName;
type = "kein SDE-Layer";
}
}
private void fillDefQueryProps(IFeatureLayer flyr)
{
IFeatureLayerDefinition flyrdef = flyr as IFeatureLayerDefinition;
if (flyrdef != null)
{
if (flyrdef.DefinitionExpression != "")
{
defquery = flyrdef.DefinitionExpression;
}
}
}
public void processFeatureLayer(ILayer lyr)
{
type = "Vektor";
fillLayerProps(lyr);
fillDatalayerProps(lyr);
IFeatureLayer flyr = lyr as IFeatureLayer;
fillDefQueryProps(flyr);
processJoins(flyr);
processRelates(flyr);
IGeoFeatureLayer gflyr = flyr as IGeoFeatureLayer;
if (gflyr.DisplayAnnotation == true)
{
IAnnotateLayerPropertiesCollection labelPropsColl = gflyr.AnnotationProperties;
for (int collIndex=0; collIndex < labelPropsColl.Count; collIndex++)
{
IAnnotateLayerProperties annoLayerProps;
IElementCollection elCol1;
IElementCollection elCol2;
labelPropsColl.QueryItem(collIndex, out annoLayerProps, out elCol1, out elCol2);
string sql = annoLayerProps.WhereClause;
ILabelEngineLayerProperties2 labelEngineProps = (ILabelEngineLayerProperties2)annoLayerProps;
string expr = labelEngineProps.Expression;
this.label = this.label + sql + "?" + expr + "/";
}
}
this.label = this.label.TrimEnd('/');
IFeatureRenderer rend = gflyr.Renderer;
if (rend is IUniqueValueRenderer)
{
string felder = "";
IUniqueValueRenderer u = rend as IUniqueValueRenderer;
for (int i = 0; i < u.FieldCount; i++)
{
felder = felder + u.get_Field(i) + "/";
}
symbfields = felder.TrimEnd('/') + " (UniqueValueRenderer)";
} else if (rend is IProportionalSymbolRenderer)
{
IProportionalSymbolRenderer prop = rend as IProportionalSymbolRenderer;
symbfields = prop.Field + " (ProportionalSymbolRenderer)";
} else if (rend is IClassBreaksRenderer)
{
IClassBreaksRenderer cl = rend as IClassBreaksRenderer;
symbfields = cl.Field + " (ClassBreaksRenderer)";;
} else if (rend is ISimpleRenderer)
{
symbfields = "kein Feld (SimpleRenderer)";
} else
{
symbfields = "unbekannter Renderer";
}
}
private void processJoins(IFeatureLayer flyr)
{
IDisplayTable dispTbl = flyr as IDisplayTable;
ITable tbl = dispTbl.DisplayTable;
IRelQueryTable rqt;
ITable destTable;
IDataset dataset;
string destName;
string destServer;
string destInstance;
string destUser;
string res = "";
string joinType;
// Holt iterativ alle Joins!
while (tbl is IRelQueryTable)
{
rqt = (IRelQueryTable)tbl;
IRelQueryTableInfo rqtInfo = (IRelQueryTableInfo)rqt;
IRelationshipClass relClass = rqt.RelationshipClass;
destTable = rqt.DestinationTable;
if (rqtInfo.JoinType == esriJoinType.esriLeftInnerJoin)
{
joinType = "esriLeftInnerJoin";
} else
{
joinType = "esriLeftOuterJoin";
}
dataset = (IDataset)destTable;
destName = dataset.Name;
destServer = dataset.Workspace.ConnectionProperties.GetProperty("server").ToString();
destInstance = dataset.Workspace.ConnectionProperties.GetProperty("instance").ToString();
destUser = dataset.Workspace.ConnectionProperties.GetProperty("user").ToString();
res = res + "(" + destName + "/" + destServer + "/" + destInstance + "/" + destUser + "/" + relClass.OriginPrimaryKey + "/" + relClass.OriginForeignKey + "/" + joinType + ")";
tbl = rqt.SourceTable;
}
joininfo = res;
}
private void processRelates(IFeatureLayer flyr)
{
string res = "";
string destName = "";
string destServer = "";
string destInstance = "";
string destUser = "";
IRelationshipClassCollection relClassColl = (IRelationshipClassCollection)flyr;
IEnumRelationshipClass enumRelClass = relClassColl.RelationshipClasses;
enumRelClass.Reset();
IRelationshipClass relClass = enumRelClass.Next();
while (relClass != null)
{
IDataset dset = (IDataset)relClass;
ITable destTable = (ITable)relClass.DestinationClass;
IDataset dsetDest = (IDataset)destTable;
destName = dsetDest.Name;
destServer = dsetDest.Workspace.ConnectionProperties.GetProperty("server").ToString();
destInstance = dsetDest.Workspace.ConnectionProperties.GetProperty("instance").ToString();
destUser = dsetDest.Workspace.ConnectionProperties.GetProperty("user").ToString();
res = res + "(" + destName + "/" + destServer + "/" + destInstance + "/" + destUser + "/" + relClass.OriginPrimaryKey + "/" + relClass.OriginForeignKey + "/" + dset.BrowseName + ")";
relClass = enumRelClass.Next();
}
relateinfo = res;
}
public void processRasterCatalogLayer(ILayer lyr)
{
type = "RasterKatalog";
fillLayerProps(lyr);
fillDatalayerProps(lyr);
IFeatureLayer flyr = lyr as IFeatureLayer;
fillDefQueryProps(flyr);
}
public void processAnnotationLayer(ILayer lyr)
{
type = "Annotation";
fillLayerProps(lyr);
fillDatalayerProps(lyr);
IFeatureLayer flyr = lyr as IFeatureLayer;
fillDefQueryProps(flyr);
}
public void processAnnotationSubLayer(ILayer lyr)
{
type = "AnnotationClass";
fillLayerProps(lyr);
// bei AnnotationSubLayern hat nur der Parent-AnnotationLayer die
// gewünschten Informationen.
IAnnotationSublayer sub = lyr as IAnnotationSublayer;
ILayer parentLayer = sub.Parent as ILayer;
fillDatalayerProps(parentLayer);
IFeatureLayer flyr = parentLayer as IFeatureLayer;
fillDefQueryProps(flyr);
}
public void processRasterLayer(ILayer lyr)
{
type = "Raster";
fillLayerProps(lyr);
fillDatalayerProps(lyr);
}
public void processGroupLayer(ILayer lyr)
{
type = "GroupLayer";
fillLayerProps(lyr);
}
public void processOtherLayer(ILayer lyr)
{
type = "anderer Layer";
fillLayerProps(lyr);
}
public string writeCSV()
{
string output = mxdname + ";" + name + ";" + type + ";" + owner + ";" + tablename + ";" + server + ";" + instance + ";" + username.ToUpper() + ";" + version + ";" + minscale + ";" + maxscale + ";" + defquery + ";" + joininfo + ";" + symbfields + ";" + parent + ";" + label + ";" + relateinfo;
return output;
}
private List<ILayer> getLayerList(UID id)
{
List<ILayer> res = new List<ILayer>();
// try-catch ist nötig, da get_Layers() eine Exception auslöst,
// wenn es keine passenden Layer findet!
try
{
IEnumLayer lyrs = mxd.get_Map(0).get_Layers(id, true);
lyrs.Reset();
ILayer lyr = lyrs.Next();
while (lyr != null)
{
res.Add(lyr);
lyr = lyrs.Next();
}
}
catch
{
}
return res;
}
}
}