模型在導入各類數據時(如管道、檢查井、泵站、閘門等),往往需要給定一個唯一的ID編號。有時,原始數據中的ID可能並不是唯一的,甚至,更糟糕的情況是連ID都沒有。

以下這個小腳本將簡單地使用數字作為ID,並且該ID號會改變(充當數據集的行號)。 在下面的例子中,我們將它用於多邊形,但可以適用於任何模型對象。

class Importer
@@polygon_id = 1

def Importer.OnEndRecordPolygon(obj)
obj[polygon_id] = @@polygon_id

@@polygon_id += 1
end
end

腳本用Ruby語言編寫,需要保存為擴展名為.rb的文件,然後可以在InfoWorks ICM和InfoNet的數據導入中心(如下所示)中使用。

注意:第一,建議在英文版中才使用,避免不必要的報錯。第二,ID號那一欄要填寫字母(任意),隨後會覆蓋。第三,針對不同類型的導入對象,上述腳本可進行相應修改,例如導入節點,polygon_id可相應改為node_id,OnEndRecordPolygon(obj)必須相應改為OnEndRecordNode(obj)。

圖1:數據導入中心

為了生成更加複雜的ID,上面的腳本可以進行擴展。假設原始GIS數據中包含一欄屬性「Structure」,下列腳本可用於生成由「Structure」+數字組成的ID。

class Importer

# A lookup from structure name to count of each structure從結構名稱到每個結構的計數的查找
@@lookup_id = Hash.new

def Importer.OnEndRecordPolygon(obj)

# Get the value of the Structure in the source object從源對象中獲取「結構」的值
structure = obj[Structure]

# Get the current counter for this structure獲得這個結構的當前數量
counter = @@lookup_id[structure]

# 如果計數器尚未設置,請將計數器設置為1
# (類似於 "counter = 1 if counter.nil?")
counter ||= 1

# Set the Polygon ID in the network to structure name + the counter將網路中的多邊形ID設置為結構名稱+計數值
obj[polygon_id] = structure + " " + counter.to_s

# 數值加1
@@lookup_id[structure] = counter + 1
end
end

如有任何問題,歡迎聯繫:

InfoWorks ICM官方QQ討論羣:339073787

郵箱:[email protected]


推薦閱讀:
相關文章