阅读:3813回复:10
[求助]请问:如何用程序新增一个图层
<P>我想在每添加一个Element 就作为一个新层,因此在添加Element前先建一个Anno层,请问怎么写代码?</P>
|
|
1楼#
发布于:2005-09-27 15:45
<P>怎么都没有回应的哦</P>
|
|
2楼#
发布于:2005-09-27 16:31
<P>使用Workspace类的IFeatureWorkspace可创建新的FeatureClass</P>
|
|
3楼#
发布于:2005-09-27 20:00
<P>Public Function CreateShapefile(strFolder As String, strName As String, _<BR> geomType As esriGeometryType) As esriGeoDatabase.IFeatureClass</P> <P>'' 在目录里建立一个shp图层.<BR>'' 注意: shapefile的名字不包括 .shp 扩展名<BR>'' 作者:gisempire :)'' 修改时间 </P> <P>Const strShapeFieldName As String = "Shape"</P> <P> On Error GoTo EH<BR> Set CreateShapefile = Nothing<BR> If strFolder = "" Then Exit Function</P> <P> ' Open the folder to contain the shapefile as a workspace<BR> Dim pFWS As esriGeoDatabase.IFeatureWorkspace<BR> Dim pWorkspaceFactory As esriGeoDatabase.IWorkspaceFactory<BR> Set pWorkspaceFactory = New esriDataSourcesFile.ShapefileWorkspaceFactory<BR> Set pFWS = pWorkspaceFactory.OpenFromFile(strFolder, 0)</P> <P> ' Set up a simple fields collection<BR> Dim pFields As esriGeoDatabase.IFields<BR> Dim pFieldsEdit As esriGeoDatabase.IFieldsEdit<BR> Set pFields = New esriGeoDatabase.Fields<BR> Set pFieldsEdit = pFields</P> <P> Dim pField As esriGeoDatabase.IField<BR> Dim pFieldEdit As esriGeoDatabase.IFieldEdit</P> <P> ' Make the shape field<BR> ' it will need a geometry definition, with a spatial reference<BR> Set pField = New esriGeoDatabase.Field<BR> Set pFieldEdit = pField<BR> pFieldEdit.Name = strShapeFieldName<BR> pFieldEdit.Type = esriFieldTypeGeometry</P> <P> Dim pGeomDef As esriGeoDatabase.IGeometryDef<BR> Dim pGeomDefEdit As esriGeoDatabase.IGeometryDefEdit<BR> Set pGeomDef = New esriGeoDatabase.GeometryDef<BR> Set pGeomDefEdit = pGeomDef<BR> With pGeomDefEdit<BR> .GeometryType = geomType<BR> Set .SpatialReference = New esriGeometry.UnknownCoordinateSystem<BR> End With<BR> Set pFieldEdit.GeometryDef = pGeomDef<BR> pFieldsEdit.AddField pField</P> <P> ' Create the shapefile<BR> ' (some parameters apply to geodatabase options and can be defaulted as Nothing)</P> <P> Set CreateShapefile = pFWS.CreateFeatureClass(strName, pFields, Nothing, _<BR> Nothing, esriFTSimple, strShapeFieldName, "")<BR> Exit Function<BR>EH:<BR> MsgBox Err.Description, vbInformation, "createShapefile"<BR>End Function</P> |
|
|
4楼#
发布于:2005-09-28 16:59
<P>谢谢 俺整出来来了 用 IFeatureWorkspaceAnno的CreateAnnotationClass 尽管出来的层不好</P>
<P>但是还是可以用的</P> |
|
5楼#
发布于:2005-11-08 16:55
<P>楼主是怎么实现的?</P>
<P>可否共享一下?</P> |
|
6楼#
发布于:2005-11-09 23:39
<DIV><B>以下是引用<I>luomingjun</I>在2005-11-8 16:55:06的发言:</B><BR>
<P>楼主是怎么实现的?</P> <P>可否共享一下?</P></DIV> <P>开发帮助里有完整的例子 <H1>IFeatureWorkspaceAnno Example</H1> <P>The following example show how to use the <STRONG>CreateAnnotationClass </STRONG>on <STRONG>IFeatureWorkspaceAnno </STRONG>to create a new feature-linked annotation class. In this example, the annotation class is feature-linked to the "sew_str" feature class and is created in the same feature dataset as the feature class it is linked to.</P> <P>The label expression is a simple expression of the values in the field called DESCRIPTION in the sew_str feature class. A text symbol for the feature-linked annotation is red with a font of "Courier New".</P><CODE><PRE>Dim myTxtSym As IFormattedTextSymbol Private Sub NewAnnoClass() ' get a reference to the linked feature class Dim pWS As IWorkspace Dim pWSF As IWorkspaceFactory Set pWSF = New AccessWorkspaceFactory Set pWS = pWSF.OpenFromFile("D:\data\acsa_new.mdb", 0) Dim PFWSAnno As IFeatureWorkspaceAnno Set PFWSAnno = pWS Dim pFWS As IFeatureWorkspace Set pFWS = pWS Dim pFDataset As IFeatureDataset Set pFDataset = pFWS.OpenFeatureDataset("Sewer") Dim psrcFClass As IFeatureClass Set psrcFClass = pFWS.OpenFeatureClass("sew_str") ' set up reference scale Dim pGLS As IGraphicsLayerScale Set pGLS = New GraphicsLayerScale Dim pGeoDS As IGeoDataset Set pGeoDS = pFDataset pGLS.Units = esriFeet pGLS.ReferenceScale = 2000 ' set up symbol collection Dim pSymbolColl As ISymbolCollection Set pSymbolColl = New SymbolCollection MakeText Set pSymbolColl.Symbol(0) = myTxtSym ' set up the annotation labeling properties including the expression Dim pAnnoProps As IAnnotateLayerProperties Set pAnnoProps = New LabelEngineLayerProperties pAnnoProps.FeatureLinked = True pAnnoProps.AddUnplacedToGraphicsContainer = False pAnnoProps.CreateUnplacedElements = True pAnnoProps.DisplayAnnotation = True pAnnoProps.UseOutput = True Dim aAnnoVBScriptEngine As IAnnotationExpressionEngine Set aAnnoVBScriptEngine = New AnnotationVBScriptEngine Dim pLELayerProps As ILabelEngineLayerProperties Set pLELayerProps = pAnnoProps Set pLELayerProps.ExpressionParser = aAnnoVBScriptEngine pLELayerProps.Expression = "[DESCRIPTION]" pLELayerProps.IsExpressionSimple = True pLELayerProps.Offset = 0 pLELayerProps.SymbolID = 0 Set pLELayerProps.Symbol = myTxtSym Dim pATP As IAnnotateLayerTransformationProperties Set pATP = pAnnoProps pATP.ReferenceScale = pGLS.ReferenceScale pATP.Units = esriFeet pATP.ScaleRatio = 1 Dim pAnnoPropsColl As IAnnotateLayerPropertiesCollection Set pAnnoPropsColl = New AnnotateLayerPropertiesCollection pAnnoPropsColl.Add pAnnoProps ' use the AnnotationFeatureClassDescription co-class to get the list of required fields and the default name of the shape field Dim pOCDesc As IObjectClassDescription Set pOCDesc = New AnnotationFeatureClassDescription Dim pFDesc As IFeatureClassDescription Set pFDesc = pOCDesc ' create the new class Dim pNewClass As IFeatureClass Set pNewClass = PFWSAnno.CreateAnnotationClass("AnnoTest", pOCDesc.RequiredFields, pOCDesc.InstanceCLSID, pOCDesc.ClassExtensionCLSID, pFDesc.ShapeFieldName, "", pFDataset, psrcFClass, pAnnoPropsColl, pGLS, pSymbolColl, True) MsgBox "done" End Sub Public Sub MakeText( ' helper function to create the text symbol Set myTxtSym = New TextSymbol '** Set the font for myTxtSym Dim myFont As IFontDisp Set myFont = New StdFont myFont.Name = "Courier New" myFont.Size = 9 myTxtSym.Font = myFont '** Set the Color for myTxtSym to be Dark Red Dim myColor As IRgbColor Set myColor = New RgbColor myColor.Red = 150 myColor.Green = 0 myColor.Blue = 0 myTxtSym.Color = myColor '** Set other properties for myTxtSym myTxtSym.Angle = 0 myTxtSym.RightToLeft = False myTxtSym.VerticalAlignment = esriTVABaseline myTxtSym.HorizontalAlignment = esriTHAFull myTxtSym.CharacterSpacing = 200 myTxtSym.Case = esriTCNormal End Sub</PRE></CODE> |
|
|
7楼#
发布于:2005-11-14 12:02
呵呵,多看例子会有帮助的!
|
|
8楼#
发布于:2005-11-17 17:35
<P>呵呵 就是 </P>
|
|
9楼#
发布于:2005-12-01 10:45
<P>如果照开发帮助里面的例子,翻译成VC的写法,根本就不能实现。我也不晓得原因,VB和VC难道有什么差异吗?经过艰苦琢磨,下面VC写法能够正确完成。</P>
<P>double x = 49954;<BR> double y = 103545;<BR> IElementPtr pElement;<BR> IPointPtr pPoint;<BR> <BR> pPoint.CreateInstance(CLSID_Point);<BR> pPoint->put_X(x);<BR> pPoint->put_Y(y);<BR> <BR> pElement = MakeTextElement("文本数据", x, y, 0);<BR> pElement->put_Geometry(pPoint);<BR> <BR> IDatasetPtr pDataset = ipFeatureClass;<BR> IWorkspacePtr ipWorkspace;<BR> pDataset->get_Workspace(;ipWorkspace);<BR> IFeatureWorkspacePtr graphicWorkspace = ipWorkspace;<BR> IFeatureDatasetPtr FDataset;<BR> ipFeatureClass->get_FeatureDataset(;FDataset);<BR> ILayerPtr Layer;<BR> BSTR Name;<BR> pDataset->get_Name(;Name); <BR> IFDOGraphicsLayerFactoryPtr pFDOGLFactory(CLSID_FDOGraphicsLayerFactory);<BR> pFDOGLFactory->OpenGraphicsLayer(graphicWorkspace, FDataset, Name, ;Layer);<BR> <BR> IFDOGraphicsLayerPtr pFDOGraphicsLayer;<BR> pFDOGraphicsLayer.CreateInstance(CLSID_FDOGraphicsLayer);<BR> pFDOGraphicsLayer = Layer;<BR> <BR> HRESULT result = pFDOGraphicsLayer->BeginAddElements();<BR> result = pFDOGraphicsLayer->DoAddFeature(NULL, pElement, 0);<BR> result = pFDOGraphicsLayer->EndAddElements();</P> |
|
|
上一页
下一页