Beispiel #1
0
        private void Build929(string strReadCsvPath, string exportName, string exportPath)
        {
            #region RoadLighting
            string strID     = "";
            string strZoneID = "";
            long   strNO     = 0;
            try
            {
                Hashtable hasInfo   = new Hashtable();
                Hashtable hasInfoRe = new Hashtable();

                //string strPath1 = GetExportVirthPath("TDI002", "in") + "shp" + @"\";
                string strPath1 = @"F:\shp\Subzone" + exportPath.Substring(exportPath.Length - 8) + @"\";
                string strPath2 = "";
                lState.Text = "Get Export Path!";
                #region 读取输出shp,加载到数据集与图层

                MapLayer outLayer = null;
                ESRI.MapObjects2.Core.GeoDataset outDataset = null;

                ESRI.MapObjects2.Core.DataConnection outConnection = new DataConnection();
                outConnection.Database = exportPath;
                lState.Text            = "Connect shp!";
                if (outConnection.Connect())
                {
                    outLayer   = new MapLayer();
                    outDataset = outConnection.FindGeoDataset(exportName);

                    if (outDataset != null)
                    {
                        outLayer.GeoDataset = outDataset;
                    }
                }
                if (!outLayer.Valid)
                {
                    MessageBox.Show(exportName + " is no exist!", "error");
                    return;
                }
                #endregion
                lState.Text = "Check Directory!";
                #region 读取内存数据,AddNew到输出shp
                if (!System.IO.Directory.Exists(strPath1))
                {
                    // 目录不存在,建立目录
                    System.IO.Directory.CreateDirectory(strPath1);
                }
                lState.Text = "Start Export!";

                XmlElement theMasterZoneID = null, theSHPShapeFilename = null, theSHXShapeFilename = null, theDBFShapeFilename = null, root = null;

                //XmlDocument xmldoc = new XmlDocument();
                //xmldoc.Load("20150917200500_ArchSD_Masterzone.xml");
                //root = xmldoc.DocumentElement;
                {
                    strID       = textOne.Text;
                    lState.Text = strID;

                    //strPath2 = strPath1;// +strID.Replace("/", "_") + @"\";
                    strPath2 = strPath1 + strID.Replace("/", "_") + @"\";
                    if (!System.IO.Directory.Exists(strPath2))
                    {
                        // 目录不存在,建立目录
                        System.IO.Directory.CreateDirectory(strPath2);
                    }

                    String SHPShapeFilename = "Subzone_Shape.shp";
                    String SHXShapeFilename = "Subzone_Shape.shx";
                    String DBFShapeFilename = "Subzone_Shape.dbf";

                    String sourcePath = Application.StartupPath + @"\template\temp.shp";
                    String targetPath = strPath2 + SHPShapeFilename; // @"Subzone_Shape_" + (i + 1) + ".shp";
                    //String targetPath = exportPath + @"\Subzone_Shape\" + List[i].ToString().Replace("/", "_") + ".shp";
                    bool isrewrite = true;                           // true=覆盖已存在的同名文件,false则反之
                    System.IO.File.Copy(sourcePath, targetPath, isrewrite);

                    sourcePath = Application.StartupPath + @"\template\temp.shx";
                    targetPath = strPath2 + SHXShapeFilename;// @"Subzone_Shape_" + (i + 1) + ".shx";
                    System.IO.File.Copy(sourcePath, targetPath, isrewrite);

                    sourcePath = Application.StartupPath + @"\template\temp.dbf";
                    targetPath = strPath2 + DBFShapeFilename;// @"Subzone_Shape_" + (i + 1) + ".dbf";
                    System.IO.File.Copy(sourcePath, targetPath, isrewrite);

                    MapLayer cLayer = null;
                    ESRI.MapObjects2.Core.GeoDataset cDataset = null;

                    ESRI.MapObjects2.Core.DataConnection cConnection = new DataConnection();
                    cConnection.Database = strPath2;

                    if (cConnection.Connect())
                    {
                        cLayer = new MapLayer();
                        //cDataset = cConnection.FindGeoDataset(@"Subzone_Shape_" + (i + 1));
                        cDataset = cConnection.FindGeoDataset(SHPShapeFilename.Replace(".shp", ""));
                        if (cDataset != null)
                        {
                            cLayer.GeoDataset = cDataset;
                        }
                    }

                    if (!cLayer.Valid)
                    {
                        MessageBox.Show(exportName + " is no exist!", "error");
                        return;
                    }
                    Recordset cRecs = cLayer.Records;
                    if (!cRecs.Updatable)
                    {
                        MessageBox.Show(exportName + " is not editable!", "error");
                        return;
                    }

                    Recordset rs         = outLayer.SearchExpression("\"RefSlope\" ='" + strID + "'");
                    string    BuildingID = "";
                    string    SIStatus   = "";
                    rs.MoveFirst();
                    if (!rs.EOF)
                    {
                        while (!rs.EOF)
                        {
                            cRecs.MoveFirst();
                            cRecs.AddNew();
                            object geometry = rs.Fields.Item("Shape").Value;
                            cRecs.Fields.Item("Shape").Value = geometry;
                            SetLog("SubZoneID," + strID);
                            cRecs.Fields.Item("SubZoneID").Value = strID;// RefSlope;
                            cRecs.Update();
                            rs.MoveNext();
                        }
                        cRecs.StopEditing();
                    }
                    else
                    {
                        //BuildingID = rs.Fields.Item("BuildingID").ValueAsString;
                        richText1.AppendText(strZoneID + "," + SHPShapeFilename + "\n");
                        //日志记录
                        SetLog("No Record BuildingID:" + strZoneID + "," + SHPShapeFilename);
                    }
                }
                #endregion
            }
            catch (System.Exception ex)
            {
                //MessageBox.Show(ex.Message.ToString());
                SetLog("Error:" + ex.Message.ToString() + " @" + strID + "|");
            }
            #endregion
        }
Beispiel #2
0
        private void Build929AIMS1(string strReadCsvPath, string exportName, string exportPath)
        {
            #region RoadLighting
            string strID     = "";
            string strZoneID = "";
            long   strNO     = 0;
            try
            {
                Hashtable hasInfo   = new Hashtable();
                Hashtable hasInfoRe = new Hashtable();

                //string strPath1 = GetExportVirthPath("TDI002", "in") + "shp" + @"\";
                string strPath1 = @"F:\shp\Subzone20171204" + @"\";
                string strPath2 = "";
                lState.Text = "Get Export Path!";
                #region 读取输出shp,加载到数据集与图层

                MapLayer outLayer = null;
                ESRI.MapObjects2.Core.GeoDataset outDataset = null;

                ESRI.MapObjects2.Core.DataConnection outConnection = new DataConnection();
                outConnection.Database = exportPath;
                lState.Text            = "Connect shp!";
                if (outConnection.Connect())
                {
                    outLayer   = new MapLayer();
                    outDataset = outConnection.FindGeoDataset(exportName);

                    if (outDataset != null)
                    {
                        outLayer.GeoDataset = outDataset;
                    }
                }

                if (!outLayer.Valid)
                {
                    MessageBox.Show(exportName + " is no exist!", "error");
                    return;
                }
                #endregion
                lState.Text = "Check Directory!";
                #region 读取内存数据,AddNew到输出shp
                if (!System.IO.Directory.Exists(strPath1))
                {
                    // 目录不存在,建立目录
                    System.IO.Directory.CreateDirectory(strPath1);
                }
                lState.Text = "Start Export!";

                XmlElement theMasterZoneID = null, theSHPShapeFilename = null, theSHXShapeFilename = null, theDBFShapeFilename = null, root = null;

                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load("20150917200500_ArchSD_Masterzone.xml");
                root = xmldoc.DocumentElement;
                //outLayer.FilterExpression = "RefSlope='10NW-B/C16'";
                //for (int i = 0; i < List.Count; i++)
                //MessageBox.Show(dt.Rows.Count + "!", "error");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    strID       = dt.Rows[i]["BuildId"].ToString();
                    lState.Text = strID;

                    strNO = i;
                    if (radioOne.Checked)
                    {
                        if (textOne.Text != strID)
                        {
                            continue;
                        }
                    }
                    textOne.Text = strID;

                    //strPath2 = strPath1;// +strID.Replace("/", "_") + @"\";
                    strPath2 = strPath1 + strID.Replace("/", "_") + @"\";
                    if (!System.IO.Directory.Exists(strPath2))
                    {
                        // 目录不存在,建立目录
                        System.IO.Directory.CreateDirectory(strPath2);
                    }

                    if (strID == @"11NE-A/C879")
                    {
                        string text1 = "1";
                    }

                    strZoneID = dt.Rows[i]["MasterZoneID"].ToString();
                    //XmlNode rootMasterZone = root.SelectSingleNode("/MasterZones/MasterZone[MasterZoneID='" + strZoneID + "']");

                    //XmlNode Subzones = rootMasterZone.SelectSingleNode("Subzones");
                    //XmlNode Subzone = Subzones.SelectSingleNode("Subzone");
                    //XmlNode Polygon = Subzone.SelectSingleNode("Polygon");

                    //String SHPShapeFilename = (Polygon.SelectSingleNode("SHPShapeFilename")).InnerText;
                    //String SHXShapeFilename = (Polygon.SelectSingleNode("SHXShapeFilename")).InnerText;
                    //String DBFShapeFilename = (Polygon.SelectSingleNode("DBFShapeFilename")).InnerText;
                    //SHPShapeFilename = SHPShapeFilename.Replace("shp/TCB929/", "");
                    //SHXShapeFilename = SHXShapeFilename.Replace("shp/TCB929/", "");
                    //DBFShapeFilename = DBFShapeFilename.Replace("shp/TCB929/", "");

                    String SHPShapeFilename = "Subzone_Shape.shp";
                    String SHXShapeFilename = "Subzone_Shape.shx";
                    String DBFShapeFilename = "Subzone_Shape.dbf";



                    //if (SHPShapeFilename.IndexOf("Subzone_Shape_") < 0)
                    //{
                    //    richText1.AppendText("xml lost:" + strZoneID + "," + SHPShapeFilename + "\n");
                    //    continue;
                    //}

                    String sourcePath = Application.StartupPath + @"\template\temp.shp";
                    String targetPath = strPath2 + SHPShapeFilename; // @"Subzone_Shape_" + (i + 1) + ".shp";
                    //String targetPath = exportPath + @"\Subzone_Shape\" + List[i].ToString().Replace("/", "_") + ".shp";
                    bool isrewrite = true;                           // true=覆盖已存在的同名文件,false则反之
                    System.IO.File.Copy(sourcePath, targetPath, isrewrite);

                    sourcePath = Application.StartupPath + @"\template\temp.shx";
                    targetPath = strPath2 + SHXShapeFilename;// @"Subzone_Shape_" + (i + 1) + ".shx";
                    System.IO.File.Copy(sourcePath, targetPath, isrewrite);

                    sourcePath = Application.StartupPath + @"\template\temp.dbf";
                    targetPath = strPath2 + DBFShapeFilename;// @"Subzone_Shape_" + (i + 1) + ".dbf";
                    System.IO.File.Copy(sourcePath, targetPath, isrewrite);

                    //sourcePath = Application.StartupPath + @"\template\temp.prj";
                    //targetPath = strPath2 +  @"Subzone_Shape_" + (i + 1) + ".prj";
                    //System.IO.File.Copy(sourcePath, targetPath, isrewrite);

                    MapLayer cLayer = null;
                    ESRI.MapObjects2.Core.GeoDataset cDataset = null;

                    ESRI.MapObjects2.Core.DataConnection cConnection = new DataConnection();
                    cConnection.Database = strPath2;

                    if (cConnection.Connect())
                    {
                        cLayer = new MapLayer();
                        //cDataset = cConnection.FindGeoDataset(@"Subzone_Shape_" + (i + 1));
                        cDataset = cConnection.FindGeoDataset(SHPShapeFilename.Replace(".shp", ""));
                        if (cDataset != null)
                        {
                            cLayer.GeoDataset = cDataset;
                        }
                    }

                    if (!cLayer.Valid)
                    {
                        MessageBox.Show(exportName + " is no exist!", "error");
                        return;
                    }
                    Recordset cRecs = cLayer.Records;
                    if (!cRecs.Updatable)
                    {
                        MessageBox.Show(exportName + " is not editable!", "error");
                        return;
                    }

                    Recordset rs         = outLayer.SearchExpression("\"SLOPE_NO\" ='" + strID + "'");
                    string    BuildingID = "";
                    string    SIStatus   = "";
                    rs.MoveFirst();
                    if (!rs.EOF)
                    {
                        while (!rs.EOF)
                        {
                            //BuildingID = rs.Fields.Item("BuildingID").ValueAsString;
                            //string RefSlope = rs.Fields.Item("RefSlope").ValueAsString;
                            //string SubDivNo = rs.Fields.Item("SubDivNo").ValueAsString;
                            //SIStatus = dt.Rows[i]["EqualToMasterZone"].ToString();//hasInfo[BuildingID] as string;

                            cRecs.MoveFirst();
                            cRecs.AddNew();
                            object geometry = rs.Fields.Item("Shape").Value;
                            cRecs.Fields.Item("Shape").Value = geometry;

                            //if (long.TryParse(sss[1], out y))
                            //    outRecs.Fields.Item("INV_GID").Value = (long)y;

                            //SetLog("SubZoneID," + RefSlope);
                            SetLog("SubZoneID," + strID);

                            cRecs.Fields.Item("SubZoneID").Value = strID;// RefSlope;
                            //cRecs.Fields.Item("SubDivNo").Value = SubDivNo;
                            //cRecs.Fields.Item("Status").Value = SIStatus;

                            cRecs.Update();

                            rs.MoveNext();
                        }
                        cRecs.StopEditing();
                    }
                    else
                    {
                        //BuildingID = rs.Fields.Item("BuildingID").ValueAsString;
                        richText1.AppendText(strZoneID + "," + SHPShapeFilename + "\n");
                        //日志记录
                        SetLog("No Record BuildingID:" + strZoneID + "," + SHPShapeFilename);
                    }
                }

                //true追加内容,False为覆盖
                //StreamWriter sw = new StreamWriter(strReadCsvPath.Replace(".csv", ".sql"), true);
                //string txtOutPut = "";

                //lisError.Items.Add("ok!" + exportName + "|" + IDCnt + "|" + hasInfo.Count + "|" + IDReCnt);
                //System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff");
                #endregion
            }
            catch (System.Exception ex)
            {
                //MessageBox.Show(ex.Message.ToString());
                SetLog("Error:" + ex.Message.ToString() + " @" + strID + "|");
            }
            #endregion
        }