ArEngine对shp文件进行相交分析时,报尝试读取或者写入受保护的内存,这通常指示其他内存已经损坏
调用IBasicGeoprocessor.Intersect()方法对shp文件进行相交分析时,报错尝试读取或者写入受保存的内存运行到 pOutputFeatClass = pBGP.Intersect(pInputTable, false, pOverlayTable, false, tol, pFeatClassName);就报错
public DataTable Intersect_China()--------------------编程问答-------------------- 这个问题解决了,又出现新问题了。生成的相交文件是个空的shp面文件。但是我要生成的是点文件
{
#region 获取权限
IAoInitialize aoinitialize = new AoInitializeClass();
aoinitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
#endregion
string shpFilePath = Application.StartupPath;
IWorkspaceFactory pWorkspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(shpFilePath, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass("国界.shp");
ITable pInputTable = pFeatureClass as ITable;
System.Threading.Thread.Sleep(3000);
IFeatureClass pOverlayClass = pFeatureWorkspace.OpenFeatureClass("晒选前.shp");
ITable pOverlayTable = pOverlayClass as ITable;
if (pInputTable == null)
{
MessageBox.Show("Table QI failed");
return null;
}
if (pOverlayTable == null)
{
MessageBox.Show("Table QI failed");
return null;
}
IFeatureClassName pFeatClassName;
pFeatClassName = new FeatureClassNameClass();
pFeatClassName.FeatureType = esriFeatureType.esriFTSimpleJunction;
pFeatClassName.ShapeFieldName = "Shape";
pFeatClassName.ShapeType = pFeatureClass.ShapeType;
double tol = 0.3;
IBasicGeoprocessor pBGP;
pBGP = new BasicGeoprocessorClass();
//pBGP.SpatialReference = pMap.SpatialReference;
IFeatureClass pOutputFeatClass;
Control.CheckForIllegalCrossThreadCalls = false;
System.Threading.Thread.Sleep(3000);
pOutputFeatClass = pBGP.Intersect(pInputTable, false, pOverlayTable, false, tol, pFeatClassName);
ITable SechDatatable = pOutputFeatClass as ITable;
DataTable dt = new DataTable("Temp");
try
{
IQueryFilter queryFilter = new QueryFilterClass();
ICursor pCursor =SechDatatable.Search(queryFilter,true);
IRow pRow = pCursor.NextRow();
if (pRow != null)
{
DataColumn dataColumn = null;
for (int i = 0; i < pRow.Fields.FieldCount; i++)
{
if (pRow.Fields.get_Field(i).AliasName != "图层别名")
{
dataColumn = dt.Columns.Add(pRow.Fields.get_Field(i).AliasName);
dataColumn.ReadOnly = true;
}
else
{
dt.Columns.Add(pRow.Fields.get_Field(i).AliasName);
//dataColumn.Unique = true;
}
}
while (pRow != null)
{
DataRow pDataRow = dt.NewRow();
for (int j = 0; j < pCursor.Fields.FieldCount; j++)
{
pDataRow[j] = pRow.get_Value(j);
}
dt.Rows.Add(pDataRow);
pRow = pCursor.NextRow();
}
}
return dt;
}
catch (System.Exception ex)
{
MessageBox.Show("转换出错," + ex.Message, "提示");
return null;
}
}
public DataTable intial()
{
string a= DateTime.Now.ToShortTimeString();
IAoInitialize aoinitialize = new AoInitializeClass();
aoinitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
string shpFilePath = Application.StartupPath;
IFeatureClass pFeatureClass = GetFeatureClass(shpFilePath,"国界.shp");
ITable pInputTable = pFeatureClass as ITable;
IFeatureClass pOverlayClass = GetFeatureClass(shpFilePath,"晒选前.shp");// pFeatureWorkspace.OpenFeatureClass("晒选前.shp");
ITable pOverlayTable = pOverlayClass as ITable;
if (pInputTable == null)
{
MessageBox.Show("Table QI failed");
return null;
}
if (pOverlayTable == null)
{
MessageBox.Show("Table QI failed");
return null;
}
string workspacename=shpFilePath;
string layername="国界-筛选.shp";
IFeatureClassName pFeatClassName;
pFeatClassName = new FeatureClassNameClass();
pFeatClassName.FeatureType = esriFeatureType.esriFTSimple;
pFeatClassName.ShapeFieldName = "Shape";
//
pFeatClassName.ShapeType = pOverlayClass.ShapeType;
MessageBox.Show(pOverlayClass.ShapeType.ToString());
IWorkspaceName pworspaname = new WorkspaceNameClass();
pworspaname.WorkspaceFactoryProgID = "esriDatasourcesFile.ShapeFileWorkspaceFactory";
pworspaname.PathName = workspacename;
IDatasetName pdatasetname = pFeatClassName as IDatasetName;
pdatasetname.Name = layername;
pdatasetname.WorkspaceName = pworspaname;
double tol = 0.3;
IBasicGeoprocessor pBGP;
pBGP = new BasicGeoprocessorClass();
IFeatureClass pOutputFeatClass;
string aa= DateTime.Now.ToShortTimeString();
pOutputFeatClass = pBGP.Intersect(pInputTable, false, pOverlayTable, false, tol, pFeatClassName);
string b= pOutputFeatClass.AliasName.ToString();
MessageBox.Show(b);
string aaa= DateTime.Now.ToShortTimeString();
#region 将得到的
ITable SechDatatable = pOutputFeatClass as ITable;
DataTable dt = new DataTable("Temp");
try
{
IQueryFilter queryFilter = new QueryFilterClass();
ICursor pCursor = SechDatatable.Search(queryFilter, true);
IRow pRow = pCursor.NextRow();
if (pRow != null)
{
DataColumn dataColumn = null;
for (int i = 0; i < pRow.Fields.FieldCount; i++)
{
if (pRow.Fields.get_Field(i).AliasName != "图层别名")
{
dataColumn = dt.Columns.Add(pRow.Fields.get_Field(i).AliasName);
dataColumn.ReadOnly = true;
}
else
{
dt.Columns.Add(pRow.Fields.get_Field(i).AliasName);
//dataColumn.Unique = true;
}
}
while (pRow != null)
{
DataRow pDataRow = dt.NewRow();
for (int j = 0; j < pCursor.Fields.FieldCount; j++)
{
pDataRow[j] = pRow.get_Value(j);
}
dt.Rows.Add(pDataRow);
pRow = pCursor.NextRow();
}
}
return dt;
}
catch (System.Exception ex)
{
MessageBox.Show("转换出错," + ex.Message, "提示");
return null;
}
#endregion
}
public IFeatureClass GetFeatureClass(string path, string className)
{
IWorkspaceFactory pWorkspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(path, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(className);
return pFeatureClass;
}
补充:.NET技术 , C#