创建Annotation要素类(Creating annotation and dimension feature classes)
2013-01-14 14:28
399 查看
这两天一直在找关于创建Annotation的方法,后来发现,其实官方帮助文档上讲的很详细,现将贴出来代码,以备以后查看。
SummaryThistopicexplainshowtocreateannotationanddimensionfeatureclasses.Creatingtheseclassesisdifferentthancreatingregularfeatureclassesbecauseannotationanddimensionclassesstoreadditionalinformation,
suchas,symbolcollections(inthecaseofannotationfeatureclasses)anddimensionstyles(inthecaseofdimensionfeatureclasses).
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#]
[VB.NET]
Creatingagraphicslayerscale
Agraphicslayerscaleisusedtosetthereferencescaleoftheannotationfeatureclass.TheIGraphicsLayerScaleinterfacehastwoproperties,
ReferenceScaleandUnits.Settheunitstothesameunitsusedbythefeatureclass'sspatialreference,exceptwhenthespatialreferenceisunknown(inwhichcase,usetheunitthescaleiscalculated
from).
Thefollowingcodeexampleshowshowtocreateagraphicslayerscale(thisexampleassumesthereferenceScaleandreferenceScaleUnitsvariablesarepreviouslydefined,andareoftypesdoubleand
esriUnits,respectively):
[C#]
[VB.NET]
[C#]
[VB.NET]
doesnotacceptafieldscollectionasaninputparameter.Instead,theclassdescription(alongwiththeRequiredFieldsproperty)canbeusedtoacquireaGeometryDefobject,whichCreateAnnotationLayerdoesrequire.
ThefollowingcodeexampleshowshowtogetaGeometryDeffromaninstanceoftheAnnotationFeatureClassDescriptionclassandapplyaspatialreferencetoit:
[C#]
[VB.NET]
Usingtheannotationlayerfactory
Thefinalstepistocreateanannotationlayerfactoryanduseittocreatetheannotationfeatureclass.IAnnotationLayerFactory.CreateAnnotationLayerreturnsan
IAnnotationLayer,whichcanbeaddedtothecurrentmapinArcMaporanArcObjectsmappingapplication.
Inthefollowingcodeexample,theannotationfeatureclassisretrievedfromtheannotationlayer:
[C#]
[VB.NET]
[C#]
[VB.NET]
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#]
[VB.NET]
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#]
[VB.NET]
[C#]
[VB.NET]
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
Creatingannotationanddimensionfeatureclasses |
suchas,symbolcollections(inthecaseofannotationfeatureclasses)anddimensionstyles(inthecaseofdimensionfeatureclasses).
Inthistopic
WorkingwithannotationanddimensionfeatureclassesCreatingastandardannotationfeatureclass
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.TheIAnnotationLayerFactoryinterface—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.CreateAnnotationLayerdoesnotacceptafieldscollectionasaninputparameter.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.CreateAnnotationLayerreturnsanIAnnotationLayer,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:
CreatingfeatureclassesConvertinglabelstogeodatabaseannotationforanentiremap
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
Developmentlicensing | Deploymentlicensing |
---|---|
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |
相关文章推荐
- jsf in action 笔记:bean的创建和初始化(一)(3.3 Creating and initializing beans)--2008.04.12
- 创建模块化游戏(Creating Moddable Games with XML and Scripting Part I)代码阅读,关于整体架构!
- 创建模块化游戏 I(翻译)(Creating Moddable Games with XML and Scripting Part I)
- Creating and Opening Files(创建与打开文件)
- ArcCatalog创建FeatureClass提示“Database user name and current user schema do not match”
- VS2010使用介绍创建可重用代码(一)---Creating and Using a Dynamic Link Library (C++)
- Android Material Design-Creating Lists and Cards(创建列表和卡片)-(三)
- Creating and Running a Wearable App(创建并且运行智能手表应用)
- (转载)攻略:创建和使用动态链接库Walkthrough: Creating and Using a Static Library
- MainActivity and its super classes have no public methods with the @Subscribe annotation
- 使用vs2010创建可重用代码(二)Creating and Using a Static Library (C++)
- 创建和扩展Flex 2组件(Creating and Extending Flex 2 Components)学习笔记
- VS2010使用介绍创建可重用代码(一)---Creating and Using a Dynamic Link Library (C++)
- 3-2 创建菜单和工具条(Creating Menus and Toolbars)
- 创建和使用范围(Creating and Using Ranges)CFString in Core Foundation
- Android Wear 进阶 2.1 Creating and Running a Wearable App 创建和运行手表应用
- 创建模块化游戏(Creating Moddable Games with XML and Scripting Part I)代码阅读,关于整体架构!
- Android Material Design-Creating Lists and Cards(创建列表和卡片)-(三)
- 2. 创建多网站和商店(Creating Multiple Websites and Stores)
- 使用vs2010创建可重用代码(三)Creating and Using a Managed Assembly (C++)