{"id":1546,"date":"2020-05-08T11:23:09","date_gmt":"2020-05-08T11:23:09","guid":{"rendered":"https:\/\/wetransform.eu\/?post_type=news-and-events&#038;p=1546"},"modified":"2022-07-28T07:59:36","modified_gmt":"2022-07-28T07:59:36","slug":"sort-complex-objects","status":"publish","type":"news-and-events","link":"https:\/\/wetransform.to\/de\/neuigkeiten-veranstaltungen\/sort-complex-objects\/","title":{"rendered":"Groovy Week 2020: Sorting complex objects for Transport Networks"},"content":{"rendered":"<p>In our fifth and final installment of the 2020 Groovy Week, we will address a type of dataset that is often complex and has specific issues that need to be solved - a transport network, for which we want to create topologically correct link sequences. Like in the previous Groovy Week posts, note that this article assumes you have working knowledge of hale studio and know the terminology.<\/p>\n<h2>Friday's Script: Sorting complex objects for Transport Network Link Sequences (Thorsten)<\/h2>\n<p>Most of the time, the order in which properties are written to a feature doesn't really matter. However, in some cases the correct order is very important, e.g. for link sequence features that are common in INSPIRE transport Network data sets.<\/p>\n<p>In this post, we will thus examine how we can use sorting in a Groovy Script to ensure that we get the correct order of references to a set of <code>RoadLink<\/code> features. In this data set, there was no single simple property that could be used to determine the correct sequence, but rather a combination of sequence and linear referencing properties that would need to be used.<\/p>\n<p>The context in which this script is used is in a <em>Groovy Script (greedy)<\/em> property-level function, with a <em>Merge<\/em> type-level function. The <em>Merge<\/em> function acts like a <code>Group By<\/code> in SQL - it creates groups of features based on shared properties. In this data set, we merge on the <code>ROUTE_ID<\/code> property, a foreign key that indicates to which <code>RoadLinkSequence<\/code> a <code>RoadLink<\/code> should belong. In such a Merge case, each source property may be available many times. A <em>greedy<\/em> Groovy function will take all these instances of source properties and provide them as a list to the script. You will notice, that when accessing the source feature's properties, we are using only lists.<\/p>\n<p>To perform the actual sorting, the script builds a sortable composite key as a single string, and inserts these keys into a <code>TreeMap<\/code>. A <code>TreeMap<\/code> is sorted according to the natural ordering of its keys, so when using simple strings, we do not need to come up with our own sorting or comparator approach.<\/p>\n<p>Building a working composite key was the main challenge here - we kept getting key collisions for various reasons, but in the end, the approach below produced the correct order and was free of any collisions.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/JBoudewijn\/ad7df51795643e49ad234421edab8068.js\"><\/script><\/p>\n<p>Towards the end of the script, the keys and <code>RoadLink<\/code> IDs are stored in the <code>sortedEdgeIDMap<\/code>, over whose sorted value set we then iterate to emit the target <code>DirectedLink<\/code> properties in the correct order. <\/p>\n<p>You can download the script snippet and import them in hale studio as a Groovy snippet by going to <em>File<\/em> -&gt; <em>Import<\/em> -&gt; <em>Groovy Snippet<\/em>. Please note that some scripts use protected functions, so you might need to <em>Lift Groovy Restrictions<\/em> to execute the script. Make sure you replace the placeholder attribute names with your own attribute names.<\/p>\n<p>Happy transforming!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our fifth and final installment of the 2020 Groovy Week, we will address a type of dataset that is often complex and has specific issues that need to be solved &#8211; a transport network, for which we want to create topologically correct link sequences. Like in the previous Groovy Week posts, note that this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[48],"tags":[47,21,46],"class_list":["post-1546","news-and-events","type-news-and-events","status-publish","hentry","category-tutorials","tag-groovy","tag-halestudio","tag-tutorial"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Groovy Week 2020: Sorting complex objects for Transport Networks - wetransform<\/title>\n<meta name=\"description\" content=\"We will address a type of dataset that is often complex and has specific issues that need to be solved - a transport network.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wetransform.to\/de\/neuigkeiten-veranstaltungen\/sort-complex-objects\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Groovy Week 2020: Sorting complex objects for Transport Networks\" \/>\n<meta property=\"og:description\" content=\"We will address a type of dataset that is often complex and has specific issues that need to be solved - a transport network.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wetransform.to\/de\/neuigkeiten-veranstaltungen\/sort-complex-objects\/\" \/>\n<meta property=\"og:site_name\" content=\"wetransform\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-28T07:59:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wetransform.to\/wp-content\/uploads\/2022\/04\/logo-large-e1657284415170.png\" \/>\n\t<meta property=\"og:image:width\" content=\"254\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@wetransformto\" \/>\n<meta name=\"twitter:label1\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data1\" content=\"3\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wetransform.to\\\/de\\\/neuigkeiten-veranstaltungen\\\/sort-complex-objects\\\/\",\"url\":\"https:\\\/\\\/wetransform.to\\\/de\\\/neuigkeiten-veranstaltungen\\\/sort-complex-objects\\\/\",\"name\":\"Groovy Week 2020: Sorting complex objects for Transport Networks - wetransform\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/wetransform.to\\\/de\\\/#website\"},\"datePublished\":\"2020-05-08T11:23:09+00:00\",\"dateModified\":\"2022-07-28T07:59:36+00:00\",\"description\":\"We will address a type of dataset that is often complex and has specific issues that need to be solved - a transport network.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wetransform.to\\\/de\\\/neuigkeiten-veranstaltungen\\\/sort-complex-objects\\\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wetransform.to\\\/de\\\/neuigkeiten-veranstaltungen\\\/sort-complex-objects\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wetransform.to\\\/de\\\/neuigkeiten-veranstaltungen\\\/sort-complex-objects\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/wetransform.to\\\/de\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"News & Events\",\"item\":\"https:\\\/\\\/wetransform.to\\\/de\\\/neuigkeiten-veranstaltungen\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Groovy Week 2020: Sorting complex objects for Transport Networks\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\\\/\\\/wetransform.to\\\/de\\\/#website\",\"url\":\"http:\\\/\\\/wetransform.to\\\/de\\\/\",\"name\":\"wetransform\",\"description\":\"Making environmental data useful and accessible\",\"publisher\":{\"@id\":\"http:\\\/\\\/wetransform.to\\\/de\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\\\/\\\/wetransform.to\\\/de\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"de\"},{\"@type\":\"Organization\",\"@id\":\"http:\\\/\\\/wetransform.to\\\/de\\\/#organization\",\"name\":\"wetransform\",\"url\":\"http:\\\/\\\/wetransform.to\\\/de\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"http:\\\/\\\/wetransform.to\\\/de\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/wetransform.to\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/large-logo-whitebg.png\",\"contentUrl\":\"https:\\\/\\\/wetransform.to\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/large-logo-whitebg.png\",\"width\":1024,\"height\":1024,\"caption\":\"wetransform\"},\"image\":{\"@id\":\"http:\\\/\\\/wetransform.to\\\/de\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/wetransformto\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/wetransform-gmbh\\\/\"]}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Groovy Week 2020: Sorting complex objects for Transport Networks - wetransform","description":"We will address a type of dataset that is often complex and has specific issues that need to be solved - a transport network.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wetransform.to\/de\/neuigkeiten-veranstaltungen\/sort-complex-objects\/","og_locale":"de_DE","og_type":"article","og_title":"Groovy Week 2020: Sorting complex objects for Transport Networks","og_description":"We will address a type of dataset that is often complex and has specific issues that need to be solved - a transport network.","og_url":"https:\/\/wetransform.to\/de\/neuigkeiten-veranstaltungen\/sort-complex-objects\/","og_site_name":"wetransform","article_modified_time":"2022-07-28T07:59:36+00:00","og_image":[{"width":254,"height":200,"url":"https:\/\/wetransform.to\/wp-content\/uploads\/2022\/04\/logo-large-e1657284415170.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@wetransformto","twitter_misc":{"Gesch\u00e4tzte Lesezeit":"3\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wetransform.to\/de\/neuigkeiten-veranstaltungen\/sort-complex-objects\/","url":"https:\/\/wetransform.to\/de\/neuigkeiten-veranstaltungen\/sort-complex-objects\/","name":"Groovy Week 2020: Sorting complex objects for Transport Networks - wetransform","isPartOf":{"@id":"http:\/\/wetransform.to\/de\/#website"},"datePublished":"2020-05-08T11:23:09+00:00","dateModified":"2022-07-28T07:59:36+00:00","description":"We will address a type of dataset that is often complex and has specific issues that need to be solved - a transport network.","breadcrumb":{"@id":"https:\/\/wetransform.to\/de\/neuigkeiten-veranstaltungen\/sort-complex-objects\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wetransform.to\/de\/neuigkeiten-veranstaltungen\/sort-complex-objects\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wetransform.to\/de\/neuigkeiten-veranstaltungen\/sort-complex-objects\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wetransform.to\/de\/"},{"@type":"ListItem","position":2,"name":"News & Events","item":"https:\/\/wetransform.to\/de\/neuigkeiten-veranstaltungen\/"},{"@type":"ListItem","position":3,"name":"Groovy Week 2020: Sorting complex objects for Transport Networks"}]},{"@type":"WebSite","@id":"http:\/\/wetransform.to\/de\/#website","url":"http:\/\/wetransform.to\/de\/","name":"wetransform","description":"Making environmental data useful and accessible","publisher":{"@id":"http:\/\/wetransform.to\/de\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/wetransform.to\/de\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"de"},{"@type":"Organization","@id":"http:\/\/wetransform.to\/de\/#organization","name":"wetransform","url":"http:\/\/wetransform.to\/de\/","logo":{"@type":"ImageObject","inLanguage":"de","@id":"http:\/\/wetransform.to\/de\/#\/schema\/logo\/image\/","url":"https:\/\/wetransform.to\/wp-content\/uploads\/2022\/07\/large-logo-whitebg.png","contentUrl":"https:\/\/wetransform.to\/wp-content\/uploads\/2022\/07\/large-logo-whitebg.png","width":1024,"height":1024,"caption":"wetransform"},"image":{"@id":"http:\/\/wetransform.to\/de\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/wetransformto","https:\/\/www.linkedin.com\/company\/wetransform-gmbh\/"]}]}},"_links":{"self":[{"href":"https:\/\/wetransform.to\/de\/wp-json\/wp\/v2\/news-and-events\/1546","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wetransform.to\/de\/wp-json\/wp\/v2\/news-and-events"}],"about":[{"href":"https:\/\/wetransform.to\/de\/wp-json\/wp\/v2\/types\/news-and-events"}],"author":[{"embeddable":true,"href":"https:\/\/wetransform.to\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wetransform.to\/de\/wp-json\/wp\/v2\/comments?post=1546"}],"version-history":[{"count":5,"href":"https:\/\/wetransform.to\/de\/wp-json\/wp\/v2\/news-and-events\/1546\/revisions"}],"predecessor-version":[{"id":3749,"href":"https:\/\/wetransform.to\/de\/wp-json\/wp\/v2\/news-and-events\/1546\/revisions\/3749"}],"wp:attachment":[{"href":"https:\/\/wetransform.to\/de\/wp-json\/wp\/v2\/media?parent=1546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wetransform.to\/de\/wp-json\/wp\/v2\/categories?post=1546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wetransform.to\/de\/wp-json\/wp\/v2\/tags?post=1546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}