- GIS论坛-GIS空间站 ( http://bbs.gissky.net/Default.asp )
-- 编程技术交流 ( http://bbs.gissky.net/ShowForum.asp?forumid=22 )
--- [求助]用MapX+C#编的查找最近,谁能告诉我错在哪里? ( http://bbs.gissky.net/ShowPost.asp?id=42102 )

TopMap活动


作者:trilobitehy
发表时间:2007-11-23 22:11:33

       目的是查找距指定的站点在指定距离范围内的指定类型的单位,现在前三部分都正确,而在最后的按距离查找时报错:fs = axMap1.Layers._Item("临时图层").SearchWithinDistance(ftResult,Dis, MapXLib.MapUnitConstants.miUnitMeter, MapXLib.SearchTypeConstants.miSearchTypeCentroidWithin);//报错Invalid Distance Type for Coordinate System in Buffer Operation

 

代码如下:

 private void button1_Click(object sender, EventArgs e) //查找最近

        {

            MapXLib.Features fs = null;

            //查找指定的站点

            MapXLib.Dataset TempDS1 = null;

            MapXLib.Features TempFeatures1 = null;

            MapXLib.Layer TempLayer1 = null;

            MapXLib.Variables Var1 = new MapXLib.Variables();

            MapXLib.Feature ftr1 = new MapXLib.Feature();

            MapXLib.Point Pt1=new MapXLib.Point();

            MapXLib.Feature ftResult = new MapXLib.Feature();

 

            TempDS1 = axMap1.DataSets._Item("站点");

            TempLayer1 = TempDS1.Layer;

 

            ftr1 =axMap1.Layers._Item("站点").AllFeatures._Item(1);

            Var1.Add("f", ftr1);

            TempFeatures1 = TempLayer1.Search("名称 LIKE \"%" + cbCentre.Text + "%\"", Var1);

            ftResult = TempFeatures1._Item(1);

         

           //查找指定类型的单位:

            MapXLib.Dataset TempDS2 = null;

            MapXLib.Features TempFeatures2 = null;

            MapXLib.Layer TempLayer2 = null;

            MapXLib.Variables Var2 = new MapXLib.Variables();

            MapXLib.Feature ftr2 = new MapXLib.Feature();

           

                TempDS2 = axMap1.DataSets._Item("单位");

                TempLayer2 = TempDS2.Layer;

 

                ftr2 = axMap1.Layers._Item("单位").AllFeatures._Item(1);

                Var2.Add("f", ftr2);

                TempFeatures2 = TempLayer2.Search("类型 LIKE \"%" + cbSth.Text.Trim() + "%\"", Var2);

         

            //将查找结果存入临时图层

                axMap1.Layers.CreateLayer("临时图层", System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);

                for (int i = 1; i <= TempFeatures2.Count; i++)

                {

                    axMap1.Layers._Item("临时图层").AddFeature(TempFeatures2._Item(i), System.Reflection.Missing.Value);

                }

          

            //设置查找距离             

               double Dis = 0.0;

                switch (cbDis.Text)

                {

                    case "500内":

                        Dis = 500.0/axMap1.Zoom;

                        break;

                    case "1000内":

                        Dis = 1000.0/axMap1.Zoom;

                        break;

                    case "2000内":

                        Dis = 2000.0/axMap1.Zoom;

                        break;

                    case "5000内":

                        Dis = 5000.0/axMap1.Zoom;

                        break;

                }

            //查找

                fs = axMap1.Layers._Item("临时图层").SearchWithinDistance(ftResult,Dis, MapXLib.MapUnitConstants.miUnitMeter, MapXLib.SearchTypeConstants.miSearchTypeCentroidWithin);//报错Invalid Distance Type for Coordinate System in Buffer Operation

                for (int i = 1; i <= fs.Count; i++)

                {

                    listResults.Items.Add(fs._Item(i).FeatureID );

                }

                TempDS1 = null;

                TempDS2 = null;

                TempFeatures1 = null;

                TempFeatures2 = null;

                TempLayer1 = null;

                TempLayer2 = null;

                axMap1.Layers.Remove("临时图层");

        }



Powered by GIS空间站 © 2002-2007