MapXtreme2004初學者資料(整理)--有些功能很有價值

由於項目的需要我現在又開始研究GIS了。由於我們項目是用.net開發的,所以GIS工具也是當前最新的MapXtreme2004,對於新事物我都有一種衝動,所以研究起來也相當有勁, 
不過這個也不是那麼容易,中文資料太少(本人英語水平有限,正在努力中……),通過網絡還是找到了很多零散的資料,在此整理一下。留於以後研究。 
1.asp.net中如何用MapControl 動態加載地圖 
MapControl1.Map.Clear(); 
MapGeosetLoader gl=new MapGeosetLoader(@"F:\test.gst"); 
MapControl1.Map.Load(gl); 
其實根據不同的格式加載地圖的辦法也有多種,MapWorkSpaceLoader 
2.創建MSW文件 
MapInfo.Persistence.WorkSpacePersistence wsp = new MapInfo.Persistence.WorkSpacePersistence(); 
wsp.Save ("c:\\temp\\newwork.mws"); //保存文件 
3.創建InfoTool的事件 
InfoTool的事件與button不一樣,而是 InfoRetrieved。 
創建後將是這樣: 
private void InfoToolControl1_InfoRetrieved(object sender, MapInfo.Web.UI.WebControls.InfoToolEventArgs e) 

  string Info = ""; 
  foreach(MapInfo.Data.ITableFeatureCollection fc in e.Features) 
  { 
    foreach(MapInfo.Data.Feature f in fc) 
    { 
       Info= string.Format(Info + f[1].ToString() + " "); 
     } 
  fc.Table.Close(); 
  } 

4.如何通過web.config來加載地圖 
在web.config中,在下添加的Key

In the HTML view of the form under the mapinfowebuiwebcontrols:MapControl tag, set the following properties: 
在HTML視圖中,更改 mapinfowebuiwebcontrols:MapControl的屬性MapAlias必須以.MSW結尾 
UseDesigntimeWorkspace="fale" ,這一句要刪除WorkspaceFileName="WebForm1MapControl1.mws" 
5.在添加了新層後如何更新地圖讓InfoTool可以獲取他的信息 
MapInfo.Data.Table tab = MapInfo.Engine.Session.Current.Catalog.OpenTable(@"C:\Program Files\MapInfo\MapXtreme2004\Maps\World\world.tab"); 
MapInfo.Mapping.FeatureLayer fl = new MapInfo.Mapping.FeatureLayer(tab); 
this.MapControl1.Map.Layers.Add(fl); 
this.MapControl1.SelectableLayers.Add(fl.Name);

6.MapXtreme2004應用問答- - by jerry429 
問:如何在桌面程序中更改地圖的座標系? 
問:在C#應用中如何讀取存在ORACLE(或SQL Server)中的MapInfo表? 
問:在C#桌面與Web應用中讀取硬盤上MapInfo表一法 
問:如何在MapXtreme2004桌面應用程序中的任務欄上顯示出鼠標的座標? 
問:如何使用代碼修改桌面應用程序的座標系統? 
問:如何在桌面程序中更改地圖的座標系? 
答:代碼如下: 
    using MapInfo.Geometry; 
    //要使用到MapInfo.Geometry命名空間 
    Map map = mapControl1.Map; 
    MapInfo.Geometry.CoordSys coordSys = Session.Current.CoordSysFactory.CreateLongLat(DatumID.NAD83); 
    //DatumID爲枚舉類型,其中列出了經緯度座標系統的大量枚舉類型,參閱幫助可獲取更多信息。 
    map.SetDisplayCoordSys(coordSys); 
問:在C#應用中如何讀取存在ORACLE(或SQL Server)中的MapInfo表? 
答:讀取ORACLE中表的方法如下代碼: 
   using MapInfo.Data;           //這裏要添加對MapInfo數據的引用 
   MIConnection Connection=new MIConnection(); 
   Connection.Open(); 
   MapInfo.Data.Table [] tables=new MapInfo.Data.Table[4]; 
   TableInfoServer tis1=new TableInfoServer("WORLD","SVR=MYORACLE;UID=system;PWD=manager","select * from world",MapInfo.Data.ServerToolkit.Oci); 
   tables[0]=Connection.Catalog.OpenTable(tis1); 
   TableInfoServer tis2=new TableInfoServer("WORLDCAP","SVR=MYORACLE;UID=system;PWD=manager","select * from worldcap",MapInfo.Data.ServerToolkit.Oci); 
   tables[1]=Connection.Catalog.OpenTable(tis2); 
   TableInfoServer tis3=new TableInfoServer("wldcty25","SVR=MYORACLE;UID=system;PWD=manager","select * from wldcty25",MapInfo.Data.ServerToolkit.Oci); 
   tables[2]=Connection.Catalog.OpenTable(tis3); 
   TableInfoServer tis4=new TableInfoServer("OCEAN","SVR=MYORACLE;UID=system;PWD=manager","select * from OCEAN",MapInfo.Data.ServerToolkit.Oci); 
   tables[3]=Connection.Catalog.OpenTable(tis4); 
   MapControl1.Map.Load(new MapInfo.Mapping.MapTableLoader(tables)); 
   Connection.Close(); 
而讀取存放在SQL Server2000中的表時,應當使用如下修改過的代碼: 
   /* SQL Server數據庫連接*/ 
   MIConnection Connection=new MIConnection(); 
   Connection.Open(); 
   MapInfo.Data.Table [] tables=new MapInfo.Data.Table[2]; 
   TableInfoServer tis1=new TableInfoServer("CH_SHENGHUI","DRIVER={SQL Server};SERVER=YC31;DATABASE=MYWEBGIS;Trusted_Connection=Yes","select * from CH_SHENGHUI",MapInfo.Data.ServerToolkit.Odbc);//注意這裏使用的是Odbc,且區分大小寫。 
   tables[0]=Connection.Catalog.OpenTable(tis1); 
   TableInfoServer tis2=new TableInfoServer("CH_SHENGJIE_P","DRIVER={SQL Server};SERVER=YC31;DATABASE=MYWEBGIS;Trusted_Connection=Yes","select * from CH_SHENGJIE_P",MapInfo.Data.ServerToolkit.Odbc);//注意這裏使用的是Odbc,且區分大小寫。 
   tables[1]=Connection.Catalog.OpenTable(tis2); 
   mapControl1.Map.Load(new MapInfo.Mapping.MapTableLoader(tables)); 
   Connection.Close(); 
   /*上面的TableInfoServer語句分開來寫可以表達成如下方法。*/ 
   /* 
   TableInfoServer tiServer = new TableInfoServer("SHENGHUI"); 
   tiServer.ConnectString = "DRIVER={SQL Server};SERVER=YC31;DATABASE=MYWEBGIS;Trusted_Connection=Yes"; 
   tiServer.Query = "Select * from CH_SHENGHUI"; 
   tiServer.Toolkit = ServerToolkit.Odbc; 
   MapTableLoader tl = new MapTableLoader(tiServer); 
   mapControl1.Map.Load(tl); 
   */ 
問:在C#桌面與Web應用中讀取硬盤上MapInfo表一法 
答:二者皆可使用如下代碼: 
  using MapInfo.Data; 
  MIConnection Connection=new MIConnection(); 
  Connection.Open(); 
  tables[0]=Connection.Catalog.OpenTable(@"G:\Ch_shenghui.TAB"); 
  tables[1]=Connection.Catalog.OpenTable(@"G:\Shengjie_p.TAB"); 
  mapControl1.Map.Load(new MapInfo.Mapping.MapTableLoader(tables)); 
問:如何在MapXtreme2004桌面應用程序中的任務欄上顯示出鼠標的座標? 
答: 
1、添加mapControl1的MouseMove事件; 
2、該事件及其中代碼如下: 
public void MapControl1_MouseMove(object sender, MouseEventArgs e) 

    System.Drawing.PointF DisplayPoint = new PointF(e.X,e.Y); 
    MapInfo.Geometry.DPoint MapPoint = new MapInfo.Geometry.DPoint(); 
    MapInfo.Geometry.DisplayTransform converter = this.mapControl1.Map.DisplayTransform; 
    converter.FromDisplay(DisplayPoint, out MapPoint); 
    this.statusBar1.Text = "Cursor Location: " + MapPoint.x.ToString() + ", " + MapPoint.y.ToString(); 

問:如何使用代碼修改桌面應用程序的座標系統 
答:代碼如下: 
Map map = mapControl1.Map; 
MapInfo.Geometry.CoordSys coordSys = Session.Current.CoordSysFactory.CreateLongLat(DatumID.WGS84); 
map.SetDisplayCoordSys(coordSys);

7.在一個程序中要找到固定點附近最近的圖元,於是想用SearchNearst。 
但是總是出現異常,說"不能對NonEarth座標系應用Spherical操作" 
所以想問一下,MXT04中的SearchNearst方法是不是不支持NonEarth座標系? 
//這個問題在MapXtreme2004的6.0和6.1版本都會有。以後版本會改正。 
//暫時解決方案:在經緯度投影座標系中操作。 
   try 
   { 
    MapInfo.Mapping.Map  _map=mapControl1.Map; 
    MapInfo.Data.Catalog _catalog=Session.Current.Catalog; 
    //打開非地球座標系的圖層,並設置地圖座標系 
    mapControl1.Map.Load(new MapTableLoader(@"E:\MapInfo\培訓材料\技術培訓教材與PPT\MapXtreme2004\示例\OpenTable\MAP_AREA.TAB")); 
    Cursor.Current = Cursors.WaitCursor; 
    MapInfo.Geometry.CoordSysFactory cf=new MapInfo.Geometry.CoordSysFactory(); 
    MapInfo.Geometry.CoordSys Nonearth=cf.CreateFromMapBasicString("CoordSys NonEarth Units \"m\"  Bounds (-2000000, -2000000) (2000000, 2000000)"); 
    _map.SetDisplayCoordSys (Nonearth); 
    //確定查找點-爲非地球座標的中心點 
    MapInfo.Geometry.DPoint pt=new MapInfo.Geometry.DPoint(_map.Center.x,_map.Center.y); 
    //將地圖座標系轉換爲經緯度投影 
    MapInfo.Geometry.CoordSys LonLat=cf.CreateFromMapBasicString("CoordSys Earth Projection 1, 0"); 
    _map.SetDisplayCoordSys (LonLat); 
    //將非地球座標下的查找點轉換我經緯度投影下的點 
    MapInfo.Geometry.CoordinateTransform Transformer=cf.CreateCoordinateTransform(LonLat,Nonearth); 
    MapInfo.Geometry.DPoint dpt=Transformer.CoordSys2ToCoordSys1(pt); 
    //設置查找半徑 
    Distance d = MapInfo.Mapping.SearchInfoFactory.ScreenToMapDistance(_map, 3); 
    SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchNearest(dpt, LonLat, d); 
    IResultSetFeatureCollection fc = _catalog.Search("MAP_AREA", si); 
    Session.Current.Selections.DefaultSelection.Add(fc); 
   } 
   finally 
   { 
    Cursor.Current = Cursors.Default; 
   } 
nonearth問題在6.2中已經完全解決. 
8.有兩個MapControls,怎樣使其中一個保存爲.MWS 
MapInfo.Persistence.WorkSpacePersistence wsp = new MapInfo.Persistence.WorkSpacePersistence(); 
System.IO.FileStream file = new System.IO.FileStream("C:\\temp\\Test.mws", System.IO.FileMode.CreateNew); 
wsp.Save(this.mapControl2.Map.Clone() as MapInfo.Mapping.Map,file); 
file.Close(); 
9.查看特定幾個圖層 
假定讓lyr1和lyr2兩個圖層充滿整個地圖窗口: 
Table[] ts= new Table[2]; 
ts[0] = lyr1.Table; 
ts[1] = lyr2.Table; 
IMapLayerFilter iml = MapLayerFilterFactory.FilterByTable(ts); 
MapLayerEnumerator mle = mapControl1.Map.Layers.GetMapLayerEnumerator(iml); 
mapControl1.Map.SetView(mle); 
10.//創建臨時層 
TableInfoMemTable tblInfoTemp = new TableInfoMemTable("Animation"); 
MapInfo.Data.Table tblTemp = cat.GetTable("Animation"); 
if (tblTemp != null) //Table exists close it 

cat.CloseTable("Animation"); 

tblInfoTemp.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(MapControl1.Map.GetDisplayCoordSys())); 
tblInfoTemp.Columns.Add(ColumnFactory.CreateStyleColumn()); 
tblInfoTemp.Columns.Add(ColumnFactory.CreateStringColumn("NAME", 40)); 
tblInfoTemp.Columns.Add(ColumnFactory.CreateStringColumn("Dept", 15)); 
tblInfoTemp.Columns.Add(ColumnFactory.CreateIntColumn("Level")); //TableInfoMemTable是TableInfo類繼承來的 
tblTemp = cat.CreateTable(tblInfoTemp); 
FeatureLayer lyr = new FeatureLayer(tblTemp); 
MapControl1.Map.Layers.Add(lyr);

posted @ 2006-01-05 17:28 路燈十三 閱讀(332) | 評論(1) | 編輯

從MapX到MapXtreme2004[2]-圖層操作

        Mapx中基本的圖層操作還是比較簡單的,集中在對Layers和Layer的處理上,對別的沒有太多要求。 
在MapXtreme中,要完成類似功能,發生了一點變化,如下: 
1、圖層的顯示 
在MapXtreme中,圖層的顯示控制發生了奇怪的變化,有一個IsVisible屬性,但它是隻讀的,不能通過它來改變圖層的顯示。要控制圖層的顯示與隱藏,可以通過設置Layer.Enable來控制。 
2、圖層的動態添加 
代碼如下: 
        Catalog _catalog=MapInfo.Engine.Session.Current.Catalog; 
        MapInfo.Data.Table _tempTable=null; 
        Map _map=MapControl1.Map ;    
        TableInfo ti = TableInfoFactory.CreateTemp("臨時");  
        _tempTable = _catalog.CreateTable(ti); 
        _map.Layers.Insert(0, new FeatureLayer(_tempTable)); 
可以看出:加圖層實際就是加表;Catalog對象統管表的加載以及列舉; 
查幫助還可以瞭解:表信息其實還可以包括表的類型和座標系。類型是指原生表,文本,access ... 
上面的ti也可以這樣取得,但是,上面的表默認是MeMTab,應該是內存中的吧。 
        CoordSys cs=_map.GetDisplayCoordSys(); 
        TableInfo ti = TableInfoFactory.CreateTemp("臨時",MapInfo.Data.TableType.Native,cs); 
以上只能算是學習心得,肯定錯誤百出,但總比什麼都沒有強,至少能夠提供一個思路。至於表如何保存,Mapx中的動畫層和標籤層在MapxTreme中如何對應,因爲暫時不急用,先放着。

posted @ 2006-01-05 17:26 路燈十三 閱讀(311) | 評論(0) | 編輯

OleDbDataAdapter 類

OleDbDataAdapter 類

表示一組數據命令和一個數據庫連接,它們用於填充 DataSet 和更新數據源。

有關此類型所有成員的列表,請參閱 OleDbDataAdapter 成員

System.Object 
System.MarshalByRefObject 
System.ComponentModel.Component 
System.Data.Common.DataAdapter 
System.Data.Common.DbDataAdapter 
System.Data.OleDb.OleDbDataAdapter

[Visual Basic]
NotInheritable Public Class OleDbDataAdapter
   Inherits DbDataAdapter
   Implements IDbDataAdapter
[C#]
public sealed class OleDbDataAdapter : DbDataAdapter,
   IDbDataAdapter
[C++]
public __gc __sealed class OleDbDataAdapter : public DbDataAdapter,
   IDbDataAdapter
[JScript]
public class OleDbDataAdapter extends DbDataAdapter implements
   IDbDataAdapter
線程安全

此類型的所有公共靜態(Visual Basic 中爲 Shared)成員是線程安全的。但不保證任何實例成員是線程安全的。

備註

OleDbDataAdapter 充當 DataSet 和數據源之間用於檢索和保存數據的橋接器。OleDbDataAdapter 通過以下方法提供這個橋接器:使用Fill 將數據從數據源加載到 DataSet 中,使用 Update 將 DataSet 中所作的更改發回數據源。

當 OleDbDataAdapter 填充 DataSet 時,它將爲返回的數據創建必需的表和列(如果它們還不存在的話)。但是,除非MissingSchemaAction 屬性設置爲 AddWithKey,否則這個隱式創建的架構中就將不包括主鍵信息。也可以使用 FillSchema,讓OleDbDataAdapter 創建 DataSet 的架構,並在用數據填充它之前就將主鍵信息包括進去。有關更多信息,請參見向 DataSet 添加現有約束。

請注意,包括 MSDataShape 提供程序在內的某些 OLE DB 提供程序並不返回基表或主鍵信息。其結果是,OleDbDataAdapter 不能爲任何已創建的 DataTable 正確地設置 PrimaryKey 屬性。在這種情況下,應該顯式指定 DataSet 中表的主鍵。

OleDbDataAdapter 還包括 SelectCommandInsertCommandDeleteCommandUpdateCommand 和 TableMappings 屬性,以便於數據的加載和更新。

當創建 OleDbDataAdapter 的實例時,屬性都設置爲其初始值。有關這些值的列表,請參見 OleDbDataAdapter 構造函數。

示例

[Visual Basic, C#, C++] 以下示例使用 OleDbCommandOleDbDataAdapter 和 OleDbConnection 從 Access 數據源選擇記錄,並用選定行填充 DataSet。然後返回已填充的 DataSet。爲完成此任務,向該方法傳遞一個已初始化的 DataSet、一個連接字符串和一個查詢字符串,後者是一個 SQL SELECT 語句。

[Visual Basic] 
Public Function SelectOleDbSrvRows(dataSet As DataSet, connection As String, query As String) As DataSet
    Dim conn As New OleDbConnection(connection)
    Dim adapter As New OleDbDataAdapter()
    adapter.SelectCommand = new OleDbCommand(query, conn)
    adapter.Fill(dataset)
    Return dataset
End Function

[C#] 
public DataSet SelectOleDbSrvRows(DataSet dataset,string connection,string query) 
{
    OleDbConnection conn = new OleDbConnection(connection);
    OleDbDataAdapter adapter = new OleDbDataAdapter();
    adapter.SelectCommand = new OleDbCommand(query, conn);
    adapter.Fill(dataset);
    return dataset;
}


[C++] 
public:
DataSet* SelectOleDbSrvRows(DataSet* dataset,String* connection,String* query) 
{
    OleDbConnection* conn = new OleDbConnection(connection);
    OleDbDataAdapter* adapter = new OleDbDataAdapter();
    adapter->SelectCommand = new OleDbCommand(query, conn);
    adapter->Fill(dataset);
    return dataset;
}

[JScript] 沒有可用於 JScript 的示例。若要查看 Visual Basic、C# 或 C++ 示例,請單擊頁左上角的“語言篩選器”按鈕 語言篩選器

要求

命名空間: System.Data.OleDb

平臺: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列

程序集: System.Data (在 System.Data.dll 中)

請參見

OleDbDataAdapter 成員 | System.Data.OleDb 命名空間 | OleDbConnection | OleDbCommand | DataSet | DataTable

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章