FME Object API Write to SDE30 空间表实例

//FME Object API Write to SDE30 空间表实例
//vp:hsg 
//create date:2012-07-06
        static void WriteExample_SDE()
        {
            // Creates the session
            IFMEOSession fmeSession = FMEObjects.CreateSession();
            fmeSession.Init(null);

            // Creates the oracle spatial writer
            IFMEOWriter fmeWriter = fmeSession.CreateWriter("SDE30", null);

            //日志文件设置
            string appPath = Assembly.GetExecutingAssembly().Location;
            int index = appPath.LastIndexOf("\\", appPath.Length - 1);
            string appFolder = appPath.Substring(0, index);
            string logFilePath = appFolder + "\\log.txt";
            //----------------
            //Get the log file object from the session
            IFMEOLogFile fmeLogFile = fmeSession.LogFile();
            //Set the path of the log file
            fmeLogFile.SetFileName(logFilePath, false);
            //----------------

            string FeatureType = "V_TDLYXZ_DLTB_H";


            IFMEOReader fmeReader = fmeSession.CreateReader("ORACLE8I", true, null);
            StringCollection readerParams = new StringCollection();
            #region //设置参数
            readerParams.Add("DATASET");
            readerParams.Add("xpserver");
            //
            readerParams.Add("USER_NAME");
            readerParams.Add("cdbfsgdb");
            //
            readerParams.Add("PASSWORD");
            readerParams.Add("1");
            //
            //打开图层名称(要素类)v_tdlyxz_dltb_h
            /**/
            readerParams.Add("DEF");
            readerParams.Add(FeatureType);
            //
            readerParams.Add("IDs");
            readerParams.Add(FeatureType);
            //
            readerParams.Add("WHERE_CLAUSE");
            readerParams.Add("zldwdm like '510113%' ");             
            //
            #endregion
            fmeReader.Open("xpserver", readerParams);  //oracle的net service名称xpserver

            StringCollection writerParms = new StringCollection();
            #region //设置参数
            writerParms.Add("SERVER");  //服务器
            writerParms.Add("rjb-scsup");   //服务器的值
            //
            writerParms.Add("INSTANCE");   //实例
            writerParms.Add("port:5151");  //实例的值
            //
            writerParms.Add("USERID");   //用户名
            writerParms.Add("sde");      //用户名的值
            //
            writerParms.Add("PASSWORD");   //密码
            writerParms.Add("sde");        //密码的值
            //
            writerParms.Add("VERSION_NAME");   //版本
            writerParms.Add("SDE.DEFAULT");    //版本的值
            //
            writerParms.Add("DEF");          //要写入的要素类
            writerParms.Add(FeatureType);    //要写入的要素类的值
            //
            writerParms.Add("IDs");          //要写入的要素类
            writerParms.Add(FeatureType);    //要写入的要素类的值
            //
            writerParms.Add("WRITER_MODE");
            writerParms.Add("INSERT");  //INSERT | UPDATE | DELETE
            //
            writerParms.Add("SIMPLIFY_GEOM");   
            writerParms.Add("YES");  //YES | NO

            #endregion
            fmeWriter.Open("rjb-scsup", writerParms);  //oracle的SDE名称rjb-scsup

            //插入原有要素(//读取要的数据要素)            
            bool bReadTrue = true;
            IFMEOFeature fmefeat_insert=null;
            int index_insert = 0;
            while (bReadTrue == true)
            {
                fmefeat_insert = fmeSession.CreateFeature();
                bReadTrue = fmeReader.Read(fmefeat_insert);
                if (bReadTrue == true)
                {
                    if (fmefeat_insert != null)
                    {                        
                        //fmeWriter.Write(fmedelfeat);
                        IFMEOFeature fmeFeature = fmeSession.CreateFeature();
                        fmeFeature.FeatureType = FeatureType;   //图层名称
                        fmeFeature.SetSequencedAttribute("fme_type", "fme_area");
                        fmeFeature.GeometryType = FMEOGeometry.Polygon;  //面
                        fmeFeature.Dimension = FMEODimension.Two;   //二维
                        fmeFeature.SetGeometry(fmefeat_insert.GetGeometry()); //图形
                        fmefeat_insert.CloneAttributes(fmeFeature);           //属性
                        //
                        fmeWriter.Write(fmeFeature);
                        //
                        index_insert += 1;
                        Console.WriteLine("插入要素index=" + index_insert);
                    }
                }
            }
            fmeReader.Dispose();
            fmeReader = null;


            #region //创建一个新要素 Creates a feature to write out
            /*
            IFMEOFeature fmeFeature = fmeSession.CreateFeature();
            fmeFeature.FeatureType = FeatureType;   //图层名称
            fmeFeature.SetSequencedAttribute("fme_type", "fme_area");
            fmeFeature.GeometryType = FMEOGeometry.Polygon;  //面
            fmeFeature.Dimension = FMEODimension.Two;   //二维
            fmeFeature.Add2DCoordinate(5, 5);
            fmeFeature.Add2DCoordinate(5, 10);
            fmeFeature.Add2DCoordinate(10, 10);
            fmeFeature.Add2DCoordinate(5, 5);
            //            
            fmeFeature.SetStringAttribute("FID", System.Guid.NewGuid().ToString());
            fmeFeature.SetStringAttribute("zldwdm","51011300X");
            // Writes the created feature. A table named DRAWING will be created.
            fmeWriter.Write(fmeFeature);
             */
            #endregion

            // Closes the writer
            fmeWriter.Close();
            fmeWriter.Dispose();
        }
----the--end---

你可能感兴趣的:(object,api,String,null,insert,dataset)