AE创建各种类型的featureclass代码Word格式.docx
《AE创建各种类型的featureclass代码Word格式.docx》由会员分享,可在线阅读,更多相关《AE创建各种类型的featureclass代码Word格式.docx(62页珍藏版)》请在冰豆网上搜索。
SpatialReference;
pFieldEdit.GeometryDef_2=pGeometryDef;
pFieldsEdit.AddField(pField);
//新建字段
pField=newFieldClass();
pFieldEdit=pFieldasIFieldEdit;
pFieldEdit.Length_2=15;
SchoolName"
pFieldEdit.AliasName_2="
pFieldEdit.Type_2=esriFieldType.esriFieldTypeStrin
g;
stringmappath=@"
E:
\data"
stringlayername="
school"
IWorkspaceFactorypWorkspaceFactory=newShapefileW
orkspaceFactory();
IFeatureWorkspacepFeatureWorkspace=pWorkspaceFact
ory.OpenFromFile(mappath,0)asIFeatureWorkspace;
pFeatureWorkspace.CreateFeatureClass(layername+"
.shp
"
pFields,null,null,esriFeatureType.esriFTSimple,"
"
);
axMapControl1.AddShapeFile(mappath,layername+"
代码中路径名称可以自定义
postedon2008-07-1215:
28duckweeds阅读(137)评论(0)编辑收藏网摘所属分类:
AE+C#
AE创建各种类型的featureclass代码
VB.Net源码
'
<
summary>
创建Annotation类型的featureclass
/summary>
paramname="
pWorkspace"
>
annotation的工作空间<
/param>
pTextSymbol"
annotation的symbol<
pRefeScale"
annotation的比例<
pAnnoFeatName"
annotation的名称<
returns>
创建的AnnotationFeatureclass<
/returns>
remarks>
<
/remarks>
PrivateFunctionCreateAnnoFeatCls(ByValpWorkspaceAsIFeatureWorkspace,ByValpTextSymbolAsITextSymbol,ByValpRefeScaleAsDouble,ByValpAnnoFeatNameAsString,OptionalByValpSymbolIDAsInteger=0)AsIFeatureClass
DimpFieldAsIFieldDimpFieldsAsIFieldsDimpSourceAsIClone
DimpObjectClassDescAsIObjectClassDescription
DimpFeatClassDescAsIFeatureClassDescription
创建Annotation的Fields
pObjectClassDesc=NewAnnotationFeatureClassDescriptionpFeatClassDesc=pObjectClassDesc
pSource=pObjectClassDesc.RequiredFieldspFields=pSource.Clone
创建Annotation的Geometrydefintion
pField=pFields.Field(pFields.FindField(pFeatClassDesc.ShapeFieldName))
创建Referencescale
DimpGraphicsLayerScaleAsIGraphicsLayerScale
pGraphicsLayerScale=NewGraphicsLayerScalepGraphicsLayerScale.ReferenceScale=pRefeScalepGraphicsLayerScale.Units=esriUnits.esriMeters
创建Symbolcollection
DimpSymbolCollAsISymbolCollection2
DimpSymbolIdentAsISymbolIdentifier2=NewSymbolIdentifierpSymbolColl=NewSymbolCollectionpSymbolColl.AddSymbol(pTextSymbol,"
Default"
pSymbolIdent)
IfpSymbolID=1ThenpSymbolColl.AddSymbol(pTextSymbol,"
Default1"
创建Label的相关属性
DimpOverposterPropertiesAsIOverposterProperties
DimpAnnoPropsCollAsIAnnotateLayerPropertiesCollection
DimpLabelEngineLPAsILabelEngineLayerPropertiesDimpAnnotateLayerPropsAsIAnnotateLayerPropertiespOverposterProperties=NewBasicOverposterPropertiespAnnoPropsColl=NewAnnotateLayerPropertiesCollectionpLabelEngineLP=NewLabelEngineLayerPropertiespAnnotateLayerProps=pLabelEngineLPpAnnotateLayerProps.Class="
pLabelEngineLP.Symbol=pTextSymbolpLabelEngineLP.SymbolID=pSymbolIdent.IDpAnnoPropsColl.Add(pLabelEngineLP)
创建Annotationlayer
DimpAnnoLayerFactoryAsIAnnotationLayerFactoryDimpAnnoLayerAsIAnnotationLayerpAnnoLayerFactory=NewFDOGraphicsLayerFactory
pAnnoLayer=pAnnoLayerFactory.CreateAnnotationLayer(pWorkspace,Nothing,pAnnoFeatName,pField.GeometryDef,Nothing,pAnnoPropsColl,pGraphicsLayerScale,pSymbolColl,False,False,False,True,pOverposterProperties,"
)
ReturnCType(pAnnoLayer,IFeatureLayer).FeatureClass
EndFunction
创建存于Shapefile中的featureclass
sDir"
sName"
shapeType"
hasM"
hasZ"
pSR"
pFields"
PublicSharedFunctionCreateShapefile(ByValsDirAsString,ByValsNameAsString,ByValshapeTypeAsesriGeometryType,_
ByValhasMAsBoolean,ByValhasZAsBoolean,ByValpSRAsISpatialReference,ByValpFieldsAsIFields)AsIFeatureClass
Try
DimshapeWorkspaceFactoryAsIWorkspaceFactoryshapeWorkspaceFactory=NewShapefileWorkspaceFactoryDimshapeWorkspaceAsIFeatureWorkspace
shapeWorkspace=shapeWorkspaceFactory.OpenFromFile(sDir,0)If(NotshapeWorkspaceIsNothing)Then
IfpFieldsIsNothingThenpFields=CreateBasicFields(shapeType,hasM,hasZ,pSR)'
DimpFClassAsIFeatureClass
pFClass=shapeWorkspace.CreateFeatureClass(sName,pFields,Nothing,Nothing,esriFeatureType.esriFTSimple,"
Shape"
"
ReturnpFClass
EndIf
ReturnNothing
CatchexAsExceptionMsgBox(ex.Message)ReturnNothing
EndTry
创建存于内存中的Featureclass
featureClassName"
PublicSharedFunctionGetSimpleFeatureClass(ByValpFieldsAsIFields,ByValfeatureClassNameAsString)AsIFeatureClass
DimpSwfAsIWorkspaceFactory=NewInMemoryWorkspaceFactory
DimpWorkspaceNameAsIWorkspaceName=pSwf.Create("
MyWorkspace"
Nothing,0)DimpFWSAsIFeatureWorkspace=CType(pWorkspaceName,IName).Open()
DimpFCAsIFeatureClass=pFWS.CreateFeatureClass(featureClassName,pFields,Nothing,Nothing,esriFeatureType.esriFTSimple,"
Nothing)
ReturnpFC
CatchexAsException
创建存于Access中的featureclass
pAccessPath"
pAccessName"
PublicFunctionCreateAccessFeatureClass(ByValpFieldsAsIFields,ByValpAccessPathAsString,ByValpAccessNameAsString,ByValfeatureClassNameAsString)AsIFeatureClass
DimpSwfAsIWorkspaceFactory=NewESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryDimpWorkspaceNameAsIWorkspaceName=pSwf.Create(pAccessPath,pAccessName,Nothing,0)DimpFWSAsIFeatureWorkspace=CType(pWorkspaceName,IName).Open()
pFields=CreateBasicFields(esriGeometryType.esriGeometryPoint,False,False,New
UnknownCoordinateSystem)
AE+C#实现鹰眼功能——
(二)(带鼠标拖动)
vs2005+AE9.2实现,主要功能:
鹰眼视图里面鼠标左键画红框,右键拖动
代码中主视图为Mapcontrol1,鹰眼视图为MapControl2。
主要利用了Envelope进行视图范围传递,从而控制视图同步等。
代码如下:
几个变量声明:
//变量
IMapDocumentpMapDocument=newMapDocumentClass();
IEnvelopepEn=newEnvelopeClass();
objectoFillobject=newobject();
privatevoidCreateOverviewSymbol()
{
IRgbColoriRgb=newRgbColorClass();
iRgb.RGB=255;
ILineSymbolpOutline=newSimpleLineSymbolClass();
pOutline.Color=iRgb;
pOutline.Width=2.3;
ISimpleFillSymbolpSimpleFillSymbol=newSimpleFillSymbolClass();
pSimpleFillSymbol.Outline=pOutline;
pSimpleFillSymbol.Style=esriSimpleFillStyle.esriSFSHollow;
oFillobject=pSimpleFillSymbol;
}
控制拖动变量:
privateIMoveEnvelopeFeedbackpSmallViewerEnvelope;
//鹰眼小地图的红框,IMov
eEnvelopeFeedback,用来移动Envelope的接口
privateIPointpSmallViewerMouseDownPt;
//拖动时鼠标落点
privateboolisTrackingSmallViewer=false;
//标识是否在拖动
staticintmoveCount=0;
//记录移动的个数,为移动过程中显示红框用。
axMapControl1_OnMapReplaced事件:
axMapControl2.LoadMxFile(axMapControl1.DocumentFilename);
两个视图加载数据可能存在鹰眼视图数据显示不完全(不知道是不是我电脑的毛病。
。
),这样加载可以控制数据的同步更新
axMapControl1_OnExtentUpdated事件:
pEn=e.newEnvelopeasIEnvelope;
axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForegro
und,null,null);
axMapControl1_OnAfterDraw:
esriViewDrawPhaseviewDrawPhase=(esriViewDrawPhase)e.viewDrawPhase;
if(viewDrawPhase==esriViewDrawPhase.esriViewForeground)
axMapControl2.DrawShape(pEn,refoFillobject);
axMapControl2_OnMouseDown:
if(e.button==1)//左键画红框
pEn=axMapControl2.TrackRectangle();
axMapControl1.Extent=pEn;
if(e.button==2)//右键拖动红框
pSmallViewerMouseDownPt=newPointClass();
pSmallViewerMouseDownPt.PutCoords(e.mapX,e.mapY);
axMapControl1.CenterAt(pSmallViewerMouseDownPt);
isTrackingSmallViewer=true;
if(pSmallViewerEnvelope==null)
pSmallViewerEnvelope=newMoveEnvelopeFeedbackClass();
pSmallViewerEnvelope.Display=axMapControl2.ActiveView.ScreenDisplay;
pSmallViewerEnvelope.Symbol=(ISymbol)oFillobject;
pSmallViewerEnvelope.Start(pEn,pSmallViewerMouseDownPt);
axMapControl2_OnMouseMove:
if(isTrackingSmallViewer)
moveCount++;
if(moveCount%4==0)//因为一刷新,红框就没了。
所以每移动4次就刷新一下,
保持红框的连续性。
axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewFore
ground,null,null);
pSmallViewerEnvelope.MoveTo(pSmallViewerMouseDownPt);
axMapControl2_OnMouseUp:
if(pSmallViewerEnvelope!
=null)
pEn=pSmallViewerEnvelope.St