初探GIS Mapxtreme 添加点 层 线
1、添加点

///</summary>///添加点
/// </summary>
/// <param name="layerName">图层名称</param>
/// <param name="dPoint">点的坐标</param>
/// <param name="shortCode">点代码 32-67</param>
/// <param name="color">点的颜色</param>
/// <param name="obj">表数据</param>
public void AddPoint(string layerName, DPoint dPoint, short shortCode, Color color, params object[] obj)
{
MapInfo.Mapping.Map map = MapInfo.Engine.Session.Current.MapFactory[0];
MapInfo.Mapping.FeatureLayer featureLayer = (MapInfo.Mapping.FeatureLayer)map.Layers[layerName];
MapInfo.Data.Table table = featureLayer.Table;
FeatureGeometry point = new MapInfo.Geometry.Point(featureLayer.CoordSys, dPoint);
MapInfo.Styles.SimpleVectorPointStyle simpleVectorPointStyle = new MapInfo.Styles.SimpleVectorPointStyle(shortCode, color, 12);
MapInfo.Styles.CompositeStyle compositeStyle = new MapInfo.Styles.CompositeStyle(simpleVectorPointStyle);
MapInfo.Data.Feature pointRow = new MapInfo.Data.Feature(table.TableInfo.Columns);
pointRow.Geometry = point;
pointRow.Style = compositeStyle;
pointRow["fx"] = dPoint.x;
pointRow["fy"] = dPoint.y;
pointRow["id"] = int.Parse(obj[0].ToString());
pointRow["名"] = obj[1];
table.InsertFeature(pointRow);
}
2、添加线

/// <summary>
/// 向图层中添加线段
/// <param name="tempLayerTableName">表名</param>
/// <param name="tempLayerName">图层名</param>
/// <param name="startPoint">线段起点坐标</param>
/// <param name="endPoint">线段终点坐标</param>
/// <param name="obj">字段数据</param>
/// </summary>
public void AddLineToLayer(string tempLayerTableName, string tempLayerName, DPoint startPoint, DPoint endPoint,int ifg, params object[] obj)
{
MapInfo.Mapping.Map map = MapInfo.Engine.Session.Current.MapFactory[0];
FeatureLayer featureLayer = (MapInfo.Mapping.FeatureLayer)map.Layers[tempLayerName];
MapInfo.Data.Table tblTemp = MapInfo.Engine.Session.Current.Catalog.GetTable(tempLayerTableName);
FeatureGeometry pgLine = MultiCurve.CreateLine(featureLayer.CoordSys, startPoint, endPoint);
MapInfo.Styles.SimpleLineStyle simpleLineStyle = new MapInfo.Styles.SimpleLineStyle(new LineWidth(1, LineWidthUnit.Pixel),
ifg, System.Drawing.Color.Red);
MapInfo.Styles.CompositeStyle compositeStyle = new MapInfo.Styles.CompositeStyle(simpleLineStyle);
MapInfo.Data.Feature ptLine = new MapInfo.Data.Feature(tblTemp.TableInfo.Columns);
ptLine.Geometry = pgLine;
ptLine.Style = compositeStyle;
//ptLine["index"] = int.Parse(obj[0].ToString());
//ptLine["name"] = obj[1].ToString();
featureLayer.Table.InsertFeature(ptLine);
}
3、添加图层

/// <summary>
/// 创建临时图层
/// <param name="tableName">表名</param>
/// <param name="layerName">图层名</param>
/// <param name="layerName">map</param>
/// </summary>
public void CreateLayer(string tableName, string layerName, Map map)
{
MapInfo.Data.TableInfoMemTable tableInfoMemTable = new MapInfo.Data.TableInfoMemTable(tableName);
tableInfoMemTable.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(map.GetDisplayCoordSys()));
tableInfoMemTable.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());
tableInfoMemTable.Columns.Add(MapInfo.Data.ColumnFactory.CreateIntColumn("id"));//创建整形的列,当然还有其它日期型的,doule型的等等
tableInfoMemTable.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("名", 100));//创建字符串型的列,并指定长度
tableInfoMemTable.Columns.Add(MapInfo.Data.ColumnFactory.CreateDoubleColumn("fx"));//创建字符串型的列,并指定长度
tableInfoMemTable.Columns.Add(MapInfo.Data.ColumnFactory.CreateDoubleColumn("fy"));//创建字符串型的列,并指定长度
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(tableInfoMemTable);
MapInfo.Mapping.FeatureLayer tempLayer = new MapInfo.Mapping.FeatureLayer(table, layerName, layerName);
map.Layers.Add(tempLayer);
}
标签:
GIS Mapxtreme
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?