TransWikia.com

Find Raster data in a Mapinfo workspace

Geographic Information Systems Asked on July 12, 2021

I want to check if there is a raster layer in a map window using Mapbasic v2019.

For Group Layers I use the following but I want to do the equivalent with Rasters.

Sub Remove_Group (ByVal Group_Name as String)
OnError GoTo GroupError
dim mapwindowid,groupid,groupcount,x as integer

mapwindowid = FrontWindow()
groupid = MapperInfo( mapwindowid, 29) '29 is MAPPER_INFO_GROUPLAYERS
x=1
while x <=groupcount
    if GroupLayerInfo ( mapwindowid, groupid, 1 ) = Group_Name then '1 is GROUPLAYER_INFO_NAME
        x=x+1
    End If
Wend

groupcount = GroupLayerInfo (mapwindowid, groupid, 5)  '5 is GROUPLAYER_INFO_ALL_LAYERS
'print ("GroupCount is: "&groupcount)
if groupcount=0 then
    Set Map Window mapwindowid GroupLayer Group_Name Ungroup
End if

OnError GoTo 0
Exit Sub
GroupError:
Print ("=== An error has occured - please take a screen grab and email the following text to [email protected]"&chr$(13)&"Error Code is "& Err()& " | " & Error$()&chr$(13))
Resume Next

End Sub

For groupid = MapperInfo( mapwindowid, 29) '29 is MAPPER_INFO_GROUPLAYERS I need to find a function to see if the data is raster or vector in MapperInfo

I see LayerInfo has LAYER_INFO_TYPE that has value 2 for raster images but then I need to list each layer from mapperinfo and then check each one if it’s type 2. There should be an easier way…

One Answer

You'll have to loop through the layers in your map and check the type of each.

mapwindowid = FrontWindow()
For layerid = MapperInfo( mapwindowid, MAPPER_INFO_LAYERS) To 1 Step -1
    if LayerInfo( mapwindowid, layerid, LAYER_INFO_TYPE) In (LAYER_INFO_TYPE_IMAGE, LAYER_INFO_TYPE_GRID, LAYER_INFO_TYPE_WMS, LAYER_INFO_TYPE_TILESERVER)  then 
        Print "Map has raster layer!"
        Exit For
    End If
Next

Note that I check the layer against all raster layer types: image, grid, WMS, and Tile Server.

Correct answer by Peter Horsbøll Møller on July 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP