mapgis7.0二次开发小试牛刀

it2022-05-05  87

private void 查找与替换ToolStripMenuItem_Click(object sender, EventArgs e)         {             mapXBase.IXMap m_IMap;             mapXBase.IXMapLayer m_IMapLayer;

 

            m_IMap = axMxWorkSpace1.ActiveMap;             //m_IMapLayer = m_IMap.ActiveLayer;             mc_basXcls7Lib.mcFeatureCls m_NewFCLs = null;             m_NewFCLs = (mc_basXcls7Lib.mcFeatureCls)m_IMap.get_Layer(1).XClass;             mc_basObj7Lib.mcField myField;             mc_basObj7Lib.mcFields myFields=null;             Search mySearch = new Search();             if (m_NewFCLs != null)             {                 m_NewFCLs.GetFields(out myFields);                 myField = myFields.get_fldEntry(0);                 for (short i = 0; i < myFields.numbfield; i++)                 {                     mySearch.addElement(myFields.get_fldEntry(i).fieldname);                 }             }             mySearch.ShowDialog();             string field_name = mySearch.get_zd_name();  //要替换的字段名             string field_name_look = mySearch.get_search_begain();//要替换的查找记录             string field_name_replace = mySearch.get_search_end();//替换为什么             mc_basObj7Lib.mcFeature myfeature;             mc_basObj7Lib.mcObjectID myid;             int j =return_fieldID(field_name,myFields);             //mc_basObj7Lib.mcRecord myRecord;             mc_basObj7Lib.mcFldNames myAtt=null;             string condition = field_name + " LIKE "+"  '%" + field_name_look + "%'";//一定要用大写LIKE,否则的话不能执行G_SQL             int  subTypeCode = -1; //子类型字段的值,该参数缺省为-1             string orderByFld = field_name; //结果排序字段名             short isAsc=1;             mc_basObj7Lib.mcQueryCondition myQueryCondition=new mc_basObj7Lib.mcQueryCondition();                          mc_basObj7Lib.meObjType myobjtype;             mc_basXcls7Lib.mcSelectOption mySelectOption=new mc_basXcls7Lib.mcSelectOption();             mc_basXcls7Lib.mcSelectSet mySet = new mc_basXcls7Lib.mcSelectSet();             myQueryCondition.SetAttCondition(condition, myAtt);             int m_FCLsId = 0;             if (m_NewFCLs.AttSelect(myQueryCondition, out mySet, mySelectOption, subTypeCode, orderByFld, isAsc) > -1)             {                 mySet.fset.MoveFirst();                 int num_move = mySet.fset.MoveFirst();                 while (num_move>-1)                 {                     myid = mySet.fset.GetObjID();                     mc_basObj7Lib.mcRecord myRecord;                     mySet.fset.GetAtt(out myRecord);                     object myreplace = null;                     myRecord.GetFldVal(field_name, out myreplace);                     string ztf_test = myreplace.ToString().Trim();                     ztf_test=ztf_test.Replace(field_name_look, field_name_replace);                     myRecord.SetFldFromStr(field_name, ztf_test);                     m_NewFCLs.UpdateAtt(myid, myRecord);                     num_move=mySet.fset.MoveNext();                 }             }         }                 private void 线对线吸引ToolStripMenuItem_Click(object sender, EventArgs e)         {             mapXBase.IXMap m_IMap;             mapXBase.IXMapLayer m_IMapLayer;             m_IMap = axMxWorkSpace1.ActiveMap;             shuxing myshuxing = new shuxing();             for (int i = 1; i < m_IMap.LayerCount+1; i++)             {                 m_IMapLayer = m_IMap.get_Layer(i);                 myshuxing.addElement(m_IMapLayer.LayerName.ToString().Trim());             }             myshuxing.ShowDialog();             string look_layer=myshuxing.get_layer_begin().ToString();             string idea_layer=myshuxing.get_layer_end().ToString();             string NotNullField = myshuxing.get_NotNullField().ToString().Trim();             double look_radio = myshuxing.get_look_rad();             mc_basXcls7Lib.mcFeatureCls myCLs = null;             myCLs = (mc_basXcls7Lib.mcFeatureCls)m_IMap.get_LayerByName(look_layer).XClass;             mc_basXcls7Lib.mcFeatureCls myCls2 = null;             myCls2 = (mc_basXcls7Lib.mcFeatureCls)m_IMap.get_LayerByName(idea_layer).XClass;

            mc_basXcls7Lib.mcSelectSet mySet;             mc_basXcls7Lib.mcSelectSet mySet2;             mc_basObj7Lib.mcQueryCondition myQueryCondition = new mc_basObj7Lib.mcQueryCondition();             myQueryCondition.SetAttCondition("'" + NotNullField + "' !=''", null);

            if (myCLs.AttSelect(myQueryCondition, out mySet, null, -1, "", 1) > -1)             {                 mySet.fset.MoveFirst();                 int move_number = mySet.fset.MoveFirst();                 mc_basObj7Lib.mcFeature myFeature = new mc_basObj7Lib.mcFeature();                 while (move_number > -1)                 {                     mc_basObj7Lib.mcObjectID myLineID = new mc_basObj7Lib.mcObjectID();                     mc_basObj7Lib.mcObjectID myArcID = new mc_basObj7Lib.mcObjectID();                     mc_basObj7Lib.mcObjectID myFeatureID = new mc_basObj7Lib.mcObjectID();                     myFeatureID = mySet.fset.GetObjID();                     myLineID = getLineIDformFeatureID(myFeatureID);                     myArcID = getArcIDformFeatureID(myFeatureID);                     mc_basObj7Lib.mcLinInfo mylininfo = new mc_basObj7Lib.mcLinInfo();                     mc_basObj7Lib.mcGeoVarLine myGeoVarLine = new mc_basObj7Lib.mcGeoVarLine();//定义一条新的折线                     mc_basObj7Lib.IGeoLine myGeoLine;                     mc_basObj7Lib.mcGeoLines myGeoLines;                     mySet.glinset.GetPos(out myGeoLines, out mylininfo);                     //myCLs.glin.GetPos(myLineID, out myGeoLines, out mylininfo);                     // myGeoLines.GetLine(0, out myGeoLine);                     myCLs.sarc.Get(myLineID, out myGeoLine);//从空间弧段中取几何线                     mc_basObj7Lib.mc3Dots my3Dots = new mc_basObj7Lib.mc3Dots();                     myGeoLine.Get3Dots(out my3Dots);                     mc_basObj7Lib.mc3Dot replaceDot = new mc_basObj7Lib.mc3Dot();                     mc_basObj7Lib.mcObjectIDs myArcIDs = new mc_basObj7Lib.mcObjectIDs();                     bool flag_cycle = true;                     for (int b = 0; b < my3Dots.count; b++)                     {                         if (myCls2.AttSelect(myQueryCondition, out mySet2, null, -1, "", 1) > -1)                         {                             mySet2.fset.MoveFirst();                             int num_2 = mySet2.fset.MoveFirst();                             while (num_2 > -1)                             {                                 mc_basObj7Lib.mcObjectID replaceFeatureID = new mc_basObj7Lib.mcObjectID();                                 replaceFeatureID = mySet2.fset.GetObjID();                                 mc_basObj7Lib.mcObjectID replaceLineID = new mc_basObj7Lib.mcObjectID();                                 replaceLineID = getLineIDformFeatureID(replaceFeatureID);                                 mc_basObj7Lib.mcObjectID replaceArcID = new mc_basObj7Lib.mcObjectID();                                 replaceArcID = getArcIDformFeatureID(replaceFeatureID);                                 mc_basObj7Lib.IGeoLine myGeoLine2;                                 myCls2.sarc.Get(replaceLineID, out myGeoLine2);                                 mc_basObj7Lib.mc3Dots pointDots = new mc_basObj7Lib.mc3Dots();                                 mc_basObj7Lib.mc3Dot pointDot = new mc_basObj7Lib.mc3Dot();                                 myGeoLine2.Get3Dots(out pointDots);                                 for (int c = 0; c < pointDots.count; c++)                                 {                                     pointDot = pointDots.get_item(c);                                     if (point_compare(my3Dots.get_item(b), pointDots.get_item(c), look_radio))                                     {                                         myGeoVarLine.Append3D(pointDots.get_item(c));                                         flag_cycle = false;                                         goto myLabel;                                     }                                 }                                 num_2 = mySet2.fset.MoveNext();                             }                             myLabel:                             if (flag_cycle)                             {                                 myGeoVarLine.Append3D(my3Dots.get_item(b));                             }                         }                     }                     myCLs.sarc.Update(myArcID, myGeoVarLine);                     //myCLs.glin.Update(myLineID, myArcIDs, mylininfo);                     mySet.fset.Get(out myFeature);                     myCLs.feature.UpdateLin(myFeatureID, (mc_basObj7Lib.IGeoLine)myGeoVarLine, myFeature.att, mylininfo);                     myCLs.feature.Update(myFeatureID, myFeature);                     move_number = mySet.fset.MoveNext();                 }             }             this.axMxWorkSpace1.Save();         }         //返回ArcID         public mc_basObj7Lib.mcObjectID getArcIDformFeatureID(mc_basObj7Lib.mcObjectID featureID)         {             mc_basObj7Lib.mcObjectID ArcID = new mc_basObj7Lib.mcObjectID();             ArcID.Int = featureID.Int - 1;             ArcID.Int64 = Convert.ToInt64(featureID.Int - 1);             ArcID.String = Convert.ToString(featureID.Int - 1);             ArcID = (mc_basObj7Lib.mcObjectID)ArcID;             return ArcID;         }         //返回LineID         public mc_basObj7Lib.mcObjectID getLineIDformFeatureID(mc_basObj7Lib.mcObjectID featureID1)         {             mc_basObj7Lib.mcObjectID LineID = new mc_basObj7Lib.mcObjectID();             LineID.Int = featureID1.Int - 2;             LineID.Int64 = Convert.ToInt64(featureID1.Int - 2);             LineID.String = Convert.ToString(featureID1.Int - 2);             LineID = (mc_basObj7Lib.mcObjectID)LineID;             return LineID;         }

//比较点位距离         public bool point_compare(mc_basObj7Lib.mc3Dot Dot1,mc_basObj7Lib.mc3Dot Dot2, double space)         {             double x1=Dot1.x;             double y1=Dot1.y;             double x2=Dot2.x;             double y2 = Dot2.y;             double sq1 = x1 * x1 + y1 * y1;             double sq2 = x2 * x2 + y2 * y2;             double sq_space = space * space;             if (Math.Abs(sq1 - sq2) < sq_space)             {                 return true;             }             else             {                 return false;             }         }

 

/根据字段名检测字段所在的fieldID         public int return_fieldID(string field_name, mc_basObj7Lib.mcFields myfields)         {             int return_num = -1;             for (short num = 0; num < myfields.numbfield; num++)             {                 string mystring = myfields.get_fldEntry(num).ToString().Trim();                 if (mystring == field_name)                 {                     return_num = Convert.ToInt16(num);                     break;                 }             }             return return_num;         }

//线对线吸引窗口 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;

 

namespace DocumentOper {     public partial class shuxing : Form     {         public string layer_begin;         public string layer_end;         public double look_rad;         public string NotNullField;         public shuxing()         {             InitializeComponent();         }         public string get_layer_begin()         {             return layer_begin;         }         public string get_layer_end()         {             return layer_end;         }         public double get_look_rad()         {             return look_rad;         }         public string get_NotNullField()         {             return NotNullField;         }         public void addElement(object element)         {             this.comboBox1.Items.Add(element);             this.comboBox2.Items.Add(element);         }         private void button1_Click(object sender, EventArgs e)         {             if (this.comboBox1.SelectedIndex > -1)             {                 layer_begin = this.comboBox1.GetItemText(comboBox1.SelectedItem).ToString().Trim();                 layer_end = this.comboBox2.GetItemText(comboBox2.SelectedItem).ToString().Trim();                 look_rad = Convert.ToDouble(this.textBox1.Text.ToString().Trim());                 NotNullField = this.textBox2.Text.ToString().Trim();                 this.Close();             }             else             {                 MessageBox.Show("请选择!");                 return;             }         }

        private void button2_Click(object sender, EventArgs e)         {             this.FindForm().Close();             this.comboBox1.Items.Clear();             this.comboBox2.Items.Clear();             this.Close();         }

        private void shuxing_FormClosed(object sender, FormClosedEventArgs e)         {             this.comboBox1.Items.Clear();             this.comboBox2.Items.Clear();         }     } } //属性替换窗口 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;

namespace DocumentOper {     public partial class Search : Form     {         private string zd_name;         private string search_begain;         private string search_end;         public Search()         {             InitializeComponent();         }         public string get_zd_name()         {             return zd_name;         }         public string get_search_begain()         {             return search_begain;         }         public string get_search_end()         {             return search_end;         }         private void button2_Click(object sender, EventArgs e)         {             this.textBox1.Text = "";             this.textBox2.Text = "";         }

        private void button1_Click(object sender, EventArgs e)         {             if (this.comboBox1.SelectedIndex > -1)             {                 zd_name = this.comboBox1.GetItemText(comboBox1.SelectedItem).ToString().Trim();                 search_begain = this.textBox1.Text.ToString().Trim();                 search_end = this.textBox2.Text.ToString().Trim();                 this.Close();             }             else             {                 MessageBox.Show("请选择一个要查找的字段");             }         }         public void addElement(object element)         {             this.comboBox1.Items.Add(element);         }

        private void Search_FormClosed(object sender, FormClosedEventArgs e)         {             this.comboBox1.Items.Clear();         }     } }

转载于:https://www.cnblogs.com/jamszeng/archive/2008/05/07/1187118.html

相关资源:mapgis7.0

最新回复(0)