初探GIS Mapxtreme 添加点 层 线

1、添加点

View Code
                  初探GIS Mapxtreme 添加点 层 线
        ///</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、添加线

  View Code
   
     
/// <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、添加图层

View Code
   
     
/// <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);
}

你可能感兴趣的:(map)