arcengine 以数据库方式读取dbf表

 public static System.Data.DataTable StatAttributively(string filepath, string groupbyfield, string typeColumn, string summaryfield)
    {
        //  filepath = @"D:\sichuan_county_landuse.dbf"; // = openFileDialog1.FileName.Replace(".shp", ".dbf");

        string areaFilePath = filepath.Replace(".shp", "_area.shp");
        Lib.Geoprocessor.CalculateAreas(filepath, areaFilePath);


        string dir = System.IO.Path.GetDirectoryName(areaFilePath);
        string file = System.IO.Path.GetFileName(areaFilePath).Replace(".shp", ".dbf");
        string connStr = "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + dir + ";Exclusive=No;";
        OdbcConnection conn2 = new OdbcConnection(connStr);
        conn2.Open();

        string sqlGetTypes = "select distinct " + typeColumn + " from " + file;

        //string SelectYuJu =
        //    @"SELECT name as 名称,sum(iif(土地利用类='耕地',AREA,0) ) as 耕地,sum(iif(土地利用类='林地',AREA,0) ) as 林地,sum(iif(土地利用类='牧草地',AREA,0) ) as 牧草地,sum(iif(土地利用类='水域',AREA,0) ) as 水域,sum(iif(土地利用类='未利用土地',AREA,0) ) as 未利用土地 FROM [" +
        //    file + "]  group by name";
        OdbcDataAdapter daTJ = new OdbcDataAdapter(sqlGetTypes, conn2);
        System.Data.DataTable tableTJ = new System.Data.DataTable();
        daTJ.Fill(tableTJ); //OK

        string sqlCalculate = "select " + groupbyfield + " as 名称";
        for (int i = 0; i < tableTJ.Rows.Count; i++)
            if (!tableTJ.Rows[i][typeColumn].ToString().Trim().Equals(""))
            sqlCalculate += ", sum(iif(" + typeColumn + "= '" + tableTJ.Rows[i][typeColumn].ToString().Trim() +
                            "',f_area,0)) as " + tableTJ.Rows[i][typeColumn].ToString().Trim();
        sqlCalculate += " from [" + file + "] group by " + groupbyfield;
        daTJ = new OdbcDataAdapter(sqlCalculate, conn2);
        DataTable dt = new DataTable();
        daTJ.Fill(dt);

     
        conn2.Close();
        return dt;
    }

 

转载自:https://blog.csdn.net/tianxinzhe032/article/details/6660043

You may also like...