///
/// 創建區域
///
///區域信息
///點集
private void CreateRect(RectInfo rectinfo,List points)
{
try
{
//RectInfo 的定義請看下面
Catalog Cat = MapInfo.Engine.Session.Current.Catalog;
Table tblTemp = Cat.GetTable(m_RectLayerName);
if (tblTemp == null) return;
FeatureGeometry geometry = new MultiPolygon(this.MapCoordSys, CurveSegmentType.Linear, points.ToArray());
CompositeStyle style = GetOpaqueStyle(OpaqueType.NoNe, Color.Red); //GetOpaqueStyle在下面也有
Feature ftr = new Feature(tblTemp.TableInfo.Columns);
ftr.Geometry = geometry;
ftr.Style = style;
ftr["Name"] = rectinfo.FeatureName; //字段一的內容
ftr["Remark"] = rectinfo.Remark; //字段二的內容
ftr["Type"] = rectinfo.Type; //字段二的內容
rectinfo.FeatureKey = tblTemp.InsertFeature(ftr).ToString();
tblTemp.TableInfo.WriteTabFile();//保存到文件
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 自定義區域信息
///
public class RectInfo
{
private string _FeatureKey = string.Empty;
///
/// 圖元的KEY值
///
public string FeatureKey
{
get { return _FeatureKey; }
set
{
if (_FeatureKey != value)
{
_FeatureKey = value;
}
}
}
private string _FeatureName;
///
/// 圖元名稱
///
public string FeatureName
{
get { return _FeatureName; }
set
{
if (_FeatureName != value)
{
_FeatureName = value;
}
}
}
private string _Type;
///
/// 類型
///
public string Type
{
get { return _Type; }
set
{
if (_Type != value)
{
_Type = value;
}
}
}
private string _Remark;
///
/// 備註
///
public string Remark
{
get { return _Remark; }
set
{
if (_Remark != value)
{
_Remark = value;
}
}
}
///
/// 構造函數
///
public RectInfo()
{ }
///
/// 構造函數
///
/// 名稱
/// 類型
/// 備註
public RectInfo(string _FeatureName, string _Type, string _Remark)
{
FeatureName = _FeatureName;
Type = _Type;
Remark = _Remark;
}
}
///
/// 創建style
///
/// 不透明類型:ALL全部不透明(白色實心);BORDER邊界不透明(填充部分透明);NONE全透明
/// 如果opaqueType=BORDER,此處設定邊界顏色
/// 組合style
private CompositeStyle GetOpaqueStyle(OpaqueType opaqueType, System.Drawing.Color borderColor)
{
MapInfo.Styles.SimpleInterior simpleInterior;
if (opaqueType == OpaqueType.ALL)
simpleInterior = new MapInfo.Styles.SimpleInterior(); //缺省構造函數是白色實心
else
simpleInterior = new MapInfo.Styles.SimpleInterior(1); //0是線透明,1是面透明
MapInfo.Styles.LineWidth lineWidth = new MapInfo.Styles.LineWidth(1, MapInfo.Styles.LineWidthUnit.Point);
MapInfo.Styles.SimpleLineStyle simpleLineStyle;
if (opaqueType == OpaqueType.ALL)
simpleLineStyle = new MapInfo.Styles.SimpleLineStyle(lineWidth, 1, borderColor);
else if (opaqueType == OpaqueType.BORDER)
simpleLineStyle = new MapInfo.Styles.SimpleLineStyle(lineWidth, 2, borderColor); //2表示填充透明,即能夠顯示輪廓
else
simpleLineStyle = new MapInfo.Styles.SimpleLineStyle(lineWidth, 0); //0表示全部透明,即連輪廓都看不到
MapInfo.Styles.AreaStyle areaStyle = new MapInfo.Styles.AreaStyle(simpleLineStyle, simpleInterior);
MapInfo.Styles.CompositeStyle compositeStyle = new MapInfo.Styles.CompositeStyle(areaStyle, null, null, null);
return compositeStyle;
}
///
/// 區域,線路樣式類型
///
public enum OpaqueType
{
///
/// 全部不透明
///
ALL,
///
/// 邊界不透明
///
BORDER,
///
/// 全透明
///
NoNe
}