Buscar este blog

miércoles, 28 de noviembre de 2012

Create ShapeFile with Polyline

Dim nombreShape = "capaPrueba5" Dim nombreCampoShape = "Shape" Dim pFeatCur As IFeatureCursor = Nothing Dim fcShapefile As IFeatureClass = Nothing Try Dim ruta As String = "C:\CJMC" 'Se abre la carpeta que contiene el shapefile como un Workspace Dim pFWS As IFeatureWorkspace Dim pWorkspaceFactory As IWorkspaceFactory 'Se abre... pWorkspaceFactory = New ShapefileWorkspaceFactory() pFWS = pWorkspaceFactory.OpenFromFile(ruta, 0) 'Colección de campos simples Dim pColeccionCampos As IFields Dim pColeccionCamposEdit As IFieldsEdit 'Se instancian... pColeccionCampos = New Fields pColeccionCamposEdit = pColeccionCampos 'Se crea un campo, para campo geométrico. Dim pCampoGeom As IFieldEdit pCampoGeom = New Field pCampoGeom.Name_2 = nombreCampoShape pCampoGeom.Type_2 = esriFieldType.esriFieldTypeGeometry 'Definicion del tipo de geometría etc. para el campo geométrico Dim pGeomDef As IGeometryDefEdit pGeomDef = New GeometryDef With pGeomDef .GeometryType_2 = esriGeometryType.esriGeometryPolyline .SpatialReference_2 = pLine.SpatialReference End With 'Asigno la definicion al campo pCampoGeom.GeometryDef_2 = pGeomDef 'Añado el campo a la coleccion de campos que llevará el shapefile pColeccionCamposEdit.AddField(pCampoGeom) If System.IO.File.Exists(ruta) = True Then 'campos(aux) Es el nombre del campo adicional que va a llevar el Shapefile Dim campoAdicional As IFieldEdit = Nothing campoAdicional = New Field() campoAdicional.Name_2 = "prueba" campoAdicional.Type_2 = esriFieldType.esriFieldTypeString campoAdicional.Length_2 = 50 pColeccionCamposEdit.AddField(campoAdicional) End If fcShapefile = pFWS.CreateFeatureClass(nombreShape, pColeccionCampos, Nothing, Nothing, esriFeatureType.esriFTSimple, nombreCampoShape, "") 'Inicializo el cursor de insercion pFeatCur = fcShapefile.Insert(True) 'Bucle sobre líneas del fichero. Mientras haya línea avanzo. Dim pFeatBuf As IFeatureBuffer pFeatBuf = fcShapefile.CreateFeatureBuffer 'Meto la línea en el Shape si tiene punto If Not pLine Is Nothing Then Dim posicion As Integer pFeatBuf.Shape = pLine 'Inserto el elemento en el cursor pFeatCur.InsertFeature(pFeatBuf) End If pFeatBuf = Nothing pFeatCur.Flush() Catch ex As Exception Finally End Try Carlos Javier Martín Cano