{"id":186,"date":"2013-04-19T16:03:06","date_gmt":"2013-04-19T21:03:06","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=186"},"modified":"2013-04-19T16:03:06","modified_gmt":"2013-04-19T21:03:06","slug":"change-nodelinkzone-numbers-in-visum-via-com-limit-of-visum","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2013\/04\/19\/change-nodelinkzone-numbers-in-visum-via-com-limit-of-visum\/","title":{"rendered":"Change Node\/Link\/Zone Numbers in Visum via COM + limit of Visum"},"content":{"rendered":"<p>I believe anyone who has created once Visum network out of big extrenal datasets (mainly GIS &#8211; .shp) came across problems with numbering duplicates. Here I will show you how to overcome those issues. There are two ways: one is scripting (snippet below), another is via Access database.<\/p>\n<p><b>Case:<\/b><br \/>\nWe have model of Krak\u00f3w (city ca. 1mln inhabitants), we are creating regional model of Ma\u0142opolska &#8211; Krak\u00f3w is it&#8217;s capital.<\/p>\n<div>We have detailed GIS network from regional municipality, we have our own Krak\u00f3w model with Visum network. We want to merge them together.<\/div>\n<div>In most cases we will have problems with duplicate keys in database (i.e. &#8220;<i>Node with ID 301 already defined in the network<\/i>&#8220;). That&#8217;s mainly due to very decent DB architecture behind visum data. Each network object belongs to specific table with well defined &#8216;<b>primary key<\/b>&#8216; and &#8216;<b>foreign key<\/b>&#8216; &#8211; which basically cannot have duplicates (<i>http:\/\/en.wikipedia.org\/wiki\/Foreign_key<\/i>).<\/div>\n<div>It goes like this:<\/div>\n<ul>\n<li>each node is identified by it&#8217;s\u00a0<b>NO<\/b><\/li>\n<li>each link is identified by its\u00a0<b>FromNodeNo<\/b>\u00a0and\u00a0<b>ToNodeNo<\/b>\u00a0(those are foreign keys, plus implicitly it has it&#8217;s own primary key NO &#8211; I assume)<\/li>\n<li>each turn has its\u00a0<b>FromNode, ViaNode<\/b>\u00a0and\u00a0<b>ToNode<\/b><\/li>\n<\/ul>\n<p>If during import of any external objects those numbers will get confused we get rubbish results (either all network is mixed up, either it&#8217;s not imported at all.<\/p>\n<p><b>Toy-network example:<\/b><\/p>\n<p>1. I created following network and exported it to .shp:<\/p>\n<table cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><a href=\"http:\/\/4.bp.blogspot.com\/-it9ZggG9vuI\/UQEyzNua99I\/AAAAAAAAAeg\/OPWgqfGM8Mw\/s1600\/6.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/4.bp.blogspot.com\/-it9ZggG9vuI\/UQEyzNua99I\/AAAAAAAAAeg\/OPWgqfGM8Mw\/s320\/6.png\" width=\"320\" height=\"219\" border=\"0\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td>Network no 1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>2. I created another network like this:<\/p>\n<table cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><a href=\"http:\/\/2.bp.blogspot.com\/-9zdaBdc8Hfg\/UQEzN4C_IkI\/AAAAAAAAAeo\/j6Qv2FsUDNg\/s1600\/1.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/2.bp.blogspot.com\/-9zdaBdc8Hfg\/UQEzN4C_IkI\/AAAAAAAAAeo\/j6Qv2FsUDNg\/s320\/1.png\" width=\"320\" height=\"131\" border=\"0\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td>Network no 2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>3. I tried to import network 1 into network 2:<br \/>\na) result without setting &#8220;Offset parameter&#8221;:<\/p>\n<div><a href=\"http:\/\/3.bp.blogspot.com\/-S8ff4j0t6r0\/UQEzkKWjVtI\/AAAAAAAAAew\/g_1xVbgy-JE\/s1600\/2.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/3.bp.blogspot.com\/-S8ff4j0t6r0\/UQEzkKWjVtI\/AAAAAAAAAew\/g_1xVbgy-JE\/s320\/2.png\" width=\"320\" height=\"126\" border=\"0\" \/><\/a><\/div>\n<p>No network import at all.<br \/>\nb) when You set &#8220;Offset&#8221; to a number greater than max NodeNo, you will get something<br \/>\nfirst you get error for some links (which were already defined in network no 2)<\/p>\n<div><a href=\"http:\/\/1.bp.blogspot.com\/-VFqDIpKfx3o\/UQE0Cfdxi8I\/AAAAAAAAAe4\/_DdiZLnBqQg\/s1600\/3.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/1.bp.blogspot.com\/-VFqDIpKfx3o\/UQE0Cfdxi8I\/AAAAAAAAAe4\/_DdiZLnBqQg\/s320\/3.png\" width=\"320\" height=\"127\" border=\"0\" \/><\/a><\/div>\n<p>and finally the resulting network will be as follows:<\/p>\n<table cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><a href=\"http:\/\/1.bp.blogspot.com\/-kgzTzh4qZrE\/UQE0RtZW14I\/AAAAAAAAAfI\/dTTfElBQwSg\/s1600\/4.png\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/1.bp.blogspot.com\/-kgzTzh4qZrE\/UQE0RtZW14I\/AAAAAAAAAfI\/dTTfElBQwSg\/s320\/4.png\" width=\"320\" height=\"139\" border=\"0\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td>network 1 imported into network 2 (marked added links) all together network makes no sense<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>As we see there&#8217;s a lot of confusion.<\/p>\n<p><b>Solution:<\/b><br \/>\n<b><br \/>\n<\/b>there are two methods: one is scripting, another is via Access DB.<b><br \/>\n<\/b><\/p>\n<p>Scripting is easier and faster and can be automated, but it doesn&#8217;t work for many objects (it works for nodes, doesn&#8217;t work for links). See examples below(all scripts in python):<\/p>\n<p>a) Bulk (didn&#8217;t work with older versions of Visum) &#8211; much faster:<\/p>\n<p><i>def get_Nodes(Attr):<br \/>\nreturn Visum.Net.Nodes.GetMultiAttValues(Attr)<\/i><br \/>\n<i><br \/>\n<\/i><i>Nodes=get_Nodes(&#8220;No&#8221;)<br \/>\nNodes=list(Nodes)<br \/>\nNodes=[list(node) for node in Nodes]<br \/>\nfor i,node in enumerate(Nodes):<br \/>\nnode[1]=i+100000000 #put max node no in your network here<\/p>\n<p># we need to do it twice: once we add big number to all elements and the we can give them ordered numbers starting from whatever<br \/>\nVisum.Net.Nodes.SetMultiAttValues(&#8220;No&#8221;,Nodes)<\/p>\n<p>Nodes=get_Nodes(&#8220;No&#8221;)<br \/>\nNodes=list(Nodes)<br \/>\nNodes=[list(node) for node in Nodes]<br \/>\nfor i,node in enumerate(Nodes):<br \/>\nnode[1]=i+1000000 #give your threshold here (nodes will start fron No=1000000<\/p>\n<p>Visum.Net.Nodes.SetMultiAttValues(&#8220;No&#8221;,Nodes)<\/i><\/p>\n<p>b) element by element &#8211; can be very slow:<\/p>\n<p><i>Nodes=Visum.Net.Nodes.GetMultiAttValues(&#8220;No&#8221;)<br \/>\nNodes=[node[1] for node in Nodes]<br \/>\nfor node in Nodes:<br \/>\nVisum.Net.Nodes.ItemByKey(node).SetAttValue(&#8220;No&#8221;,node+<\/i>\u00a0<i>100000000\u00a0<\/i><i>)<br \/>\ni+=1<br \/>\nfor node in Nodes:<br \/>\nVisum.Net.Nodes.ItemByKey(node+<\/i>\u00a0<i>100000000<\/i>\u00a0<i>).SetAttValue(&#8220;No&#8221;,i)<\/i><i><br \/>\ni+=1<\/i><\/p>\n<p>2) Access DataBase:<br \/>\nI&#8217;m not ver familiar with Access so just a picture of what I do:<br \/>\na) Export network into Access DB (can take a lot of time)<br \/>\nb) Open access file and edit tables<br \/>\nc) Change keys in tables (for links it&#8217;s good to change name of &#8220;No&#8221; column into anything else and create additional column named No, then set this column as a key.<br \/>\nd) make the new column &#8220;Autoincrement&#8221; &#8211; so the number will be integers starting from 1<br \/>\n(for links it needs to be different, links have directed numbers so it shall be like this:\u00a0<i>1 1 2 2 3 3 4 4 5 5 6 6 &#8230; &#8211;\u00a0<\/i>I did it in excel and pasted.<br \/>\ne) you save the file and Import it into Visum<\/p>\n<p>This way we merged four different shapefiles with overlapping numbers and two different Visum networks.<br \/>\nEverything is neatly numbered starting from one onwards.<\/p>\n<p>PS. We came across another issue which seemed strange but we found very easy explanation. During import we got following message that node number exceeds: 2 147 483 648. Which happened to be max of LongInt datatype, so actually that&#8217;s the limit of Visum \ud83d\ude42 You cannot go any further. Simply reduce umbers by means of the solutions above.<\/p>\n<p>Hope it helps!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I believe anyone who has created once Visum network out of big extrenal datasets (mainly GIS &#8211; .shp) came across problems with numbering duplicates. Here&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[],"class_list":["post-186","post","type-post","status-publish","format-standard","hentry","category-visum"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=186"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/186\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}