Sei sulla pagina 1di 4

[VB6] NumLayers and LayerType

1 de 4

http://www.mapwindow.org/phorum/read.php?11,5104,printview,page=1

Search MapWindow.org
Go

Home
Project Introduction
News
Open Source License
Buy CD & T-shirt
Contact
Products
MapWindow 4 Desktop
MapWindow 6 Alpha
HydroDesktop
MapWinGIS ActiveX
DotSpatial Library
Downloads
MapWindow 4 Desktop
MapWindow 6 Alpha
HydroDesktop
MapWinGIS ActiveX
DotSpatial Library
Documentation
MapWindow 4 Desktop
MapWindow 6 Alpha
HydroDesktop
MapWinGIS ActiveX
DotSpatial Library
Community
Discussion Forums
Mailing Lists
Issue Tracking
Internationalization
People
Service Vendors
Project Management
Source Code
Events
2010 Conference - Orlando
2011 Conference - San Diego
2012 Conference - Europe

This script using the ActiveX and VB6 to loop trough the layers and get some

MapWinGIS ActiveX Sample Code : MapWindow Discussion Forum

properties of the layers. Getting the Layertype using eLayerType isn't working, I've filed a bug report:

[VB6] NumLayers and LayerType


Posted by: pmeems ()
Date: December 08, 2006 01:17AM
This script using the ActiveX and VB6 to loop trough the layers and get some properties of the layers.
Getting the Layertype using eLayerType isn't working, I've filed a bug report: Bug #372

'Boolean
Dim bStatus As Boolean
'String
Dim sDir As String
Dim sFilename As String
'Long
Dim handle As Long, i As Long
'Object
Dim oMap As MapWinGIS.Map
Dim oSf As New MapWinGIS.Shapefile
Dim oGrid As New MapWinGIS.Grid
Dim oIm As New MapWinGIS.Image
Dim oCs As New MapWinGIS.GridColorScheme
Dim oUtils As New MapWinGIS.utils
'Init:
Set oMap = frmShapefiles.Map1 'Change this to your needs
sDir = "C:\test\NumLayersAndLayerType\" 'Change this to your needs
'For testing purposes first add some files to the map:
'Open shapefiles:
With oSf
sFilename = sDir & "Points.shp"

23/04/2014 10:57

[VB6] NumLayers and LayerType

2 de 4

http://www.mapwindow.org/phorum/read.php?11,5104,printview,page=1

bStatus = .open(sFilename)
If Not bStatus Then MsgBox "Cannot open shapefile (" & sFilename & ") " & .ErrorMsg(.LastErrorCode)
End With 'oSf
Call oMap.AddLayer(oSf, True)
oSf.Close
Set oSf = New MapWinGIS.Shapefile
With oSf
sFilename = sDir & "Lines.shp"
bStatus = .open(sFilename)
If Not bStatus Then MsgBox "Cannot open shapefile (" & sFilename & ") " & .ErrorMsg(.LastErrorCode)
End With 'oSf
Call oMap.AddLayer(oSf, True)
oSf.Close
Set oSf = New MapWinGIS.Shapefile
With oSf
sFilename = sDir & "Polygons.shp"
bStatus = .open(sFilename)
If Not bStatus Then MsgBox "Cannot open shapefile (" & sFilename & ") " & .ErrorMsg(.LastErrorCode)
End With 'oSf
Call oMap.AddLayer(oSf, True)
oSf.Close
'Open gridfile
sFilename = sDir & "Grid.asc"
With oGrid
bStatus = .open(sFilename, UnknownDataType, True, Ascii)
If Not bStatus Then MsgBox "Cannot open gridfile (" & sFilename & ") " & .ErrorMsg(.LastErrorCode)
End With 'oGrid
With oCs
.UsePredefined oGrid.Minimum, oGrid.Maximum, Meadow
.NoDataColor = vbWhite
End With 'cs
Set oIm = oUtils.GridToImage(oGrid, oCs)
bStatus = oMap.AddLayer(oIm, True)
oGrid.Close
MsgBox "Number of layers: " & oMap.NumLayers
For i = 0 To oMap.NumLayers - 1
handle = oMap.LayerHandle(i)
'Get layertype:
'LayerType isn't available trough MapWinGis,
'Filed a bugreport: #372
'get layerposition:
MsgBox oMap.LayerPosition(handle)
Next i
'cleanup:
Set oMap = Nothing
Set oSf = Nothing
Set oGrid = Nothing
Set oIm = Nothing
Set oCs = Nothing
Set oUtils = Nothing
End Sub

--Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8


Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group
Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.
--Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS
Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl
*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Edited 1 time(s). Last edit at 12/08/2006 01:22AM by pmeems.

Re: [VB6] NumLayers and LayerType

23/04/2014 10:57

[VB6] NumLayers and LayerType

3 de 4

http://www.mapwindow.org/phorum/read.php?11,5104,printview,page=1

Posted by: cmichaelis ()


Date: December 10, 2006 08:31PM
The function GetLayerType from MapWindow is a good example of how to retrieve a layer type from the ActiveX control. A similar approach can be used in VB6 I
believe, although I couldn't tell you the exact syntax differences. It's been a while...

Friend Function GetLayerType(ByVal LayerHandle As Integer) As MapWindow.Interfaces.eLayerType


Dim lyrObj As Object
lyrObj = frmMain.MapMain.get_GetObject(LayerHandle)
If lyrObj Is Nothing Then
Return MapWindow.Interfaces.eLayerType.Invalid
Exit Function
End If
If TypeOf lyrObj Is MapWinGIS.Shapefile Then
Dim sf As MapWinGIS.Shapefile = CType(lyrObj, MapWinGIS.Shapefile)
Select Case sf.ShapefileType
Case MapWinGIS.ShpfileType.SHP_POLYGON, MapWinGIS.ShpfileType.SHP_POLYGONM, MapWinGIS.ShpfileType.SHP_POLYGONZ
Return MapWindow.Interfaces.eLayerType.PolygonShapefile
Case MapWinGIS.ShpfileType.SHP_POINT, MapWinGIS.ShpfileType.SHP_POINTM, MapWinGIS.ShpfileType.SHP_POINTZ
Return MapWindow.Interfaces.eLayerType.PointShapefile
Case MapWinGIS.ShpfileType.SHP_POLYLINE, MapWinGIS.ShpfileType.SHP_POLYLINEM, MapWinGIS.ShpfileType.SHP_POLYLINEZ
Return MapWindow.Interfaces.eLayerType.LineShapefile
Case MapWinGIS.ShpfileType.SHP_MULTIPOINT, MapWinGIS.ShpfileType.SHP_MULTIPOINTM, MapWinGIS.ShpfileType.SHP_MULTIPOINTZ
Return MapWindow.Interfaces.eLayerType.PointShapefile
Case Else
Return MapWindow.Interfaces.eLayerType.Invalid
End Select
ElseIf TypeOf lyrObj Is MapWinGIS.Image Then
If frmMain.Legend.Layers.ItemByHandle(m_LayerHandle).Type = CType(MapWindow.Interfaces.eLayerType.Grid, Integer) Then
Return MapWindow.Interfaces.eLayerType.Grid
Else
Return MapWindow.Interfaces.eLayerType.Image
End If
Else
Return MapWindow.Interfaces.eLayerType.Invalid
End If
End Function

I hope that helps!


--Chris

Sorry, you can't reply to this topic. It has been closed.

Banner Exchange

Send us your banner logo (160x120) for the space above, and add this MapWindow banner ad to your site:

23/04/2014 10:57

[VB6] NumLayers and LayerType

4 de 4

http://www.mapwindow.org/phorum/read.php?11,5104,printview,page=1

Just paste this text in your page:

<a
href="http://www.M
apWindow.org
/download.php"><i

Home | Buy | Download | Documentation | Code Repository | Open Source License | Discussion Forum | Contact | Site Statistics

Copyright 1998-2010 - Daniel P. Ames and the MapWindow Open Source Team
last updated: 17 March 2010

23/04/2014 10:57

Potrebbero piacerti anche