修改本地地图的空间属性
在开发个人版的地图程序中,经常有需要修改本地地图的空间,使之与数据库记录对应上.
在本地库可以不需要创建工作空间,可以直接修改其空间属性,不说了,贴上代码自己看吧
Code
/// <summary>
/// 修改空间属性字段
/// </summary>
/// <param name="ManagerId"></param>
/// <param name="ManagerName"></param>
/// <param name="RoadId"></param>
/// <param name="StartStake"></param>
private void UpdateFields(string ManagerId, string ManagerName, string RoadId, string StartStake)
{
//需要先判断要修改的值不能为空,否则修改后记录对应不上地图
if (!string.IsNullOrEmpty(ManagerId) && !string.IsNullOrEmpty(ManagerName))
{
//遍历所有的图层
for (int i = 0; i < axMapControl.LayerCount; i++)
{
//定义一个要素图层
IFeatureLayer pLayer = null;
//定义一个要素类
IFeatureClass iFeatureClass = null;
try
{
//获得图层
pLayer = (IFeatureLayer)axMapControl.get_Layer(i);
iFeatureClass = pLayer.FeatureClass;
//创建一个游标
IFeatureCursor pCursor;
//创建查询条件
IQueryFilter pFilter = new QueryFilterClass();
pFilter.WhereClause = " LXBM = '" + RoadId.Trim() + "'" + " AND QDZH='" + StartStake.Trim() + "'";
pCursor = iFeatureClass.Search(pFilter, false);
IFeature pFeature;
//获得查询结果并 赋值
pFeature = pCursor.NextFeature();
if (pFeature != null)
{
pFeature.set_Value(5, ManagerId);
pFeature.set_Value(6, ManagerName);
pFeature.Store();
pFeature = pCursor.NextFeature();
}
}
catch
{
}
}
}
}
/// <summary>
/// 修改空间属性字段
/// </summary>
/// <param name="ManagerId"></param>
/// <param name="ManagerName"></param>
/// <param name="RoadId"></param>
/// <param name="StartStake"></param>
private void UpdateFields(string ManagerId, string ManagerName, string RoadId, string StartStake)
{
//需要先判断要修改的值不能为空,否则修改后记录对应不上地图
if (!string.IsNullOrEmpty(ManagerId) && !string.IsNullOrEmpty(ManagerName))
{
//遍历所有的图层
for (int i = 0; i < axMapControl.LayerCount; i++)
{
//定义一个要素图层
IFeatureLayer pLayer = null;
//定义一个要素类
IFeatureClass iFeatureClass = null;
try
{
//获得图层
pLayer = (IFeatureLayer)axMapControl.get_Layer(i);
iFeatureClass = pLayer.FeatureClass;
//创建一个游标
IFeatureCursor pCursor;
//创建查询条件
IQueryFilter pFilter = new QueryFilterClass();
pFilter.WhereClause = " LXBM = '" + RoadId.Trim() + "'" + " AND QDZH='" + StartStake.Trim() + "'";
pCursor = iFeatureClass.Search(pFilter, false);
IFeature pFeature;
//获得查询结果并 赋值
pFeature = pCursor.NextFeature();
if (pFeature != null)
{
pFeature.set_Value(5, ManagerId);
pFeature.set_Value(6, ManagerName);
pFeature.Store();
pFeature = pCursor.NextFeature();
}
}
catch
{
}
}
}
}