Mapxtreme getting started

Source: Internet
Author: User
Tags sql server driver odbc sql server driver

Q: Read the Mapinfo table on the hard disk in C # desktop and Web applications.
A: You can use the following code:
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 ));
Q: How do I display the coordinates of the mouse on the taskbar of the mapxtreme2004 desktop application?
A:
1. Add the mapcontrol1 mousemove event;
2. The event and its Code are as follows:
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 ();
}
Q: How can I use code to modify the coordinate system of a desktop application?
A: The Code is as follows:
Map map = mapcontrol1.map;
MapInfo. Geometry. coordsys = session. Current. coordsysfactory. createlonglat (datumid. WGS84 );
Map. setdisplaycoordsys (coordsys );

7. To find the closest element near a fixed point in a program, you want to use searchnearst.
But there is always an exception, saying "You cannot apply spherical operations to the nonearth Coordinate System"
Therefore, do the searchnearst method in mxt04 not support the nonearth coordinate system?
// This issue can be found in versions 6.0 and 6.1 of mapxtreme2004. Later versions will be corrected.
// Temporary solution: operate in the projection Coordinate System of latitude and longitude.
Try
{
MapInfo. Mapping. Map _ map = mapcontrol1.map;
MapInfo. Data. Catalog _ catalog = session. Current. Catalog;
// Open the layer of the non-earth coordinate system and set the map coordinate system
Mapcontrol1.map. Load (New maptableloader (@ "E:/Mapinfo/training materials/technical training materials and PPT/mapxtreme2004/example/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,200 0000 )");
_ Map. setdisplaycoordsys (nonearth );
// Determine the search point-the center point of the non-earth Coordinate
MapInfo. Geometry. dpoint Pt = new MapInfo. Geometry. dpoint (_ map. Center. X, _ map. Center. y );
// Convert the map coordinate system to latitude and longitude projection
MapInfo. Geometry. coordsys lonlat = Cf. createfrommapbasicstring ("coordsys Earth projection 1, 0 ");
_ Map. setdisplaycoordsys (lonlat );
// Convert the lookup point under non-Earth coordinates to the point under my latitude and longitude projection
MapInfo. Geometry. coordinatetransform transformer = Cf. createcoordinatetransform (lonlat, nonearth );
MapInfo. Geometry. dpoint DPT = transformer. coordsys2tocoordsys1 (PT );
// Set the search radius
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;
}
The nonearth problem has been completely solved in 6.2.
8. There are two mapcontrols. How to save one of them as. 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. View specific Layers
Assume that the layers lyr1 and lyr2 are filled with the entire map window:
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. // create a temporary layer 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 is inherited by the tableinfo class.
Tbltemp = cat. createtable (tblinfotemp );
Featurelayer lyr = new featurelayer (tbltemp );
Mapcontrol1.map. layers. Add (lyr );

1. Question about loading layers from the Oracle table... Miconnection connection = new miconnection ();
Connection. open ();
Tableinfoserver tis1 = new tableinfoserver ("world ",
"Srvr = ora8i; uid = wzzwd = 11111111 ",
"Select * from world", MapInfo. Data. servertoolkit. OCI );
MapInfo. Data. Table [] tables = new MapInfo. Data. Table [2];
Tables [0] = connection. Catalog. OpenTable (tis1 );
Tableinfoserver tis2 = new tableinfoserver ("worldcap ",
"Srvr = ora8i; uid = wzzwd = 11111111 ",
"Select * From worldcap", MapInfo. Data. servertoolkit. OCI );
Tables [1] = connection. Catalog. OpenTable (tis2 );
Mapcontrol1.map. Load (New MapInfo. Mapping. maptableloader (tables ));

2. There is a binding code for XY coordinate points in sqlsever.
// XY binding: The layer containing X and Y coordinate points is placed in the SQL Server database, and the point layer is generated based on XY coordinates.
// 1. Create a mapinfo_mapcatalog table in the database where the table exists; otherwise, an error is returned:
// "An unhandled exception of Type 'mapinfo. Data. tableexception' occurred in MapInfo. coreengine. dll.
// Additional information: the table cannot be opened. ODBC error: ODBC rc =-1, ODBC sqlstate = s0002, DBMS rc = 208, dbms msg = [Microsoft] [odbc SQL Server Driver] [SQL Server] Object Name 'mapinfo. invalid mapinfo_mapcatalog.
// 2. Create a primary key for the table containing XY coordinate points; otherwise, an error is returned:
// "Additional Information: The table cannot be opened. The unique key cannot be identified and remote data cannot be accessed. "

// Create an XY space Scheme
MapInfo. Data. spatialschemaxy xy = new MapInfo. Data. spatialschemaxy ();
XY. xcolumn = "X ";
XY. ycolumn = "Y ";
XY. nullpoint = "0.0, 0.0 ";
XY. styletype = MapInfo. Data. styletype. None;
XY. defaultstyle = new MapInfo. Styles. compositestyle ();
XY. coordsys = MapInfo. Engine. session. Current. coordsysfactory. createlonglat (MapInfo. Geometry. datumid. WGS84 );

// Create tableinfo
MapInfo. data. tableinfoserver Ti = new MapInfo. data. tableinfoserver ("customers", "driver = {SQL Server}; server = lixiaohui; database = test; uid = SAWD = sa;", "select * From us_cust", MapInfo. data. servertoolkit. ODBC );
Ti. spatialschema = xy;
MapInfo. Data. Table micustomers = MapInfo. Engine. session. Current. Catalog. OpenTable (Ti );
MapInfo. Mapping. featurelayer = new MapInfo. Mapping. featurelayer (micustomers );
Mapcontrol1.map. layers. Add (featurelayer );
Mapcontrol1.map. setview (featurelayer );

3. How to view the entire map = mapcontrol1.map;
Imaplayerfilter lyrfilter = maplayerfilterfactory. filterbytype (typeof (featurelayer ));
Maplayerenumerator lyrenum = map. layers. getmaplayerenumerator (lyrfilter );
Map. setview (lyrenum );
Or:
Map map = mapcontrol1.map;
Imaplayerfilter lyrfilter = new filterbylayertype (layertype. Normal );
Maplayerenumerator lyrenum = map. layers. getmaplayerenumerator (lyrfilter );
Map. setview (lyrenum );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.