Jerry
Thank you for responding to my post.
I was looking for a more difficult solution, then I found one of your old posts, and now see that loading a shapefile only takes one line of code.
- I have had some success, I have a VBA program that reads the data from the table, and makes the map almost correctly. However, it does not recognize symbol type values. A copy of the source code is at the end of this email.
This map loads the shapefiles as layers using: lhandle = Map0.AddLayerFromFilename(filenames(i), fosVectorDatasource, True)
- I want to change the program to load the shapefiles as shapefiles.
Why?
- I will be adding code that searches through the shapefiles to find a record, then zoom to that feature on the map.
- I have had better success setting feature colors and symbols with shapefiles using functions such as:
sf.DefaultDrawingOptions.FillBgColor = RGB(RGB_Red, RGB_Green, RGB_Blue)
- I have had problems loading the map with shapefiles. The following line of code throws a “Object Required” Error. I don’t understand what object is missing.
open_sf = sf.Open(filenames, Null)
- When I was able to load shapefiles, MapWinGIS would load one layer, then clear the layer and load the next.
- It would not load one layer on top of the other.
- It would not apply the feature color and symbol settings.
I assume there are commands that add the layers to AxMap1, post feature symbology and draws the map to the output screen. I have not found these commands yet.
- The database table is as follows. I am able to read the data with my VBA program in MS Access.
Shape_Name | Layer_Name | MapWinGIS_Shape_Type | Directory_Path | File_Name | RED | GREEN | BLUE | Size | Transparency | Symbol |
- | - | - | - | - | - | - | - | - | - | - |
sf_Boundary | Boundary_Layer | SHP_POLYGON | C:\Users\SP_ETL\Desktop\OldPost\gis\shp\ | OldPost_Boundary.shp | 0 | 255 | 0 | 6 | 0 | 0 |
sf_Bridges | Bridges_Layer | SHP_POINT | C:\Users\SP_ETL\Desktop\OldPost\gis\shp\ | OldPost_Bridge.shp | 255 | 0 | 0 | 25 | 255 | 1 |
sf_Culverts | Culverts_Layer | SHP_POINT | C:\Users\SP_ETL\Desktop\OldPost\gis\shp\ | OldPost_Culvert.shp | 0 | 0 | 255 | 25 | 255 | 5 |
sf_Highways | Highways_Layer | SHP_POLYLINE | C:\Users\SP_ETL\Desktop\OldPost\gis\shp\ | OldPost_Highway.shp | 255 | 181 | 145 | 4 | 255 | 0 |
sf_Roads_LMG | Roads_LMG_Layer | SHP_POLYLINE | C:\Users\SP_ETL\Desktop\OldPost\gis\shp\ | OldPost_Road_LMG.shp | 202 | 0 | 202 | 4 | 255 | 0 |
sf_Prim_Grid_Roads | Prim_Grid_Roads_Layer | SHP_POLYLINE | C:\Users\SP_ETL\Desktop\OldPost\gis\shp\ | OldPost_Road_PrimGrid.shp | 0 | 255 | 0 | 4 | 255 | 0 |
sf_Roads_MFA | Roads_MFA_Layer | SHP_POLYLINE | C:\Users\SP_ETL\Desktop\OldPost\gis\shp\ | OldPost_Road_MFA.shp | 0 | 128 | 255 | 4 | 255 | 0 |
sf_Roads_GRID | Roads_GRID_Layer | SHP_POLYLINE | C:\Users\SP_ETL\Desktop\OldPost\gis\shp\ | OldPost_Road_Grid.shp | 255 | 0 | 0 | 4 | 255 | 0 |
sf_Roads_Undev | Roads_Undev_Layer | SHP_POLYLINE | C:\Users\SP_ETL\Desktop\OldPost\gis\shp\ | OldPost_Road_Undev.shp | 0 | 0 | 0 | 1 | 255 | 0 |
- Working VBA Code that loads shapefiles as layers and draws an almost correct map.
Public Sub Form_Load()
Dim lay(15), filenames(15), open_sf(15)
Dim db As DAO.Database
Dim rst_MapConfigData As DAO.Recordset2
Dim sf As New MapWinGIS.Shapefile
Dim xMap0 As New MapWinGIS.Map
Set db = CurrentDb()
sql_MapConfigData = “SELECT * FROM [TBL Map Config Data];”
Set rst_MapConfigData = db.OpenRecordset(sql_MapConfigData)
rst_MapConfigData.MoveLast
rst_MapConfigData.MoveFirst
For i = 1 To rst_MapConfigData.RecordCount
filenames(i) = rst_MapConfigData.Fields(“Directory_Path”) & rst_MapConfigData.Fields(“File_Name”)
Shape_Name = rst_MapConfigData.Fields(“Shape_Name”)
Layer_Name = rst_MapConfigData.Fields(“Layer_Name”)
Shape_Type = rst_MapConfigData.Fields(“MapwinGIS_Shape_Type”)
RGB_Red = CInt(rst_MapConfigData.Fields(“RED”))
RGB_Green = CInt(rst_MapConfigData.Fields(“GREEN”))
RGB_Blue = CInt(rst_MapConfigData.Fields(“BLUE”))
Size = CInt(rst_MapConfigData.Fields(“Size”))
Transparency = CInt(rst_MapConfigData.Fields(“Transparency”))
Symbol = CInt(rst_MapConfigData.Fields(“Symbol”))
lhandle = Map0.AddLayerFromFilename(filenames(i), fosVectorDatasource, True)
Select Case Shape_Type
Case “SHP_POINT” ’ POINT Shape
Map0.ShapeLayerPointColor(lhandle) = RGB(RGB_Red, RGB_Green, RGB_Blue)
Map0.ShapeLayerPointSize(lhandle) = Size
Map0.ShapeLayerPointType(lhandle) = 5
Map0.ShapeLayerFillTransparency(lhandle) = Transparency
Case “SHP_POLYLINE” ’ LINE Shape
Map0.ShapeLayerLineColor(lhandle) = RGB(RGB_Red, RGB_Green, RGB_Blue)
Map0.ShapeLayerLineWidth(lhandle) = Size
Case “SHP_POLYGON” ’ POLYGON Shape
Map0.ShapeLayerLineColor(lhandle) = RGB(RGB_Red, RGB_Green, RGB_Blue)
Map0.ShapeLayerLineWidth(lhandle) = Size
Map0.ShapeLayerFillTransparency(lhandle) = Transparency
Case Else ’ UNKOWN or MISSING Shape try to draw as a RED line
Map0.ShapeLayerLineColor(lhandle) = RGB(255, 0, 0)
Map0.ShapeLayerLineWidth(lhandle) = 4
End Select
rst_MapConfigData.MoveNext
Next i
endproc:
Map0.ZoomToLayer (lhandle)
End Sub
- The output from the working version of my VBA Code