Mark 创建路径(c#)-动态分段
2013-12-26 18:31
330 查看
http://bbs.esrichina-bj.cn/ESRI/viewthread.php?action=printable&tid=128564
public void CreateRoutesUsing2Fields(string sAccessWS, string sLineFC, string sOutRouteFC, string sWhereClause, string sRouteIDField, string sFromMeasureField, string sToMeasureField)
{
try
{
IWorkspaceFactory wsf = new AccessWorkspaceFactoryClass();
IWorkspace ws = wsf.OpenFromFile(sAccessWS, 0);
IFeatureWorkspace fws = (IFeatureWorkspace)ws;
IFeatureClass lineFC = fws.OpenFeatureClass(sLineFC);
// Create an output feature class name object. We'll write to a stand alone feature class in the
// the same workspace as the inputs
IDataset ds = (IDataset)ws;
IWorkspaceName outWSN = (IWorkspaceName)ds.FullName;
IFeatureClassName outFCN = new FeatureClassNameClass();
IDatasetName outDSN = (IDatasetName)outFCN;
outDSN.WorkspaceName = outWSN;
outDSN.Name = sOutRouteFC; //This name should not already exist
// Create a geometry definition for the new feature class. For the most part, we will copy the geometry
// definition from the input lines. We'll explicitly set the M Domain, however. You should always set an
// M Domain that is appropriate to your data. What is below is just a sample.
IFields flds = lineFC.Fields;
Int32 i = flds.FindField(lineFC.ShapeFieldName);
IField fld = flds.get_Field(i);
IClone GDefclone = (IClone)fld.GeometryDef;
IGeometryDef gDef = (IGeometryDef)GDefclone.Clone();
ISpatialReference2 srRef = (ISpatialReference2)gDef.SpatialReference;
srRef.SetMFalseOriginAndUnits(-1000, 10000);
// Create a selection set to limit the number of lines that will be used to create routes
IQueryFilter qFilt = new QueryFilterClass();
qFilt.WhereClause = sWhereClause;
ISelectionSet2 selSet = (ISelectionSet2)lineFC.Select(qFilt, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, ws);
// Create a new RouteMeasureCreator object. Note that below, we use the selection set and not the
// InputFeatureClass property
IRouteMeasureCreator routeCreator = new RouteMeasureCreatorClass();
routeCreator.InputFeatureSelection = selSet;
routeCreator.InputRouteIDFieldName = sRouteIDField;
IEnumBSTR errors = routeCreator.CreateUsing2Fields(sFromMeasureField, sToMeasureField, outFCN, gDef, "", null);
// The results of running CreatingUsing2Fields returns IEnumBSTR, which is a container
// for a list of error strings indicating why certain lines could not be used to create routes.
string sError = errors.Next();
do
{
System.Windows.Forms.MessageBox.Show(sError);
sError = errors.Next();
} while (sError.Length != 0);
}
catch(Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
}
}
这段代码能否实现创建路径功能???
CreateUsing2Fields(sFromMeasureField, sToMeasureField, outFCN, gDef, "", null);
上面一行代码各个参数是什么意思呀~~为什么运行的时候出现错误
public void CreateRoutesUsing2Fields(string sAccessWS, string sLineFC, string sOutRouteFC, string sWhereClause, string sRouteIDField, string sFromMeasureField, string sToMeasureField)
{
try
{
IWorkspaceFactory wsf = new AccessWorkspaceFactoryClass();
IWorkspace ws = wsf.OpenFromFile(sAccessWS, 0);
IFeatureWorkspace fws = (IFeatureWorkspace)ws;
IFeatureClass lineFC = fws.OpenFeatureClass(sLineFC);
// Create an output feature class name object. We'll write to a stand alone feature class in the
// the same workspace as the inputs
IDataset ds = (IDataset)ws;
IWorkspaceName outWSN = (IWorkspaceName)ds.FullName;
IFeatureClassName outFCN = new FeatureClassNameClass();
IDatasetName outDSN = (IDatasetName)outFCN;
outDSN.WorkspaceName = outWSN;
outDSN.Name = sOutRouteFC; //This name should not already exist
// Create a geometry definition for the new feature class. For the most part, we will copy the geometry
// definition from the input lines. We'll explicitly set the M Domain, however. You should always set an
// M Domain that is appropriate to your data. What is below is just a sample.
IFields flds = lineFC.Fields;
Int32 i = flds.FindField(lineFC.ShapeFieldName);
IField fld = flds.get_Field(i);
IClone GDefclone = (IClone)fld.GeometryDef;
IGeometryDef gDef = (IGeometryDef)GDefclone.Clone();
ISpatialReference2 srRef = (ISpatialReference2)gDef.SpatialReference;
srRef.SetMFalseOriginAndUnits(-1000, 10000);
// Create a selection set to limit the number of lines that will be used to create routes
IQueryFilter qFilt = new QueryFilterClass();
qFilt.WhereClause = sWhereClause;
ISelectionSet2 selSet = (ISelectionSet2)lineFC.Select(qFilt, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, ws);
// Create a new RouteMeasureCreator object. Note that below, we use the selection set and not the
// InputFeatureClass property
IRouteMeasureCreator routeCreator = new RouteMeasureCreatorClass();
routeCreator.InputFeatureSelection = selSet;
routeCreator.InputRouteIDFieldName = sRouteIDField;
IEnumBSTR errors = routeCreator.CreateUsing2Fields(sFromMeasureField, sToMeasureField, outFCN, gDef, "", null);
// The results of running CreatingUsing2Fields returns IEnumBSTR, which is a container
// for a list of error strings indicating why certain lines could not be used to create routes.
string sError = errors.Next();
do
{
System.Windows.Forms.MessageBox.Show(sError);
sError = errors.Next();
} while (sError.Length != 0);
}
catch(Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
}
}
这段代码能否实现创建路径功能???
CreateUsing2Fields(sFromMeasureField, sToMeasureField, outFCN, gDef, "", null);
上面一行代码各个参数是什么意思呀~~为什么运行的时候出现错误
相关文章推荐
- Mark 创建路径(c#)-动态分段
- 创建路径(c#)-动态分段
- c#通过类名动态创建对象方法
- C#动态程序集的加载、创建实例、序列化与反序列化
- C# 反射动态创建窗体
- C#动态创建Access数据库表
- C# 动态创建DataTable
- C# 动态创建窗体
- 在C# 编程中通过类名动态创建实例
- c#动态创建自定义的控件及显示控件查找控件
- C#创建高质量(清晰)缩略图——动态调整大小
- 用C#替换宏,实现动态创建Excel下拉框及批注
- C#运用ADO.net动态创建excle并进行相应的数据修改显示
- C# 动态创建组件(属性及事件)
- 第七章 业务数据库的管理(五)-- C#动态创建控件
- c# 创建动态控件
- c# winform 反射 动态创建窗口
- C#中动态创建控件及事件处理程序
- C#动态创建和动态使用程序集、类、方法、字段等(二)
- C#中动态创建控件及事件处理程序