簡單幾何圖形
簡單的幾何圖形是獨立的幾何圖形,不關聯影響位置表現的FME屬性的,就是說,簡單幾何圖形要素包含以下屬性:
fme_geometry,fme_type:{fme_line,fme_line},{fme_point,fme_point},{fme_polygon,fme_area}
下面的代碼示範如何從一個簡單幾何圖形要素擷取座標並加入points列表colDisplayList集合:
Private Sub GetSimpleCoords(ByVal fmeFeature As FMEOFeature,
ByVal colDisplayList As Collection)
Dim objPoint As clsPointObject
Dim lCoordCount As Integer
Dim i As Integer
Dim colPointList As New Collection
lCoordCount = fmeFeature.numCoords
For i = 0 To lCoordCount - 1
Set objPoint = New clsPointObject
objPoint.X = fmeFeature.xCoordinate(i)
objPoint.Y = fmeFeature.yCoordinate(i)
Call colPointList.Add(objPoint)
Next i
Call colDisplayList.Add(colPointList)
End Sub
上面的clsPointObject類代碼如下
Dim dXCoord As Double
Dim dYCoord As Double
Public Property Get X() As Double
X = dXCoord
End Property
Public Property Let X(ByVal dX As Double)
dXCoord = dX
End Property
Public Property Get Y() As Double
Y = dYCoord
End Property
Public Property Let Y(ByVal dY As Double)
dYCoord = dY
End Property
弧和橢圓幾何圖形
EllipsoidGeometry類(詳見FME Feature Conceptual Data Model)描述了圓和橢圓。橢圓幾何圖形要素的fme_geometry為fme_point,fme_type為fme_ellipse。
ArcGeometry類描述了圓或橢圓弧,它的fme_geometry為fme_point,fme_type為fme_arc。ArcGeometry包含的屬性還有:fme_rotation,fme_fme_primary_axis,fme_secondary_axis,fme_start_angle,fme_sweep_angle,具體描述如下:
範例:
a=主半徑
b=次半徑
tS=起始角
tE=終止角
tE-tS=夾角角度
thetaS=起始角度=45
thetaE=終止角度=180
thetaE-thetaS=夾角角度=135
屬性值
fme_primary_axis=a=2.0
fme_secondary_axis=b=1.5
fme_start_angle=tS=arctan((a/b)*tan(thetaS))
fme_sweep_angle=tE-tS=arctan((a/b)*tan(thetaE))
arc tan stands for the inverse tangent of an angle.
一個橢圓幾何圖形是一個特殊的弧幾何圖形,其夾角為360度。
下面的代碼用FMEOFeature的convertArcToPoints方法獲得弧或橢圓類型要素的向量表達,獲得的點被添加到colDisplayList集合。
Private Sub GetArcCoords(ByVal fmeFeature As FMEOFeature, _
ByVal sFmeType As String, _
ByVal colDisplayList As Collection)
Dim dCenterX As Double
Dim dCenterY As Double
Dim dRotation As Double
Dim dPrimaryAxis As Double
Dim dSecondaryAxis As Double
Dim dStartAngle As Double
Dim dSweepAngle As Double
Dim dEndAngle As Double
Dim fmeTempFeature As FMEOFeature
Set fmeTempFeature = m_fmeSession.createFeature()
Call fmeFeature.Clone(fmeTempFeature)
dCenterX = fmeTempFeature.xCoordinate(0)
dCenterY = fmeTempFeature.yCoordinate(0)
dPrimaryAxis = fmeTempFeature.attribute( _
kFME_Primary_Axis)
dSecondaryAxis = fmeTempFeature.attribute( _
kFME_Secondary_Axis)
dRotation = fmeTempFeature.attribute(kFME_Rotation)
If sFmeType = kFME_Type_Arc Then
dStartAngle = fmeTempFeature.attribute( _
kFME_Start_Angle)
dSweepAngle = fmeTempFeature.attribute( _
kFME_Sweep_Angle)
dEndAngle = dStartAngle + dSweepAngle
ElseIf sFmeType = kFME_Type_Ellipse Then
dStartAngle = 0
dEndAngle = 360
Else
Debug.Print "Invalid fme_type: " & sFmeType
Exit Sub
End If
Call fmeTempFeature.convertArcToPoints(dCenterX, _
dCenterY, dPrimaryAxis, dSecondaryAxis, _
0, dStartAngle, dEndAngle, dRotation)
Call GetSimpleCoords(fmeTempFeature, colDisplayList)
End Sub
converArcToPoints用於將弧或橢圓轉化為一組線段,為了不改變原始要素,先用clone方法複製了原始要素,GetSimpleCoords過程是之前章節編寫的代碼,用於將要素點寫入列表集合。
環幾何圖形
DountGeometry類用來表達有洞的面要素,例如有島的湖,標準的DonutGeometry包含的所有內部多邊形都是完全被包含在外部多邊形中,但也不保證所有的環都符合這個規則,例如從支援環幾何圖形存在自相交或重疊的資料來源讀取資料時,FME對象將尊重未經處理資料,下面是一個環幾何圖形:
環幾何圖形要素的fme_geometry為fme_dount,fme_type為fme_area。在要素邏輯圖中,DountGeometry類是兩個或多個PolygeonGeometry類,1個外部多邊形和1個或多個內部多邊形。
下面的代碼將讀取環幾何圖形要素的點到colDisplayList集合,FMEOFeature對象的getDontParts方法用於獲得組成環的多邊形,GetSimpleCoords過程是之前章節編寫的代碼,用於將要素點寫入列表集合。
Private Sub GetDonutCoords(ByVal fmeFeature As FMEOFeature, _
ByVal colDisplayList As Collection)
Dim fmeFeatureVector As FMEOFeatureVector
Dim fmePolygonFeature As FMEOFeature
Dim lEntries As Integer
Dim i As Integer
Set fmeFeatureVector = m_fmeSession.createFeatureVector
Call fmeFeature.getDonutParts(fmeFeatureVector)
lEntries = fmeFeatureVector.entries
For i = 0 To lEntries - 1
Set fmePolygonFeature = fmeFeatureVector.element(i)
Call GetSimpleCoords(fmePolygonFeature, _
colDisplayList)
Next i
End Sub
提醒:FMEOFeature的getDonuParts方法不會清除輸入要素向量。
Aggregate(彙總)幾何圖形
彙總幾何圖形要素的fme_geometry為fme_aggregate、fme_type為fme_point,fme_line,fme_area。FME彙總要素是由多個幾何圖形組成:幾何圖形均為獨立的幾何圖形。通常情況下,彙總是由同類型部分組成,如果fme_type為fme_point,彙總包含的是點幾何圖形,fme_type為fme_line,彙總包含的是線幾何圖形,以此類推,你的應用程式也可處理不同類的彙總體,不同類彙總體沒有fme_type值。
下面的代碼擷取彙總體的點並寫入colDisplayList集合,FMEOFeature的splitAggregate方法用來分解彙總體的組成部分,splitAggregate方法的第二個布爾值參數表示如何分解彙總體中的彙總體,如果為FALSE,僅分解第一級彙總體。
Private Sub GetAggregateCoords( _
ByVal fmeFeature As FMEOFeature, _
ByVal colDisplayList As Collection)
Dim fmeFeatureVector As FMEOFeatureVector
Dim fmeComponentFeature As FMEOFeature
Dim lEntries As Integer
Dim i As Integer
Set fmeFeatureVector = m_fmeSession.createFeatureVector
Call fmeFeature.splitAggregate(fmeFeatureVector, True)
lEntries = fmeFeatureVector.entries
For i = 0 To lEntries - 1
Set fmeComponentFeature = fmeFeatureVector.element(i)
Call GetFeatureCoords(fmeComponentFeature, _
colDisplayList)
Next i
End Sub
上面代碼將提取每一個彙總體組成部分的點。
Private Sub GetFeatureCoords( _
ByVal fmeFeature As FMEOFeature, _
ByVal colDisplayList As Collection)
Dim sFmeType As String
Dim sFmeGeometry As String
Dim lFmeGeometry As Long
Dim colPointList As Collection
lFmeGeometry = fmeFeature.GeometryType
sFmeGeometry = fmeFeature.attribute(kFME_Geometry)
sFmeType = fmeFeature.attribute(kFME_Type)
Select Case lFmeGeometry
Case Is = foPoint
Select Case sFmeType
Case Is = kFME_Type_Point, kFME_Type_Text
Call GetSimpleCoords(fmeFeature, _
colDisplayList)
Case Is = kFME_Type_Arc, kFME_Type_Ellipse
Call GetArcCoords(fmeFeature, sFmeType, _
colDisplayList)
End Select
Case Is = foLine, foPolygon
Call GetSimpleCoords(fmeFeature, colDisplayList)
Case Is = foDonut
Call GetDonutCoords(fmeFeature, colDisplayList)
Case Is = foAggregate
Call GetAggregateCoords(fmeFeature, colDisplayList)
End Select
End Sub
注意:GetSimpleCoords,GetArcCoords,GetDonutCoords過程都是之前編寫的代碼。
處理OpenGIS Geometries
OpenGIS為要素幾何圖形定義了一個Well-Know Text(WKT)表達方法,FMEOFeature對象允許應用程式使用importGeometryFromOGCWKT匯入WKT或用exportGeometryFromOGCWKT匯出WKT。
使用Schema(模式)要素
當你需要理解輸入資料的結構、定義新的結構、改變已存在的結構時,模式要素非常有用。
FME對象資料要素使用良好的分類方法,如:Theme、Layer,Level,Table,Class,File等,一個模式要素提供了要素的分類資料模型。
注意:要素的類型容易和fme_type混淆,在要素邏輯資料模型圖表中,他們被分別表示為Feature::FeatureType和Feature::fme_type。
本教程第4章Reading Features from a Dataset中描述如何用FMEOFeature的readSchema方法訪問模式要素。對應的資料要素的模式要素可以用FMEOFeature的getFeatureType方法獲得。
例如:
屬性類型
屬性值
下面的代碼將獲得資料要素的每一個使用者屬性模式:
Public Sub GetSchemaInfo( _
ByRef fmeDataFeature As FMEOFeature, _
ByRef fmeSchemaFeature As FMEOFeature)
Dim i As Integer
Dim lCount As Integer
Dim sName As String
Dim sType As String
Dim sMsg As String
Dim fmeAttributeNames As FMEOStringArray
Set fmeAttributeNames = m_fmeSession.createStringArray
Call fmeDataFeature.allAttributeNames(fmeAttributeNames)
lCount = fmeAttributeNames.entries
For i = 0 To lCount - 1
sName = fmeAttributeNames.element(i)
sType = fmeSchemaFeature.attribute(sName)
If sType <> "" Then
sMsg = sMsg & sName & ": "
sMsg = sMsg & sType & vbCrLf
End If
Next
MsgBox sMsg, vbOKOnly, "GetSchemaInfo"
Exit Sub
End Sub
下表為使用者屬性的有效類型:
如果想為要素添加一個使用者屬性並寫入目標資料集,則必須添加一個屬性到對應的模式要數來指示屬性類型,屬性被添加到模式要素必須要有相同名的屬性添加到資料要素,並且值必須符合上表的屬性類型。
注意:模式不包含FME屬性的類型資訊(例如:fme_rotation),模式屬性名稱字以*號開頭的不能被你的應用程式使用。
模式要素包含一個幾何要素類型描述,下面的代碼示範如何返回要素類型列表:
Public Sub GetGeomInfo(ByRef fmeSchemaFeature As FMEOFeature)
Dim i As Integer
Dim sName As String
Dim sGeom As String
Dim sMsg As String
Dim bFinished As Boolean
i = 0
bFinished = False
Do While Not bFinished
sName = "fme_geometry{" & i & "}"
sGeom = fmeSchemaFeature.attribute(sName)
If sGeom <> "" Then
sMsg = sMsg & sName & ": "
sMsg = sMsg & sGeom & vbCrLf
Else
bFinished = True
End If
i = i + 1
Loop
MsgBox sMsg, vbOKOnly, "GetGeomInfo"
End Sub
參考資料:
《Building Applications with FME Objects》February 2005
轉載請註明文章來源 http://www.cnblogs.com/booolee