sqfqh0088
路人甲
路人甲
  • 注册日期2005-08-23
  • 发帖数7
  • QQ
  • 铜币35枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1444回复:1

谁能帮我看下这段代码?

楼主#
更多 发布于:2006-06-05 15:56
<P>在arcengine中有一个将Annotation Features转换为Polygon Features的例子,是用vb写的,我改成了用c#写的,可是为什么有好几个地方老说我未将对象引用设置到对象的实例??那为高人帮我看看应该怎么改????</P>
<P>private void AnnoPolyCon()<BR>{<BR> int FLayerNum;<BR> int FDOLayerNum;<BR> double ReferenceScale;<BR> double MapScale;<BR> double OutputDPI;<BR> double OptimumScale;<BR> double ScreenResolution;<BR> double AnnoScaleFactor;<BR> double TempTextSize;<BR> double FinalOutputScale;<BR> <BR> //USER SETTINGS<BR> //SET these variables for your individual case<BR> FDOLayerNum = 0;           //Set annotation layer here (zero-based: 0 is first layer in TOC)<BR> FLayerNum = 1;             //Set empty feature layer here (zero-based: 1 is second layer in TOC)<BR> OutputDPI = 1200;          //Highest DPI of your final output device(s)<BR> ScreenResolution = 96;     //Resolution of your monitor<BR> FinalOutputScale = 24000;  //Final scale that your map will be printed with<BR> <BR> IMap pMap;<BR> pMap = this.axMapControl1.ActiveView.FocusMap;<BR> IActiveView pActiveView;<BR> pActiveView = pMap as IActiveView;<BR> <BR> IScreenDisplay pScreenDisplay;<BR> pScreenDisplay = pActiveView.ScreenDisplay;<BR> <BR> IDisplayTransformation pDisplayTransform;<BR> pDisplayTransform = pScreenDisplay.DisplayTransformation;<BR> <BR> IFeatureLayer pFLayer;<BR> pFLayer = pMap.get_Layer(FLayerNum) as IFeatureLayer;<BR> <BR> IFeatureClass pFClass;<BR> pFClass = pFLayer.FeatureClass;<BR> <BR> IClass pClass;<BR> pClass = pMap.get_Layer(FDOLayerNum) as IClass;<BR> <BR> IAnnoClass pAnnoClass;<BR> pAnnoClass = pClass.Extension as IAnnoClass;<BR> <BR> ReferenceScale = pMap.ReferenceScale;</P>
<P> pMap.MapScale = 10000;<BR> MapScale = pMap.MapScale;<BR> OptimumScale = (ScreenResolution / OutputDPI) * (FinalOutputScale / 2);<BR> AnnoScaleFactor = pAnnoClass.ReferenceScale / OptimumScale;   <FONT color=#ff0000>  //这里说未将对象引用设置到对象的实例<BR></FONT> <BR> IFDOGraphicsLayer pFDOGraphicsLayer;<BR> pFDOGraphicsLayer = pMap.get_Layer(FDOLayerNum) as IFDOGraphicsLayer;<BR> <BR> IFDOGraphicsLayerRead pFDOGraphicsRead;<BR> pFDOGraphicsRead = pFDOGraphicsLayer as IFDOGraphicsLayerRead;<BR> <BR> pMap.ReferenceScale = 0;<BR> pMap.MapScale = OptimumScale;<BR> <BR> //Generate graphacigs for<BR> pFDOGraphicsRead.StartGeneratingGraphics(null, pScreenDisplay, true, true, false);  <FONT color=#f70909>//这里说未将对象引用设置到对象的实例<BR><BR></FONT> <BR> IElement pAnnoElement;<BR> pAnnoElement = pFDOGraphicsRead.NextGraphic;<BR> while(pAnnoElement != null)<BR> {<BR>     IPolygon pPolygon;<BR>     pPolygon = new PolygonClass();<BR>   <BR>    ITextElement pTextElement;<BR>  pTextElement = pAnnoElement as ITextElement;<BR>   <BR>     ITextSymbol pTextSymbol;<BR>     pTextSymbol = pTextElement.Symbol;<BR>   <BR>     //Temporarily change textsymbol's size<BR>     TempTextSize = pTextSymbol.Size;<BR>     pTextSymbol.Size = TempTextSize * AnnoScaleFactor;<BR>   <BR>     IQueryGeometry pTextQuery;<BR>     pTextQuery = pTextSymbol as IQueryGeometry;<BR>   <BR>     IGeometry pTextPointGeo;<BR>     pTextPointGeo = pAnnoElement.Geometry;<BR>   <BR>     //Setup screen for drawing<BR>     pScreenDisplay.StartDrawing(pScreenDisplay.WindowDC, pScreenDisplay.ActiveCache);<BR>   <BR>     //Get ESRI geometry from Text<BR>  pPolygon = pTextQuery.GetGeometry(pScreenDisplay.WindowDC, pDisplayTransform, pTextPointGeo) as IPolygon;<BR>   <BR>     //Ensure geometry is suitable for a feature (sorts inner/outter rings)<BR>  ITopologicalOperator2 pTopoOperator2;<BR>  pTopoOperator2 = pPolygon as ITopologicalOperator2;<BR>  pTopoOperator2.IsKnownSimple_2 = false;<BR>  pPolygon.SimplifyPreserveFromTo();<BR>  pScreenDisplay.FinishDrawing();<BR>   <BR>     //Restore textsymbol size<BR>  pTextSymbol.Size = TempTextSize;<BR>   <BR>     //Store geometry in a feature<BR>  IFeature pFeature;<BR>  pFeature = pFClass.CreateFeature();<BR>  pFeature.Shape = pPolygon;<BR>  pFeature.Store();<BR>   <BR>     //Move to next piece of anno and loop<BR>     pAnnoElement = pFDOGraphicsRead.NextGraphic;<BR> }<BR> <BR> //Restore dataframe's previous extent<BR> pMap.ReferenceScale = ReferenceScale;<BR> pMap.MapScale = MapScale;<BR> pActiveView.Refresh();<BR>}</P>
喜欢0 评分0
xxhhoddity
路人甲
路人甲
  • 注册日期2003-08-24
  • 发帖数409
  • QQ
  • 铜币1295枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2006-06-06 09:02
<P>pMap.get_Layer(FDOLayerNum)</P>
<P>判断该句返回 是否为null</P>
GIS GSI IGS ISG SIG SGI
举报 回复(0) 喜欢(0)     评分
游客

返回顶部