博客
关于我
MapXtreme 2005 学习心得 一些基础函数代码(四)
阅读量:801 次
发布时间:2023-02-07

本文共 3196 字,大约阅读时间需要 10 分钟。

MapInfo 开发实例:基础操作示例

一、创建图层

1. 创建图层函数代码:CreateLayer

public static void CreateLayer(string tableName, string layerName){    MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[0];    MapInfo.Mapping.FeatureLayer myLayer = new MapInfo.Mapping.FeatureLayer(table, layerName, layerName);    myMap.Layers.Add(myLayer);}

2. 添加点函数代码:AddPoint

public static void AddPoint(string layerName, DPoint dPoint, short shortCode, Color color){    MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[0];    FeatureLayer workLayer = myMap.Layers[layerName];    FeatureGeometry point = new FeatureGeometry(workLayer.CoordSys, dPoint);    // 设置样式    Style style = new SimpleVectorPointStyle(shortCode, color, 20);    CompositeStyle compositeStyle = new CompositeStyle(style);    // 添加点    Feature pointRow = new Feature(table.TableInfo.Columns);    pointRow.Geometry = point;    pointRow.Style = compositeStyle;    pointRow["index"] = Random().Next(999);    pointRow["value"] = "这是一个点";    table.InsertFeature(pointRow);}

3. 添加线函数代码:AddLine

public static void AddLine(string layerName, DPoint startPoint, DPoint endPoint, short shortCode, Color color){    MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[0];    FeatureLayer workLayer = myMap.Layers[layerName];    FeatureGeometry line = MultiCurve.CreateLine(workLayer.CoordSys, startPoint, endPoint);    // 设置样式    Style lineStyle = new SimpleLineStyle(new LineWidth(3, LineWidthUnit.Pixel), shortCode, color);    CompositeStyle compositeStyle = new CompositeStyle(lineStyle);    // 添加线    Feature lineRow = new Feature(table.TableInfo.Columns);    lineRow.Geometry = line;    lineRow.Style = compositeStyle;    lineRow["index"] = Random().Next(999);    lineRow["value"] = "这是一个线";    table.InsertFeature(lineRow);}

二、显示标注文本

1. 显示标注函数代码:ShowValue

public static void ShowValue(string tableName, string columnName){    MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[0];    // 创建标注图层    LabelLayer labelLayer = new LabelLayer();    myMap.Layers.Add(labelLayer);    // 获取表    Table table = MapInfo.Engine.Session.Current.Catalog.GetTable(tableName);    // 绑定数据源    LabelSource source = new LabelSource(table);    // 设置显示的字段    source.DefaultLabelProperties.Caption = columnName;    // 添加到标注图层    labelLayer.Sources.Append(source);    // 加载数据    source.Load();    // 设置样式    source.DefaultLabelProperties.Visibility.Enabled = true;    source.DefaultLabelProperties.Visibility.VisibleRangeEnabled = true;    source.DefaultLabelProperties.Visibility.VisibleRange = new VisibleRange(0.01, 10, MapInfo.Geometry.DistanceUnit.Mile);    source.DefaultLabelProperties.Visibility.AllowDuplicates = true;    source.DefaultLabelProperties.Visibility.AllowOverlap = true;    source.DefaultLabelProperties.Visibility.AllowOutOfView = true;    // 设置字体样式    Font font = new Font("黑体", 12);    font.ForeColor = System.Drawing.Color.Red;    source.DefaultLabelProperties.Style.Font = font;}

三、使用命名空间

using MapInfo.Geometry;using MapInfo.Mapping;using MapInfo.Styles;using MapInfo.Data;using MapInfo.Text;using System.Drawing;

通过以上代码示例,可以快速实现MapInfo环境下的基础操作,包括图层的创建、几何对象的添加以及标注的显示。这些代码可以整合到一个类中,记得添加必要的命名空间声明。

转载地址:http://igufk.baihongyu.com/

你可能感兴趣的文章
Mysql 数据类型一日期
查看>>
MySQL 数据类型和属性
查看>>
mysql 敲错命令 想取消怎么办?
查看>>
Mysql 整形列的字节与存储范围
查看>>
mysql 断电数据损坏,无法启动
查看>>
MySQL 日期时间类型的选择
查看>>
Mysql 时间操作(当天,昨天,7天,30天,半年,全年,季度)
查看>>
MySQL 是如何加锁的?
查看>>
MySQL 是怎样运行的 - InnoDB数据页结构
查看>>
mysql 更新子表_mysql 在update中实现子查询的方式
查看>>
MySQL 有什么优点?
查看>>
mysql 权限整理记录
查看>>
mysql 权限登录问题:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
查看>>
MYSQL 查看最大连接数和修改最大连接数
查看>>
MySQL 查看有哪些表
查看>>
mysql 查看锁_阿里/美团/字节面试官必问的Mysql锁机制,你真的明白吗
查看>>
MySql 查询以逗号分隔的字符串的方法(正则)
查看>>
MySQL 查询优化:提速查询效率的13大秘籍(避免使用SELECT 、分页查询的优化、合理使用连接、子查询的优化)(上)
查看>>
mysql 查询数据库所有表的字段信息
查看>>
【Java基础】什么是面向对象?
查看>>