MapWinGIS Manual for Vb, VBA

I’m a newbie in MapWinGIS and I have a global Question. Unfortunately I’m not a C ++ user. Is there a current manual VB or VBA for MapWinGIS?

I am currently having problems with establishing a connection to a PostgreSQL database. I’m using MS-Access as a frontend for Postgres and to display the factual data the solution works fine. Now I have implemented MapWinGIS in the Access frontend and would like to use it to access the GIS data from Postgres. I Wrote a short procedure in Access for loading the Data. This works very well with shape files, e.g .:

Private Sub LoadData()
    shpLayer.Open ("C:\GIS-SH\LANIS-SH\Natura2000\ffh_gebiete_5000_utm32\ffh_gebiete_5000_utm32.shp")
    LayerHandle = TestMap.AddLayer(shpLayer, True)
End Sub

To establish the connection to Postgres, it doesn’t, e.g .:

Private Sub LoadData()
    LayerHandle = TestMap.AddLayerFromDatabase("host='localhost' port='5432' dbname='DVL-GIS-DB-Test-local' user='postgres' password='postgres'", "SELECT * FROM gtb_flaeche", True)
End Sub

I would also be grateful for any tips for programming a cursor to identify polygon object data, especially to get the object ID for further processing in an Access database.

Hello @DetlevF, and welcome.

I believe that you need to prefix the connection string with “PG:”. We use GDAL to connect to non-Shapefile datasources, and you can check out their online help here regarding your connection string.

Let us know if that doesn’t resolve it.

Regards,
Jerry.

Hello @jerryfaust ,
many thanks for your quick reply. Now I changed the code like this:

Private Sub LoadData()
    str_pgConnString = "PG:host=localhost port=5432 dbname=DVL-GIS-DB-Test-local user=postgres password=postgres"
    qrySQL = "SELECT * FROM public.gtb_flaeche"
    LayerHandle = TestMap.AddLayerFromDatabase(pgConnString, qrySQL, True)
    MsgBox (LayerHandle)
End Sub

The MsgBox I put in for debug. It shows -1, so furthermore no layer is loaded.

ps. I also testet it with this connection string:

“PG:host=‘localhost’ port=‘5432’ dbname=‘DVL-GIS-DB-Test-local’ user=‘postgres’ password=‘postgres’”

Again no positive result.

Ok. You want the connection string with the single quotes around your parameters (e.g. host=‘localhost’, etc). What I would try next is to go a step at a time; open a connection, check for layers, etc. and see where it breaks down. Something like this:

    Dim ds As New OgrDatasource()
    If ds.Open(“PG:host=‘localhost’ port=‘5432’ dbname=‘DVL-GIS-DB-Test-local’ user=‘postgres’ password=‘postgres’”) Then
        Dim layerCount As Integer = ds.LayerCount
        For i As Integer = 0 To layerCount - 1
            Dim ogr As OgrLayer = ds.GetLayer(i)
            If ogr IsNot Nothing Then
                Debug.Print(ogr.Name)
                LayerHandle = TestMap.AddLayer(ogr)
            End If
        Next
    End If

Hopefully this will reveal where the problem is.

Regards,
Jerry.

Hi, many thanks for helping again,
I now have the solution. The correct hint was the prefix “PG:”. In my last code snippet from yesterday there was a small typo in the transition of the variable “str_pgConnString”. After the correction, the application runs fine. Here is the correct code. It works with or without single quotes:

Private Sub LoadData()
Dim str_pgConStr As String
Dim qrySQL As String

    str_pgConStr = "PG:host='localhost' port='5432' dbname='DVL-GIS-DB-Test-local' user='postgres' password='postgres'"
    qrySQL = "SELECT * FROM gtb_flaeche"
    LayerHandle = TestMap.AddLayerFromDatabase(str_pgConStr, qrySQL, True)

End Sub

By the way, how can I activate the code-container here for correct presentation of the code?

Thanks so far!

Hello @DetlevF

I’m glad it’s working now. Regarding the formatting, one thing to keep in mind is that the code cannot be at the left edge - it must be indented. If the pasted coded is not already indented, I just add 4 spaces to the beginning of each line. Hopefully that’s all it is for you.

Regards,
Jerry.

You can also add 3 ` (back tick) before and after your code snippet to create a code container.
On my keyboard, it is the key left of the 1. So not the quote: ’