空间数据范围发生变化后如何更新数据的显示范围

时间:2022-12-16 16:22:52

    在数据编辑或者数据出现脏数据的情况下,空间数据的显示可能会出现全图显示无法完整的显示主要数据的问题,遇到这种情况需要更新数据范围才能正确显示全图数据范围,需要通过代码的方式更新数据范围,核心代码如下:

    c# engine:

 ISchemaLock schemaLock = (ISchemaLock)temp.FeatureClass;
            try
            {
                IFeatureClassManage featureClassManage = (IFeatureClassManage)temp.FeatureClass;
                featureClassManage.UpdateExtent();
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
            catch (Exception e)
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }

vba:

Public Sub UpdateFCExtent()
  Dim pApp As IGxApplication
  Dim pGxObj As IGxObject
  Dim pGXDataset As IGxDataset
  Set pApp = Application
  Set pGxObj = pApp.SelectedObject
  Set pGXDataset = pGxObj
   
  Dim pFC As IFeatureClass
  Set pFC = pGXDataset.Dataset

  Dim pFeatureClassManage As IFeatureClassManage
  Set pFeatureClassManage = pFC

  pFeatureClassManage.UpdateExtent
End Sub

[Visual Basic 6.0]:

Public Sub reCalcExt()
  Dim pGXApplication As IGxApplication
  Set pGXApplication = Application
 
  Dim pGxObject As IGxObject
  Set pGxObject = pGXApplication.SelectedObject
 
  If Not TypeOf pGxObject.InternalObjectName Is IFeatureClassName Then
    Exit Sub
  End If
 
  Dim pName As IName
  Set pName = pGxObject.InternalObjectName
  Dim pSchemaLock As ISchemaLock
  Set pSchemaLock = pName.Open
 
  pSchemaLock.ChangeSchemaLock esriExclusiveSchemaLock
  Dim pFeatureClassManage As IFeatureClassManage
  Set pFeatureClassManage = pSchemaLock
  pFeatureClassManage.UpdateExtent
 
  Exit Sub
 
ErrHandler:
  pSchemaLock.ChangeSchemaLock esriSharedSchemaLock
End Sub

Python:

# coding:cp936
import _winreg
import comtypes
from comtypes.client import GetModule
from comtypes.client import CreateObject
# 查找 ArcGIS 10 的安装路径,我的是64位系统所以有 Wow6432Node,32位系统的话就去掉那个节点
keyESRI = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE//Wow6432Node//ESRI//Desktop10.0")
ArcGISPath = _winreg.QueryValueEx(keyESRI, "InstallDir")[0] + "com//"
# 载入必要的库
GetModule(ArcGISPath + 'esriDataSourcesFile.olb')
GetModule(ArcGISPath + 'esriGeoDatabase.olb')
GetModule(ArcGISPath + 'esriSystem.olb')
GetModule((comtypes.GUID("{6FCCEDE0-179D-4D12-B586-58C88D26CA78}"), 1, 0)) # esriVersion
import comtypes.gen.esriDataSourcesFile as esriDataSourcesFile
import comtypes.gen.esriGeoDatabase as esriGeoDatabase
import comtypes.gen.esriSystem as esriSystem
import comtypes.gen.ArcGISVersionLib as esriVersion
# ArcGIS 10.0 以上需要先绑定版本,9.x 不用下面这两句
versionManager = CreateObject(esriVersion.VersionManager, interface = esriVersion.IArcGISVersion)
versionManager.LoadVersion(esriVersion.esriArcGISDesktop, "10.0")
# 初始化 Ao,和 C++ 里面一样的做法
aoInit = CreateObject(esriSystem.AoInitialize, interface = esriSystem.IAoInitialize)
pCode = esriSystem.esriLicenseProductCodeArcInfo
status = aoInit.IsProductCodeAvailable(pCode)
if status == esriSystem.esriLicenseAvailable:
    aoInit.Initialize(pCode)
shpFileWSFactory = CreateObject(esriDataSourcesFile.ShapefileWorkspaceFactory, interface = esriGeoDatabase.IWorkspaceFactory)
shpFileWS = shpFileWSFactory.openFromFile(r'D:/Temp/p/testtooldata', 0).QueryInterface(esriGeoDatabase.IFeatureWorkspace)
featureClass = shpFileWS.openFeatureClass("test1")
featureManger = featureClass.QueryInterface(esriGeoDatabase.IFeatureClassManage)
featureManger.UpdateExtent()
del featureManger
del featureClass