Add Labels using Information from Another Layer
This code exemplifies using the SelectShapes method to obtain information from the shapes on another layer that intersect with the points on your active layer. This method uses rectangular extents, and so it is better to use the shapefile that has points or rectangular shapes to build the extents object, and then use your irregular polygon layer as the layer that you are selecting shapes from.
'In one polygon layer, you have the shapes of counties, each county having a name. 'You also have a point layer showing the location of delivery trucks. 'The goal is to add a label for each truck showing which county they are in. Sub Label_Trucks() 'shpTrucks is a global MapWinGIS.Shapefile of points with truck locations 'lyrTrucks is an integer value corresponding to the handle of the trucks layer 'shpCounties is a global MapWinGIS.Shapefile of polygons with counties. 'Assume that the county name field is in the second column of the DBF, or column 1. Dim Trk As Integer Dim ext As New MapWinGIS.Extents Dim pt As MapWinGIS.Point Dim shapes As Object ' can be variant in VB6 or a dynamic array of integers Dim Text As String For Trk = 0 To shpTrucks.numShapes - 1 pt = shpTrucks.QuickPoint(Trk, 0) ext.SetBounds(pt.x, pt.y, 0, pt.x, pt.y, 0) If shpCounties.SelectShapes(ext, 0.0, MapWinGIS.SelectMode.INTERSECTION, shapes) = True Then 'Hypothetically we should only be getting one shape here, but you could 'also loop through the shapes array in other situations Text = shpCounties.CellValue(1, shapes(0)) 'DBF fields are 0 based index AxMap1.AddLabelEx(lyrTrucks, Text, Convert.ToUInt32(RGB(0, 0, 0)), pt.x, pt.y, MapWinGIS.tkHJustification.hjLeft, 0.0) End If Next Trk End Sub
Code posted by Shade1974 on 12/9/2005