Guten Morgen,
brauche ganz dringend Hilfe,
versuche mittlerweile ganz verzweifelt ein neues Polygon einem neu angelegten Shapefile zuzuordnen bzw. einzufügen. Habe dazu bisher folgendes programmiert:
Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
'.....................................................................
'Create a rubberband polygon
Dim pMxDoc As IMxDocument
Dim pActiveView As IActiveView
Dim pScreenDisplay As IScreenDisplay
Dim pRubberPolygon As IRubberBand
Dim pFillSymbol As ISimpleFillSymbol
Dim pRgbColor As IRgbColor
Dim pPolygon As IPolygon
Set pMxDoc = Application.Document
Set pActiveView = pMxDoc.FocusMap
Set pScreenDisplay = pActiveView.ScreenDisplay
Set pRubberPolygon = New RubberPolygon
Set pFillSymbol = New SimpleFillSymbol
Set pRgbColor = New RgbColor
pRgbColor.Red = 0
pFillSymbol.Color = pRgbColor
Set pPolygon = pRubberPolygon.TrackNew(pScreenDisplay, pFillSymbol)
With pScreenDisplay
.StartDrawing pScreenDisplay.hDC, esriNoScreenCache
.SetSymbol pFillSymbol
.DrawPolygon pPolygon
.FinishDrawing
End With
'....................................................................
'create a new Shapefile
Const strFolder As String = "c:\workspc"
Const strName As String = "MyShapeFile1"
Const strShapeFieldName As String = "Shape"
' Open the folder to contain the shapefile as a workspace
Dim pFWS As IFeatureWorkspace
Dim pWorkspaceFactory As IWorkspaceFactory
Set pWorkspaceFactory = New ShapefileWorkspaceFactory
Set pFWS = pWorkspaceFactory.OpenFromFile(strFolder, 0)
' Set up a simple fields collection
Dim pFields As IFields
Dim pFieldsEdit As IFieldsEdit
Set pFields = New esriCore.Fields
Set pFieldsEdit = pFields
Dim pField As IField
Dim pFieldEdit As IFieldEdit
' Make the shape field
' it will need a geometry definition, with a spatial reference
Set pField = New esriCore.Field
Set pFieldEdit = pField
pFieldEdit.Name = strShapeFieldName
pFieldEdit.Type = esriFieldTypeGeometry
Dim pGeomDef As IGeometryDef
Dim pGeomDefEdit As IGeometryDefEdit
Set pGeomDef = New GeometryDef
Set pGeomDefEdit = pGeomDef
With pGeomDefEdit
.GeometryType = esriGeometryPolygon
Set .SpatialReference = New UnknownCoordinateSystem
End With
Set pFieldEdit.GeometryDef = pGeomDef
pFieldsEdit.AddField pField
' Add another miscellaneous text field
Set pField = New esriCore.Field
Set pFieldEdit = pField
With pFieldEdit
.Length = 30
.Name = "Text"
.Type = esriFieldTypeString
End With
pFieldsEdit.AddField pField
' Create the shapefile
' (some parameters apply to geodatabase options and can be defaulted as Nothing)
Dim pFeatClass As IFeatureClass
Set pFeatClass = pFWS.CreateFeatureClass(strName, pFields, Nothing, _
Nothing, esriFTSimple, strShapeFieldName, "")
'....................................................................
'Hier müßte jetzt das pPolygon in die neu angelegte Shapedatei geschrieben werden
'allerdings weiss ich nicht wie ich das Polygon pPolygon übergeben???????????
'????????????????
' mit " pFeatClass.CreateFeature.Store" wird nur ein "leeres" Polygon angelegt
' wie muss ich pPolygon übergeben????
pFeatClass.CreateFeature.Store
End Sub
Im oberen Teil des Programmes lege ich ein Polygon mittels Rubberband an, was ich in der Map in entsprechender Form und Größe aufziehe. Anschließend erstelle ich ein neues Shapefile. Nun aber mein Problem, wie kann ich das aufgezogene Rubberband-Polygon 'pPolygon' in die Shapedatei schreiben.
Bin für jede Hilfe ganz dankbar.
L.G. Danni
brauche ganz dringend Hilfe,
versuche mittlerweile ganz verzweifelt ein neues Polygon einem neu angelegten Shapefile zuzuordnen bzw. einzufügen. Habe dazu bisher folgendes programmiert:
Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
'.....................................................................
'Create a rubberband polygon
Dim pMxDoc As IMxDocument
Dim pActiveView As IActiveView
Dim pScreenDisplay As IScreenDisplay
Dim pRubberPolygon As IRubberBand
Dim pFillSymbol As ISimpleFillSymbol
Dim pRgbColor As IRgbColor
Dim pPolygon As IPolygon
Set pMxDoc = Application.Document
Set pActiveView = pMxDoc.FocusMap
Set pScreenDisplay = pActiveView.ScreenDisplay
Set pRubberPolygon = New RubberPolygon
Set pFillSymbol = New SimpleFillSymbol
Set pRgbColor = New RgbColor
pRgbColor.Red = 0
pFillSymbol.Color = pRgbColor
Set pPolygon = pRubberPolygon.TrackNew(pScreenDisplay, pFillSymbol)
With pScreenDisplay
.StartDrawing pScreenDisplay.hDC, esriNoScreenCache
.SetSymbol pFillSymbol
.DrawPolygon pPolygon
.FinishDrawing
End With
'....................................................................
'create a new Shapefile
Const strFolder As String = "c:\workspc"
Const strName As String = "MyShapeFile1"
Const strShapeFieldName As String = "Shape"
' Open the folder to contain the shapefile as a workspace
Dim pFWS As IFeatureWorkspace
Dim pWorkspaceFactory As IWorkspaceFactory
Set pWorkspaceFactory = New ShapefileWorkspaceFactory
Set pFWS = pWorkspaceFactory.OpenFromFile(strFolder, 0)
' Set up a simple fields collection
Dim pFields As IFields
Dim pFieldsEdit As IFieldsEdit
Set pFields = New esriCore.Fields
Set pFieldsEdit = pFields
Dim pField As IField
Dim pFieldEdit As IFieldEdit
' Make the shape field
' it will need a geometry definition, with a spatial reference
Set pField = New esriCore.Field
Set pFieldEdit = pField
pFieldEdit.Name = strShapeFieldName
pFieldEdit.Type = esriFieldTypeGeometry
Dim pGeomDef As IGeometryDef
Dim pGeomDefEdit As IGeometryDefEdit
Set pGeomDef = New GeometryDef
Set pGeomDefEdit = pGeomDef
With pGeomDefEdit
.GeometryType = esriGeometryPolygon
Set .SpatialReference = New UnknownCoordinateSystem
End With
Set pFieldEdit.GeometryDef = pGeomDef
pFieldsEdit.AddField pField
' Add another miscellaneous text field
Set pField = New esriCore.Field
Set pFieldEdit = pField
With pFieldEdit
.Length = 30
.Name = "Text"
.Type = esriFieldTypeString
End With
pFieldsEdit.AddField pField
' Create the shapefile
' (some parameters apply to geodatabase options and can be defaulted as Nothing)
Dim pFeatClass As IFeatureClass
Set pFeatClass = pFWS.CreateFeatureClass(strName, pFields, Nothing, _
Nothing, esriFTSimple, strShapeFieldName, "")
'....................................................................
'Hier müßte jetzt das pPolygon in die neu angelegte Shapedatei geschrieben werden
'allerdings weiss ich nicht wie ich das Polygon pPolygon übergeben???????????
'????????????????
' mit " pFeatClass.CreateFeature.Store" wird nur ein "leeres" Polygon angelegt
' wie muss ich pPolygon übergeben????
pFeatClass.CreateFeature.Store
End Sub
Im oberen Teil des Programmes lege ich ein Polygon mittels Rubberband an, was ich in der Map in entsprechender Form und Größe aufziehe. Anschließend erstelle ich ein neues Shapefile. Nun aber mein Problem, wie kann ich das aufgezogene Rubberband-Polygon 'pPolygon' in die Shapedatei schreiben.
Bin für jede Hilfe ganz dankbar.
L.G. Danni
- Anmelden oder Registieren, um Kommentare verfassen zu können
Gespeichert von Gast am Mo., 26.07.2004 - 09:28
PermalinkDim pFeatCur As IFeatureCursor
Dim pFeatBuf As IFeatureBuffer
Dim id As Variant
Set pFeatCur = pFeatClass.Insert(True)
Set pFeatBuf = pFeatClass.CreateFeatureBuffer
Set pFeatBuf.Shape = pPolygon
id = pFeatCur.InsertFeature(pFeatBuf)
Gespeichert von Gast am Mo., 26.07.2004 - 11:07
Permalinkhabs mittlerweile auch so gelöst bekommen :)