[mapguide-users] Insert point feature .NET

Nico777 nicolas.leclerc at dessausoprin.com
Tue Jul 17 14:46:30 EDT 2007


Hi all

I'm trying to let the user insert a point feature in VB.NET along with some
string attributes. The feature source is an SHP file and the code was
translated/modified from the PHP example (draw_line). The user can get the
X, Y coordinates from another button (works fine).

Everything compiles fine and execute well but no feature is added to the
feature source. I tried with a converted SDF feature source (didnt change a
thing). 

Did I miss something ? Did I do something wrong :)

Any help would be appreciated 

here's the code :

Protected Sub bntCreateProjet_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles bntCreateProjet.Click
        'Add the feature

        Try
            'Get the session ID
            Dim sessionID As String
            sessionID = Me.Session("SessionID")

            'Initialize the Web Tier
            InitializeWebTier()

            'Get 'User info' from the sessionID, connect to the site server
            Dim UserInfo As New OSGeo.MapGuide.MgUserInformation(sessionID)
            Dim mySiteConn As New OSGeo.MapGuide.MgSiteConnection()
            mySiteConn.Open(UserInfo)

            'Get the ressource and feature services
            Dim ressourceService As OSGeo.MapGuide.MgService
            ressourceService =
mySiteConn.CreateService(OSGeo.MapGuide.MgServiceType.ResourceService)
            Dim featureService As OSGeo.MapGuide.MgFeatureService
            featureService =
mySiteConn.CreateService(OSGeo.MapGuide.MgServiceType.FeatureService)

            'Create a point feature and add it to the feature source
            'Create the point properties
            Dim batchPropColl As New
OSGeo.MapGuide.MgBatchPropertyCollection()
            Dim propColl As New OSGeo.MapGuide.MgPropertyCollection()

            'Set some informations (string values)
            Dim NoProp As New OSGeo.MapGuide.MgStringProperty("NoProjet",
Me.txtNo.Value)
            Dim NomProp As New OSGeo.MapGuide.MgStringProperty("NomProjet",
Me.txtNom.Value)

            'Set geometry
            Dim wtkReaderWriter As New OSGeo.MapGuide.MgWktReaderWriter()
            Dim agfReaderWriter As New OSGeo.MapGuide.MgAgfReaderWriter()

            Dim geo As OSGeo.MapGuide.MgGeometry
            geo = wtkReaderWriter.Read("POINT XY (" & Me.txtX2.Value & " " &
Me.txtY2.Value & ")")
            Dim geoByteReader As OSGeo.MapGuide.MgByteReader
            geoByteReader = agfReaderWriter.Write(geo)
            Dim geoProp As New OSGeo.MapGuide.MgGeometryProperty("SHPGEOM",
geoByteReader)

            'Fill the properties collection
            propColl.Add(geoProp)
            propColl.Add(NoProp)
            propColl.Add(NomProp)

            'Create an insert feature command
            Dim cmd As New OSGeo.MapGuide.MgInsertFeatures(LayerName,
propColl)
            Dim featCmdColl As New
OSGeo.MapGuide.MgFeatureCommandCollection()
            featCmdColl.Add(cmd)

            Dim resID As New
OSGeo.MapGuide.MgResourceIdentifier("Library://91045/Data/Projets.FeatureSource")

            'Execute the update
            featureService.UpdateFeatures(resID, featCmdColl, False)


        Catch ex As OSGeo.MapGuide.MgException
            Response.Write(ex.GetMessage)
            Response.Write(ex.GetDetails)
        End Try

    End Sub

    Private Sub InitializeWebTier()
        Dim sAppPath As String =
Request.ServerVariables("APPL_PHYSICAL_PATH")
        Dim sConfigPath As String = sAppPath & "webconfig.ini"
        MapGuideApi.MgInitializeWebTier(sConfigPath)
    End Sub

-- 
View this message in context: http://www.nabble.com/Insert-point-feature-.NET-tf4098806s16610.html#a11655548
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list