Arcengine 操作积累
Posted king2019blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Arcengine 操作积累相关的知识,希望对你有一定的参考价值。
修改shp数据字段名字
public bool UpdateArea(IFeatureClass pfeatureclass, string oldfieldName, string newfieldName)
{
bool updateSuc = false;
try
{
using (ComReleaser comReleaser = new ComReleaser())
{
if (pfeatureclass == null) return false;
ITable pTable = pfeatureclass as ITable;
IFields pfields = pfeatureclass.Fields;
IField pfield = null;
for (int i = 0; i < pfields.FieldCount; i++)
{
pfield = pfields.get_Field(i);
if (pfield.Name.ToLower() == oldfieldName.ToLower())
{
//添加新字段
IField pField = new FieldClass();
IFieldEdit pFieldEdit = pField as IFieldEdit;
pFieldEdit.Name_2 = newfieldName;
pFieldEdit.AliasName_2 = newfieldName;
pFieldEdit.Type_2 = pfield.Type;
pFieldEdit.Length_2 = pfield.Length;
pFieldEdit.Precision_2 = pfield.Precision;
pFieldEdit.Scale_2 = pfield.Scale;
pTable.AddField(pField);
break;
}
}
int Index = pTable.FindField(newfieldName);
int indexP = pTable.FindField(oldfieldName);
if (Index == -1 || indexP == -1) return false;
ICursor updateCursor = pTable.Update(null, true);
comReleaser.ManageLifetime(updateCursor);
IRow row = null;
while ((row = updateCursor.NextRow()) != null)
{
//旧字段值赋值给新字段
double v = Convert.ToDouble(row.get_Value(indexP));
row.set_Value(Index, v);
updateCursor.UpdateRow(row);
}
pTable.DeleteField(pfield); //赋值完后,删除旧字段
}
updateSuc = true;
}
catch (Exception ex)
{
updateSuc = false;
}
return updateSuc;
}
批量将一个字段的值赋值给另一个字段
public bool BatchSetValue(string pFeatureClassName, string fromFieldName, string toFieldName)
{
bool updateSuc = false;
try
{
using (ESRI.ArcGIS.ADF.ComReleaser comReleaser = new ESRI.ArcGIS.ADF.ComReleaser())
{
IFeatureClass pFeatureClass = gms.GetFeatureClass(pFeatureClassName);
if (pFeatureClass == null) return false;
int fromIndex = pFeatureClass.Fields.FindField(fromFieldName);
int toIndex = pFeatureClass.Fields.FindField(toFieldName);
if (fromIndex == -1 || toIndex == -1) return false;
IQueryFilter pQueryfilter = new QueryFilterClass();
//pQueryfilter.WhereClause = "1=1";
pQueryfilter.SubFields = pFeatureClass.OIDFieldName + "," + fromFieldName + "," + toFieldName + ",Shape";
IFeatureCursor pFeatureCursor = null;
pFeatureCursor = pFeatureClass.Update(pQueryfilter, true);
IFeature pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{
object A = pFeature.get_Value(fromIndex);
pFeature.set_Value(toIndex, pFeature.get_Value(fromIndex));
//pFeature.Store();
pFeatureCursor.UpdateFeature(pFeature);
pFeature = pFeatureCursor.NextFeature();
}
}
updateSuc = true;
}
catch (Exception ex)
{
LogManager.LogHelper.WriteMessage(ex.Message, ex.StackTrace, LogManager.LogHelper.LogType.ERROR);
updateSuc = false;
}
return updateSuc;
}
根据要素选择集,创建新图层
IFeatureLayer featureLayer = new FeatureLayerClass();
featureLayer.FeatureClass = featureClass;
IFeatureSelection featureSelection = featureLayer as IFeatureSelection;
IQueryFilter queryFilter1 = new QueryFilterClass();
queryFilter1.WhereClause = "XZQDM like '" + xz_xzqdm + "%'";
featureSelection.SelectFeatures(queryFilter1, esriSelectionResultEnum.esriSelectionResultNew, false);
ISelectionSet selectionSet = featureSelection.SelectionSet;
IFeatureLayer newFeatureLayer = null;
if (selectionSet.Count > 0)
{
IFeatureLayerDefinition featureLayerDefinition = featureLayer as IFeatureLayerDefinition;
newFeatureLayer = featureLayerDefinition.CreateSelectionLayer(featureClass.AliasName, true, null, null);
}
AE二次开发中,过滤后的图层,实现缩放至图层效果
//实现过滤后的图层,缩放到图层
IEnvelope pEnvelope = new EnvelopeClass();
//关键代码,替换了要素遍历,提高效率
IEnumGeometryBind enumGeometryBind = new EnumFeatureGeometryClass();
enumGeometryBind.BindGeometrySource(null, pFeatureClassDLTB);
IEnumGeometry enumGeometry = (IEnumGeometry)enumGeometryBind;
IGeometryFactory geoFactory = new GeometryEnvironment() as IGeometryFactory;
IGeometry geo = geoFactory.CreateGeometryFromEnumerator(enumGeometry);
pEnvelope.Union(geo.Envelope);
System.Runtime.InteropServices.Marshal.ReleaseComObject(geo);
System.Runtime.InteropServices.Marshal.ReleaseComObject(geoFactory);
System.Runtime.InteropServices.Marshal.ReleaseComObject(enumGeometry);
mcView.ActiveView.FullExtent = pEnvelope;
以上是关于Arcengine 操作积累的主要内容,如果未能解决你的问题,请参考以下文章
[工作积累] UE4 并行渲染的同步 - Sync between FParallelCommandListSet & FRHICommandListImmediate calls(代码片段
利用ArcEngine开发地图发布服务,将mxd文档一键发布成wmts,并根据需要对地图进行空间查询,返回客户端geojson