您好,欢迎来到年旅网。
搜索
您的当前位置:首页ArcGISEngine实现Style符号样式文件管理工具共5页文档

ArcGISEngine实现Style符号样式文件管理工具共5页文档

来源:年旅网
其实我们在使用ArcGIS Engine开发完成的ServerStyle样式文件的管理功能,自我感觉有几个比较难处理的地方,写下来,与大家共享:

1.在里实现System.Drawing.Image到stdole.IPicture的相互转换方法,这里就要用到个让人不经意的类System.Windows.Forms.AxHost,通过继承它实现的两个静态方法GetIPictureFromImage()和GetImageFromIPicture()来实现它们之间的相互转换方法,这具很经典吧...,方法实现如下: public static stdole.IPictureDisp

GetIPictureFromImage( System.Drawing.Image image ) {

return OleConverter.GetIPictureFromPicture( image ) as stdole.IPictureDisp; }

public static System.Drawing.Image

GetImageFromIPicture( stdole.IPicture pPicture ) {

return OleConverter.GetPictureFromIPicture( pPicture ); }

2.通过修改模板(Gap和Mark)来改变线符号大小:在线符号编辑器功能里有个缩放符号大小的功能,我们可以通过修改线符号的ITemplate来完成这样的功能,这个功能可是我几经尝试才实现,没有功劳,也有苦劳呀!呵呵.. ///

/// 修改模板(Gap和Mark)来改变符号大小 ///

private void ModifyTemplate( ITemplate pTemplate, double dblScale ) {

int patternElementCount = pTemplate.PatternElementCount; if( patternElementCount == 0 ) return;

double[] dblElement = new Double[patternElementCount * 2]; for( int index = 0; index < patternElementCount; index++ ) pTemplate.GetPatternElement( index, out dblElement[index * 2], out dblElement[index * 2 + 1] );

pTemplate.ClearPatternElements();

for( int index = 0; index < patternElementCount; index++ ) pTemplate.AddPatternElement( dblElement[index * 2] * dblScale, dblElement[i

第 1 页

ndex * 2 + 1] * dblScale ); }

就是下图左上角符号预览的缩放功能,这是ArcMap里的样式管理器一样的功能 3.还有就是要重写几个控件了,比如用ListBox显示多层符号的控件了,还有预览符号的PictureBox控件,还有显示字体和索引符号的控件,还有线LineTemplate设置控件(这个控件比较麻烦),当然这些,只要你有点开发方面的基础,应该是没有问题的了!好了!其实这个功能就是内容比较多而已,当你完成第一个符号编辑器后,以后其它符号的实现方法都差不多一样的了!呵呵..

在做符号管理功能时,对指定符号生成图片是最主要的方法之一,当然在ArcGIS Engine里也提供了丰富的接口来完成这样的功能,结合的GDI+,使完成图片的生成方法更加简单!下面我传上代码的实现,希望能给大家带来一些参考

。。。。

using System;

using System.Drawing; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geometry;

namespace StyleConfigManager {

///

/// ClsDrawSymbols 的摘要说明。 ///

public class ClsDrawSymbols {

///

/// 从符号中创建指定大小的图片 ///

public static Image CreatePictureFromSymbol( ISymbol pSymbol, double dblWidth, double dblHeight, double dblGap) {

Bitmap bitmap = new Bitmap( (int)dblWidth, (int)dblHeight );

Graphics gImage = Graphics.FromImage( bitmap ); IntPtr hdc = new IntPtr(); hdc = gImage.GetHdc();

第 2 页

DrawToDC( hdc.ToInt32(), dblWidth, dblHeight, dblGap, pSymbol, false );

gImage.ReleaseHdc(hdc); gImage.Dispose(); return bitmap; }

///

/// 从符号中创建指定大小的图片 ///

public static Image CreatePictureFromSymbol( ISymbol pSymbol, double dblWidth,

double dblHeight, double dblGap, bool blnLine ) {

Bitmap bitmap = new Bitmap( (int)dblWidth, (int)dblHeight );

Graphics gImage = Graphics.FromImage( bitmap ); IntPtr hdc = new IntPtr(); hdc = gImage.GetHdc();

DrawToDC( hdc.ToInt32(), dblWidth, dblHeight, dblGap, pSymbol, blnLine );

gImage.ReleaseHdc(hdc); gImage.Dispose(); return bitmap; }

private static void DrawToDC(int hDC, double dblWidth, double dblHeight, double dblGap, ISymbol pSymbol, bool blnLine ) {

IEnvelope pEnvelope = new EnvelopeClass();

pEnvelope.PutCoords(dblGap, dblGap, dblWidth - dblGap, dblHeight - dblGap);

ITransformation pTransformation = CreateTransFromDC(hDC, dblWidth, dblHeight);

IGeometry pGeom = CreateSymShape(pSymbol, pEnvelope, blnLine );

pSymbol.SetupDC(hDC, pTransformation); pSymbol.Draw(pGeom);

第 3 页

pSymbol.ResetDC(); }

private static ITransformation CreateTransFromDC(int hDC, double dblWidth, double dblHeight) {

IEnvelope pBoundsEnvelope = new EnvelopeClass();

pBoundsEnvelope.PutCoords(0, 0, dblWidth, dblHeight);

tagRECT deviceRect = new tagRECT(); deviceRect.left = 0; deviceRect = 0; deviceRect.right

= (int)dblWidth;

deviceRect.bottom =

(int)dblHeight;

IDisplayTransformation pDisplayTransformation = new DisplayTransformationClass();

pDisplayTransformation.VisibleBounds = pBoundsEnvelope; pDisplayTransformation.Bounds = pBoundsEnvelope;

pDisplayTransformation.set_DeviceFrame( ref deviceRect ); pDisplayTransformation.Resolution = 96;

return pDisplayTransformation as ITransformation; }

private static IGeometry CreateSymShape( ISymbol pSymbol, IEnvelope pEnvelope, bool blnLine ) {

if (pSymbol is IMarkerSymbol) {

IArea pArea = pEnvelope as IArea;

return pArea.Centroid; } else if (pSymbol is ILineSymbol || pSymbol is ITextSymbol) {

if( blnLine ) {

IPointCollection pPC = new PolylineClass(); IPoint pPoint = new PointClass(); pPoint.PutCoords( pEnvelope.XMin, pEnvelope.YMax );

第 4 页

object obj = Type.Missing;

pPC.AddPoint( pPoint, ref obj, ref obj ); pPoint = new PointClass();

pPoint.PutCoords( pEnvelope.XMin + pEnvelope.Width / 3

, pEnvelope.YMin );

obj = Type.Missing;

pPC.AddPoint( pPoint, ref obj, ref obj ); pPoint = new PointClass();

pPoint.PutCoords( pEnvelope.XMax - pEnvelope.Width / 3, pEnvelope.YMax );

obj = Type.Missing;

pPC.AddPoint( pPoint, ref obj, ref obj );

pPoint = new PointClass();

pPoint.PutCoords( pEnvelope.XMax, pEnvelope.YMin );

obj = Type.Missing;

pPC.AddPoint( pPoint, ref obj, ref obj );

return pPC as IPolyline; } else {

IPolyline pPolyline = new PolylineClass(); IPoint pFromPoint = new PointClass();

pFromPoint.PutCoords( pEnvelope.XMin, pEnvelope.YMin + pEnvelope.Height / 2 );

IPoint pToPoint = new PointClass(); pToPoint.PutCoords( pEnvelope.XMax, pEnvelope.YMin + pEnvelope.Height / 2 );

pPolyline.FromPoint = pFromPoint; pPolylineoint = pToPoint; return pPolyline;

} } else

return pEnvelope; }

第 5 页

} }

第 6 页

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- oldu.cn 版权所有 浙ICP备2024123271号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务