.Net Codes & Tutorials

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 write Special characters in a file using vb.net

You may need to read / write some special symbols like these æ,Ø,å etc, into a text file. I had a similar situation where I needed to write some danish characters into the file.
Below is what I had used.
Dim encoding As Encoding
encoding = New UTF8Encoding()

Dim sw As StreamWriter
sw = New StreamWriter("filename.txt", False, encoding)
sw.WriteLine("vaøøibhav")
sw.WriteLine("vøøøøvvs")
sw.Close()
 
And if all fails, try this
Dim sw As New StreamWriter("filename.txt", False, System.Text.Encoding.Default)