FME Object API Write to Oracle8i 空间表实例

FME Object API Write to Oracle8i 空间表实例

//FME Object API Write to Oracle8i 空间表实例
        static void WriteExample_Oracle8i()
        {
            // Creates the session
            IFMEOSession fmeSession = FMEObjects.CreateSession();
            fmeSession.Init(null);

            // Creates the oracle spatial writer
            IFMEOWriter fmeWriter = fmeSession.CreateWriter("ORACLE8I", null);
                        
            StringCollection writerParms = new StringCollection();
            writerParms.Add("USER_NAME");  //用户名
            writerParms.Add("cdbfsgdb");   //用户名的值
            writerParms.Add("PASSWORD");   //密码
            writerParms.Add("1");          //密码的值
            fmeWriter.Open("xpserver", writerParms);  //oracle的Net Service名称xpserver

            string FeatureType = "drawing";  //图层名称
            // Adds schema information for writer
            IFMEOFeature schemaFeature = fmeSession.CreateFeature();
            schemaFeature.FeatureType = FeatureType;   //图层名称
            //
            //添加字段            
            schemaFeature.SetStringAttribute("FID", "VARCHAR2(40)");         //添加FID字段
            schemaFeature.SetStringAttribute("BSM", "NUMBER(10,0)");         //添加BSM字段
            schemaFeature.SetStringAttribute("TBMJ", "NUMBER(38,2)");        //添加TBMJ字段
            schemaFeature.SetStringAttribute("TBDLMJ", "NUMBER(38,2)");      //添加TBDLMJ字段
            schemaFeature.SetStringAttribute("CD", "NUMBER(10,1)");          //添加CD字段
            schemaFeature.SetStringAttribute("KD", "NUMBER(10,1)");          //添加KD字段
            //
            schemaFeature.SetSequencedAttribute("GEOMETRY", "GEOMETRY");     //添加几何字段
            //
            fmeWriter.AddSchema(schemaFeature);
            //
            schemaFeature.Dispose();

            // Creates a feature to write out
            IFMEOFeature fmeFeature = fmeSession.CreateFeature();
            fmeFeature.FeatureType = FeatureType;   //图层名称
            fmeFeature.SetSequencedAttribute("fme_type", "fme_line");
            fmeFeature.GeometryType = FMEOGeometry.Line;  //线
            fmeFeature.Dimension = FMEODimension.Two;   //二维
            fmeFeature.Add2DCoordinate(5, 5);
            fmeFeature.Add2DCoordinate(5, 10);
            fmeFeature.Add2DCoordinate(10, 10);
            //
            fmeFeature.SetIntAttribute("BSM", 1);
            fmeFeature.SetStringAttribute("FID", System.Guid.NewGuid().ToString());
            fmeFeature.SetDoubleAttribute("KD", 2.3);
            fmeFeature.SetDoubleAttribute("CD", 5);
            fmeFeature.SetDoubleAttribute("TBMJ", 5*2.3);
            fmeFeature.SetDoubleAttribute("TBDLMJ", 5 * 2.3-1);
            // Writes the created feature. A table named DRAWING will be created.
            fmeWriter.Write(fmeFeature);

            // Closes the writer
            fmeWriter.Close();
            fmeWriter.Dispose();

            // Clean up 
            fmeFeature.Dispose();
            fmeSession.Dispose();
        }


你可能感兴趣的:(FME Object API Write to Oracle8i 空间表实例)