spacer1
spacer2 1_1 1_2
2_1
 Subscribe
 The MP2K Update!
 
 
 
 Magazine
Front Cover
What's New
Articles
News
Sample Data
Gallery
Advertise
About
 Features
MapPoint 2013
Press Releases
MapPoint Forums
Companies
Link to MP2Kmag
Wish List
MapPoint Trial
Authors
 Earlier Content
Past News Items
Past What's New Announcements
 Sponsors
 Order

MapPoint 2013

Programming MapPoint in .NET

MapPoint Book

  Spatial Community
SVG Tutorials
MapPoint

Map Visitors

  ARTICLES  


Functional Programming with MapPoint and F#: Part 1

The first of two articles by Richard Marsden on MapPoint and F#. Recently released as a full product by Microsoft, F# can be used as a functional language or as an imperative or object-oriented language, and is useful for multi-threaded programming.

F# is functional language for the .NET framework that is based on OCaml. Originally developed by Microsoft Research (Cambridge), it has recently been released as a full product by Microsoft. Functional programming has been favored by academia for a long time, but it has never expanded beyond niche applications in the commercial world. Although functional programming promises to be safer, the lack of supporting libraries and standard inter-language interfaces has been a major hurdle. F# might prove to be a major force in the adoption of functional programming. F# programs can easily access the entire .NET framework, and are about as fast as comparable C# programs. F# is also multi-paradigm. It can be used in a functional manner, but it can also be used as an imperative or objective oriented language. This allows you to easily switch to the most appropriate paradigm for the problem at hand.

Another force in F#'s favor is that of multi-threaded programming. F#'s objects and values are naturally immutable - making it much easier to write thread-safe code.

That is enough of an introduction to F#. If you would like to learn F#, there are already a number of very good books and websites. A good book that I recommend is "Expert F#" by Don Syme, Adam Granicz, Antonio Cisternino; published by Apress.

The following examples were typed into the F# command line environment (FSI.exe), but they can also be entered into a file and compiled using Visual Studio. Both are included in the F# download from Microsoft. When using the command line environment, each line is evaluated when it is completed with a ';;' token. F#’s responses are not displayed for clarity. F# uses // for one line comments.

Using Late Binding

Following on from my previous article about late binding and C#, we shall first look at calling MapPoint from F# using late binding. This uses a traditional imperative approach. It also does not require a COM interop file to be created, but it is more verbose and is weakly typed. In the fsi command line environment, type:

And that is all there is to it. It is very similar to the C# version, although the casting syntax is a little strange.

Using Early Binding

Next we shall look at early binding. This is more convenient because it allows compile-time type checking. It is also more natural and less verbose. First you should create a MapPoint COM Interop called "Interop.MapPoint.dll", if you do not already have one. Normally you would use visual Studio to create this for you when you add a COM reference, but F# Projects in Visual Studio 2008 do not currently have this option. Therefore you should create it manually using the tlbimp.exe utility. You will need to change the paths, but an example usage is as follows: Tlbimp.exe MPNA82.tlb /out:"Interop.MapPoint.dll" /namespace:Interop.MapPoint /sysarray /transform:dispret

We are now ready to use MapPoint in F#. First we need to reference the COM Interop that we have just created, and any .NET namespaces that we need:

Next we create a new MapPoint instance. This time we use a functional approach to also set the Visible property in the same line of code. This uses an intermediate object ‘app’ which is "returned" to mappoint.

Next we will do something useful and create a pushpin. Although it is essentially an assignment, the assignment performs a number of operations to create a temporary pushpin object p. The balloon state is then set, and MapPoint's view is moved to the pushpin. After all these operations are complete, the pushpin object p is returned as the value for oPin:

And that is it! I have only touched on functional programming and not done it justice. Readers interested in functional programming should read more about F#, or learn a pure functional language such as OCaml or Standard ML.

In part 2, I shall use F# to work through an existing pushpin set, classifying pushpins according to their existing data fields and assigning pushpin symbols accordingly.

Discuss this story in the forum.

Author: Richard Marsden
Email: enquiries(AT)winwaed.com
URL: http://www.winwaed.com
Richard Marsden is the proprietor of Winwaed Software Technology, LLC which provides software consulting and development services, specializing in both MapPoint and online mapping applications. He operates the Mapping-Tools.com Website for MapPoint Tools and Utilities, and recently launched the GeoWeb Guru a community website for developers of the geospatial web. In 2008, Richard was awarded Virtual Earth MVP status by Microsoft.

Prior to Winwaed, Richard worked as a software developer working on seismic processing algorithms for the oil exploration industry. He holds geology and geophysics degrees from the University of Cambridge (Churchill College), and the University of Durham; and an interdisciplinary MBA from the University of Dallas.



Google
 
MP2Kmag Internet


 Recent Discussion
-GCPowerStation v17.2
-GCPowerStation v17.2
-Gaussian 09W v8.0 Rev B.01 SMP
-Gaussian 09 E.01 Linux64
-Atmel Studio v.7.0.1931
-Steinberg Cubase Elements v9.5.40 WiN
-Nero Platinum 2019 Suite 20.0.05900 Multilingual
-Serif DrawPlus X8 14.0.0.19
-PROMT Master 19 Final + PROMT 19 Dictionary Collection
-Apple Logic Pro X v.10.4.2 Multilanguage (MacOSX)
-PROMT Expert 19 Final + PROMT 19 Dictionary Collection
-Waves Complete v2018.10.16 WiN by R2R
-VMware Fusion Pro 10.1.1 MacOSX
-Foxit Phantompdf Business v.9.3.0.10826 Multilanguage
-Bluestacks v4.31.56.2510 Multilingual
-Xara Web Designer Premium 16.0.0.55162 (x64) Portable
-Adobe Bridge CC 6.1.1.10 Update 3 by m0nkrus
-Garmin MapSource v5.4
-Alien Skin Exposure X4 Bundle 4.0.2.43 | macOS
-Unity Asset Cubebrush - Scrap City Assets 1.0 x64
-Magix Samplitude Pro X3 Suite v.14.4.0.518 Multilanguage
-Waves Complete v2018.10.16
-Oxygen XML Editor 18.0 (Win/Mac/Lnx)
-Steinberg Cubase Elements v9.5.40 WiN
-The Foundry Nuke Studio 11.2v4 Win x64
 Resources
Browse GIS books and periodicals
Find a MapPoint Partner or Consultant
Real Estate Thornbrook Subdivision


Want Your Site To Appear Here?

   © 1999-2012 MP2K. Questions and comments to: website@mp2kmag.com
  Microsoft and MapPoint 2002/2004/2006/2009/2010/2011/2013 are either trademarks or registered trademarks of Microsoft.