Ejemplo n.º 1
0
        internal static string CreateNewTimShapefile(string timFeatureType, string shapefileName)
        {
            DataTable coordTable = new DataTable();
            DataTable attTable   = new DataTable();

            ShapeFile.ShapeFileTypes shpfiletype = ShapeFile.ShapeFileTypes.Point;
            if (timFeatureType == "Constant")
            {
                shpfiletype = ShapeFile.ShapeFileTypes.Point;
                attTable.Columns.Add("Head");
                attTable.Columns.Add("Name");
                attTable.Columns.Add("Layer1");
            }

            if (timFeatureType == "FlowLineSink")
            {
                shpfiletype = ShapeFile.ShapeFileTypes.PolyLine;
                //attTable.Columns.Add("sigma");
                attTable.Columns.Add("Name");
                attTable.Columns.Add("Sigma1");
            }
            if (timFeatureType == "ResLineSink")
            {
                shpfiletype = ShapeFile.ShapeFileTypes.PolyLine;
                //attTable.Columns.Add("Head");
                attTable.Columns.Add("Resistance");
                attTable.Columns.Add("BotElev");
                attTable.Columns.Add("Width");
                attTable.Columns.Add("Name");
                attTable.Columns.Add("Head1");
            }
            if (timFeatureType == "HeadLineSink")
            {
                shpfiletype = ShapeFile.ShapeFileTypes.PolyLine;
                //attTable.Columns.Add("Head");
                attTable.Columns.Add("Name");
                attTable.Columns.Add("Head1");
            }
            if (timFeatureType == "Well")
            {
                shpfiletype = ShapeFile.ShapeFileTypes.Point;
                attTable.Columns.Add("Discharge");
                attTable.Columns.Add("Radius");
                attTable.Columns.Add("Name");
                attTable.Columns.Add("Layer1");
            }
            ShapeFile newTimShp = new ShapeFile(shpfiletype, coordTable, attTable);

            newTimShp.Write(ArcTimData.StaticClass.infoTable.Rows[0]["ShapefilePath"].ToString() + "\\" + shapefileName + "_Tim.shp");
            return(shapefileName + "_Tim.shp");
        }
Ejemplo n.º 2
0
        //public static DataTable getModelData()
        //{

        //    //DataTable modelData = TimLib.Utilities.Read(dbfFilename);
        //    DataTable modelData =ModelSettingsWindow.ds.Tables["aquiferData"];
        //    modelData.WriteXml("xlData.xml");
        //    //DataSet temp = modelData.DataSet;
        //    //temp.Tables.Remove(modelData);
        //    ModelName = modelData.Columns[0].ColumnName;
        //    ArcTim5PropertiesMenu.StaticClass.numLayers = Convert.ToInt16(modelData.Rows[0][0].ToString());
        //    ModelSettingsWindow.numberOfLayers = ArcTim5PropertiesMenu.StaticClass.numLayers;
        //    return modelData;
        //}
        //public static void setModelData(string filename, DataTable modelDataTable)
        //{

        //    // write code to write new .dbf file with data from dialog
        //    //bool fileexists = ArcTimUtilites.DoesFileExists(filename);
        //    //DataSet ds = new DataSet();
        //    //ds.Tables.Add(modelDataTable);
        //    bool fileexport = TimLib.Utilities.EportDBF(modelDataTable, filename);


        //}
        public static string createTimShapefile(string filename, DataTable dtable, string fileType)
        {
            string    TimFileName = filename + "_Tim";
            ShapeFile OldShp      = new ShapeFile(ArcTimData.StaticClass.infoTable.Rows[0]["ShapefilePath"].ToString() + "\\" + filename + ".shp");
            DataTable coordTable  = new DataTable("coordinates");
            DataTable attTable    = new DataTable("attributes");
            DataTable OldAttTable = new DataTable("oldAttTable");

            ShapeFile.ShapeFileTypes shpfileType = ShapeFile.ShapeFileTypes.Point;
            coordTable  = OldShp.CoordinateTable;
            OldAttTable = OldShp.AttributeTable;

            if (fileType == "constant")
            {
                shpfileType = ShapeFile.ShapeFileTypes.Point;
                int   count   = dtable.Rows.Count;
                int[] attName = new int[count];
                for (int i = 0; i < count; i++)
                {
                    attTable.Columns.Add(dtable.Rows[i][0].ToString());
                    attName[i] = OldAttTable.Columns.IndexOf(dtable.Rows[i][1].ToString());
                }
                attTable.Columns.Add("Name");
                attTable.Columns.Add("Layer1");
                DataRow r;
                for (int j = 0; j < OldAttTable.Rows.Count; j++)
                {
                    r = attTable.NewRow();
                    for (int k = 0; k < count; k++)
                    {
                        r[0] = OldAttTable.Rows[j][attName[k]].ToString();
                        r[1] = "Constant";
                        r[2] = 1;
                    }
                    attTable.Rows.Add(r);
                }
            }
            if (fileType == "hls")
            {
                shpfileType = ShapeFile.ShapeFileTypes.PolyLine;
                int   count   = dtable.Rows.Count;
                int[] attName = new int[count];
                for (int i = 0; i < count; i++)
                {
                    attTable.Columns.Add(dtable.Rows[i][0].ToString());
                    attName[i] = OldAttTable.Columns.IndexOf(dtable.Rows[i][1].ToString());
                }
                //attTable.Columns.Add("Name");

                DataRow r;
                for (int j = 0; j < OldAttTable.Rows.Count; j++)
                {
                    r = attTable.NewRow();


                    r[0] = OldAttTable.Rows[j][attName[0]].ToString();
                    r[1] = OldAttTable.Rows[j][attName[1]].ToString();


                    attTable.Rows.Add(r);
                }
            }
            if (fileType == "rls")
            {
                shpfileType = ShapeFile.ShapeFileTypes.PolyLine;
                int   count   = dtable.Rows.Count;
                int[] attName = new int[count];
                for (int i = 0; i < count; i++)
                {
                    attTable.Columns.Add(dtable.Rows[i][0].ToString());
                    attName[i] = OldAttTable.Columns.IndexOf(dtable.Rows[i][1].ToString());
                }
                //attTable.Columns.Add("Name");

                DataRow r;
                for (int j = 0; j < OldAttTable.Rows.Count; j++)
                {
                    r = attTable.NewRow();


                    r[0] = OldAttTable.Rows[j][attName[0]].ToString();
                    r[1] = OldAttTable.Rows[j][attName[1]].ToString();
                    r[2] = OldAttTable.Rows[j][attName[2]].ToString();
                    r[3] = OldAttTable.Rows[j][attName[3]].ToString();
                    r[4] = OldAttTable.Rows[j][attName[4]].ToString();



                    attTable.Rows.Add(r);
                }
            }
            if (fileType == "fls")
            {
                shpfileType = ShapeFile.ShapeFileTypes.PolyLine;
                int   count   = dtable.Rows.Count;
                int[] attName = new int[count];
                for (int i = 0; i < count; i++)
                {
                    attTable.Columns.Add(dtable.Rows[i][0].ToString());
                    attName[i] = OldAttTable.Columns.IndexOf(dtable.Rows[i][1].ToString());
                }
                //attTable.Columns.Add("Name");

                DataRow r;
                for (int j = 0; j < OldAttTable.Rows.Count; j++)
                {
                    r = attTable.NewRow();


                    r[0] = OldAttTable.Rows[j][attName[0]].ToString();
                    r[1] = OldAttTable.Rows[j][attName[1]].ToString();



                    attTable.Rows.Add(r);
                }
            }
            if (fileType == "well")
            {
                shpfileType = ShapeFile.ShapeFileTypes.Point;
                int   count   = dtable.Rows.Count;
                int[] attName = new int[count - 1];
                for (int i = 0; i < count - 1; i++)
                {
                    attTable.Columns.Add(dtable.Rows[i][0].ToString());
                    attName[i] = OldAttTable.Columns.IndexOf(dtable.Rows[i][1].ToString());
                }
                //attTable.Columns.Add("Name");
                for (int i = 0; i < Convert.ToInt32(dtable.Rows[count - 1][1]); i++)
                {
                    attTable.Columns.Add("Layer" + Convert.ToString(i + 1));
                }
                DataRow r;
                for (int j = 0; j < OldAttTable.Rows.Count; j++)
                {
                    r = attTable.NewRow();

                    for (int k = 0; k < attName.Length; k++)
                    {
                        r[k] = OldAttTable.Rows[j][attName[k]].ToString();
                    }

                    attTable.Rows.Add(r);
                }
            }
            //ShapeFile.ShapeFileTypes.Point
            ShapeFile newTimShp = new ShapeFile(shpfileType, coordTable, attTable);

            newTimShp.Write(ArcTimData.StaticClass.infoTable.Rows[0]["ShapefilePath"].ToString() + "\\" + filename + "_Tim.shp");
            //next step... bring shapefile into map document
            //extrapolate to other feature types
            return(filename + "_Tim.shp");
        }