用mapxtreme开发小结1(c#)

创建新表 Temp
    MapInfo.Data.Table tblTemp = Session.Current.Catalog.GetTable( " Temp " );
    
if  (tblTemp != null ) tblTemp.Close();
    mapControl1.Map.Clear();

    
//  create a temporary table and add a featurelayer for it
    FeatureLayer layerTemp = new  FeatureLayer(Session.Current.Catalog.CreateTable(    TableInfoFactory.CreateTemp( " Temp " ),  new  TableSessionInfo()));
    mapControl1.Map.Layers.Add(layerTemp);
                

图层筛选器

1  ToolFilter toolFilter  =  (ToolFilter) mapControl1.Tools.AddMapToolProperties.InsertionLayerFilter ;
2  if  (toolFilter  !=   null   &&   ! toolFilter.IncludeLayer(layerTemp) ) 
3  toolFilter.SetExplicitInclude(layerTemp,  true ); 
4  toolFilter = (ToolFilter) mapControl1.Tools.SelectMapToolProperties.EditableLayerFilter;
5  if  (toolFilter  !=   null   &&   ! toolFilter.IncludeLayer(layerTemp) ) 
6      toolFilter.SetExplicitInclude(layerTemp,  true ); 

设置地图中心点 

1  mapControl1.Map.SetView( new  DPoint( - 100 , 30 ),
2  Session.Current.CoordSysFactory.CreateLongLat(DatumID.WGS84), 60000000 );

 一些winform的知识:  

      string strPath=Application.StartupPath;

      strPath=strPath.Substring(0,strPath.LastIndexOf(Path.DirectorySeparatorChar)+1) // get rid of \bin

注册表操作:

      Microsoft.Win32.RegistryKey keySamp = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"SOFTWARE\MapInfo\MapXtreme\6.8.0");

      keySamp.Close();

完整代码示例

 

 1  string  strPath = Application.StartupPath;
 2  strPath = strPath.Substring( 0 ,strPath.LastIndexOf(Path.DirectorySeparatorChar));  //  get rid of \Debug
 3  strPath = strPath.Substring( 0 ,strPath.LastIndexOf(Path.DirectorySeparatorChar) + 1 //  get rid of \bin
 4                       +   " Data "   +  Path.DirectorySeparatorChar;
 5  if  (File.Exists(strPath  +  strFName) == false )
 6  {
 7       //  check the registry for a known sample data search path
 8      Microsoft.Win32.RegistryKey keySamp  =  Microsoft.Win32.Registry.LocalMachine.CreateSubKey( @" SOFTWARE\MapInfo\MapXtreme\6.8.0 " );
 9       if  (keySamp  !=   null )
10      {
11           string  s  =  ( string )keySamp.GetValue( " SampleDataSearchPath " );
12          keySamp.Close();
13 
14                   if  (s  ==   null ) { s  =  Environment.CurrentDirectory; }
15                   else
16                  {
17                         if  (s.EndsWith(Path.DirectorySeparatorChar.ToString())  ==   false )
18                        {
19                              s  +=  Path.DirectorySeparatorChar;
20                        }
21 
22                        strPath  =  s;
23                   }
24      }
25  }

MapInfo.Geometry.DPoint ctr=mapControl1.Map.Center;
   MapInfo.Geometry.Distance z=mapControl1.Map.Zoom;

if (File.Exists(strPath+strFName))
    {
     mapControl1.Map.Load(new MapTableLoader(strPath + strFName));
     mapControl1.Map.Center=ctr; 
     mapControl1.Map.Zoom=z;  //地图缩放比例
    }
    else
    {
     txtResults.Text="Couldn't find table: \r\n"
      + strPath + strFName
      + "\r\n\r\nTo enable this function, copy the relevant files "
      + "to the above location, or reinstall the sample data.\r\n\r\n";
    }    
关于FeatureLayer的

 

1  FeatureLayer lyrTemp = (FeatureLayer) mapControl1.Map.Layers[ " Temp " ];
2  if  (lyrTemp != null )
3  {
4      IFeatureEnumerator fen  =  (lyrTemp.Table  as  IFeatureCollection).GetFeatureEnumerator();
5       int  n = 0 ;
6       while  (fen.MoveNext()) n ++ ;
7      txtNumObjects.Text = n.ToString();
8  }

 

显示选定的图元?图层个数:
1 
2              IEnumerator se  =  MapInfo.Engine.Session.Current.Selections.GetEnumerator();
3               int  i = 0 ;
4               while  (se.MoveNext()) i +=  ((Selection)se.Current).TotalCount;
5              txtNumSelected.Text = i.ToString();

转载于:https://www.cnblogs.com/aion111/archive/2009/04/17/1437763.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值