Tuesday, 20 May 2014

Set Map Window Projection from Layer - Alter Layer Control Right Click Menu

Hi All,
This is quick post to demonstrate a useful tool for changing map projections based on a layer. By default MapInfo will assign a map projection based on the dominant raster layer. If you change raster layers the map projection may, but not always change. This tool will allow you to select a layer in the layer control, right click and set projection from layer.


Include "Mapbasic.def"
Include "Menu.def"

Declare Sub Main
Declare Sub
SetMapWinProjection

'----------------------------------------------------------------
Sub Main
OnError Goto
CatchEx


   Alter Menu ID M_SHORTCUT_LC_LAYERS Add
   "(-",
   "Set Map Projection From Layer"
   Calling SetMapWinProjection

Done:
   Exit Sub
CatchEx:
   Note Error$()
   Resume Done
End Sub
'----------------------------------------------------------------
Sub SetMapWinProjectionOnError Goto CatchEx

   If LayerControlInfo(LC_INFO_SEL_COUNT) = 0 then
      Note "Please select a layer!"
      Goto Done
   End If

   If LayerControlInfo(LC_INFO_SEL_COUNT) > 1 then
      Note "Please select one layer you want to set the map projection from"
      Goto Done
   End If

   Dim strLayerAlias as String
   strLayerAlias = LayerControlSelectionInfo(1,LC_SEL_INFO_NAME)
   Print("Layer Name: " & strLayerAlias)

   Print("Layer Type: "  LayerControlSelectionInfo(1,LC_SEL_INFO_TYPE))

   Dim iMapWinID as integer
   iMapWinID = LayerControlSelectionInfo(1,LC_SEL_INFO_MAPWIN_ID)
   Print("Layer's Map Window ID: " & iMapWinID)

   Dim strCmd as String
   strCmd = "Set Map " TableInfo(strLayerAlias,TAB_INFO_COORDSYS_CLAUSE)
   Print "strCmd = " & strCmd
   Run Command strCmd

Done:
   Exit Sub
CatchEx:
   Note Error$()

   Resume Done 
End Sub

1 comment:

  1. Nice post,i found lot of information regarding gis. I updated my knowledge with this blog.it can help me to crack GIS jobs in Hyderabad.

    ReplyDelete