Showing posts with label MapInfo. Show all posts
Showing posts with label MapInfo. Show all posts

How to get a feature collection from current selection in MapInfo MapXtreme

If you are looking for answers to the below questions ?

How to get a feature collection from current selection in MapXtreme ?
How to get a feature collection using a select region tool in MapXtreme ?
How to get a feature collection of all the selected regions in MapXteme ?

If yes I have an answers for you,
1. First select a layer as Feature Layer, this layer will be the layer where you will be searching for the selected regions.
2. Now, Using Session.Current.Selection.DefaultSelection() pass the table of the currently selected layer as shown in the code below.
3. The above used method will return a IResultSetFeatureCollection irfc, here you will get a collection of all the selected region of that layer.
Below is the code that does the same.

C# code
FeatureLayer lyr=mapControl1.Map.Layers["layerNameToGoHere"] as FeatureLayer ;
IResultSetFeatureCollection irfc = Session.Current.Selections.DefaultSelection[lyr.Table ];
 
VB.NET Code
Dim lyr as FeatureLayer =mapControl1.Map.Layers["layerNameToGoHere"]
Dim irfc as IResultSetFeatureCollection = Session.Current.Selections.DefaultSelection

How to save current map window image in your had drive

In this tutorial i will show you that how can we save  the current map window image to your hard drive.

private void button1_Click (object sender, EventArgs e)
{
MapInfo.Mapping.MapExport exportObject = new MapInfo.Mapping.MapExport (this.mapControl1.Map.Clone () as MapInfo.Mapping.Map);
exportObject.ExportSize = new MapInfo.Mapping.ExportSize (this.mapControl1.Map.Size.Width, this.mapControl1.Map.Size.Height);
exportObject.Format = MapInfo.Mapping.ExportFormat.Bmp;  / / Save to the clipboard
System.Windows.Forms.Clipboard.SetDataObject (exportObject.Export ()); / / Save to your hard drive
exportObject.Export (@ "D: \ Image.bmp");
MessageBox.Show ("Save successful!");
}

How to decide visibility of the layers using check boxes

In this small tutorial i will show you that how can we decide visibility of the layers depending on check boxes in MapInfo

  
code is very simple as shown bellow.

   private void checkBox1_CheckedChanged (object sender, EventArgs e)
         {
             this.mapControl1.Map.Layers [checkBox1.Text.ToString ()]. ​​Enabled = checkBox1.Checked;
         }

How to make a layer selectable or not selectable in MapInfo MapXtreme

In this tutorial i will show you that how can we make a layer selectable  or not selectable

/ / All the layers are not optional
                 MapInfo.Mapping.LayerHelper.SetSelectable (item, false);
   / / A layer is not optional
             foreach (MapInfo.Mapping.IMapLayer layer in mapControl1.Map.Layers)
             {
                 if (object.ReferenceEquals (layer, mapControl1.Map.Layers ["GZ_River_LL"]))
                 {
                     MapInfo.Mapping.LayerHelper.SetSelectable (layer, false);
                 }
         }

How to obtain current mouse co ordinates in MapInfo MapXtreme

Here i will show you that how can we get the current mouse co ordinates in the MapInfo MapXtreme

private void mapControl1_MouseMove (object sender, MouseEventArgs e)
         {
             System.Drawing.PointF DisplayPoint = new PointF (eX, eY); / / create two-dimensional midpoint of x and y coordinates of the ordered pair
             MapInfo.Geometry.DPoint MapPoint = new MapInfo.Geometry.DPoint (); // create a point layer
             MapInfo.Geometry.DisplayTransform converter =
              this.mapControl1.Map.DisplayTransform; converter.FromDisplay (DisplayPoint, out MapPoint); / / display coordinates of a point into the map coordinates of the point or layer
             this.statusBar1.Text = "Cursor Location:" + MapPoint.x.ToString () + "," + MapPoint.y.ToString ();
         }

 
Explanation:

DisplayTransform.FromDisplay method (Rectangle, DRect)
Will display the coordinates of the rectangle into a map or a layer of rectangular coordinates.
public void FromDisplay (
Rectangle srcRect,out DRect destRect)
Rectangle srcRect :  display coordinates of the rectangle.
out DRect destRect : map or a layer of rectangular coordinates.



DisplayTransform.ToDisplay method (DPoint, Point) Point of the map or layer into a display point.
public void ToDisplay (
DPoint pntSrc,out Point pntDest )
DPoint pntSrc : maps or layers points out Point pntDest  : display points.

How to save a .GST geoset file using MapInfo

It is possible to save a map in .gst form using the WorkSpacePersistence class.

1. Firstly you will need to create an object of FileStream class.

2. The First argument in the constructor of the FileStream class is the file path i.e path where this file needs to be saved.

3. Second argument is the FileMode, I have used FileMode.Create. There are various other option when using FileStream, refer this link same.

4. Use the save method from the WorkSpacePersistance class, pass the map and stream as arguments.

(Note : myMap is the name of the MapControl I have used in my application)

Dim stream As Stream
stream = New FileStream("D:/vaibhav/mumbai.gst", FileMode.Create)

Dim wsp As New MapInfo.Persistence.WorkSpacePersistence()
wsp.Save(myMap.Map, stream)