현재 사용자가지도 (mxd)를 시스템에로드 할 때 프로젝트를 위해 몇 가지 사용자 정의 기능을 만듭니다. 내 문제는 이미 레이어를 이미 만들 었는지 확인하는 방법을 모른다는 것입니다 (사용자가 mxd를로드하고 레이어를 만들고 저장하고 mxd를 다시로드하고 레이어가 이미 있는지 확인해야 함).
ArcEngine10에 FeatuerLayerClass에 대한 고유 ID가 있고 FeatureLayerClass.FeatureClass에 OIDName 및 ObjectClassID가 있지만 작동하지 않는 것 같습니다 (ObjectClassId를 할당 할 수없고 OIDName에 UniqueId를 사용하려고 함)?
이처럼 featurelayerclass 비즈니스 오브젝트로 계층을 작성했습니다.
암호:
/// <summary>
/// Unique Route LayerId
/// </summary>
public static Guid RouteFeatureLayerId
{
get { return Guid.Parse("ba25a332-0e48-4ce5-a4c5-38dc36c0700c"); }
}
/// <summary>
/// Feature class that stores info on the routes
/// </summary>
public FeatureLayerClass RouteFeatureLayer
{
get
{
if (_routeFeatureClass == null)
{
IPropertySet property = new PropertySetClass();
property.SetProperty("Id", RouteFeatureLayerId);
_routeFeatureClass = new FeatureLayerClass();
_routeFeatureClass.FeatureClass = CreateFeatureClass(Workspace, null, ShapeType.Polylines.ToString(), CreateFields(ShapeType.Polylines, FeatureLayerType.Routes), null, null, "");
_routeFeatureClass.Name = "Routes";
_routeFeatureClass.Visible = true;
_routeFeatureClass.Cached = true;
_routeFeatureClass.AddExtension(property);
CustomLayers.Add(_routeFeatureClass);
}
return _routeFeatureClass;
}
set
{
_routeFeatureClass = value;
}
}
작업 공간 만들기
/// <summary>
/// Create a workspace for the shapefile or geodatabase
/// </summary>
private IWorkspace CreateWorkspace(string workspaceType, string workspaceDirectory)
{
Type factoryType = null;
IWorkspaceFactory workspaceFactory = null;
switch (workspaceType)
{
case "Shapefile":
// Instantiate a Shapefile workspace factory
factoryType = Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory");
break;
case "PersonalGeodatabase":
// Instantiate an Access workspace factory
factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory");
break;
case "FileGeodatabase":
// Instantiate a file geodatabase workspace factory
factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
break;
}
workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
//Create a directory hierarchy to seperate out datasets created for Points, Polylines, and Polygons
Directory.CreateDirectory(workspaceDirectory);
IWorkspaceName workspaceName = workspaceFactory.Create(workspaceDirectory + "\\", workspaceType, null, 0);
IName Name = (IName)workspaceName;
IWorkspace workspace = (IWorkspace)(Name.Open());
return workspace;
}
FeatureClass 생성
/// <summary>
/// Helper to create a Feature Class.
/// </summary>
private IFeatureClass CreateFeatureClass(IWorkspace workspace, IFeatureDataset featureDataset, string featureClassName, IFields fields, ESRI.ArcGIS.esriSystem.UID CLSID, ESRI.ArcGIS.esriSystem.UID CLSEXT, string configKeyword)
{
IFeatureClass featureClass = null;
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace; // Explicit Cast
string shapeFieldName = String.Empty;
try
{
if (featureClassName == "")
{
return null; // name was not passed in
}
//else if (((IWorkspace2)workspace).get_NameExists(esriDatasetType.esriDTFeatureClass, featureClassName))
//{
// featureClass = featureWorkspace.OpenFeatureClass(featureClassName); // feature class with that name already exists
// return featureClass;
//}
// assign the class id value if not assigned
if (CLSID == null)
{
CLSID = new ESRI.ArcGIS.esriSystem.UIDClass();
CLSID.Value = "esriGeoDatabase.Feature";
}
// locate the shape field
for (Int32 j = 0; j < fields.FieldCount; j++)
{
if (fields.get_Field(j).Type == esriFieldType.esriFieldTypeGeometry)
{
shapeFieldName = fields.get_Field(j).Name;
}
}
// finally create and return the feature class
if (featureDataset == null)
{
// if no feature dataset passed in, create at the workspace level
featureClass = featureWorkspace.CreateFeatureClass(featureClassName, fields, CLSID, CLSEXT, esriFeatureType.esriFTSimple, shapeFieldName, configKeyword);
}
else
{
featureClass = featureDataset.CreateFeatureClass(featureClassName, fields, CLSID, CLSEXT, esriFeatureType.esriFTSimple, shapeFieldName, configKeyword);
}
}
catch (Exception ex)
{
Debug.Assert(false, ex.ToString());
Logger.Log.Debug(ex);
}
return featureClass;
}
레이어를 얻는 코드
/// <summary>
/// Finds the layer
/// </summary>
/// <returns>the subcatchment layer</returns>
private IGeoFeatureLayer GetLayer(FeatureLayerClass featureLayer)
{
IGeoFeatureLayer layer = null;
ILayerExtensions layerExtension;
for (int x = 0; x < MapControl.LayerCount; x++)
{
layerExtension = ((ILayerExtensions)MapControl.get_Layer(x));
if (featureLayer.ExtensionCount > 0 && layerExtension.ExtensionCount > 0 &&
layerExtension.get_Extension(0) is PropertySetClass &&
featureLayer.get_Extension(0) is PropertySetClass &&
((PropertySetClass)layerExtension.get_Extension(0)).GetProperty("Id") == ((PropertySetClass)featureLayer.get_Extension(0)).GetProperty("Id"))
{
layer = MapControl.get_Layer(x) as IGeoFeatureLayer;
break;
}
}
return layer;
}
감사합니다. Kevin