[gdal-dev] C# Binding ForceToMultiPolygon

Edi.Karadumi edikaradumi at gmail.com
Mon Dec 27 12:11:30 EST 2010


Hi everyone,
im a new user to ogr and i have used c# binding and then converted them to
use to my application in vb.net.
Im making an application to import shape files to postgres. I have made the
connection, imported the data, but i need to know the progress so i have
used a loop to transfer the data. Also i have imported them to an existing
layer in postgres, but its type is multipolygon and sometimes i have poligon
so it throws an exception. I have read that exists some function
forcetopolygon and forcetomultipolygon but i cant find them i c# bindings.
can anyone help me? here is the code:

Ogr.RegisterAll()

                inputDs = Ogr.Open(filePath, 0)

                If inputDs IsNot Nothing Then
                    If inputDs.GetLayerCount > 0 Then
                        oInputLayer = inputDs.GetLayerByIndex(0)

                        drv = Ogr.GetDriverByName("PostgreSQL")
                        outputDs = drv.Open(ServerConnection, 1)
                        '***********
                        'the postgre table has multiple geometry columns
                        '*************
                        oOutputLayer =
outputDs.GetLayerByName(CadastralZoneImportTable + "(polygon)")
                        
                        Dim i As Long
                       
                        oInputLayer.ResetReading()
                        If oInputLayer.GetFeatureCount(1) > 0 Then

                            Dim MaxFeaturesCount =
oInputLayer.GetFeatureCount(1)
                            Dim j As Long = 0

                            oOutputLayer.StartTransaction()
                            For i = 0 To MaxFeaturesCount - 1
                                oOutputFeature = New
OSGeo.OGR.Feature(oOutputLayer.GetLayerDefn)
                                oInputFeature = oInputLayer.GetNextFeature

                                If oInputFeature.GetFieldIndex("cze_number")
>= 0 Then
                                    oOutputFeature.SetField("cze_number",
oInputFeature.GetFieldAsInteger("cze_number"))
                                End If

                                If oInputFeature.GetFieldIndex("cze_name")
>= 0 Then
                                    oOutputFeature.SetField("cze_name",
oInputFeature.GetFieldAsString("cze_name"))
                                End If

                                If oInputFeature.GetFieldIndex("bau_total")
>= 0 Then
                                    oOutputFeature.SetField("bau_total",
oInputFeature.GetFieldAsString("bau_total"))
                                End If

                                If oInputFeature.GetGeometryRef IsNot
Nothing Then
                                   
oOutputFeature.SetGeometryDirectly(oInputFeature.GetGeometryRef)
                                End If
                                'here throws the exception about the
multipolygon
                                oOutputLayer.CreateFeature(oOutputFeature)

                                oOutputFeature.Dispose()
                                oInputFeature.Dispose()

                            Next

                            If i = MaxFeaturesCount Then
                                oOutputLayer.CommitTransaction()
                            Else
                                oOutputLayer.RollbackTransaction()
                            End If

                        End If

                    End If
                Else

                    MsgBox("error importing file: " + filePath,
MsgBoxStyle.SystemModal + MsgBoxStyle.Information)

                End If
-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/C-Binding-ForceToMultiPolygon-tp5869504p5869504.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list