[gdal-dev] C# Binding ForceToMultiPolygon

Tamas Szekeres szekerest at gmail.com
Wed Dec 29 20:15:51 EST 2010


Hi,

What is the detailed error message you get?
Could you provide some test data to reproduce this problem?
Have you tried with ogr2ogr to convert this data source from shapefile to
postgis?

Best regards,

Tamas



2010/12/27 Edi.Karadumi <edikaradumi at gmail.com>

>
> 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.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20101230/00596965/attachment.html


More information about the gdal-dev mailing list