您的位置:首页 > Web前端

创建Annotation要素类(Creating annotation and dimension feature classes)

2013-01-14 14:28 399 查看
这两天一直在找关于创建Annotation的方法,后来发现,其实官方帮助文档上讲的很详细,现将贴出来代码,以备以后查看。

Creatingannotationanddimensionfeatureclasses

SummaryThistopicexplainshowtocreateannotationanddimensionfeatureclasses.Creatingtheseclassesisdifferentthancreatingregularfeatureclassesbecauseannotationanddimensionclassesstoreadditionalinformation,
suchas,symbolcollections(inthecaseofannotationfeatureclasses)anddimensionstyles(inthecaseofdimensionfeatureclasses).

Inthistopic

Workingwithannotationanddimensionfeatureclasses
Creatingastandardannotationfeatureclass

Creatingannotationclassesandasymbolcollection
Creatingagraphicslayerscale
Creatingoverposterproperties
CreatingaGeometryDef
Usingtheannotationlayerfactory
Completecodeexample

Creatingadimensionfeatureclass

Settingextensionpropertiesandcreatingdimensionstyles
Completecodeexample

Workingwithannotationanddimensionfeatureclasses

Annotationanddimensionclassesarespecialtypesoffeatureclassesthathaveadditionalpropertiesandcustombehavior.Formoreinformationonthisbehavior,seetheArcGISDesktopHelptopics,

Whatisannotation?and
Whataredimensions?.
Foradevelopercreatingthesefeatureclasses,therearesomesimilaritiesbetweenthetwotypesofclasses.Eachisimplementedasthefollowingtwo-partsolution:

Newtypesaredefinedforeachoftheclass'sinstances.
Eachhasaclassextensionthatimplementsadditionalbehaviorandmanagesstoredproperties.

Theobjectsinstantiatedfromtheclassesarenotfeatures(ESRI.ArcGIS.Geodatabase.Feature),butAnnotateFeatureandDimensionFeature(bothfoundintheESRI.ArcGIS.Cartoassemblyandnamespace).TheseclassesextendFeature,overridingsomeofitsbehavior,
andimplementingadditionalfunctionalitythroughIAnnotateFeatureand
IAnnotateFeature2(forannotationfeatures)and
IDimensionFeature(fordimensionfeatures).
TherequiredclassextensionsforannotationfeatureclassesanddimensionfeatureclassesareAnnotationFeatureClassExtension(implementsnumerousannotation-specificinterfaces)andDimensionFeatureClassExtension(primarilyaccessedthrough
IDimensionClassExtensionand
IDimensionClassExtension2).Bothstoredata,suchas,symbolcollections(forannotationfeatureclasses)anddimensionstyles(fordimensionfeatureclasses)usingextensionproperties;however,donotaccessthepropertieswith
IClass.ExtensionProperties,asbothoftheclassextensionshavemembersdefinedintheirinterfacesthatprovideabetterwayofaccessingandmodifyingtheproperties.Seethefollowingcodeexamplesthatincludeexamplesof
thesemembers.

Thistopicdiscussesthecreationofstandardannotationfeatureclasses,butdoesnotdiscussthecreationoffeature-linkedannotationfeatureclasses.Typically,feature-linkedannotationfeatureclassesarecreatedbyconvertinglabelswiththeConvertLabelsToAnnotation
class.FormoreinformationonhowtousetheConvertLabelsToAnnotationclass,see
Convertinglabelstogeodatabaseannotationforanentiremapand
Convertinglabelstogeodatabaseannotationforasinglelayer.

Creatingastandardannotationfeatureclass

Creatingastandardannotationfeatureclasshaslittleincommonwithcreatingaregularfeatureclass.The
IAnnotationLayerFactoryinterface—implementedbytheFDOGraphicsLayerFactoryclass—shouldbeusedtogenerateanewannotationfeatureclass.The
CreateAnnotationLayermethodofthatinterfacerequiresthefollowingparameterstocreateaclass:

Theworkspacewheretheclassiscreated.
Thefeaturedatasetthatcontainstheclass.Passingnulltothisparametercreatestheclassattheworkspacelevel.

Theclassname.
AnIGeometryDefreferencefortheclass.
Anassociatedfeatureclass.Forstandardannotationfeatureclasses,passanullvalueintothisparameter.

Acollectionofannotationlayerpropertiesasan
IAnnotateLayerPropertiesCollectionreference.Eachmemberinthecollectionrepresentsanannotationclass,viewableinArcCatalogthroughtheannotationfeatureclass'sproperties(atleastoneclassisrequired).

AnIGraphicsLayerScalereference.Thisallowsthereferenceunitsandreferencescaleoftheclasstobeset.

AsymbolcollectionasanISymbolCollectionreference.Eachmemberofthecollectionrepresentsanannotationstylewithintheclass(atleastonestyleisrequired).

SeveralBooleanvaluesthatdeterminetheclass'sbehavior.
AnIOverposterPropertiesreference.Instandardannotationfeatureclasses,theseareunused,butrequiredwhencreatingtheannotationfeatureclass.

Aconfigurationkeyword.Thisprovidesthesamefunctionalitythatconfigurationkeywordsprovidetomethods,suchas
IFeatureWorkspace.CreateFeatureClass.

Theprocessofacquiringseveraloftheprecedingparameters(suchas,thetargetworkspace)issimilartothatofaregularfeatureclass,andcanbefoundinothertopics.Thefollowingsectionsdiscusshowtocreateacollectionofannotationlayer
properties,agraphicslayerscaleobject,asymbolcollection,andcreatetheannotationfeatureclass.

Annotationfeatureclassandannotationclassarenotsynonymous.Annotationfeatureclassreferstotheactualdatasetinthegeodatabase,whereas,annotationclassreferstothedifferentclassesofannotationwithinthefeatureclass.Thesecanbeviewed
throughthefeatureclass'spropertiesinArcCatalogundertheAnnotationClassestab.

Creatingannotationclassesandasymbolcollection

Annotationfeatureclassescontainoneormoreannotationclasses.Eachannotationclasscontainspropertiesthatdeterminehowasubsetofannotationinthefeatureclassdisplays.Ifthereismorethanoneannotationclassinanannotationfeatureclass,
subtypesarealsocreatedforeachannotationclass.
Whenanannotationclassiscreated,itssymbolmustbeaddedtothesymbolcollectionthatisusedtocreatetheannotationfeatureclass.Thefollowingcodeexampleshowshowtocreateanannotationclass,additssymboltoanewsymbolcollection,then
addtheclasstoapropertiescollection:
[C#]

//Createanannotationclassandprovideitwithaname.
ILabelEngineLayerPropertieslabelEngineLayerProperties=new
LabelEngineLayerPropertiesClass();
IAnnotateLayerPropertiesannotateLayerProperties=(IAnnotateLayerProperties)
labelEngineLayerProperties;
annotateLayerProperties.Class="AnnotationClass1";

//Getthesymbolfromtheannotationclass.Makeanychangestoitsproperties
//here.
ITextSymbolannotationTextSymbol=labelEngineLayerProperties.Symbol;
ISymbolannotationSymbol=(ISymbol)annotationTextSymbol;

//Createasymbolcollectionandaddthedefaultsymbolfromthe
//annotationclasstothecollection.AssigntheresultingsymbolID
//totheannotationclass.
ISymbolCollectionsymbolCollection=newSymbolCollectionClass();
ISymbolCollection2symbolCollection2=(ISymbolCollection2)symbolCollection;
ISymbolIdentifier2symbolIdentifier2=null;
symbolCollection2.AddSymbol(annotationSymbol,"AnnotationClass1",out
symbolIdentifier2);
labelEngineLayerProperties.SymbolID=symbolIdentifier2.ID;

//Addtheannotationclasstoacollection.
IAnnotateLayerPropertiesCollectionannotateLayerPropsCollection=new
AnnotateLayerPropertiesCollectionClass();
annotateLayerPropsCollection.Add(annotateLayerProperties);

[VB.NET]

'Createanannotationclassandprovideitwithaname.
DimlabelEngineLayerPropertiesAsILabelEngineLayerProperties=NewLabelEngineLayerPropertiesClass()
DimannotateLayerPropertiesAsIAnnotateLayerProperties=CType(labelEngineLayerProperties,IAnnotateLayerProperties)
annotateLayerProperties.Class="AnnotationClass1"

'Getthesymbolfromtheannotationclass.Makeanychangestoitspropertieshere.
DimannotationTextSymbolAsITextSymbol=labelEngineLayerProperties.Symbol
DimannotationSymbolAsISymbol=CType(annotationTextSymbol,ISymbol)

'Createasymbolcollectionandaddthedefaultsymbolfromthe
'annotationclasstothecollection.AssigntheresultingsymbolID
'totheannotationclass.
DimsymbolCollectionAsISymbolCollection=NewSymbolCollectionClass()
DimsymbolCollection2AsISymbolCollection2=CType(symbolCollection,ISymbolCollection2)
DimsymbolIdentifier2AsISymbolIdentifier2=Nothing
symbolCollection2.AddSymbol(annotationSymbol,"AnnotationClass1",symbolIdentifier2)
labelEngineLayerProperties.SymbolID=symbolIdentifier2.ID

'Addtheannotationclasstoacollection.
DimannotateLayerPropsCollectionAsIAnnotateLayerPropertiesCollection=NewAnnotateLayerPropertiesCollectionClass()
annotateLayerPropsCollection.Add(annotateLayerProperties)

Creatingagraphicslayerscale

Agraphicslayerscaleisusedtosetthereferencescaleoftheannotationfeatureclass.TheIGraphicsLayerScaleinterfacehastwoproperties,
ReferenceScaleandUnits.Settheunitstothesameunitsusedbythefeatureclass'sspatialreference,exceptwhenthespatialreferenceisunknown(inwhichcase,usetheunitthescaleiscalculated
from).
Thefollowingcodeexampleshowshowtocreateagraphicslayerscale(thisexampleassumesthereferenceScaleandreferenceScaleUnitsvariablesarepreviouslydefined,andareoftypesdoubleand
esriUnits,respectively):
[C#]

//Createagraphicslayerscaleobject.
IGraphicsLayerScalegraphicsLayerScale=newGraphicsLayerScaleClass();
graphicsLayerScale.ReferenceScale=referenceScale;
graphicsLayerScale.Units=referenceScaleUnits;

[VB.NET]

'Createagraphicslayerscaleobject.
DimgraphicsLayerScaleAsIGraphicsLayerScale=NewGraphicsLayerScaleClass()
graphicsLayerScale.ReferenceScale=referenceScale
graphicsLayerScale.Units=referenceScaleUnits

Creatingoverposterproperties

Overposterpropertiesarethelabelingpropertiesforthefeatureclass'slabelengine.Withstandardannotationfeatureclasses,theyareunused,butarerequiredwhencreatingthefeatureclasses.Seethefollowingcodeexample:
[C#]

//Createtheoverposterpropertiesforthestandardlabelengine.
IOverposterPropertiesoverposterProperties=newBasicOverposterPropertiesClass();

[VB.NET]

'Createtheoverposterpropertiesforthestandardlabelengine.
DimoverposterPropertiesAsIOverposterProperties=NewBasicOverposterPropertiesClass()

CreatingaGeometryDef

Aswithobjectclassesandfeatureclasses,theAnnotationFeatureClassDescriptionclasscanbeusedtosimplifythecreationofannotationfeatureclasses.Unlikeotherfeatureclasscreationmethods,however,IAnnotationLayerFactory.CreateAnnotationLayer
doesnotacceptafieldscollectionasaninputparameter.Instead,theclassdescription(alongwiththeRequiredFieldsproperty)canbeusedtoacquireaGeometryDefobject,whichCreateAnnotationLayerdoesrequire.
ThefollowingcodeexampleshowshowtogetaGeometryDeffromaninstanceoftheAnnotationFeatureClassDescriptionclassandapplyaspatialreferencetoit:
[C#]

//Instantiateaclassdescriptionobject.
IObjectClassDescriptionocDescription=newAnnotationFeatureClassDescriptionClass();
IFeatureClassDescriptionfcDescription=(IFeatureClassDescription)ocDescription;

//Gettheshapefieldfromtheclassdescription'srequiredfields.
IFieldsrequiredFields=ocDescription.RequiredFields;
intshapeFieldIndex=requiredFields.FindField(fcDescription.ShapeFieldName);
IFieldshapeField=requiredFields.get_Field(shapeFieldIndex);
IGeometryDefgeometryDef=shapeField.GeometryDef;
IGeometryDefEditgeometryDefEdit=(IGeometryDefEdit)geometryDef;
geometryDefEdit.SpatialReference_2=spatialReference;

[VB.NET]

'Instantiateaclassdescriptionobject.
DimocDescriptionAsIObjectClassDescription=NewAnnotationFeatureClassDescriptionClass()
DimfcDescriptionAsIFeatureClassDescription=CType(ocDescription,IFeatureClassDescription)

'Gettheshapefieldfromtheclassdescription'srequiredfields.
DimrequiredFieldsAsIFields=ocDescription.RequiredFields
DimshapeFieldIndexAsInteger=requiredFields.FindField(fcDescription.ShapeFieldName)
DimshapeFieldAsIField=requiredFields.Field(shapeFieldIndex)
DimgeometryDefAsIGeometryDef=shapeField.GeometryDef
DimgeometryDefEditAsIGeometryDefEdit=CType(geometryDef,IGeometryDefEdit)
geometryDefEdit.SpatialReference_2=spatialReference

Usingtheannotationlayerfactory

Thefinalstepistocreateanannotationlayerfactoryanduseittocreatetheannotationfeatureclass.IAnnotationLayerFactory.CreateAnnotationLayerreturnsan
IAnnotationLayer,whichcanbeaddedtothecurrentmapinArcMaporanArcObjectsmappingapplication.

Inthefollowingcodeexample,theannotationfeatureclassisretrievedfromtheannotationlayer:
[C#]

//Createtheannotationlayerfactory.
IAnnotationLayerFactoryannotationLayerFactory=newFDOGraphicsLayerFactoryClass();

//Createtheannotationfeatureclassandanannotationlayerforit.
IAnnotationLayerannotationLayer=annotationLayerFactory.CreateAnnotationLayer
(featureWorkspace,featureDataset,className,geometryDef,null,
annotateLayerPropsCollection,graphicsLayerScale,symbolCollection,false,false,
false,true,overposterProperties,configKeyword);

//Getthefeatureclassfromthefeaturelayer.
IFeatureLayerfeatureLayer=(IFeatureLayer)annotationLayer;
IFeatureClassfeatureClass=featureLayer.FeatureClass;

[VB.NET]

'Createtheannotationlayerfactory.
DimannotationLayerFactoryAsIAnnotationLayerFactory=NewFDOGraphicsLayerFactoryClass()

'Createtheannotationfeatureclassandanannotationlayerforit.
DimannotationLayerAsIAnnotationLayer=annotationLayerFactory.CreateAnnotationLayer(featureWorkspace,_
featureDataset,className,geometryDef,Nothing,annotateLayerPropsCollection,graphicsLayerScale,_
symbolCollection,False,False,False,True,overposterProperties,configKeyword)

'Getthefeatureclassfromthefeaturelayer.
DimfeatureLayerAsIFeatureLayer=CType(annotationLayer,IFeatureLayer)
DimfeatureClassAsIFeatureClass=featureLayer.FeatureClass

Completecodeexample

Thefollowingcodeexamplecombinesthetwoprecedingexamplesintoacompletemethod:
[C#]

publicIFeatureClassCreateStandardAnnotationClass(IFeatureWorkspace
featureWorkspace,IFeatureDatasetfeatureDataset,StringclassName,
ISpatialReferencespatialReference,intreferenceScale,esriUnits
referenceScaleUnits,StringconfigKeyword)
{
//Createanannotationclassandprovideitwithaname.
ILabelEngineLayerPropertieslabelEngineLayerProperties=new
LabelEngineLayerPropertiesClass();
IAnnotateLayerPropertiesannotateLayerProperties=(IAnnotateLayerProperties)
labelEngineLayerProperties;
annotateLayerProperties.Class="AnnotationClass1";

//Getthesymbolfromtheannotationclass.Makeanychangestoitsproperties
//here.
ITextSymbolannotationTextSymbol=labelEngineLayerProperties.Symbol;
ISymbolannotationSymbol=(ISymbol)annotationTextSymbol;

//Createasymbolcollectionandaddthedefaultsymbolfromthe
//annotationclasstothecollection.AssigntheresultingsymbolID
//totheannotationclass.
ISymbolCollectionsymbolCollection=newSymbolCollectionClass();
ISymbolCollection2symbolCollection2=(ISymbolCollection2)symbolCollection;
ISymbolIdentifier2symbolIdentifier2=null;
symbolCollection2.AddSymbol(annotationSymbol,"AnnotationClass1",out
symbolIdentifier2);
labelEngineLayerProperties.SymbolID=symbolIdentifier2.ID;

//Addtheannotationclasstoacollection.
IAnnotateLayerPropertiesCollectionannotateLayerPropsCollection=new
AnnotateLayerPropertiesCollectionClass();
annotateLayerPropsCollection.Add(annotateLayerProperties);

//Createagraphicslayerscaleobject.
IGraphicsLayerScalegraphicsLayerScale=newGraphicsLayerScaleClass();
graphicsLayerScale.ReferenceScale=referenceScale;
graphicsLayerScale.Units=referenceScaleUnits;

//Createtheoverposterpropertiesforthestandardlabelengine.
IOverposterPropertiesoverposterProperties=newBasicOverposterPropertiesClass()
;

//Instantiateaclassdescriptionobject.
IObjectClassDescriptionocDescription=new
AnnotationFeatureClassDescriptionClass();
IFeatureClassDescriptionfcDescription=(IFeatureClassDescription)ocDescription;

//Gettheshapefieldfromtheclassdescription'srequiredfields.
IFieldsrequiredFields=ocDescription.RequiredFields;
intshapeFieldIndex=requiredFields.FindField(fcDescription.ShapeFieldName);
IFieldshapeField=requiredFields.get_Field(shapeFieldIndex);
IGeometryDefgeometryDef=shapeField.GeometryDef;
IGeometryDefEditgeometryDefEdit=(IGeometryDefEdit)geometryDef;
geometryDefEdit.SpatialReference_2=spatialReference;

//Createtheannotationlayerfactory.
IAnnotationLayerFactoryannotationLayerFactory=new
FDOGraphicsLayerFactoryClass();

//Createtheannotationfeatureclassandanannotationlayerforit.
IAnnotationLayerannotationLayer=annotationLayerFactory.CreateAnnotationLayer
(featureWorkspace,featureDataset,className,geometryDef,null,
annotateLayerPropsCollection,graphicsLayerScale,symbolCollection,false,
false,false,true,overposterProperties,configKeyword);

//Getthefeatureclassfromthefeaturelayer.
IFeatureLayerfeatureLayer=(IFeatureLayer)annotationLayer;
IFeatureClassfeatureClass=featureLayer.FeatureClass;

returnfeatureClass;
}

[VB.NET]

PublicFunctionCreateStandardAnnotationClass(ByValfeatureWorkspaceAsIFeatureWorkspace,_
ByValfeatureDatasetAsIFeatureDataset,ByValclassNameAsString,_
ByValspatialReferenceAsISpatialReference,ByValreferenceScaleAsInteger,_
ByValreferenceScaleUnitsAsesriUnits,ByValconfigKeywordAsString)AsIFeatureClass

'Createanannotationclassandprovideitwithaname.
DimlabelEngineLayerPropertiesAsILabelEngineLayerProperties=NewLabelEngineLayerPropertiesClass()
DimannotateLayerPropertiesAsIAnnotateLayerProperties=CType(labelEngineLayerProperties,IAnnotateLayerProperties)
annotateLayerProperties.Class="AnnotationClass1"

'Getthesymbolfromtheannotationclass.Makeanychangestoitspropertieshere.
DimannotationTextSymbolAsITextSymbol=labelEngineLayerProperties.Symbol
DimannotationSymbolAsISymbol=CType(annotationTextSymbol,ISymbol)

'Createasymbolcollectionandaddthedefaultsymbolfromthe
'annotationclasstothecollection.AssigntheresultingsymbolID
'totheannotationclass.
DimsymbolCollectionAsISymbolCollection=NewSymbolCollectionClass()
DimsymbolCollection2AsISymbolCollection2=CType(symbolCollection,ISymbolCollection2)
DimsymbolIdentifier2AsISymbolIdentifier2=Nothing
symbolCollection2.AddSymbol(annotationSymbol,"AnnotationClass1",symbolIdentifier2)
labelEngineLayerProperties.SymbolID=symbolIdentifier2.ID

'Addtheannotationclasstoacollection.
DimannotateLayerPropsCollectionAsIAnnotateLayerPropertiesCollection=NewAnnotateLayerPropertiesCollectionClass()
annotateLayerPropsCollection.Add(annotateLayerProperties)

'Createagraphicslayerscaleobject.
DimgraphicsLayerScaleAsIGraphicsLayerScale=NewGraphicsLayerScaleClass()
graphicsLayerScale.ReferenceScale=referenceScale
graphicsLayerScale.Units=referenceScaleUnits

'Createtheoverposterpropertiesforthestandardlabelengine.
DimoverposterPropertiesAsIOverposterProperties=NewBasicOverposterPropertiesClass()

'Instantiateaclassdescriptionobject.
DimocDescriptionAsIObjectClassDescription=NewAnnotationFeatureClassDescriptionClass()
DimfcDescriptionAsIFeatureClassDescription=CType(ocDescription,IFeatureClassDescription)

'Gettheshapefieldfromtheclassdescription'srequiredfields.
DimrequiredFieldsAsIFields=ocDescription.RequiredFields
DimshapeFieldIndexAsInteger=requiredFields.FindField(fcDescription.ShapeFieldName)
DimshapeFieldAsIField=requiredFields.Field(shapeFieldIndex)
DimgeometryDefAsIGeometryDef=shapeField.GeometryDef
DimgeometryDefEditAsIGeometryDefEdit=CType(geometryDef,IGeometryDefEdit)
geometryDefEdit.SpatialReference_2=spatialReference

'Createtheannotationlayerfactory.
DimannotationLayerFactoryAsIAnnotationLayerFactory=NewFDOGraphicsLayerFactoryClass()

'Createtheannotationfeatureclassandanannotationlayerforit.
DimannotationLayerAsIAnnotationLayer=annotationLayerFactory.CreateAnnotationLayer(featureWorkspace,_
featureDataset,className,geometryDef,Nothing,annotateLayerPropsCollection,graphicsLayerScale,_
symbolCollection,False,False,False,True,overposterProperties,configKeyword)

'Getthefeatureclassfromthefeaturelayer.
DimfeatureLayerAsIFeatureLayer=CType(annotationLayer,IFeatureLayer)
DimfeatureClassAsIFeatureClass=featureLayer.FeatureClass

ReturnfeatureClass
EndFunction

Creatingadimensionfeatureclass

Creatingadimensionfeatureclassissimilartocreatingaregularfeatureclass,exceptwiththefollowingtwomaindifferences:

WhencallingIFeatureWorkspace.CreateFeatureClassor
IFeatureDataset.CreateFeatureClasstocreatetheclass,severaloftheparametersaredifferentfromthoseusedtocreateasimplefeatureclass.

Aftertheclassiscreated,itisnotimmediatelyreadytobeused.Adimensionclassextensionmaintainsacollectionofdimensionstyles.Theseareobjectsthatdescribethelookandfeelofadimensionfeaturewhenrendered.Adimensionfeaturemust
useoneofitsclass'savailablestyles.Whenadimensionfeatureclassextensionisinitiallycreated,itsstylescollectionisempty;however,touseproperly,itmustcontainoneormorestyles.

Thefollowingarethecreation-timeparametersthatdifferbetweenasimplefeatureclassandadimensionfeatureclass:

TheFieldsparameter.DimensionfeatureclassesrequireseveralfieldsinadditiontotheObjectIDandshapefieldsrequiredbysimplefeatureclasses.

Theclassidentifier(CLSID)parameter,thegloballyuniqueidentifier(GUID)ofthetypeusedtoinstantiatetheclass'sobjects.Fordimensionfeatureclasses,theGUIDofDimensionFeaturemustbeprovided.

TheextensionclassID(EXTCLSID)parameter,theGUIDoftheclassextension.Fordimensionfeatureclasses,theGUIDofDimensionFeatureClassExtensionmustbeprovided.

TheFeatureTypeparameterthattakesavaluefromtheesriFeatureTypeenumerationtodefinethetypeoffeaturestheclassstores.SimplefeatureclassesuseesriFTSimple,butdimensionfeatureclassesrequireesriFTDimension.

Fortunately,theDimensionClassDescriptionclass(implementingthe
IObjectClassDescriptionandIFeatureClassDescriptioninterfaces)providesashortcutforobtainingtheobjectsforthreeoutoffourparameters,withthefourthbeingtrivial.AftercreatinganinstanceofDimensionClassDescription
andcastingittotheIObjectClassDescriptioninterface,the
RequiredFields,InstanceCLSID,and
ClassExtensionCLSIDpropertiesprovidethenecessaryfieldscollectionandthetwoGUIDs.TheIFeatureClassDescriptioninterfaceisrequiredtogettheShapeFieldNameparameter.

Formoreinformationaboutcreatingfeatureclasses,seeCreatingfeatureclasses.

Thefollowingcodeexampleshowshowtouseadimensionclassdescriptionobjecttocreateadimensionfeatureclass.Atthispoint,thedimensionfeatureclassisnotreadytobeused.Itmustfirstbeprovidedwithoneormoredimensionstyles.
[C#]

//CreateaDimensionClassDescriptionfortherequiredfieldsandGUIDs.
IObjectClassDescriptionocDescription=newDimensionClassDescriptionClass();

//Bydefault,adimensionfeatureclasshasanunknownspatialreference.Modifythe
//defaultGeometryDeffromtheRequiredFieldstoapplyaspatialreference.
IFieldsrequiredFields=ocDescription.RequiredFields;
intshapeFieldPosition=requiredFields.FindField("Shape");
IFieldshapeField=requiredFields.get_Field(shapeFieldPosition);
IGeometryDefgeometryDef=shapeField.GeometryDef;
IGeometryDefEditgeometryDefEdit=(IGeometryDefEdit)geometryDef;
geometryDefEdit.SpatialReference_2=spatialReference;

//Anyadditionalfieldsrequiredbythedimensionclassshouldbeaddedtothefields
//collectionatthispoint.

//Createthefeatureclass.Followingthisstep,thedimensionclassisnotreadyto
//beused,asitcontainsnodimensionstyles.
IFeatureClassdimensionFeatureClass=featureWorkspace.CreateFeatureClass(className,
requiredFields,ocDescription.InstanceCLSID,ocDescription.ClassExtensionCLSID,
esriFeatureType.esriFTDimension,"Shape","");

[VB.NET]

'CreateaDimensionClassDescriptionfortherequiredfieldsandGUIDs.
DimocDescriptionAsIObjectClassDescription=NewDimensionClassDescription()

'Bydefault,adimensionfeatureclasshasanunknownspatialreference.Modifythe
'defaultGeometryDeffromtheRequiredFieldstoapplyaspatialreference.
DimrequiredFieldsAsIFields=ocDescription.RequiredFields
DimshapeFieldPositionAsInteger=requiredFields.FindField("Shape")
DimshapeFieldAsIField=requiredFields.Field(shapeFieldPosition)
DimgeometryDefAsIGeometryDef=shapeField.GeometryDef
DimgeometryDefEditAsIGeometryDefEdit=CType(geometryDef,IGeometryDefEdit)
geometryDefEdit.SpatialReference_2=spatialReference

'Anyadditionalfieldsrequiredbythedimensionclassshouldbeaddedtothefields
'collectionatthispoint.
'Createthefeatureclass.Followingthisstep,thedimensionclassisnotreadyto
'beused,asitcontainsnodimensionstyles.
DimdimensionFeatureClassAsIFeatureClass=featureWorkspace.CreateFeatureClass(className,_
requiredFields,ocDescription.InstanceCLSID,ocDescription.ClassExtensionCLSID,_
esriFeatureType.esriFTDimension,"Shape","")

Settingextensionpropertiesandcreatingdimensionstyles

TheIDimensionClassExtensioninterfacedefinestwopropertiesthatshouldbesetbeforeusingthedimensionfeatureclass,
ReferenceScaleandReferenceScaleUnits.Adimensionclass'sreferencescaleunitsshouldbethesameastheunitsusedbytheclass'sspatialreference,exceptwhenthespatialreferenceisunknown
(inwhichcase,usetheunitthatthescaleiscalculatedfrom).
Withthefeatureclasscreated,addoneormorestylestotheclassextension'sstylescollection,whichisemptyatthispoint.Thissectionshowshowtocreateadimensionstyleandaddittotheextension'sstylescollection;however,analternative
istotakeoneormorestylesfromanexistingdimensionclassandcopythemtothenewclass.Seethefollowingillustration:

TheDimensionStyleclassimplementspropertiesthatdetermineastyle'sappearanceviathefollowinginterfaces:

IDimensionStyle—Usethe
Namepropertytogivethestyleahuman-readablenamewithinthestylecollection.Whilenotrequired(andnotusedwhilerenderingadimensionfeature),itisstronglyrecommendedthatthispropertybeset.Theinterface'sotherproperty,
ID,cannotbeset,butisautomaticallygeneratedwhenthestyleisaddedtoastylescollection.

IDimensionStyleText—Thisinterfaceexposesseveralpropertiesthatcontrolhowtextassociatedwithdimensionfeaturesusingthestyleappears.Forthemostpart,thisinvolveshowthetextispositionedinrelationtothe
feature;however,propertiessuchasTextSymbolallowthefont,color,andsizeofthetexttoalsobeset.

IDimensionStyleDisplay—Thepropertiesofthisinterfacedeterminehowadimensionfeatureisrendered.Whilesomepropertiesaresetonafeature-by-featurebasis(suchastheangleofthetext),thepropertiessetwiththis
interfaceapplytoallfeaturesthatusethestyle(forexample,thelinesymbolsusedwhilerendering).

Dimensionstylesarestoredasextensionproperties;therefore,addingordeletingthemisconsideredaschemachange,andanexclusivelockontheclassshouldbeacquiredusingthe
ISchemaLockinterfacebeforedoingso.Afterstyleshavebeenaddedorremovedfromthestylescollection,call
IDimensionClassExtension.UpdatePropertiestopersistthechanges.
Thefollowingcodeexampleshowshowtosettheextensionproperties,createasimpledimensionstyle,thenaddittotheextension:
[C#]

//Acquireanexclusiveschemalock.Thisisnecessarybecausetheclassextension's
//propertieswillbemodified,anditispossiblethatotherprocessescouldopenthe
//featureclass.
ISchemaLockschemaLock=(ISchemaLock)dimensionFeatureClass;
try
{
//Getanexclusiveschemalock.
schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

//Getareferencetothedimensionclassextensionandsettheextension'sreference
//scaleandreferencescaleunits.Theunitsshouldbethesameasthoseusedbythe
//class'sspatialreference,unlessthespatialreferenceisunknown(inwhichcase,
//theunitsshouldbesettothosethescaleiscalculatedfrom).
IDimensionClassExtensiondimensionClassExtension=(IDimensionClassExtension)
dimensionFeatureClass.Extension;
dimensionClassExtension.ReferenceScale=referenceScale;
dimensionClassExtension.ReferenceScaleUnits=referenceScaleUnits;

//Createadefaultdimensionstyleandaddittotheextension'scollectionofdimension
//styles(whichisemptyatthispoint).Anymodificationstothestyleshouldbemadeat
//thispointandanyadditionalstylesshouldalsobeaddedhere.
IDimensionStyledimensionStyle=newDimensionStyleClass();
dimensionStyle.Name="Default";
IDimensionStylesdimensionStyles=dimensionClassExtension.DimensionStyles;
dimensionStyles.AddStyle(dimensionStyle);

//Updatetheclassextensionproperties.
dimensionClassExtension.UpdateProperties();

returndimensionFeatureClass;
}

catch(COMExceptioncomExc)
{
//Eitherthelockcouldnotbeacquiredorthepropertiescouldnotbeupdated.
//Ineithercase,theclassisnotfullypreparedandshouldnotbeused.
returnnull;
}

finally
{
//Demotetheexclusivelocktoasharedlock.
schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
}

[VB.NET]

DimschemaLockAsISchemaLock=CType(dimensionFeatureClass,ISchemaLock)
Try
'Getanexclusiveschemalock.
schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock)

'Getareferencetothedimensionclassextensionandsettheextension'sreference
'scaleandreferencescaleunits.Theunitsshouldbethesameasthoseusedbythe
'class'sspatialreference,unlessthespatialreferenceisunknown(inwhichcase,
'theunitsshouldbesettothosethescaleiscalculatedfrom).
DimdimensionClassExtensionAsIDimensionClassExtension=CType(dimensionFeatureClass.Extension,IDimensionClassExtension)
dimensionClassExtension.ReferenceScale=referenceScale
dimensionClassExtension.ReferenceScaleUnits=referenceScaleUnits

'Createadefaultdimensionstyleandaddittotheextension'scollectionofdimension
'styles(whichisemptyatthispoint).Anymodificationstothestyleshouldbemadeat
'thispointandanyadditionalstylesshouldalsobeaddedhere.
DimdimensionStyleAsIDimensionStyle=NewDimensionStyleClass()
dimensionStyle.Name="Default"
DimdimensionStylesAsIDimensionStyles=dimensionClassExtension.DimensionStyles
dimensionStyles.AddStyle(dimensionStyle)

'Updatetheclassextensionproperties.
dimensionClassExtension.UpdateProperties()
ReturndimensionFeatureClass
CatchcomExcAsCOMException
'Eitherthelockcouldnotbeacquiredorthepropertiescouldnotbeupdated.
'Ineithercase,theclassisnotfullypreparedandshouldnotbeused.
ReturnNothing
Finally
'Demotetheexclusivelocktoasharedlock.
schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock)
EndTry

Completecodeexample

Thefollowingcodeexamplecombinesthetwoprecedingexamplesintoacompletemethod:
[C#]

publicIFeatureClassCreateDimensionClass(IFeatureWorkspacefeatureWorkspace,String
className,ISpatialReferencespatialReference,DoublereferenceScale,esriUnits
referenceScaleUnits)
{
//CreateaDimensionClassDescriptionfortherequiredfieldsandGUIDs.
IObjectClassDescriptionocDescription=newDimensionClassDescriptionClass();

//Bydefault,adimensionfeatureclasshasanunknownspatialreference.Modifythe
//defaultGeometryDeffromtheRequiredFieldstoapplyaspatialreference.
IFieldsrequiredFields=ocDescription.RequiredFields;
intshapeFieldPosition=requiredFields.FindField("Shape");
IFieldshapeField=requiredFields.get_Field(shapeFieldPosition);
IGeometryDefgeometryDef=shapeField.GeometryDef;
IGeometryDefEditgeometryDefEdit=(IGeometryDefEdit)geometryDef;
geometryDefEdit.SpatialReference_2=spatialReference;

//Anyadditionalfieldsrequiredbythedimensionclassshouldbeaddedtothefields
//collectionatthispoint.
//Createthefeatureclass.Followingthisstep,thedimensionclassisnotreadyto
//beused,asitcontainsnodimensionstyles.
IFeatureClassdimensionFeatureClass=featureWorkspace.CreateFeatureClass
(className,requiredFields,ocDescription.InstanceCLSID,
ocDescription.ClassExtensionCLSID,esriFeatureType.esriFTDimension,"Shape",
"");

//Acquireanexclusiveschemalock.Thisisnecessarybecausetheclassextension's
//propertieswillbemodified,anditispossiblethatotherprocessescouldopenthe
//featureclass.
ISchemaLockschemaLock=(ISchemaLock)dimensionFeatureClass;
try
{
//Getanexclusiveschemalock.
schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

//Getareferencetothedimensionclassextensionandsettheextension'sreference
//scaleandreferencescaleunits.Theunitsshouldbethesameasthoseusedbythe
//class'sspatialreference,unlessthespatialreferenceisunknown(inwhichcase,
//theunitsshouldbesettothosethescaleiscalculatedfrom).
IDimensionClassExtensiondimensionClassExtension=(IDimensionClassExtension)
dimensionFeatureClass.Extension;
dimensionClassExtension.ReferenceScale=referenceScale;
dimensionClassExtension.ReferenceScaleUnits=referenceScaleUnits;

//Createadefaultdimensionstyleandaddittotheextension'scollectionofdimension
//styles(whichisemptyatthispoint).Anymodificationstothestyleshouldbemadeat
//thispointandanyadditionalstylesshouldalsobeaddedhere.
IDimensionStyledimensionStyle=newDimensionStyleClass();
dimensionStyle.Name="Default";
IDimensionStylesdimensionStyles=dimensionClassExtension.DimensionStyles;
dimensionStyles.AddStyle(dimensionStyle);

//Updatetheclassextensionproperties.
dimensionClassExtension.UpdateProperties();

returndimensionFeatureClass;
}
catch(COMExceptioncomExc)
{
//Eitherthelockcouldnotbeacquiredorthepropertiescouldnotbeupdated.
//Ineithercase,theclassisnotfullypreparedandshouldnotbeused.
returnnull;
}
finally
{
//Demotetheexclusivelocktoasharedlock.
schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
}
}

[VB.NET]

PublicFunctionCreateDimensionClass(ByValfeatureWorkspaceAsIFeatureWorkspace,ByValclassNameAsString,_
ByValspatialReferenceAsISpatialReference,ByValreferenceScaleAsDouble,ByValreferenceScaleUnitsAsesriUnits)_
AsIFeatureClass

'CreateaDimensionClassDescriptionfortherequiredfieldsandGUIDs.
DimocDescriptionAsIObjectClassDescription=NewDimensionClassDescription()

'Bydefault,adimensionfeatureclasshasanunknownspatialreference.Modifythe
'defaultGeometryDeffromtheRequiredFieldstoapplyaspatialreference.
DimrequiredFieldsAsIFields=ocDescription.RequiredFields
DimshapeFieldPositionAsInteger=requiredFields.FindField("Shape")
DimshapeFieldAsIField=requiredFields.Field(shapeFieldPosition)
DimgeometryDefAsIGeometryDef=shapeField.GeometryDef
DimgeometryDefEditAsIGeometryDefEdit=CType(geometryDef,IGeometryDefEdit)
geometryDefEdit.SpatialReference_2=spatialReference

'Anyadditionalfieldsrequiredbythedimensionclassshouldbeaddedtothefields
'collectionatthispoint.

'Createthefeatureclass.Followingthisstep,thedimensionclassisnotreadyto
'beused,asitcontainsnodimensionstyles.
DimdimensionFeatureClassAsIFeatureClass=featureWorkspace.CreateFeatureClass(className,_
requiredFields,ocDescription.InstanceCLSID,ocDescription.ClassExtensionCLSID,_
esriFeatureType.esriFTDimension,"Shape","")

'Acquireanexclusiveschemalock.Thisisnecessarybecausetheclassextension's
'propertieswillbemodified,anditispossiblethatotherprocessescouldopenthe
'featureclass.
DimschemaLockAsISchemaLock=CType(dimensionFeatureClass,ISchemaLock)
Try
'Getanexclusiveschemalock.
schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock)

'Getareferencetothedimensionclassextensionandsettheextension'sreference
'scaleandreferencescaleunits.Theunitsshouldbethesameasthoseusedbythe
'class'sspatialreference,unlessthespatialreferenceisunknown(inwhichcase,
'theunitsshouldbesettothosethescaleiscalculatedfrom).
DimdimensionClassExtensionAsIDimensionClassExtension=CType(dimensionFeatureClass.Extension,IDimensionClassExtension)
dimensionClassExtension.ReferenceScale=referenceScale
dimensionClassExtension.ReferenceScaleUnits=referenceScaleUnits

'Createadefaultdimensionstyleandaddittotheextension'scollectionofdimension
'styles(whichisemptyatthispoint).Anymodificationstothestyleshouldbemadeat
'thispointandanyadditionalstylesshouldalsobeaddedhere.
DimdimensionStyleAsIDimensionStyle=NewDimensionStyleClass()
dimensionStyle.Name="Default"
DimdimensionStylesAsIDimensionStyles=dimensionClassExtension.DimensionStyles
dimensionStyles.AddStyle(dimensionStyle)

'Updatetheclassextensionproperties.
dimensionClassExtension.UpdateProperties()

ReturndimensionFeatureClass
CatchcomExcAsCOMException
'Eitherthelockcouldnotbeacquiredorthepropertiescouldnotbeupdated.
'Ineithercase,theclassisnotfullypreparedandshouldnotbeused.
ReturnNothing
Finally
'Demotetheexclusivelocktoasharedlock.
schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock)
EndTry
EndFunction


SeeAlso:

Creatingfeatureclasses

Convertinglabelstogeodatabaseannotationforanentiremap

Convertinglabelstogeodatabaseannotationforasinglelayer

Tousethecodeinthistopic,referencethefollowingassembliesinyourVisualStudioproject.Inthecodefiles,youwillneedusing(C#)orImports(VB.NET)directivesforthecorrespondingnamespaces(giveninparenthesisbelowifdifferentfromtheassembly
name):

ESRI.ArcGIS.Carto
ESRI.ArcGIS.Display
ESRI.ArcGIS.System(ESRI.ArcGIS.esriSystem)
ESRI.ArcGIS.Geodatabase
ESRI.ArcGIS.Geometry

DevelopmentlicensingDeploymentlicensing
ArcEditorArcEditor
ArcInfoArcInfo
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐