파이썬이 하위 유형을 처리한다고 생각하지 않기 때문에이 C # 코드를 게시하고 있습니다. Esri의 샘플 water / wastewater geodb로 테스트 한 결과 다음 미사용 도메인이 발견되었습니다.
HistoryType is not used
PLSSFirstDivisionType is not used
PLSSDirection is not used
PLSSPrincipalMeridian is not used
ParcelType is not used
PLSSSpecialSurveyType is not used
CartoLineType is not used
PLSSSecondDivisionType is not used
DBA는 종종 조회 테이블 인 도메인을 SQL을 통해 액세스 할 수 없다는 사실에 짜증을냅니다.
이 코드는 arcmap에서 테스트되었습니다 ( Matt의 설명에 따라 업데이트 됨 ).
protected override void OnClick()
{
string fgdbPath = @"C:\projects\NetTools\InfrastructureEditingTemplate\MapsandGeodatabase\LocalGovernment.gdb";
var dict = SummarizeDomains(fgdbPath);
ListDomains(dict);
// list what featureclasses use a particular domain ...
string domName = "State_Bnd_Rules";
if (dict.ContainsKey(domName))
{
if (dict[domName].Count > 0)
{
Debug.Print("{0} is used by these featureclasses: ", domName);
foreach (string fcfldName in dict[domName])
{
Debug.Print("\t{0}", fcfldName);
}
}
else
Debug.Print("{0} is not used by any featureclasses", domName);
}
else
{
Debug.Print("Domain name not found in geodb: {0}", domName);
}
}
private void ListDomains(Dictionary<string,List<string>> dict)
{
foreach (KeyValuePair<string, List<string>> kvp in dict)
{
Debug.Print("Domain {0}",kvp.Key);
if (kvp.Value.Count > 0)
{
foreach (string fcfldName in kvp.Value)
{
Debug.Print("\t{0}", fcfldName);
}
}
else
Debug.Print("\tUNUSED DOMAIN!");
}
}
private Dictionary<string, List<string>> SummarizeDomains(string fgdPath)
{
var ws = Open(fgdPath);
var dict = InitDict(ws);
var enumDs1 = ws.get_Datasets(esriDatasetType.esriDTAny);
IDataset ds;
while ((ds = enumDs1.Next()) != null)
{
Debug.Print("processing {0}", ds.Name);
if (ds is IObjectClass)
LoadDomains((IObjectClass)ds, dict);
else if (ds is IFeatureDataset)
{
var enumDs2 = ds.Subsets;
enumDs2.Reset();
IDataset ds2;
while ((ds2 = enumDs2.Next()) != null)
{
if (ds2 is IObjectClass)
LoadDomains((IObjectClass)ds2, dict);
}
}
}
return dict;
}
private void LoadDomains(IObjectClass oc, Dictionary<string, List<string>> dict)
{
if (oc is ISubtypes && ((ISubtypes)oc).HasSubtype)
LoadSubtypeDomains(oc, dict);
else
{
for (int i = 0; i < oc.Fields.FieldCount; i++)
{
var fld = oc.Fields.get_Field(i);
if (fld.Domain == null)
continue;
if (dict.ContainsKey(fld.Domain.Name))
dict[fld.Domain.Name].Add(String.Format("{0}.{1}",((IDataset)oc).Name,fld.Name));
else
throw new Exception("domain not found: " + fld.Domain.Name);
}
}
}
private void LoadSubtypeDomains(IObjectClass oc, Dictionary<string, List<string>> dict)
{
ISubtypes subTypes = oc as ISubtypes;
var enumSubtypes = subTypes.Subtypes;
enumSubtypes.Reset();
int code;
string stName;
while ((stName = enumSubtypes.Next(out code)) != null)
{
for (int i = 0; i < oc.Fields.FieldCount; i++)
{
string fldName = oc.Fields.get_Field(i).Name;
var domain = subTypes.get_Domain(code, fldName);
if (domain != null)
{
if (dict.ContainsKey(domain.Name))
dict[domain.Name].Add(String.Format("{0}.{1}.{2}",stName,((IDataset)oc).Name,fldName));
else
throw new Exception("domain not found: " + domain.Name);
}
}
}
}
private Dictionary<string, List<string>> InitDict(IWorkspace ws)
{
var dict = new Dictionary<string, List<string>>(StringComparer.InvariantCultureIgnoreCase);
var enumDomain = ((IWorkspaceDomains)ws).Domains;
enumDomain.Reset();
IDomain d = null;
while ((d = enumDomain.Next()) != null)
dict.Add(d.Name, new List<string>());
return dict;
}
private IWorkspace Open(string fgdbPath)
{
Type t = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
var wsf = Activator.CreateInstance(t) as IWorkspaceFactory;
return wsf.OpenFromFile(fgdbPath, 0);
}