ArcGIS Engine 코드 공유 - 레이어(Layer) 작업
public class LayerHelper
{
public static string GetClassOwnerName(string pDSName)
{
int index = pDSName.IndexOf(".");
if (index >= 0)
{
pDSName = pDSName.Substring(0, index);
}
else
{
pDSName = "";
}
pDSName = pDSName.ToUpper();
return pDSName;
}
public static string GetClassShortName(IDataset paramDS)
{
if (paramDS == null)
{
return "";
}
return GetClassShortName(paramDS.Name.ToUpper());
}
public static string GetClassShortName(IFeatureClass fc)
{
try
{
string str = "";
str = (fc as IDataset).Name;
int num = str.LastIndexOf(".");
if (num >= 0)
{
str = str.Substring(num + 1);
}
return str;
}
catch
{
return "";
}
}
public static string GetClassShortName(string paramName)
{
string str = paramName;
int num = paramName.LastIndexOf(".");
if (num >= 0)
{
str = paramName.Substring(num + 1);
}
return str;
}
public static ArrayList GetIntersectFeature(IGeoFeatureLayer pLayer, IGeometry pGeom)
{
ArrayList list = new ArrayList();
if (pLayer != null)
{
if ((pGeom == null) || pGeom.IsEmpty)
{
return list;
}
ISpatialReference reference = (pLayer.FeatureClass as IGeoDataset).SpatialReference;
if (reference != null)
{
pGeom.SpatialReference = reference;
pGeom.SnapToSpatialReference();
}
ISpatialFilter filter = new SpatialFilterClass();
filter.Geometry = pGeom;
filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
IFeatureCursor o = pLayer.FeatureClass.Search(filter, false);
for (IFeature feature = o.NextFeature(); feature != null; feature = o.NextFeature())
{
list.Add(feature);
}
Marshal.ReleaseComObject(o);
}
return list;
}
public static ArrayList GetIntersectFeature(IGeoFeatureLayer pLayer, IPolygon pPoly)
{
return GetIntersectFeature(pLayer, (IGeometry)pPoly);
}
public static List<IFeature> GetIntersectFeature(IFeatureClass pClass, IGeometry pGeom)
{
List<IFeature> list = new List<IFeature>();
if (pClass != null)
{
if ((pGeom == null) || pGeom.IsEmpty)
{
return list;
}
ISpatialReference reference = (pClass as IGeoDataset).SpatialReference;
if (reference != null)
{
pGeom.SpatialReference=reference;
pGeom.SnapToSpatialReference();
}
ISpatialFilter filter = new SpatialFilterClass();
filter.Geometry = pGeom;
filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
IFeatureCursor o = pClass.Search(filter, false);
for (IFeature feature = o.NextFeature(); feature != null; feature = o.NextFeature())
{
list.Add(feature);
}
Marshal.ReleaseComObject(o);
}
return list;
}
public static string GetLayerAliasName(IMap pMap, string sLayerName)
{
return QueryLayerByModelName(pMap, sLayerName).FeatureClass.AliasName;
}
public static int IndexOfLayer(IMap paramMap, ILayer paramLayer)
{
int num2 = paramMap.LayerCount;
for (int i = 0; i < num2; i++)
{
if (paramMap.get_Layer(i) == paramLayer)
{
return i;
}
}
return -1;
}
public static int IndexOfLayer(IMap pMap, string sAliasName)
{
if (pMap != null)
{
if (sAliasName == "")
{
return -1;
}
for (int i = 0; i < pMap.LayerCount; i++)
{
if (pMap.get_Layer(i).Name == sAliasName)
{
return i;
}
}
}
return -1;
}
public static string LayerTypeName(ILayer paramLayer)
{
string str = "";
if (paramLayer is IGeoFeatureLayer)
{
IFeatureClass class2 = (paramLayer as IGeoFeatureLayer).FeatureClass;
if (class2 != null)
{
str = GeometryHelper.ShapeTypeName(class2.ShapeType);
}
return str;
}
if (paramLayer is IRasterLayer)
{
return " ";
}
if (paramLayer is ITopologyLayer)
{
return " ";
}
if (paramLayer is IAnnotationLayer)
{
str = " ";
}
return str;
}
public static void LoadLayerFromStream(ILayer paramLayer, byte[] paramLayerContent)
{
if (((paramLayer != null) && (paramLayerContent != null)) && (paramLayerContent.Length != 0))
{
IPersistStream stream = paramLayer as IPersistStream;
XMLStreamClass class2 = new XMLStreamClass();
class2.LoadFromBytes(ref paramLayerContent);
stream.Load(class2);
}
}
public static ILayer QueryLayerByDisplayName(IMap paramMap, string layerName)
{
int num = paramMap.LayerCount;
layerName = layerName.ToUpper();
for (int i = 0; i < num; i++)
{
ILayer layer = paramMap.get_Layer(i);
if (layer.Name.ToUpper().Equals(layerName))
{
return layer;
}
}
return null;
}
public static IGeoFeatureLayer QueryLayerByModelName(IMap paramMap, string paramModelName)
{
if (paramMap != null)
{
if (paramModelName == null)
{
return null;
}
int num = paramMap.LayerCount;
paramModelName = paramModelName.ToUpper();
for (int i = 0; i < num; i++)
{
ILayer layer = paramMap.get_Layer(i);
if ((layer is IGeoFeatureLayer) && GetClassShortName((layer as IGeoFeatureLayer).FeatureClass as IDataset).ToUpper().Equals(paramModelName))
{
return (layer as IGeoFeatureLayer);
}
}
}
return null;
}
public static string QueryLayerModelName(ILayer curLayer)
{
if (curLayer == null)
{
return "";
}
if (curLayer is IGeoFeatureLayer)
{
return GetClassShortName((curLayer as IGeoFeatureLayer).FeatureClass as IDataset);
}
return curLayer.Name;
}
public static double QueryXYUnit(IGeoFeatureLayer paramLayer)
{
if (paramLayer != null)
{
return QueryXYUnit(paramLayer.FeatureClass);
}
return double.NaN;
}
public static double QueryXYUnit(IFeatureClass paramClass)
{
IGeoDataset dataset = paramClass as IGeoDataset;
if (dataset != null)
{
ISpatialReference reference = dataset.SpatialReference;
if (reference != null)
{
double num = 0.0;
double num2 = 0.0;
double num3 = 0.0;
reference.GetFalseOriginAndUnits(out num, out num2, out num3);
if (num3 != 0.0)
{
return (1.0 / num3);
}
}
}
return double.NaN;
}
public static byte[] SaveLayerToStream(ILayer paramLayer)
{
byte[] buffer = null;
if (paramLayer is IPersistStream)
{
IPersistStream stream = paramLayer as IPersistStream;
XMLStreamClass class2 = new XMLStreamClass();
stream.Save(class2, 0);
buffer = class2.SaveToBytes();
}
return buffer;
}
/// <summary>
/// shapefile
/// </summary>
/// <param name="sFilePath"></param>
/// <returns></returns>
public static IFeatureClass GetShapefileWorkspaceFeatureClass(string sFilePath)
{
try
{
IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
string sPath = System.IO.Path.GetDirectoryName(sFilePath);
IWorkspace pWS = pWSF.OpenFromFile(sPath, 0);
string sFileName = System.IO.Path.GetFileNameWithoutExtension(sFilePath);
IFeatureWorkspace pFWS = pWS as IFeatureWorkspace;
IFeatureClass pFC = pFWS.OpenFeatureClass(sFileName);
return pFC;
}
catch (Exception ex) { return null; }
}
public static IFeatureClassName GetFeatureClassName(IFeatureClass pfc)
{
IDataset pDS = pfc as IDataset;
IWorkspaceName workspaceName = new WorkspaceNameClass();
workspaceName = pDS.FullName as IWorkspaceName;
IFeatureClassName featureClassName = new FeatureClassNameClass();
IDatasetName datasetName = (IDatasetName)featureClassName;
datasetName.Name = pDS.Name;
datasetName.WorkspaceName = workspaceName;
return featureClassName;
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.