COORDINATES LATLON TO SHAPE, !!!!MUY URGENTE!!!!
Publicado por carmen (17 intervenciones) el 10/01/2007 13:34:08
Hola amigos, llevo varios dias intentando programar un command button y me están surgiendo muchos problemas. Primero, el lenguaje que utilizo es VB.NET con ArcObjects, bien, pues el problema me surge a la hora de programar la parte de código donde a partir de una tabla donde tengo las coordenadas de latitud y longitud de una colección de puntos pertenecientes a un polígono o a una polilinea, calculo la geometria (o el campo shape) para esa superficie. Mando el código al cual hago referencia y ojala que alguien pueda ayudarme.
Gracias.
****************************************************************************
CODIGO
****************************************************************************
Private Sub BcmdTransformarLatLon_Shape_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTransformarLatLon_Shape.Click
Dim pMxDoc As IMxDocument
pMxDoc = m_app.Document
Dim pMap As IMap
pMap = pMxDoc.FocusMap
Dim pFLayer As IFeatureLayer
pFLayer = pMxDoc.SelectedLayer
Dim pFClass As IFeatureClass
pFClass = pFLayer.FeatureClass
Dim pFields As IFields
pFields = pFClass.Fields
Dim pWFactory As IWorkspaceFactory
pWFactory = New ShapefileWorkspaceFactory
Dim pDataset As IDataset
pDataset = pFLayer.FeatureClass
Dim pFWorkspace As IFeatureWorkspace
pFWorkspace = pWFactory.OpenFromFile(pDataset.Workspace.PathName, 0)
Dim nTabla As String
nTabla = "PUNTOS_" & pFLayer.Name
Dim pTable As ITable
pTable = pFWorkspace.OpenTable(nTabla)
Dim pCursor As ICursor
pCursor = pTable.Search(Nothing, True)
Dim pRow As IRow
pRow = pCursor.NextRow
Dim idanterior As Integer = -1
'''DISTINGUIR GEOMETRIA
Dim pPolyline As IPolyline
Dim pPolygon As IPolygon
Dim tipo As String
If pFClass.ShapeType = esriGeometryType.esriGeometryPolygon Then
pPolygon = New Polygon
tipo = "poligono"
ElseIf pFClass.ShapeType = esriGeometryType.esriGeometryPolyline Then
pPolyline = New Polyline
tipo = "polilinea"
End If
Do While Not pRow Is Nothing
Dim id As Integer
id = pRow.Value(pRow.Fields.FindField("IDELEMENTO"))
Try
If idanterior <> id Then
MsgBox("Hay un cambio de registro")
'''BORRAR FEATURE CON MISMO ID
Dim pQueryFilter As IQueryFilter
pQueryFilter = New QueryFilter
Dim pFeatureCursor As IFeatureCursor
Try
pQueryFilter.WhereClause = "IDELEMENTO='" & id & "'"
pFeatureCursor = pFClass.Search(pQueryFilter, False)
Catch ex As Exception
'MsgBox(ex.Message)
pQueryFilter.WhereClause = "IDELEMENTO=" & id & ""
pFeatureCursor = pFClass.Search(pQueryFilter, False)
End Try
Dim pFeatureBorrar As IFeature
pFeatureBorrar = pFeatureCursor.NextFeature
Do While Not pFeatureBorrar Is Nothing
pFeatureBorrar.Delete()
pFeatureBorrar = pFeatureCursor.NextFeature
Loop
If idanterior <> -1 Then
Dim pFeatureNuevo As IFeature
pFeatureNuevo = pFClass.CreateFeature()
pFeatureNuevo.Value(pFeatureNuevo.Fields.FindField("IDELEMENTO")) = id
'''DISTINGUIR GEOMETRIA
If tipo = "polilinea" Then
pFeatureNuevo.Shape = pPolyline
pPolyline = New Polyline
ElseIf tipo = "poligono" Then
pFeatureNuevo.Shape = pPolygon
pPolygon = New Polygon
End If
pFeatureNuevo.Store()
End If
End If
'''LEO REGISTRO Y AÑADO SU GEOMETRIA
Dim pPointColl As IPointCollection
If tipo = "poligono" Then
pPointColl = pPolygon
ElseIf tipo = "polilinea" Then
pPointColl = pPolyline
End If
Dim pPoint As IPoint
pPoint = New Point
Dim LON As Double
LON = pRow.Fields.FindField("LON")
pPoint.X = LON
Dim LAT As Double
LAT = pRow.Fields.FindField("LAT")
pPoint.Y = LAT
pPointColl.AddPoint(pPoint)
Catch ex As Exception
MsgBox(ex.Message)
End Try
idanterior = id
'pCursor.UpdateRow(pRow)
pRow = pCursor.NextRow
Loop
End Sub
End Class
***************************************************************************
FIN CODIGO
***************************************************************************
Gracias.
****************************************************************************
CODIGO
****************************************************************************
Private Sub BcmdTransformarLatLon_Shape_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTransformarLatLon_Shape.Click
Dim pMxDoc As IMxDocument
pMxDoc = m_app.Document
Dim pMap As IMap
pMap = pMxDoc.FocusMap
Dim pFLayer As IFeatureLayer
pFLayer = pMxDoc.SelectedLayer
Dim pFClass As IFeatureClass
pFClass = pFLayer.FeatureClass
Dim pFields As IFields
pFields = pFClass.Fields
Dim pWFactory As IWorkspaceFactory
pWFactory = New ShapefileWorkspaceFactory
Dim pDataset As IDataset
pDataset = pFLayer.FeatureClass
Dim pFWorkspace As IFeatureWorkspace
pFWorkspace = pWFactory.OpenFromFile(pDataset.Workspace.PathName, 0)
Dim nTabla As String
nTabla = "PUNTOS_" & pFLayer.Name
Dim pTable As ITable
pTable = pFWorkspace.OpenTable(nTabla)
Dim pCursor As ICursor
pCursor = pTable.Search(Nothing, True)
Dim pRow As IRow
pRow = pCursor.NextRow
Dim idanterior As Integer = -1
'''DISTINGUIR GEOMETRIA
Dim pPolyline As IPolyline
Dim pPolygon As IPolygon
Dim tipo As String
If pFClass.ShapeType = esriGeometryType.esriGeometryPolygon Then
pPolygon = New Polygon
tipo = "poligono"
ElseIf pFClass.ShapeType = esriGeometryType.esriGeometryPolyline Then
pPolyline = New Polyline
tipo = "polilinea"
End If
Do While Not pRow Is Nothing
Dim id As Integer
id = pRow.Value(pRow.Fields.FindField("IDELEMENTO"))
Try
If idanterior <> id Then
MsgBox("Hay un cambio de registro")
'''BORRAR FEATURE CON MISMO ID
Dim pQueryFilter As IQueryFilter
pQueryFilter = New QueryFilter
Dim pFeatureCursor As IFeatureCursor
Try
pQueryFilter.WhereClause = "IDELEMENTO='" & id & "'"
pFeatureCursor = pFClass.Search(pQueryFilter, False)
Catch ex As Exception
'MsgBox(ex.Message)
pQueryFilter.WhereClause = "IDELEMENTO=" & id & ""
pFeatureCursor = pFClass.Search(pQueryFilter, False)
End Try
Dim pFeatureBorrar As IFeature
pFeatureBorrar = pFeatureCursor.NextFeature
Do While Not pFeatureBorrar Is Nothing
pFeatureBorrar.Delete()
pFeatureBorrar = pFeatureCursor.NextFeature
Loop
If idanterior <> -1 Then
Dim pFeatureNuevo As IFeature
pFeatureNuevo = pFClass.CreateFeature()
pFeatureNuevo.Value(pFeatureNuevo.Fields.FindField("IDELEMENTO")) = id
'''DISTINGUIR GEOMETRIA
If tipo = "polilinea" Then
pFeatureNuevo.Shape = pPolyline
pPolyline = New Polyline
ElseIf tipo = "poligono" Then
pFeatureNuevo.Shape = pPolygon
pPolygon = New Polygon
End If
pFeatureNuevo.Store()
End If
End If
'''LEO REGISTRO Y AÑADO SU GEOMETRIA
Dim pPointColl As IPointCollection
If tipo = "poligono" Then
pPointColl = pPolygon
ElseIf tipo = "polilinea" Then
pPointColl = pPolyline
End If
Dim pPoint As IPoint
pPoint = New Point
Dim LON As Double
LON = pRow.Fields.FindField("LON")
pPoint.X = LON
Dim LAT As Double
LAT = pRow.Fields.FindField("LAT")
pPoint.Y = LAT
pPointColl.AddPoint(pPoint)
Catch ex As Exception
MsgBox(ex.Message)
End Try
idanterior = id
'pCursor.UpdateRow(pRow)
pRow = pCursor.NextRow
Loop
End Sub
End Class
***************************************************************************
FIN CODIGO
***************************************************************************
Valora esta pregunta


0