ArcEngine 数据导出Shape的几种方式
ArcEngine 数据导出Shape的几种方式
这里志列出关键代码,该代码不是 方法一:创建一个shape要素类,结果与导出要素类一致,保存使用store速度最慢,忽略
方法二:使用IFeatureBuffer速度较快,缺点:数据量大,导出的时候容易报内存损坏错误使程序崩溃,把arcgis lisence服务重启几次后有时能导出成功不会崩溃,没找到原因,如有解决方案,请告知,谢谢
{
{ geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon; }
{ geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline; }
{ geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint; }
ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem tProjectedCoordinateSystem = ((featureLayer as geometryDefEdit.SpatialReference_2 = tProjectedCoordinateSystem;
fieldChecker.ValidateWorkspace = (IWorkspace)pFeatureWorkSpace; fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
{
shpFeatureClass.AddField(tfield); }
shpfeatureLayer.FeatureClass = shpFeatureClass;
tQueryFilter.WhereClause = “”; tQueryFilter.AddField(featureLayer.FeatureClass.OIDFieldName); //计算要素总数
ImportFeatureClassData_MarshalReleaseComObject(featureLayer, shpfeatureLayer, totalCount); }
public {
{
{ i++; ZzCom.CommonUtil.SimpleWaiterHelper.SetValue(i);
{ pFeatureSource = pFeatureCursorSource.NextFeature();
}
pFeatureTarget.Shape = geometry;
pFeatureCursor.InsertFeature(pFeatureBuffer);
{ pFeatureCursor.Flush();
pFeatureTarget = null; pFeatureSource = null; pFeatureBuffer = null; pFeatureCursor = null;
pFeatureBuffer = shpFeatureClass.CreateFeatureBuffer(); pFeatureCursor = shpFeatureClass.Insert(true); pFeatureTarget = pFeatureBuffer as }
pFeatureSource = pFeatureCursorSource.NextFeature(); }
pFeatureCursor.Flush();
{ System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pFeatureCursor); pFeatureCursor = null; }
{ System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pFeatureBuffer); pFeatureBuffer = null; }
{ System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pFeatureSource); pFeatureSource = null; }
{ System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pFeatureCursorSource); pFeatureCursorSource = null; }
ZzCom.CommonUtil.SimpleWaiterHelper.SetValue(totalCount);
}
{ ZzLog4net.ZzLogUtil.Logger.LogInfo(string.Format(“异常信息:{0} 异常位置:{1} 时间:'{2}'”, e.Message, e.ToString(), System.DateTime.Now));
}
{ ZzCom.CommonUtil.SimpleWaiterHelper.SetValue(totalCount);
}
} |
方法三使用IFeatureDataConverter2或者IFeatureDataConverter,速度最快,缺点无法知道导出的要素总数和当前要素,无法做进度条,不知道arcgis使用的那种方法(求告知),速度快还有进度条,这个地方要注意把大字段处理了,处理方案可以把输出字段集拷贝一份,把大字段改成string类型,或者使用IFeatureDataConverter2像以下处理。
{
{
{
}
pOutFeatureClassName = (IFeatureClassName)pOutDataset.FullName;
pInDatasetClassName = (IDatasetName)pInFeatureClassName; pInDatasetClassName.Name = ExportShapeFileName;//作为输出参数 pInDatasetClassName.WorkspaceName = outWorkspaceName;
pInFields = apFeatureClass.Fields; pFieldChecker = new pFieldChecker.InputWorkspace = apFeatureClass.FeatureDataset.Workspace; pFieldChecker.ValidateWorkspace = workspace; pFieldChecker.Validate(pInFields, out pEnumFieldError, out pOutFields);
pGeoField = null;
{
{ pGeoField = pOutFields.get_Field((int)iCounter);
} }
{ FieldErrorList.Add(fieldError.FieldIndex); fieldError = pEnumFieldError.Next(); }
{ InputQueryFilter = new InputQueryFilter.WhereClause = “”; }
{ InputQueryFilter = new InputQueryFilter.WhereClause = “”;
pSelectionSet = pFeatureSelection.SelectionSet; }
{
spatialFilter.Geometry = geometry; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; InputQueryFilter = spatialFilter as InputQueryFilter.WhereClause = “”; }
{
pField.Type == esriFieldType.esriFieldTypeRaster || pField.Type == esriFieldType.esriFieldTypeGUID) continue;
pFieldsEdit.AddField(pField);
{ InputQueryFilter.AddField(pField.Name); } strBuilderSubFields.Append(pField.Name + “,”); }
{ InputQueryFilter.SubFields = SubFields; }
pOutGeometryDef = pGeoField.GeometryDef; pOutGeometryDefEdit = (IGeometryDefEdit)pOutGeometryDef; pOutGeometryDefEdit.GridCount_2 = 1; pOutGeometryDefEdit.set_GridSize(0, 1500000);
sourceFeatureClassName = (IFeatureClassName)pOutDataset.FullName;
pShpToClsConverter2.ConvertFeatureClass(sourceDatasetName, InputQueryFilter, pSelectionSet, null, pInFeatureClassName, pOutGeometryDef, pOutFields, “”, 1000, 0); }
{
} }
|
转载自:https://blog.csdn.net/whz1571443359/article/details/79619752