FME Object API Read from Oracle8i 空间表实例

//FME Object API Read  from Oracle8i 空间表实例
        static void ReaderExample_Oracle8i()
        {
            // Creates the session
            IFMEOSession fmeSession = FMEObjects.CreateSession();
            fmeSession.Init(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);
            //----------------

            StringCollection fmeDirectives=new StringCollection();
            fmeDirectives.Add("OUTPUT_STATS");  //输出状态:无NO
            fmeDirectives.Add("YES");  
            
            
            // Creates the oracle spatial reader
            IFMEOReader fmeRead = fmeSession.CreateReader("ORACLE8I", true, fmeDirectives);

            StringCollection writerParms = new StringCollection();

            writerParms.Add("DATASET");
            writerParms.Add("xpserver");
            //
            writerParms.Add("USER_NAME");
            writerParms.Add("cdbfsgdb");
            //
            writerParms.Add("PASSWORD");
            writerParms.Add("1");
            //
            //打开图层名称(要素类)drawing
            /**/
            writerParms.Add("DEF");
            writerParms.Add("drawing");            
            //
            writerParms.Add("IDs");
            writerParms.Add("drawing");            
            //
            writerParms.Add("WHERE_CLAUSE");
            writerParms.Add(" 1=1 ");
             
            
            //打开图层名称(要素类)v_tdlyxz_dltb_h
            /*
            writerParms.Add("DEF");            
            writerParms.Add("v_tdlyxz_dltb_h");
            //
            writerParms.Add("IDs");            
            writerParms.Add("v_tdlyxz_dltb_h");
            //
            writerParms.Add("WHERE_CLAUSE");            
            writerParms.Add("zldwdm like '510112%' ");
             */
            //
            fmeRead.Open("xpserver", writerParms);
            //

            //读取模式要素
            bool bReadSchemaTrue = true;
            IFMEOFeature fmeSchemaFeature = fmeSession.CreateFeature();
            while (bReadSchemaTrue == true)
            {
                bReadSchemaTrue = fmeRead.ReadSchema(fmeSchemaFeature);
                if (bReadSchemaTrue == true)
                {
                    if (fmeSchemaFeature != null)
                    {
                        fmeLogFile.LogFeature(fmeSchemaFeature, FMEOMessageLevel.Warn, 1);
                        Console.WriteLine(fmeSchemaFeature.FeatureType + "," + fmeSchemaFeature.GeometryType.ToString());
                    }
                }
            }
            //读取数据要素
            bool bReadTrue = true;
            IFMEOFeature fmeDataFeature=null;
            IFMEOGeometry geo = null;
            while (bReadTrue == true)
            {
                fmeDataFeature =fmeSession.CreateFeature();
                bReadTrue = fmeRead.Read(fmeDataFeature);
                if (bReadTrue == true)
                {
                    if (fmeDataFeature != null)
                    {
                        //获取属性值
                        //Console.WriteLine("FID="+fmeDataFeature.GetStringAttribute("FID"));
                        //Console.WriteLine("BSM="+fmeDataFeature.GetIntAttribute("BSM"));
                        //Console.WriteLine("TBMJ=" + fmeDataFeature.GetDoubleAttribute("TBMJ"));
                        //Console.WriteLine("TBDLMJ=" + fmeDataFeature.GetStringAttribute("TBDLMJ"));
                        //
                        StringCollection fdNames = new StringCollection();
                        fmeDataFeature.GetAllAttributeNames(fdNames);
                        foreach (string fd in fdNames)
                        {
                            Console.WriteLine(fd + "=" + fmeDataFeature.GetStringAttribute(fd));
                        }
                        //获取几何图形信息
                        geo = fmeDataFeature.GetGeometry();
                        switch (fmeDataFeature.GeometryType)
                        {
                            case FMEOGeometry.Line:      //线
                                {
                                    int CoordCount = fmeDataFeature.NumberCoordinates;
                                    for (int i = 0; i < CoordCount; i++)
                                    {
                                        Console.WriteLine("x,y=(" + fmeDataFeature.GetXCoordinate(i) + "," + fmeDataFeature.GetYCoordinate(i) + ")");
                                    }
                                }
                                break;
                            case FMEOGeometry.Point:     //点
                                {
                                    int CoordCount = fmeDataFeature.NumberCoordinates;
                                    for (int i = 0; i < CoordCount; i++)
                                    {
                                        Console.WriteLine("x,y=(" + fmeDataFeature.GetXCoordinate(i) + "," + fmeDataFeature.GetYCoordinate(i) + ")");
                                    }
                                }
                                break;
                            case FMEOGeometry.Polygon:   //面
                                {
                                    IFMEOFeatureVector fmeFeatVector = fmeSession.CreateFeatureVector();
                                    fmeDataFeature.GetDonutParts(fmeFeatVector);
                                    int rings = fmeFeatVector.Count;
                                    IFMEOFeature polygonFeat = null;
                                    for (int r = 0; r < rings; r++)
                                    {
                                        polygonFeat = fmeFeatVector.GetAt(r);
                                        int CoordCount = polygonFeat.NumberCoordinates;
                                        Console.WriteLine("ring id=" + r + "coordnums=" + CoordCount);
                                        for (int i = 0; i < CoordCount; i++)
                                        {
                                            Console.WriteLine("x,y=(" + polygonFeat.GetXCoordinate(i) + "," + polygonFeat.GetYCoordinate(i) + ")");
                                        }
                                        polygonFeat.Dispose();
                                        polygonFeat = null;
                                    }
                                    fmeFeatVector.Dispose();
                                    fmeFeatVector = null;
                                }
                                break;
                            default:
                                break;
                        }
                        //
                    }
                }
            }
            fmeRead.Dispose();
            fmeRead = null;
            
            // Clean up 
            //fmeFeature.Dispose();
            fmeSession.Dispose();
            fmeSession = null;
        }


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