MapXtreme 2005 学习心得 一些基础函数代码(四)

简介:

网上看到的基本上代码都大同小异,经过本人小小修改或未修改的代码如下:

 一:先创建图层

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


 /// <summary>
    
/// 创建临时图层
    
/// by 路过秋天
    
/// <param name="tableName">表名</param>
    
/// <param name="layerName">图层名</param>
    
/// </summary>

    public static void CreateLayer(string tableName, string layerName)
    
{
        MapInfo.Mapping.Map myMap 
= MapInfo.Engine.Session.Current.MapFactory[0];//取得当前地图

        
//建立内存表信息(TableInfo中的一种,所以当然还有其它很多种表类型)
        MapInfo.Data.TableInfoMemTable tblInfo = new MapInfo.Data.TableInfoMemTable(tableName);
        
//向表信息中添加可绘图列(必备的列)
        tblInfo.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(myMap.GetDisplayCoordSys()));
        tblInfo.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());
        
//向表信息中添加其它数据列(可选的列)
        tblInfo.Columns.Add(MapInfo.Data.ColumnFactory.CreateIntColumn("index"));//创建整形的列,当然还有其它日期型的,doule型的等等
        tblInfo.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("value"20));//创建字符串型的列,并指定长度

        
//确保当前目录下不存在同名表
        MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable(tableName);
        
if (table != null)
        
{
            MapInfo.Engine.Session.Current.Catalog.CloseTable(tableName);
        }

        
//根据表信息创建临时表
        table = MapInfo.Engine.Session.Current.Catalog.CreateTable(tblInfo);

        
//创建图层(并关联表)
        FeatureLayer tempLayer = new FeatureLayer(table, layerName, layerName);
        
        myMap.Layers.Add(tempLayer);
    }

 

二:在图层的基础上,创建点,线,或其它图型

1:创建点函数代码:AddPoint


 /// <summary>
    
/// 添加点
    
/// by 路过秋天
    
/// </summary>
    
/// <param name="layerName">图层名称</param>
    
/// <param name="dPoint">点的坐标</param>
    
/// <param name="shortCode">点的代码,不同的数字有不同的形状(圆型,三角型,正方型等)</param>
    
/// <param name="color">点的颜色</param>

    public static void AddPoint(string layerName, DPoint dPoint, short shortCode, Color color)
    
{
        MapInfo.Mapping.Map myMap 
= MapInfo.Engine.Session.Current.MapFactory[0];
        
//获取图层和表
        FeatureLayer workLayer = (MapInfo.Mapping.FeatureLayer)myMap.Layers[layerName];
        MapInfo.Data.Table table 
= workLayer.Table;
        
//创建点
        FeatureGeometry point = new MapInfo.Geometry.Point(workLayer.CoordSys, dPoint);
        
//以下两行是图形的样式
        MapInfo.Styles.SimpleVectorPointStyle spsPoint = new MapInfo.Styles.SimpleVectorPointStyle(shortCode, color, 20);
        MapInfo.Styles.CompositeStyle pointStyle 
= new MapInfo.Styles.CompositeStyle(spsPoint);
        
//接下来创建一行数据
        MapInfo.Data.Feature pointRow = new MapInfo.Data.Feature(table.TableInfo.Columns);
        pointRow.Geometry 
= point;//必备列[图形]
        pointRow.Style = pointStyle;//必备列[图形样式]
        pointRow["index"= new Random().Next(999);
        pointRow[
"value"= "this is a point";
        
//将一行数据放入表中
        table.InsertFeature(pointRow);
    }

说明:

关于shortCode:

参考C:\Program Files\MapInfo\MapXtreme\6.7.1\Documentation\PDF\MapXtreme2005_DevGuide.pdf

下的Appendix G:Style Lookups(附录G,样式查找)下的Vector Symbols(矢量符号)->Map Symbols (地图符号)

 

2:创建线函数代码:AddLine


/// <summary>
    
/// 添加线[代码和创建点的相差无几]
    
/// by 路过秋天
    
/// <param name="layerName">图层名</param>
    
/// <param name="startPoint">线段起点坐标</param>
    
/// <param name="endPoint">线段终点坐标</param>
    
/// <param name="shortCode">线的shortCode(线的型状也有多种,比如单箭头,双箭头等)</param>
    
/// <param name="color">线的颜色</param>
    
/// </summary>

    public static void AddLine(string layerName, DPoint startPoint, DPoint endPoint, int shortCode, Color color)
    
{
        MapInfo.Mapping.Map myMap 
= MapInfo.Engine.Session.Current.MapFactory[0];

        
//获取图层和表
        FeatureLayer workLayer = (MapInfo.Mapping.FeatureLayer)myMap.Layers[layerName];
        MapInfo.Data.Table table 
= workLayer.Table;

        
//创建线
        FeatureGeometry line = MultiCurve.CreateLine(workLayer.CoordSys, startPoint, endPoint);
        
//以下两行是图形的样式
        MapInfo.Styles.SimpleLineStyle slsLine = new MapInfo.Styles.SimpleLineStyle(new LineWidth(3, LineWidthUnit.Pixel), shortCode, color);
        MapInfo.Styles.CompositeStyle lineStyle 
= new MapInfo.Styles.CompositeStyle(slsLine);
        
//接下来创建一行数据
        MapInfo.Data.Feature ptLine = new MapInfo.Data.Feature(table.TableInfo.Columns);
        ptLine.Geometry 
= line;
        ptLine.Style 
= lineStyle;
        ptLine[
"index"= new Random().Next(999); ;
        ptLine[
"value"= "this is a line";
        
//将线图元加入图层
        table.InsertFeature(ptLine);
    }

 

三:显示标注文本

1:显示标注文本函数代码:ShowValue


 /// <summary>
    
/// 显示标注
    
/// by 路过秋天
    
/// <param name="tableName">标注的表名</param>
    
/// <param name="columnName">标注的列名</param>
    
/// </summary>

    public static void ShowValue(string tableName, string columnName)
    
{
        MapInfo.Mapping.Map myMap 
= MapInfo.Engine.Session.Current.MapFactory[0];

        
//新建标注图层并绑定数据(整个过程有点像DataGrid控件指定数据源控件SqlDataSource,而数据源控件又绑定了DataTable)
        LabelLayer labelLayer = new LabelLayer();
        myMap.Layers.Add(labelLayer);

        
//指定要标注的数据表
        MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable(tableName);

        LabelSource source 
= new LabelSource(table);//绑定Table
        labelLayer.Sources.Append(source);//加载指定数据

        
//指定哪个字段作为显示标注(在非必备的自定义列里挑一个,比如我们就挑"value"列)
        source.DefaultLabelProperties.Caption = columnName;

        
//标注样式等属性,注意这段注释的代码,是指在一定的缩放比例范围内才显示文本,要是不注释掉,可能折腾半天也看不到为啥显示不出来文本
        
//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;
        source.Maximum 
= 50;
        source.DefaultLabelProperties.Layout.UseRelativeOrientation 
= true;
        source.DefaultLabelProperties.Layout.RelativeOrientation 
= MapInfo.Text.RelativeOrientation.FollowPath;
        source.DefaultLabelProperties.Layout.Angle 
= 33.0;
        source.DefaultLabelProperties.Layout.Offset 
= 7;
        source.DefaultLabelProperties.Layout.Alignment 
= MapInfo.Text.Alignment.CenterCenter;
        MapInfo.Styles.Font font 
= new MapInfo.Styles.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;

 


相关文章
|
5天前
|
弹性计算 关系型数据库 微服务
基于 Docker 与 Kubernetes(K3s)的微服务:阿里云生产环境扩容实践
在微服务架构中,如何实现“稳定扩容”与“成本可控”是企业面临的核心挑战。本文结合 Python FastAPI 微服务实战,详解如何基于阿里云基础设施,利用 Docker 封装服务、K3s 实现容器编排,构建生产级微服务架构。内容涵盖容器构建、集群部署、自动扩缩容、可观测性等关键环节,适配阿里云资源特性与服务生态,助力企业打造低成本、高可靠、易扩展的微服务解决方案。
1119 2
|
4天前
|
机器学习/深度学习 人工智能 前端开发
通义DeepResearch全面开源!同步分享可落地的高阶Agent构建方法论
通义研究团队开源发布通义 DeepResearch —— 首个在性能上可与 OpenAI DeepResearch 相媲美、并在多项权威基准测试中取得领先表现的全开源 Web Agent。
617 11
|
14天前
|
人工智能 运维 安全
|
5天前
|
弹性计算 Kubernetes jenkins
如何在 ECS/EKS 集群中有效使用 Jenkins
本文探讨了如何将 Jenkins 与 AWS ECS 和 EKS 集群集成,以构建高效、灵活且具备自动扩缩容能力的 CI/CD 流水线,提升软件交付效率并优化资源成本。
309 0
|
12天前
|
人工智能 异构计算
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
|
13天前
|
机器学习/深度学习 人工智能 自然语言处理
B站开源IndexTTS2,用极致表现力颠覆听觉体验
在语音合成技术不断演进的背景下,早期版本的IndexTTS虽然在多场景应用中展现出良好的表现,但在情感表达的细腻度与时长控制的精准性方面仍存在提升空间。为了解决这些问题,并进一步推动零样本语音合成在实际场景中的落地能力,B站语音团队对模型架构与训练策略进行了深度优化,推出了全新一代语音合成模型——IndexTTS2 。
822 23
|
5天前
|
缓存 供应链 监控
VVIC seller_search 排行榜搜索接口深度分析及 Python 实现
VVIC搜款网seller_search接口提供服装批发市场的商品及商家排行榜数据,涵盖热销榜、销量排名、类目趋势等,支持多维度筛选与数据分析,助力选品决策、竞品分析与市场预测,为服装供应链提供有力数据支撑。

热门文章

最新文章