• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

创建路径(c#)-动态分段

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
public void CreateRoutesUsing2Fields(string sAccessWS, string sLineFC, string sOutRouteFC, string sWhereClause, string sRouteIDField, string sFromMeasureField, string sToMeasureField)
        {
            try
            {
                //  VARIABLES
                //  sAccessWS - access workspace (i.e. "http://www.cnblogs.com/zuiyirenjian/admin/file://burt/data/dyndata/pitt.mdb")
                //  sLineFC - the input line feature class ("base_roads")
                //  sOutRouteFC - the output route feature class name ("routes")
                //  sWhereClause - query filter for line feature class if needed (i.e. "[RKey] <> 0")
                //  sRouteIDField - route ID field (i.e "Rkey")
                //  sFromMeasureField - the from-measure field (i.e. "BegMP")
                //  sToMeasureField - the to-measure field (i.e "EndMP")
 
                //Get the line feature class
                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);
            }


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
在C#中使用代理的方式触发事件的简单习作发布时间:2022-07-14
下一篇:
C#复习题发布时间:2022-07-14
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap