Exemplo n.º 1
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;//通过位置查询窗口最小化

            frmPromptQuerying frmPrompt = new frmPromptQuerying();

            frmPrompt.Show();
            System.Windows.Forms.Application.DoEvents();//'转让控制权,没有这一句的话提示窗口不能正常显示

            PerformAttributeSelect();
            frmPrompt.Dispose();
            this.Dispose();
            pMainform.frmAttriQueryisOpen = false;//当窗口关闭时,此变量为false告知系统当前没有打开的属性查询窗口
        }
Exemplo n.º 2
0
        private void PerformLocationQuery(ISpatialFilter pSpatialFilter)
        {
            try
            {
                frmPromptQuerying frmPrompt = new frmPromptQuerying(); //提示:空间查询中
                frmPrompt.Show();
                System.Windows.Forms.Application.DoEvents();           //'转让控制权,没有这一句的话提示窗口不能正常显示
                string            strLayerName;
                IFeatureLayer     pFeatureLayer;
                IFeatureSelection pFeatureSelection;                                      //用来记录查询的结果
                foreach (object itemChecked in checkedListBoxFeaturesLayer1.CheckedItems) //对于每一个选中的层都执行查询,结果合并
                {
                    strLayerName      = itemChecked.ToString();                           //这个才是待查询的layer
                    pFeatureLayer     = GetLayerbyName(strLayerName) as IFeatureLayer;
                    pFeatureSelection = pFeatureLayer as IFeatureSelection;
                    pFeatureSelection.SelectFeatures(pSpatialFilter, esriSelectionResultEnum.esriSelectionResultAdd, false);//待选的层可能不止一个
                    //通过循环依次查询每个层,把结果add起来
                }
                //如果复选框被选中,则定位到选择结果
                if (checkBoxZoomtoSelected.Checked == true)
                {
                    IEnumFeature pEnumFeature = MainAxMapControl.Map.FeatureSelection as IEnumFeature;
                    IFeature     pFeature     = pEnumFeature.Next();
                    ESRI.ArcGIS.Geometry.IEnvelope pEnvelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
                    while (pFeature != null)
                    {
                        pEnvelope.Union(pFeature.Extent);
                        pFeature = pEnumFeature.Next();
                    }
                    MainAxMapControl.ActiveView.Extent = pEnvelope;
                    MainAxMapControl.ActiveView.Refresh();//如果不这样刷新,只要查询前地图已经被放大所效果的话,定位后
                    //底图没有刷新,选择集倒是定位和刷新了
                }
                frmPrompt.Dispose();
                //把结果显示出来
                MainAxMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

                //double i = MainAxMapControl.Map.SelectionCount;
                //i = Math.Round(i, 0);//小数点后指定为0位数字
                //pMainform.toolStripStatusLabel1.Text = "当前共有" + i.ToString() + "个查询结果";
            }
            catch (Exception ex)
            {
                MessageBox.Show("生成查询结果出错!请检查 | " + ex.Message);
                return;
            }
        }
Exemplo n.º 3
0
        private void buttonApply_Click(object sender, EventArgs e)
        {
            if (textBoxWhereClause.Text == "")
            {
                MessageBox.Show("请生成查询语句!");
                return;
            }
            this.WindowState = FormWindowState.Minimized;//通过位置查询窗口最小化

            frmPromptQuerying frmPrompt = new frmPromptQuerying();

            frmPrompt.Show();
            System.Windows.Forms.Application.DoEvents();//'转让控制权,没有这一句的话提示窗口不能正常显示

            PerformAttributeSelect();
            frmPrompt.Dispose();
            this.WindowState = FormWindowState.Normal;
        }
Exemplo n.º 4
0
        private void PerformLocationQuery(ISpatialFilter pSpatialFilter)
        {
            try
            {
                frmPromptQuerying frmPrompt = new frmPromptQuerying();//��ʾ���ռ��ѯ��
                frmPrompt.Show();
                System.Windows.Forms.Application.DoEvents();//'ת�ÿ���Ȩ��û����һ��Ļ���ʾ���ڲ���������ʾ
                string strLayerName;
                IFeatureLayer pFeatureLayer;
                IFeatureSelection pFeatureSelection;//������¼��ѯ�Ľ��
                foreach (object itemChecked in checkedListBoxFeaturesLayer1.CheckedItems)    //����ÿһ��ѡ�еIJ㶼ִ�в�ѯ������ϲ�
                {

                    strLayerName = itemChecked.ToString();    //������Ǵ���ѯ��layer
                    pFeatureLayer = GetLayerbyName(strLayerName) as IFeatureLayer;
                    pFeatureSelection = pFeatureLayer as IFeatureSelection;
                    pFeatureSelection.SelectFeatures(pSpatialFilter, esriSelectionResultEnum.esriSelectionResultAdd, false);//��ѡ�IJ���ܲ�ֹһ��
                    //ͨ��ѭ�����β�ѯÿ���㣬�ѽ��add����

                }
                //�����ѡ��ѡ�У���λ��ѡ����
                if (checkBoxZoomtoSelected.Checked == true)
                {
                    IEnumFeature pEnumFeature = MainAxMapControl.Map.FeatureSelection as IEnumFeature;
                    IFeature pFeature = pEnumFeature.Next();
                    ESRI.ArcGIS.Geometry.IEnvelope pEnvelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
                    while (pFeature != null)
                    {
                        pEnvelope.Union(pFeature.Extent);
                        pFeature = pEnumFeature.Next();
                    }
                    MainAxMapControl.ActiveView.Extent = pEnvelope;
                    MainAxMapControl.ActiveView.Refresh();//���������ˢ�£�ֻҪ��ѯǰ��ͼ�Ѿ����Ŵ���Ч���Ļ�����λ��
                    //��ͼû��ˢ�£�ѡ�񼯵��Ƕ�λ��ˢ����
                }
                frmPrompt.Dispose();
                //�ѽ����ʾ����
                MainAxMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

                //double i = MainAxMapControl.Map.SelectionCount;
                //i = Math.Round(i, 0);//С�����ָ��Ϊ��λ����
                //pMainform.toolStripStatusLabel1.Text = "��ǰ����" + i.ToString() + "����ѯ���";
            }
            catch (Exception ex)
            {
                MessageBox.Show("���ɲ�ѯ�������!���� | "+ex.Message);
                return;
            }
        }
Exemplo n.º 5
0
        private ISpatialFilter GenerateSpatialFilter()
        {
            frmPromptQuerying frmPrompt = new frmPromptQuerying(4);//��ʾ����������ͼ���� Ϊ�����쳣ʱ�ܽ�����ʾ���ڹرգ����Է���try����
            try
            {
                frmPrompt.Show();
                System.Windows.Forms.Application.DoEvents();//'ת�ÿ���Ȩ��û����һ��Ļ���ʾ���ڲ���������ʾ
                //����Ҫ�����spatialfilter
                //��ù���spatialfilter.geometry������feature
                //IMap pMap;                        //����QI��IEnumLayer
                //IEnumLayer pEnumLayer;            //����������Ϊ��ѡ���layers
                //ILayer pLayer;
                IFeatureLayer pFeatureLayer = null;
                IGeometry pGeometry = null;
                IEnumFeature pEnumFeature = null;          //�����зֱ�����ʹ�úͲ�ʹ��
                IFeatureCursor pFeatureCursor = null;      //�Ѿ�ѡ���Ԫ�����ɡ�ɸѡͼ�Ρ������
                IFeatureClass pFeatureClass;
                IFeature pFeature;
                string strLayerName = comboBoxConditionLayer.Text;
                if (checkBoxUseSelectedOnly.Checked == false)    //����û��Լ�ѡ������ͼ�㡱,��������ѡ�е�Ԫ��
                {
                    pFeatureLayer = GetLayerbyName(strLayerName) as IFeatureLayer;  //���layer����������spatialfilter.geometry��
                    //���Ǹ�������ͼ�㡱

                    //���ﲻ��featureselection�����enumfeature,�Ӷ����������geometry�ϲ�������ȡfeaturecursor������Ϊ
                    //��featureselection�Ļ�����ô��ϲ�������feature��һ�������ôд��featureselection=mainaxmapcontrol.map.featureselection
                    //������ָ��featureselection��map�����һ���㣡���������featureselection=pfeaturelayer.featureselection��
                    //Ȼ��enumfeature=featureselection����ʱenumfeature����null�����е�pfeaturelayer�Ѿ���map���һ��ָ���IJ��ˣ�
                    //�����featureselection=mainaxmapcontrol.map.featureselection���ͻ������⣺Ҳ��map�����Ѿ��б�ѡ�е�Ԫ���ˣ�����ʱ�����ַ���
                    //��õ�enumfeatureֻ������Щ�Ѿ�ѡ�е�Ԫ�أ�����Ӧ����������Ӧ�û�õ���ָ��Ϊ������ͼ�㡱������feature������ֻ����featurecursor
                    //�����featureselection�Ļ���Ҫ��ôд��
                    //IFeatureSelection pFeatureSelection = MainaxMapControl.get_Layer(strLayerName) as IFeatureSelection;
                    //pFeatureSelection.SelectFeatures(null, esriSelectionResultEnum.esriSelectionResultNew, false);//��ʹ���ѱ�ѡ�е�Ԫ��ʱ������仰Խ��ȥ
                    //IEnumFeature pEnumFeature = MainaxMapControl.Map.FeatureSelection as IEnumFeature;
                    pFeatureClass = pFeatureLayer.FeatureClass;
                    pFeatureCursor = pFeatureClass.Search(null, true);
                    pFeature = pFeatureCursor.NextFeature();
                }
                else            //���ʹ�õ�ͼ����ѡ�е�Ԫ����Ϊ��ɸѡͼ�㡱
                {
                    pEnumFeature = MainAxMapControl.Map.FeatureSelection as IEnumFeature;
                    pFeature = pEnumFeature.Next();
                }

                pGeometry = pFeature.Shape;
                ITopologicalOperator pTopologicalOperator;
                //�ϲ������Ե���ɸ�ӡ���geometry
                while (pFeature != null)
                {

                    //�����һ���ǹؼ����������յ�pgeometry���Ի���������geometry
                    //��ΪTopologicalOperator�������һ��shape��һ��geometry�����Խ����������������ĺϲ�.
                    //ֻ����shapecopy���ܹ���ȷ����shape�Ļ����ļ��ͳ����Ϊ��������ⵢ����һ���ڣ�����
                    //����һ��˼·Ҳ���ԡ������˼·����ѭ���ϲ�����geometry����һ��˼·����ѭ���õ�����ÿ��
                    //geometryȥɸѡͼ�����featuresȻ��ϲ����
                    pTopologicalOperator = pFeature.ShapeCopy as ITopologicalOperator;
                    //if (checkBoxBuffer.Checked == true)
                    //{
                    //    double ddistance = Convert.ToDouble(textBoxBuffer.Text);
                    //    pGeometry = pTopologicalOperator.Buffer(ddistance);
                    //    //pTopologicalOperator.Simplify();        //ʹ���˹�ϵ�����ȷ
                    //}
                    pGeometry = pTopologicalOperator.Union(pGeometry as IGeometry);
                    if (checkBoxUseSelectedOnly.Checked == false)//�õ���featurecursor
                        pFeature = pFeatureCursor.NextFeature();
                    else pFeature = pEnumFeature.Next();
                }
                //pFeatureSelection.Clear();//������������������geometry��������featureselection�Ļ�����Ҳ��һ��ؼ���
                //�������յ���ʾҲ�������featureselection��ʾ����

                //���ɻ����������������ѭ��֮��ִ�У������Ӹ���Ч�ʣ����Ҹ������׳���
                if (checkBoxBuffer.Checked == true)
                {
                    double ddistance = Convert.ToDouble(textBoxBuffer.Text);
                    pTopologicalOperator = pGeometry as ITopologicalOperator;
                    pGeometry = pTopologicalOperator.Buffer(ddistance);
                    pTopologicalOperator.Simplify();        //ʹ���˹�ϵ�����ȷ
                    //MainAxMapControl.FlashShape(pGeometry, 2, 500, null);//��˸����֤��������ȷ���
                }
                frmPrompt.WindowState = FormWindowState.Minimized;
                frmPrompt.Dispose();
                System.Windows.Forms.Application.DoEvents();
                object m_fillsymbol;                                //�����drawshape�IJ���������object��

                IRgbColor pRgb = new RgbColorClass();               // ��ȡIRGBColor�ӿ�
                pRgb.Red = 255;                                     // ������ɫ����
                ILineSymbol outline = new SimpleLineSymbolClass();          // ��ȡILine���Žӿ�
                outline.Width = 5;
                outline.Color = pRgb;
                ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();// ��ȡIFillSymbol�ӿ�
                simpleFillSymbol.Outline = outline;
                simpleFillSymbol.Color = pRgb;
                simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSBackwardDiagonal;
                m_fillsymbol = simpleFillSymbol;
                //MainAxMapControl.DrawShape(pGeometry, ref m_fillsymbol);
                MainAxMapControl.FlashShape(pGeometry, 3, 500, m_fillsymbol);//��˸�����û�֪����ǰ��"����ͼ��"����״

                ISpatialFilter pSpatialFilter = new SpatialFilterClass();
                pSpatialFilter.Geometry = pGeometry;
                pSpatialFilter.SpatialRel = pSpatialRel;        //���Ǹ�ȫ�ֱ���
                if (checkBoxUseSelectedOnly.Checked == true)
                    pSpatialFilter.GeometryField = "Shape";     //��ʹ����ѡ�е�Ԫ����Ϊ��ɸѡͼ�㡱ʱ��
                //�޷����������ȥ���geometryfield����Ϊpfeaturelayer(����ͼ��)Ϊ��
                else
                    pSpatialFilter.GeometryField = pFeatureLayer.FeatureClass.ShapeFieldName;

                return pSpatialFilter;
            }
            catch (Exception ex)
            {
                MessageBox.Show("���ɡ�����ͼ�㡱����!���� | " + ex.Message);
                frmPrompt.Dispose();
                return null;//�����򲻷���spatialfitler
            }
        }
Exemplo n.º 6
0
        private ISpatialFilter GenerateSpatialFilter()
        {
            frmPromptQuerying frmPrompt = new frmPromptQuerying(4);//提示:构造条件图层中 为了在异常时能将此提示窗口关闭,所以放在try外面

            try
            {
                frmPrompt.Show();
                System.Windows.Forms.Application.DoEvents();//'转让控制权,没有这一句的话提示窗口不能正常显示
                //首先要构造出spatialfilter
                //获得构造spatialfilter.geometry的所有feature
                //IMap pMap;                        //用来QI到IEnumLayer
                //IEnumLayer pEnumLayer;            //接收所有作为代选层的layers
                //ILayer pLayer;
                IFeatureLayer  pFeatureLayer  = null;
                IGeometry      pGeometry      = null;
                IEnumFeature   pEnumFeature   = null;      //这两行分别用于使用和不使用
                IFeatureCursor pFeatureCursor = null;      //已经选择的元素生成“筛选图形”的情况
                IFeatureClass  pFeatureClass;
                IFeature       pFeature;
                string         strLayerName = comboBoxConditionLayer.Text;
                if (checkBoxUseSelectedOnly.Checked == false)                      //如果用户自己选择“条件图层”,而不用已选中的元素
                {
                    pFeatureLayer = GetLayerbyName(strLayerName) as IFeatureLayer; //这个layer是用来构造spatialfilter.geometry的
                    //是那个“条件图层”

                    //这里不用featureselection来获得enumfeature,从而进行下面的geometry合并,而采取featurecursor,是因为
                    //用featureselection的话,获得待合并的所有feature的一句必须这么写:featureselection=mainaxmapcontrol.map.featureselection
                    //而不能指定featureselection到map具体的一个层!(比如如果featureselection=pfeaturelayer.featureselection,
                    //然后enumfeature=featureselection,这时enumfeature就是null!其中的pfeaturelayer已经是map里的一个指定的层了)
                    //如果用featureselection=mainaxmapcontrol.map.featureselection,就会有问题:也许map上面已经有被选中的元素了,而此时用这种方法
                    //获得的enumfeature只能是这些已经选中的元素,但不应该是这样,应该获得的是指定为“条件图层”的所有feature,所以只能用featurecursor
                    //如果用featureselection的话就要这么写:
                    //IFeatureSelection pFeatureSelection = MainaxMapControl.get_Layer(strLayerName) as IFeatureSelection;
                    //pFeatureSelection.SelectFeatures(null, esriSelectionResultEnum.esriSelectionResultNew, false);//仅使用已被选中的元素时,把这句话越过去
                    //IEnumFeature pEnumFeature = MainaxMapControl.Map.FeatureSelection as IEnumFeature;
                    pFeatureClass  = pFeatureLayer.FeatureClass;
                    pFeatureCursor = pFeatureClass.Search(null, true);
                    pFeature       = pFeatureCursor.NextFeature();
                }
                else            //如果使用地图上已选中的元素作为“筛选图层”
                {
                    pEnumFeature = MainAxMapControl.Map.FeatureSelection as IEnumFeature;
                    pFeature     = pEnumFeature.Next();
                }

                pGeometry = pFeature.Shape;
                ITopologicalOperator pTopologicalOperator;
                //合并出用以当“筛子”的geometry
                while (pFeature != null)
                {
                    //下面第一句是关键,这样最终的pgeometry可以获得整个大的geometry
                    //因为TopologicalOperator本身就是一个shape,一个geometry,所以结果是它本身与参数的合并.
                    //只有用shapecopy才能够正确,用shape的话线文件就出错。为了这个问题耽搁了一星期!!!
                    //还有一种思路也可以。这里的思路是用循环合并参数geometry,另一种思路是在循环用单独的每个
                    //geometry去筛选图层里的features然后合并结果
                    pTopologicalOperator = pFeature.ShapeCopy as ITopologicalOperator;
                    //if (checkBoxBuffer.Checked == true)
                    //{
                    //    double ddistance = Convert.ToDouble(textBoxBuffer.Text);
                    //    pGeometry = pTopologicalOperator.Buffer(ddistance);
                    //    //pTopologicalOperator.Simplify();        //使拓扑关系变得正确
                    //}
                    pGeometry = pTopologicalOperator.Union(pGeometry as IGeometry);
                    if (checkBoxUseSelectedOnly.Checked == false)//用的是featurecursor
                    {
                        pFeature = pFeatureCursor.NextFeature();
                    }
                    else
                    {
                        pFeature = pEnumFeature.Next();
                    }
                }
                //pFeatureSelection.Clear();//如果不清楚这个用来获得geometry而创建的featureselection的话,这也是一句关键,
                //后面最终的显示也将把这个featureselection显示出来

                //生成缓冲区,放在上面的循环之外执行,这样子更有效率,而且更不容易出错
                if (checkBoxBuffer.Checked == true)
                {
                    double ddistance = Convert.ToDouble(textBoxBuffer.Text);
                    pTopologicalOperator = pGeometry as ITopologicalOperator;
                    pGeometry            = pTopologicalOperator.Buffer(ddistance);
                    pTopologicalOperator.Simplify();        //使拓扑关系变得正确
                    //MainAxMapControl.FlashShape(pGeometry, 2, 500, null);//闪烁以验证缓冲区正确与否
                }
                frmPrompt.WindowState = FormWindowState.Minimized;
                frmPrompt.Dispose();
                System.Windows.Forms.Application.DoEvents();
                object m_fillsymbol;                                //后面的drawshape的参数必须是object型

                IRgbColor pRgb = new RgbColorClass();               // 获取IRGBColor接口
                pRgb.Red = 255;                                     // 设置颜色属性
                ILineSymbol outline = new SimpleLineSymbolClass();  // 获取ILine符号接口
                outline.Width = 5;
                outline.Color = pRgb;
                ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();// 获取IFillSymbol接口
                simpleFillSymbol.Outline = outline;
                simpleFillSymbol.Color   = pRgb;
                simpleFillSymbol.Style   = esriSimpleFillStyle.esriSFSBackwardDiagonal;
                m_fillsymbol             = simpleFillSymbol;
                //MainAxMapControl.DrawShape(pGeometry, ref m_fillsymbol);
                MainAxMapControl.FlashShape(pGeometry, 3, 500, m_fillsymbol);//闪烁,让用户知道当前的"条件图层"的形状

                ISpatialFilter pSpatialFilter = new SpatialFilterClass();
                pSpatialFilter.Geometry   = pGeometry;
                pSpatialFilter.SpatialRel = pSpatialRel;        //这是个全局变量
                if (checkBoxUseSelectedOnly.Checked == true)
                {
                    pSpatialFilter.GeometryField = "Shape";     //当使用已选中的元素作为“筛选图层”时,
                }
                //无法像底下那样去获得geometryfield,因为pfeaturelayer(条件图层)为空
                else
                {
                    pSpatialFilter.GeometryField = pFeatureLayer.FeatureClass.ShapeFieldName;
                }

                return(pSpatialFilter);
            }
            catch (Exception ex)
            {
                MessageBox.Show("生成“条件图层”出错!请检查 | " + ex.Message);
                frmPrompt.Dispose();
                return(null);//出错则不返回spatialfitler
            }
        }