模型在导入各类数据时(如管道、检查井、泵站、闸门等),往往需要给定一个唯一的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]


推荐阅读:
相关文章