After MapControl is placed on the form, you can add layers in the form of code. You can add layers to MapControl. map attributes to add a layer. This attribute is a Map layer. You can attach a Map in three ways: MapControl. map is a Map type, indicating a Map. There is a Load method for this type. Three types of maps are supported: Geoset, Workspace, and Tables, because the Load method is an abstract class of MapLoader, class MapGeosetLoader, MapWorkSpaceLoader, and MapTableLoader represent three maps respectively. These loaders are constructed in string type, namely, three file paths, and the extension of the three files is *. gst ,*. mws and *. tab.
Now draw a layer with two groups of broken lines named test. tab.
First, analyze the two groups of broken lines. The first group of broken lines consists of five points, and the second group of broken lines consists of three points. The Table corresponding to this layer should have two rows of data.
The following code queries layer points:
Catalog Cat = MapInfo. Engine. Session. Current. Catalog;
Table tblTemp = Cat. GetTable ("");
DataTable dt = new DataTable ();
MIDataReader dr = tblTemp. ExecuteReader ();
Dt. Load (dr );
DataGridView1.DataSource = dt;
For (int I = 0; I <dt. Rows. Count; I ++)
{
MultiCurve mc = dt. Rows [I]. ItemArray [0] as MapInfo. Geometry. MultiCurve;
Curve cur = mc [0];
Foreach (var v in cur. SamplePoints ())
{
MessageBox. Show ("X:" + v. x + "Y:" + v. y );
}
}
Query using ADO. NET:
MIConnection con = new MIConnection ();
MICommand cmd = con. CreateCommand ();
Cmd. CommandText = "select * from ";
Con. Open ();
MIDataReader dr = cmd. ExecuteReader ();
While (dr. Read ())
{
MapInfo. Geometry. MultiCurve mc = dr. GetValue (0) as MapInfo. Geometry. MultiCurve;
Curve cur = mc [0];
Foreach (var v in cur. SamplePoints ())
{
MessageBox. Show ("X:" + v. x + "Y:" + v. y );
}
}
Dr. Close ();
Con. Close ();