收藏 分享(赏)

mapx下完成的多项实例程序.doc

上传人:kpmy5893 文档编号:7330602 上传时间:2019-05-15 格式:DOC 页数:9 大小:36KB
下载 相关 举报
mapx下完成的多项实例程序.doc_第1页
第1页 / 共9页
mapx下完成的多项实例程序.doc_第2页
第2页 / 共9页
mapx下完成的多项实例程序.doc_第3页
第3页 / 共9页
mapx下完成的多项实例程序.doc_第4页
第4页 / 共9页
mapx下完成的多项实例程序.doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

1、mapx 下完成的多项实例程序如何在 MapX 下读取属性值 有三种方法:1 由 Layer 对象的 KeyField 属性来设立要读取属性值的字段名。接着,由 Feature 对象的 keyValue 读取此行的属性值。2 将图层加入到 Datasets, 由 Dataset 对象的 Value(x,y )属性,通过设置行号,列号来获得属性值。3 将图层加入到 Datasets,之后由 RowValues(ftr)获取整行的值。Dim ds As MapXLib.Dataset, lyr As MapXLib.layerDim ftrs As FeaturesDim ftr As Featu

2、reDim rv As RowValueDim rvs As RowValuesDim DsName As String 数据集名Dim DsRows As Long, DsCols As LongDim i As Long, j As LongSet ds = Formmain.Map1.Datasets.Item(DsName)Set lyr = ds.layerSet ftrs = lyr.AllFeaturesDsCols = ds.Fields.CountDsCols = DsCols + 1 DsRows = ftrs.CountGrid1.Rows = DsRows + 1Gri

3、d1.Cols = DsColsGrid1.Row = 0For i = 0 To DsCols - 1Grid1.Col = iGrid1.Text = ds.Fields.Item(i + 1).NameNext iGrid1.Col = DsCols - 1Grid1.Text = “Fkey“lyr.BeginAccess miAccessReadi = 1For Each ftr In ftrsSet rvs = ds.RowValues(ftr)j = 0For Each rv In rvsIf Not IsNull(rv.Value) Then Grid1.TextArray(i

4、 * DsCols + j) = Trim(rv.Value)j = j + 1NextGrid1.TextArray(i * DsCols + j) = ftr.FeatureKeyi = i + 1Nextlyr.EndAccess miAccessEndSet ftr = NothingSet ftrs = NothingSet ds = NothingSet rv = NothingSet rvs = NothingSet lyr = Nothing注意:BeginAccess ,以及 EndAccess 可以明显的提高属性读取的速度。回页首自定义范围专题图mapx 的专题图用户可以进

5、行完全的定制,下面是自定义范围专题图的例子。Dim ds As New MapXLib.DatasetDim thm As New MapXLib.ThemeSet ds = Formmain.Map1.Datasets(ToolBars.Combo2.Text)Set thm = ds.Themes.add(0, “aa“, “aa“, False)thm.Legend.Compact = Falsethm.AutoRecompute = Falsethm.ComputeTheme = Falsethm.DataMax = 700thm.DataMin = 100thm.ThemePrope

6、rties.AllowEmptyRanges = Truethm.ThemeProperties.NumRanges = 7thm.ThemeProperties.DistMethod = miCustomRangesthm.ThemeProperties.RangeCategories(1).Max = 150thm.ThemeProperties.RangeCategories(1).Min = 50thm.ThemeProperties.RangeCategories(2).Max = 250thm.ThemeProperties.RangeCategories(2).Min = 150

7、thm.ThemeProperties.RangeCategories(3).Max = 350thm.ThemeProperties.RangeCategories(3).Min = 250thm.ThemeProperties.RangeCategories(4).Max = 450thm.ThemeProperties.RangeCategories(4).Min = 350thm.ThemeProperties.RangeCategories(5).Max = 550thm.ThemeProperties.RangeCategories(5).Min = 450thm.ThemePro

8、perties.RangeCategories(6).Max = 650thm.ThemeProperties.RangeCategories(6).Min = 550thm.ThemeProperties.RangeCategories(7).Max = 750thm.ThemeProperties.RangeCategories(7).Min = 650thm.ComputeTheme = Truethm.AutoRecompute = Truethm.Visible = True 回页首在 mapx 中查找对象的方法两种方式:1 使用 Find 对象的 Search 方法。在 mapx3

9、.5 中只能作到完全匹配查找,在 MapX4.0 中 SearchEx 方法则可以找到多个匹配的记录,其结果由 FindResult.Matches 获取。详细请参看有关 Find.SearchEx 方法的文档以及示例。2 使用 Layer 对象的 OBJECT.Search (strWhere)方法。其参数为 SQL 查询的 WHERE 子句。例如:Set ftrs = lyr.Search(“Character_Name = “北京市“) ;Set ftrs = lyrUSA.Search(“TOTPOP 1000000“)注意:1。字符串外加两个双引号。2 。首先将图层加入数据集 Dat

10、asets 才能使用查询。模糊查询最方便的方法是使用第二种方法例如Set ftrs = lyr.Search(“Character_Name like “%市“) ;模糊查询 回页首在 mapx 中如何紧缩表在 Mapx4.51 下可以使用 LayerInfo 的创建带结构的临时表和新表的功能来完成紧缩:Set lyr = Formmain.Map1.Layers(ToolBbo1.Text)Set ds = Formmain.Map1.Datasets.add(6, lyr) 获取被紧缩表的路径及表名filespec = Formmain.Map1.Layers.Item(ToolBbo1.

11、Text).filespeclayername = lyr.Name 将表临时存放于内存 LayerInfo.Type = 6 miLayerInfoTypeTempLayerInfo.AddParameter “TableStorageType“, “MemTable“ 临时文件保存在磁盘上还是内存。LayerInfo.AddParameter “Name“, “lyrpack“LayerInfo.AddParameter “Fields“, ds.FieldsLayerInfo.AddParameter “Features“, lyr.AllFeaturesFormmain.Map1.La

12、yers.add LayerInfo, LayerPos Set LayerInfo = Nothing 从地图窗口删除原表Formmain.Map1.Datasets.Remove (ds.Name)Formmain.Map1.Layers.Remove (lyr.Name)Formmain.Map1.RefreshSet lyr = NothingSet ds = Nothing Set lyr = Formmain.Map1.Layers(“lyrpack“)Set ds = Formmain.Map1.Datasets.add(6, lyr)从磁盘删除原表Kill filespec 回

13、页首在 mapx 中如何使用自定义栅格符号使用自定义符号首先需要设定 style.SymbolType 为 miSymbolTypeBitmap,然后指定SymbolBitmapName 为栅格图像名即可。下面的代码演示了如何在 delphi 中使用自定义的栅格符号首先调用自定义工具画点procedure TForm1.new1Click(Sender: TObject);beginmap1.ControlInterface.CurrentTool :=111;end;在 tooluses 事件中如下:procedure TForm1.Map1ToolUsed(Sender: TObject;

14、 ToolNum: Smallint; X1, Y1,X2, Y2, Distance: Double; Shift, Ctrl: WordBool;var EnableDefault: WordBool);varssymbol :cmapxstyle;p: CMapXPoint;f: cmapxfeature;beginssymbol:=costyle.create;ssymbol.SymbolType :=1;ssymbol.SymbolBitmapSize:=25;请注意将 test.bmp 文件考到 mapx “共有文件路径”+“CUSTSYMB”路径下,例如 C:Program Fi

15、lesCommon FilesMapInfo SharedMapX Common 是 MapX 共有文件的缺省安装路径ssymbol.SymbolBitmapName:=test.BMP;p := CoPoint.Create;f :=cofeature.Create ;p.Set_(x1,y1);if toolnum=111 then beginf:=map1.ControlInterface.FeatureFactory.CreateSymbol(p,ssymbol);map1.ControlInterface.Layers.Item(1).AddFeature(f,EmptyParam)

16、;end;回页首 在 mapx 中如何使用自定义鼠标在 mapx4.0,及以上版本中允许用户自定义鼠标。程序如下:Map1.MousePointer = miCustomCursorMap1.MouseIcon = “c:windowscursorsglobe.ani“ mapx 中还对鼠标滚动轮提供支持,属性如下Map.MouseWheelSupport=miMousewheelNoAutoScroll 回页首mapx 打印地图时的参数如何设置在 mapx 的 printmap 方法: PrintMap (hDC x, y, w, h)之中,w,h,x,y 的单位为 himetric,1 h

17、imetric=0.01 毫米。所以,打印地图时需要将 w,h 乘 100 换算为毫米。在 vb 中例子:Private Sub Command4_Click()On Error GoTo ErrorHandler Set up error handler. coords must be in himetric print same size as on screen, in upper left of pageScaleMode = 6 set mode to mm there is no Printer.StartDoc method, it seems it is done implic

18、itly when you use one of the printer.print methods so we need to print something before we print our map to start the pagePrinter.CurrentX = 0Printer.CurrentY = 0Printer.Print “ “Map1.PrintMap Printer.hDC, 0, 0, Map1.Width * 100, _Map1.Height * 100Printer.NewPage Send new page.Printer.EndDoc Printin

19、g is finished.Exit Sub在 vc 中例子/ Map.PaperUnit Property/ Map.PrintMap Methodvoid CSampleProjectView:OnPrintMap(CDC* pDC,CPrintInfo* pInfo) try / get paper width in mm and convert to HIMETRIC (100th of a mm)m_Map.SetPaperUnit(miUnitMillimeter);double pw = m_Map.GetMapPaperWidth() * 100;double ph = m_M

20、ap.GetMapPaperHeight()* 100;m_Map.PrintMap(long)pDC-m_hDC,pInfo-m_rectDraw.left,pInfo-m_rectDraw.top,(long)pw,(long)ph); catch (COleDispatchException *e) e-ReportError();e-Delete(); catch (COleException *e) e-ReportError();e-Delete(); 回页首mapx 中创建测距工具示例首先创建测距工具global const calculatedistance=1Private

21、Sub Form_Load()map1.CreateCustomTool(calcilatedistance,miToolTypepoly ,microsscursor)End SubPrivate Sub Distances_Click()map1.currenttool=calculatetoolEnd Sub然后在 mapx 的 PolyToolUsed 事件中, 用 Distance( x1,y1,x2,y2 )计算距离,由状态条中或 label 显示。Private Sub Map1_PolyToolUsed(ByVal ToolNum As Integer, ByVal Flags

22、 As Long, ByVal points As Object, ByVal bShift As Boolean, ByVal bCtrl As Boolean, EnableDefault As Boolean)Dim DisSum As DoubleDim Dis As DoubleDim n As IntegerDim pts As New MapXLib.pointsDim x1 As Double, y1 As Double, x2 As Double, y2 As DoubleSet pts = pointsDisSum = 0MDIForm1.StatusBar1.Panels

23、.Item(3).Text= Format(Str(DisSum), “#,#0.000000“)Select Case FlagsCase miPolyToolBeginCase miPolyToolInProgressIf ToolNum = CalculateDistance ThenFor i = 1 To pts.Count - 1x1 = pts.Item(i).Xy1 = pts.Item(i).Yx2 = pts.Item(i + 1).Xy3 = pts.Item(i + 1).YDis = Map1.Distance(x1, y1, x2, y2)DisSum = DisS

24、um + DisMDIForm1.StatusBar1.Panels.Item(3).Text = Format(Str(DisSum), “#,#0.000000“)Next iEnd IfCase miPolyToolEndEnd Select 回页首在 mapx 中如何实现自动滚屏mapx 支持 MouseMove 事件,可以在此事件中实现自动滚屏,示例如下:Private Sub Map1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)If map_move = True ThenIf X

25、 Map1.MapScreenWidth - 10 ThenMap1.CenterX = Map1.CenterX + 0.05Map1.RefreshElseIf X Map1.MapScreenHeight - 10 ThenMap1.CenterY = Map1.CenterY - 0.05Map1.RefreshElseIf Y 10 ThenMap1.CenterY = Map1.CenterY + 0.05Map1.RefreshEnd IfEnd IfEnd IfEnd IfEnd IfEnd Sub 回页首在 mapx 中如何实现图元的拖拽以下方法实现将选中图元移到点击处。Pr

26、ivate Sub Map1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)Dim ftr As FeatureDim lyr As LayerDim MapX As DoubleDim MapY As Doubleconvert where the mouse is clicked to the maps current coordinate systemMap1.ConvertCoord X, Y, MapX, MapY, miScreenToMapiterate through each selected feature in each layerFor Each lyr In Map1.LayersFor Each ftr In lyr.Selectionchange the offset of the featureftr.Offset MapX - ftr.CenterX, MapY - ftr.CenterYupdate the feature to make the change permanentftr.UpdateNextNextEnd SUb http:/

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报