Workflow for Exporting KML Files
I created a KML export workflow and thought I would share it. This workflow was created and tested with Workflow version 5.45
You will need the Geometry Conversion activity pack installed to use it. This workflow is not optimized and I make no guarantees to its efficiency or capability. Copy the code snippet below into a text file and save it with a .json extension. You should then be able to import it into VertiGIS Workflow.
If anyone has any suggestions for improvement please let me know.
Brandon T.
GIS Analyst @ Thompson-Nicola Regional District
{"_properties":{"isServerWorkflow":false},"components":[{"id":2,"steps":[{"id":3,"inputs":{},"position":"10,-900","purpose":"start","title":"Start","transitions":[{"id":257,"position":"100,-840 100,-790","sourceConnector":"bottom","target":{"id":256}}]},{"action":"gcx:wf:core:loop:ForEach","description":"Loop through all input features from context.","id":8,"inputs":{"items":{"accessors":["$getInputs","$getInputs","$getInputs"],"annotations":[{"count":10,"index":1,"kind":"idref"},{"count":10,"index":38,"kind":"idref"},{"count":10,"index":66,"kind":"idref"}],"code":"!$getInputs.inputs.context.graphics ? $getInputs.inputs.context : $getInputs.inputs.context.graphics","source":"!$getInputs.inputs.context.graphics ? $getInputs.inputs.context : $getInputs.inputs.context.graphics"}},"name":"forFeature","position":"-20,180","title":"For Each","transitions":[{"id":49,"inputs":{},"position":"100,340 100,390","sourceConnector":"bottom","target":{"id":48}}]},{"action":"gcx:wf:core::CreateValue","description":"Object with all relevant geometry open and close tags.","id":30,"inputs":{"expression":{"accessors":[],"annotations":[],"code":"{\n Point: {\n open: \"<Point>\",\n close: \"</Point>\"\n },\n LineString: {\n open: \"<LineString>\",\n close: \"</LineString>\"\n },\n MultiPoint: {\n multiOpen: \"<MultiGeometry>\",\n multiClose: \"</MultiGeometry>\",\n open: \"<Point>\",\n close: \"</Point>\"\n },\n Polygon: {\n open: \"<Polygon>\",\n close: \"</Polygon>\",\n outer: {\n open: \"<outerBoundaryIs><LinearRing>\",\n close: \"</LinearRing></outerBoundaryIs>\"\n },\n inner: {\n open: \"<innerBoundaryIs>\",\n close: \"</innerBoundaryIs>\"\n },\n linearRing: {\n open: \"<LinearRing>\",\n close: \"</LinearRing>\"\n }\n },\n MultiPolygon: {\n multiOpen: \"<MultiGeometry>\",\n multiClose: \"</MultiGeometry>\",\n open: \"<Polygon>\",\n close: \"</Polygon>\"\n },\n MultiLineString: {\n multiOpen: \"<MultiGeometry>\",\n multiClose: \"</MultiGeometry>\",\n open: \"<LineString>\",\n close: \"</LineString>\"\n }\n}","source":"{\n Point:{\n open:\"<Point>\",\n close:\"</Point>\"\n },\n LineString:{\n open:\"<LineString>\",\n close:\"</LineString>\"\n },\n MultiPoint:{\n multiOpen:\"<MultiGeometry>\",\n multiClose:\"</MultiGeometry>\",\n open: \"<Point>\",\n close: \"</Point>\"\n },\n Polygon:{\n open:\"<Polygon>\",\n close:\"</Polygon>\",\n outer:{\n open:\"<outerBoundaryIs><LinearRing>\",\n close:\"</LinearRing></outerBoundaryIs>\"\n },\n inner:{\n open:\"<innerBoundaryIs>\",\n close:\"</innerBoundaryIs>\"\n },\n linearRing:{\n open: \"<LinearRing>\",\n close:\"</LinearRing>\"\n }\n },\n MultiPolygon:{\n multiOpen:\"<MultiGeometry>\",\n multiClose:\"</MultiGeometry>\",\n open:\"<Polygon>\",\n close:\"</Polygon>\"\n },\n MultiLineString:{\n multiOpen: \"<MultiGeometry>\",\n multiClose:\"</MultiGeometry>\", \n open:\"<LineString>\",\n close:\"</LineString>\"\n }\n}"}},"name":"geomtags","position":"-20,20","title":"GeometryTags","transitions":[{"id":120,"inputs":{},"position":"100,130 100,180","target":{"id":8}}]},{"action":"gcx:wf:core::CreateValue","description":"Create array to hold all KML components. First element in array is KML opening tags.","id":41,"inputs":{"expression":{"accessors":["$style"],"annotations":[{"count":6,"index":98,"kind":"idref"}],"code":"[`<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n<Document>${$style.result}`]","source":"[`<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n<Document>${$style.result}`]"}},"name":"kml_components","position":"-20,-150","title":"KML Compontents Array","transitions":[{"id":119,"inputs":{},"position":"100,-30 100,20","sourceConnector":"bottom","target":{"id":30},"targetConnector":"top"}]},{"action":"gcx:wf:core::AddItem","id":48,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":[],"annotations":[],"code":"`</Document></kml>`","source":"`</Document></kml>`"}},"position":"-20,390","title":"Add: Document Closing","transitions":[{"id":218,"inputs":{},"position":"100,420 100,470","sourceConnector":"bottom","target":{"id":184},"targetConnector":"top"}]},{"action":"gcx:wf:core::CreateValue","id":155,"inputs":{"expression":"<Style id=\"defaultStyle\"><LineStyle><color>ff000000</color><width>3</width><gx:labelVisibility>1</gx:labelVisibility></LineStyle><PolyStyle><color>40ffffff</color><fill>1</fill><outline>1</outline><gx:labelVisibility>1</gx:labelVisibility></PolyStyle><IconStyle><color>ff000000</color><gx:labelVisibility>1</gx:labelVisibility></IconStyle></Style>\n"},"name":"style","position":"-20,-260","title":"Document Default Style","transitions":[{"id":180,"inputs":{},"position":"100,-200 100,-150","target":{"id":41}}]},{"action":"gcx:wf:core::CreateFile","description":"Create a KML file by joining all items in the KML Components array.","id":184,"inputs":{"content":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result.join('')","source":"$kml_components.result.join('')"},"contentType":"text/plain","name":{"accessors":["$fileName"],"annotations":[{"count":9,"index":0,"kind":"idref"}],"code":"$fileName.result","source":"$fileName.result"}},"name":"kmlFile","position":"-20,470","title":"Create KML File","transitions":[{"id":288,"position":"100,580 100,630","sourceConnector":"bottom","target":{"id":188},"targetConnector":"top"}]},{"action":"gcx:wf:forms:form:DisplayForm","id":187,"inputs":{"form":{"accessors":[],"code":"resources.forms[values.id]","values":{"id":190}}},"name":"fname_prompt","position":"-20,-680","title":"File Name Input","transitions":[{"id":242,"position":"220,-620 370,-620 370,-530","sourceConnector":"right","target":{"id":196},"targetConnector":"top"}]},{"action":"gcx:wf:app::RunCommand","id":188,"inputs":{"commandName":"system.download-file","commandParameter":{"accessors":["$fileName","$kmlFile"],"annotations":[{"count":9,"index":7,"kind":"idref"},{"count":8,"index":59,"kind":"idref"}],"code":"{\n name: $fileName.result,\n fileNameExtension: \".kml\",\n result: $kmlFile.result\n}","source":"{\nname:$fileName.result,\nfileNameExtension: \".kml\",\nresult:$kmlFile.result\n}"}},"position":"-20,630","title":"system.download-file"},{"action":"gcx:wf:core::If","id":196,"inputs":{"condition":{"accessors":["$fname_prompt"],"annotations":[{"count":13,"index":0,"kind":"idref"}],"code":"$fname_prompt.result === 'ok'","source":"$fname_prompt.result === 'ok'"}},"position":"310,-530","title":"If","transitions":[{"branch":"false","id":200,"inputs":{},"position":"430,-500 550,-500","sourceConnector":"right","target":{"id":199}},{"branch":"true","id":225,"inputs":{},"position":"310,-500 100,-500 100,-420","sourceConnector":"left","target":{"id":210},"targetConnector":"top"}]},{"action":"gcx:wf:core::Exit","id":199,"inputs":{},"position":"550,-530","title":"Exit"},{"action":"gcx:wf:core::CreateValue","description":"Replace any characters that can't be in a file name.","id":210,"inputs":{"expression":{"accessors":["$fname_prompt"],"annotations":[{"count":13,"index":3,"kind":"idref"}],"code":"`${$fname_prompt.state.fname_input.value.replace(/[*&<>:\"/\\\\|?]/g, '')}.kml`","source":"`${$fname_prompt.state.fname_input.value.replace(/[*&<>:\"/\\\\|?]/g, '')}.kml`"}},"name":"fileName","position":"-20,-420","title":"fileName","transitions":[{"id":260,"position":"100,-310 100,-260","sourceConnector":"bottom","target":{"id":155},"targetConnector":"top"}]},{"action":"gcx:wf:core::GetWorkflowInputs","id":256,"inputs":{},"name":"getInputs","position":"-20,-790","title":"Get Workflow Inputs","transitions":[{"id":258,"position":"100,-730 100,-680","target":{"id":187}}]},{"action":"gcx:wf:core::Annotation","description":"Simple JavaScript is used throughout this workflow. The functions you will encounter include all of the following:\n- _array_.map() : this function applys some action to all elements of an array object. In the context of this workflow, this function is used for formatting arrays of coordinate values.\n- _array_.flat(_depth_) : this function will flatten an array, removing nested items and making the array \"2D\". The depth value dictates how far into the nesting it will reach. For the purpose of this workflow the depth is 4.\n- _array_.join() : Pastes together all elements of an array as a string\n- Ternary Operator: This will look like _some condition_ ? _execute if true_ : _execute if false_. Ternary operators are JavaScripts version of an in-line if statement.\n- _string_.replace(/[*&<>:\"/\\\\|?]/g, '') : The replace function will find and replace all matching characters. In this workflow, this is used to ensure file name inputs ares sanitized of any reserved characters.","id":299,"inputs":{},"position":"-540,-540","title":"Notes on JavaScript","width":"wide"}]},{"id":9,"steps":[{"id":10,"inputs":{},"position":"-20,-360","purpose":"start","title":"For Each","transitions":[{"id":107,"inputs":{},"position":"70,-300 70,-250","sourceConnector":"bottom","target":{"id":19},"targetConnector":"top"}]},{"action":"uuid:aef2d828-661e-44e4-861a-03371b3c7303::ConvertArcGisGeometryToGeoJson","id":15,"inputs":{"geometry":{"accessors":["$projectGeom"],"annotations":[{"count":12,"index":0,"kind":"idref"}],"code":"$projectGeom.geometry","source":"$projectGeom.geometry"}},"name":"convertToGeoJSON","position":"-50,-90","title":"Convert ArcGIS Geometry to GeoJSON","transitions":[{"id":292,"position":"70,-30 70,20","sourceConnector":"bottom","target":{"id":102},"targetConnector":"top"}]},{"action":"gcx:wf:arcgis::ProjectServiceTask","description":"Project input geometry to Web Mercator.","id":19,"inputs":{"geometry":{"accessors":["$forFeature"],"annotations":[{"count":11,"index":0,"kind":"idref"}],"code":"$forFeature.item.geometry","source":"$forFeature.item.geometry"},"outSpatialReference":4326},"name":"projectGeom","position":"-50,-250","title":"Project Geometry","transitions":[{"id":24,"inputs":{},"position":"70,-140 70,-90","target":{"id":15}}]},{"action":"gcx:wf:core::Evaluate","id":38,"inputs":{"expression":{"accessors":["$convertToGeoJSON","$geomtags","$poly_coord_outer","$geomtags","$poly_coord_outer"],"annotations":[{"count":17,"index":0,"kind":"idref"},{"count":9,"index":46,"kind":"idref"},{"count":17,"index":109,"kind":"idref"},{"count":9,"index":215,"kind":"idref"},{"count":17,"index":279,"kind":"idref"}],"code":"$convertToGeoJSON.result.type === 'Polygon' ? $geomtags.result['Polygon']['outer']['open'] + \"<coordinates>\" + $poly_coord_outer.result.map(function (coords) { return coords.join(','); }).join(' ') + \"</coordinates>\" + $geomtags.result['Polygon']['outer']['close'] : \"<coordinates>\" + $poly_coord_outer.result.map(function (coords) { return coords.join(','); }).join(' ') + \"</coordinates>\"","source":"$convertToGeoJSON.result.type === 'Polygon' ? $geomtags.result['Polygon']['outer']['open'] + \"<coordinates>\"+$poly_coord_outer.result.map(function(coords) { return coords.join(',');}).join(' ') + \"</coordinates>\" + $geomtags.result['Polygon']['outer']['close'] : \"<coordinates>\"+$poly_coord_outer.result.map(function(coords) { return coords.join(',');}).join(' ') + \"</coordinates>\""}},"name":"poly_outer_format","position":"-50,830","title":"Evaluate Expression","transitions":[{"id":159,"inputs":{},"position":"70,890 70,940","sourceConnector":"bottom","target":{"id":158}}]},{"action":"gcx:wf:core::If","description":"If geometry is a Multi type, evaluate true.","id":102,"inputs":{"condition":{"accessors":["$convertToGeoJSON"],"annotations":[{"count":17,"index":0,"kind":"idref"}],"code":"$convertToGeoJSON.result.type.includes('Multi')","source":"$convertToGeoJSON.result.type.includes('Multi')"}},"position":"-50,20","title":"If","transitions":[{"branch":"false","id":193,"inputs":{},"position":"190,75 210,75 210,170 70,170 70,190","sourceConnector":"right","target":{"id":168},"targetConnector":"top"},{"branch":"true","id":231,"inputs":{},"position":"-50,75 -280,75 -280,190","sourceConnector":"left","target":{"id":230},"targetConnector":"top"}]},{"action":"gcx:wf:core::If","description":"Invert if coordinate exist (if exists, evaluate false)","id":109,"inputs":{"condition":{"accessors":["$convertToGeoJSON"],"annotations":[{"count":17,"index":1,"kind":"idref"}],"code":"!$convertToGeoJSON.result.coordinates.length","source":"!$convertToGeoJSON.result.coordinates.length"}},"position":"-50,270","title":"If","transitions":[{"branch":"false","id":251,"inputs":{},"position":"190,325 450,325 450,520","sourceConnector":"right","target":{"id":250},"targetConnector":"top"}]},{"action":"gcx:wf:core::CreateValue","id":112,"inputs":{"expression":{"accessors":["$convertToGeoJSON"],"annotations":[{"count":17,"index":0,"kind":"idref"}],"code":"$convertToGeoJSON.result.coordinates[0]","source":"$convertToGeoJSON.result.coordinates[0]"}},"name":"poly_coord_outer","position":"-50,600","title":"First Coordinate Array","transitions":[{"id":115,"inputs":{},"position":"70,660 70,720","sourceConnector":"bottom","target":{"id":114}}]},{"action":"gcx:wf:core::CreateValue","id":114,"inputs":{"expression":{"accessors":["$convertToGeoJSON"],"annotations":[{"count":17,"index":0,"kind":"idref"}],"code":"$convertToGeoJSON.result.coordinates.slice(1)","source":"$convertToGeoJSON.result.coordinates.slice(1)"}},"name":"poly_coord_inner","position":"-50,720","title":"Other Coordinate Array","transitions":[{"id":151,"inputs":{},"position":"70,780 70,830","sourceConnector":"bottom","target":{"id":38},"targetConnector":"top"}]},{"action":"gcx:wf:core::If","description":"If poly_coord_inner exists, return false.","id":116,"inputs":{"condition":{"accessors":["$poly_coord_inner"],"annotations":[{"count":17,"index":1,"kind":"idref"}],"code":"!$poly_coord_inner.result.length","source":"!$poly_coord_inner.result.length"}},"position":"-50,1020","title":"If","transitions":[{"branch":"true","id":166,"inputs":{},"position":"-50,1075 -70,1075 -70,1385 10,1385","sourceConnector":"left","target":{"id":173},"targetConnector":"left"},{"branch":"false","id":205,"inputs":{},"position":"190,1075 330,1075 330,1090","sourceConnector":"right","target":{"id":204},"targetConnector":"top"}]},{"action":"gcx:wf:core:loop:ForEach","description":"Loop through all multi-geometry item.","id":122,"inputs":{"items":{"accessors":["$convertToGeoJSON"],"annotations":[{"count":17,"index":0,"kind":"idref"}],"code":"$convertToGeoJSON.result.coordinates","source":"$convertToGeoJSON.result.coordinates"}},"name":"forMultiGeom","position":"-400,270","title":"For Each","transitions":[{"id":235,"inputs":{},"position":"-280,430 -280,490","sourceConnector":"bottom","target":{"id":234}}]},{"action":"gcx:wf:core::Evaluate","id":153,"inputs":{"expression":{"accessors":["$poly_coord_inner","$geomtags","$geomtags"],"annotations":[{"count":17,"index":0,"kind":"idref"},{"count":9,"index":50,"kind":"idref"},{"count":9,"index":203,"kind":"idref"}],"code":"$poly_coord_inner.result.map(function (i) { return $geomtags.result['Polygon']['linearRing']['open'] + \"<coordinates>\" + i.map(function (coords) { return coords.join(','); }).join(' ') + \"</coordinates>\" + $geomtags.result['Polygon']['linearRing']['close']; })","source":"$poly_coord_inner.result.map(function(i) { return $geomtags.result['Polygon']['linearRing']['open'] + \"<coordinates>\" + i.map(function(coords) { return coords.join(',');}).join(' ') + \"</coordinates>\" + $geomtags.result['Polygon']['linearRing']['close']})"}},"name":"polygon_inner_boundary","position":"210,1170","title":"Evaluate Expression","transitions":[{"id":164,"inputs":{},"position":"330,1230 330,1290","sourceConnector":"bottom","target":{"id":163}}]},{"action":"gcx:wf:core::Evaluate","id":156,"inputs":{"expression":{"accessors":["$geomtags","$convertToGeoJSON","$geomtags"],"annotations":[{"count":9,"index":0,"kind":"idref"},{"count":17,"index":50,"kind":"idref"},{"count":9,"index":118,"kind":"idref"}],"code":"$geomtags.result['Point']['open'] + \"<coordinates>\" + $convertToGeoJSON.result.coordinates.join(' ') + \"</coordinates>\" + $geomtags.result['Point']['close']","source":"$geomtags.result['Point']['open']+\"<coordinates>\"+$convertToGeoJSON.result.coordinates.join(' ') + \"</coordinates>\" + $geomtags.result['Point']['close']"}},"name":"point_coord","position":"700,660","title":"Evaluate Expression","transitions":[{"id":172,"inputs":{},"position":"820,720 820,770","sourceConnector":"bottom","target":{"id":170}}]},{"action":"gcx:wf:core::AddItem","id":158,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$poly_outer_format"],"annotations":[{"count":18,"index":0,"kind":"idref"}],"code":"$poly_outer_format.result","source":"$poly_outer_format.result"}},"position":"-50,940","title":"Add: Outer Polygon Coord","transitions":[{"id":160,"inputs":{},"position":"70,970 70,1020","target":{"id":116}}]},{"action":"gcx:wf:core::AddItem","id":163,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$polygon_inner_boundary","$geomtags"],"annotations":[{"count":23,"index":0,"kind":"idref"},{"count":9,"index":34,"kind":"idref"}],"code":"$polygon_inner_boundary.result + $geomtags.result['Polygon']['inner']['close']","source":"$polygon_inner_boundary.result + $geomtags.result['Polygon']['inner']['close']"}},"position":"210,1290","title":"Add: Inner Polygon Contents and Closing Tags","transitions":[{"id":165,"inputs":{},"position":"330,1320 330,1350 130,1350 130,1370","sourceConnector":"bottom","target":{"id":173},"targetConnector":"top"}]},{"action":"gcx:wf:core::AddItem","id":168,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$forFeature","$forFeature","$geomtags","$convertToGeoJSON"],"annotations":[{"count":11,"index":55,"kind":"idref"},{"count":11,"index":110,"kind":"idref"},{"count":9,"index":158,"kind":"idref"},{"count":17,"index":175,"kind":"idref"}],"code":"`<Placemark><styleUrl>#defaultStyle</styleUrl>\n<name>${$forFeature.item.title}</name>\n<description><![CDATA[${$forFeature.item.description}]]></description>${$geomtags.result[$convertToGeoJSON.result.type]['open']}`","source":"`<Placemark><styleUrl>#defaultStyle</styleUrl>\n<name>${$forFeature.item.title}</name>\n<description><![CDATA[${$forFeature.item.description}]]></description>${$geomtags.result[$convertToGeoJSON.result.type]['open']}`"}},"position":"-50,190","title":"Start placemark...","transitions":[{"id":194,"inputs":{},"position":"70,220 70,270","target":{"id":109}}]},{"action":"gcx:wf:core::AddItem","id":170,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$point_coord"],"annotations":[{"count":12,"index":0,"kind":"idref"}],"code":"$point_coord.result","source":"$point_coord.result"}},"position":"700,770","title":"Add: Point Coord","transitions":[{"id":167,"inputs":{},"position":"820,800 820,1385 250,1385","sourceConnector":"bottom","target":{"id":173},"targetConnector":"right"}]},{"action":"gcx:wf:core::AddItem","id":173,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$geomtags","$convertToGeoJSON"],"annotations":[{"count":9,"index":3,"kind":"idref"},{"count":17,"index":20,"kind":"idref"}],"code":"`${$geomtags.result[$convertToGeoJSON.result.type]['close']}</Placemark>`","source":"`${$geomtags.result[$convertToGeoJSON.result.type]['close']}</Placemark>`"}},"position":"10,1370","title":"Add: Item Closing Tag, Placemark Closing Tag"},{"action":"gcx:wf:core::Log","id":198,"inputs":{"message":{"accessors":["$convertToGeoJSON"],"annotations":[{"count":17,"index":0,"kind":"idref"}],"code":"$convertToGeoJSON.result.coordinates.flat(4).length / 2","source":"$convertToGeoJSON.result.coordinates.flat(4).length / 2"}},"position":"250,-30","title":"Log"},{"action":"gcx:wf:core::AddItem","id":204,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$geomtags"],"annotations":[{"count":9,"index":0,"kind":"idref"}],"code":"$geomtags.result['Polygon']['inner']['open']","source":"$geomtags.result['Polygon']['inner']['open']"}},"position":"210,1090","title":"Add: Inner Polygon Start Tag","transitions":[{"id":206,"inputs":{},"position":"330,1120 330,1170","target":{"id":153}}]},{"action":"gcx:wf:core::AddItem","id":230,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$forFeature","$forFeature","$geomtags","$convertToGeoJSON"],"annotations":[{"count":11,"index":55,"kind":"idref"},{"count":11,"index":110,"kind":"idref"},{"count":9,"index":158,"kind":"idref"},{"count":17,"index":175,"kind":"idref"}],"code":"`<Placemark><styleUrl>#defaultStyle</styleUrl>\n<name>${$forFeature.item.title}</name>\n<description><![CDATA[${$forFeature.item.description}]]></description>${$geomtags.result[$convertToGeoJSON.result.type]['multiOpen']}`","source":"`<Placemark><styleUrl>#defaultStyle</styleUrl>\n<name>${$forFeature.item.title}</name>\n<description><![CDATA[${$forFeature.item.description}]]></description>${$geomtags.result[$convertToGeoJSON.result.type]['multiOpen']}`"}},"position":"-400,190","title":"Add: MultiGeometry Open Tag","transitions":[{"id":232,"inputs":{},"position":"-280,220 -280,270","target":{"id":122}}]},{"action":"gcx:wf:core::AddItem","id":234,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$geomtags","$convertToGeoJSON"],"annotations":[{"count":9,"index":3,"kind":"idref"},{"count":17,"index":20,"kind":"idref"}],"code":"`${$geomtags.result[$convertToGeoJSON.result.type]['multiClose']}</Placemark>`","source":"`${$geomtags.result[$convertToGeoJSON.result.type]['multiClose']}</Placemark>`"}},"position":"-400,490","title":"Add: MultiGeometry Close Tag"},{"action":"gcx:wf:core::Evaluate","id":244,"inputs":{"expression":{"accessors":["$geomtags","$convertToGeoJSON","$geomtags"],"annotations":[{"count":9,"index":0,"kind":"idref"},{"count":17,"index":55,"kind":"idref"},{"count":9,"index":163,"kind":"idref"}],"code":"$geomtags.result['LineString']['open'] + \"<coordinates>\" + $convertToGeoJSON.result.coordinates.map(function (i) { return i.join(','); }).join(' ') + \"</coordinates>\" + $geomtags.result['LineString']['close']","source":"$geomtags.result['LineString']['open']+\"<coordinates>\"+$convertToGeoJSON.result.coordinates.map(function(i) { return i.join(',');}).join(' ') + \"</coordinates>\" + $geomtags.result['LineString']['close']"}},"name":"line_coord","position":"330,760","title":"Evaluate Expression","transitions":[{"id":248,"inputs":{},"position":"450,820 450,860","sourceConnector":"bottom","target":{"id":246}}]},{"action":"gcx:wf:core::AddItem","id":246,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$line_coord"],"annotations":[{"count":11,"index":0,"kind":"idref"}],"code":"$line_coord.result","source":"$line_coord.result"}},"position":"330,860","title":"Add: LineString Item","transitions":[{"id":255,"inputs":{},"position":"450,890 450,1070 470,1070 470,1385 250,1385","sourceConnector":"bottom","target":{"id":173},"targetConnector":"right"}]},{"action":"gcx:wf:core::Switch","description":"Switch on geometry input type.","id":250,"inputs":{"value":{"accessors":["$convertToGeoJSON"],"annotations":[{"count":17,"index":0,"kind":"idref"}],"code":"$convertToGeoJSON.result.type","source":"$convertToGeoJSON.result.type"}},"position":"330,520","title":"Switch","transitions":[{"id":252,"inputs":{},"position":"330,565 70,565 70,600","purpose":"default","sourceConnector":"left","target":{"id":112},"targetConnector":"top","title":"Polygon"},{"branch":"Point","id":254,"inputs":{},"position":"570,565 820,565 820,660","sourceConnector":"right","target":{"id":156},"targetConnector":"top"},{"branch":"LineString","id":259,"inputs":{},"position":"450,610 450,760","sourceConnector":"bottom","target":{"id":244},"targetConnector":"top"}]}]},{"id":123,"steps":[{"action":"gcx:wf:core::AddItem","id":118,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$multi_line_coord"],"annotations":[{"count":17,"index":0,"kind":"idref"}],"code":"$multi_line_coord.result","source":"$multi_line_coord.result"}},"position":"430,640","title":"Add: LineString Item","transitions":[{"id":145,"inputs":{},"position":"550,670 550,1155 220,1155","sourceConnector":"bottom","target":{"id":148},"targetConnector":"right"}]},{"id":124,"inputs":{},"position":"10,-140","purpose":"start","title":"For Each","transitions":[{"id":224,"inputs":{},"position":"100,-80 100,-10","sourceConnector":"bottom","target":{"id":197},"targetConnector":"top"}]},{"action":"gcx:wf:core::Evaluate","id":126,"inputs":{"expression":{"accessors":["$geomtags","$convertToGeoJSON","$geomtags"],"annotations":[{"count":9,"index":0,"kind":"idref"},{"count":17,"index":55,"kind":"idref"},{"count":9,"index":163,"kind":"idref"}],"code":"$geomtags.result['LineString']['open'] + \"<coordinates>\" + $convertToGeoJSON.result.coordinates.map(function (i) { return i.join(','); }).join(' ') + \"</coordinates>\" + $geomtags.result['LineString']['close']","source":"$geomtags.result['LineString']['open']+\"<coordinates>\"+$convertToGeoJSON.result.coordinates.map(function(i) { return i.join(',');}).join(' ') + \"</coordinates>\" + $geomtags.result['LineString']['close']"}},"name":"multi_line_coord","position":"430,480","title":"Evaluate Expression","transitions":[{"id":130,"inputs":{},"position":"550,540 550,640","sourceConnector":"bottom","target":{"id":118}}]},{"action":"gcx:wf:core::Switch","description":"Switch on geometry input type.","id":128,"inputs":{"value":{"accessors":["$multiType"],"annotations":[{"count":10,"index":0,"kind":"idref"}],"code":"$multiType.result","source":"$multiType.result"}},"position":"430,290","title":"Switch","transitions":[{"branch":"LineString","id":133,"inputs":{},"position":"550,380 550,480","sourceConnector":"bottom","target":{"id":126},"targetConnector":"top"},{"id":141,"inputs":{},"position":"430,335 240,335 240,360 220,360","purpose":"default","sourceConnector":"left","target":{"id":134},"targetConnector":"right","title":"Polygon"},{"branch":"Point","id":143,"inputs":{},"position":"670,335 930,335 930,380","sourceConnector":"right","target":{"id":182},"targetConnector":"top"}]},{"action":"gcx:wf:core::If","description":"Invert if coordinate exist (if exists, evaluate false)","id":132,"inputs":{"condition":{"accessors":["$convertToGeoJSON","$forMultiGeom"],"annotations":[{"count":17,"index":1,"kind":"idref"},{"count":13,"index":38,"kind":"idref"}],"code":"!$convertToGeoJSON.result.coordinates[$forMultiGeom.pass].length","source":"!$convertToGeoJSON.result.coordinates[$forMultiGeom.pass].length"}},"position":"-20,160","title":"If","transitions":[{"branch":"false","id":154,"inputs":{},"position":"220,215 550,215 550,290","sourceConnector":"right","target":{"id":128},"targetConnector":"top"}]},{"action":"gcx:wf:core::CreateValue","id":134,"inputs":{"expression":{"accessors":["$convertToGeoJSON","$forMultiGeom"],"annotations":[{"count":17,"index":0,"kind":"idref"},{"count":13,"index":37,"kind":"idref"}],"code":"$convertToGeoJSON.result.coordinates[$forMultiGeom.pass][0]","source":"$convertToGeoJSON.result.coordinates[$forMultiGeom.pass][0]"}},"name":"multi_poly_coord_outer","position":"-20,330","title":"First Coordinate Array","transitions":[{"id":157,"inputs":{},"position":"100,390 100,450","sourceConnector":"bottom","target":{"id":136}}]},{"action":"gcx:wf:core::CreateValue","id":135,"inputs":{"expression":{"accessors":["$convertToGeoJSON"],"annotations":[{"count":17,"index":0,"kind":"idref"}],"code":"$convertToGeoJSON.result.type.replace(/Multi/g, \"\")","source":"$convertToGeoJSON.result.type.replace(/Multi/g,\"\")"}},"name":"multiType","position":"-20,60","title":"Create Value","transitions":[{"id":139,"inputs":{},"position":"100,120 100,160","target":{"id":132}}]},{"action":"gcx:wf:core::CreateValue","id":136,"inputs":{"expression":{"accessors":["$convertToGeoJSON","$forMultiGeom"],"annotations":[{"count":17,"index":0,"kind":"idref"},{"count":13,"index":37,"kind":"idref"}],"code":"$convertToGeoJSON.result.coordinates[$forMultiGeom.pass].slice(1)","source":"$convertToGeoJSON.result.coordinates[$forMultiGeom.pass].slice(1)"}},"name":"multi_poly_coord_inner","position":"-20,450","title":"Other Coordinate Array","transitions":[{"id":162,"inputs":{},"position":"100,510 100,560","sourceConnector":"bottom","target":{"id":138},"targetConnector":"top"}]},{"action":"gcx:wf:core::Evaluate","id":138,"inputs":{"expression":{"accessors":["$convertToGeoJSON","$geomtags","$multi_poly_coord_outer","$geomtags","$multi_poly_coord_outer"],"annotations":[{"count":17,"index":0,"kind":"idref"},{"count":9,"index":52,"kind":"idref"},{"count":23,"index":115,"kind":"idref"},{"count":9,"index":227,"kind":"idref"},{"count":23,"index":291,"kind":"idref"}],"code":"$convertToGeoJSON.result.type.includes('Polygon') ? $geomtags.result['Polygon']['outer']['open'] + \"<coordinates>\" + $multi_poly_coord_outer.result.map(function (coords) { return coords.join(','); }).join(' ') + \"</coordinates>\" + $geomtags.result['Polygon']['outer']['close'] : \"<coordinates>\" + $multi_poly_coord_outer.result.map(function (coords) { return coords.join(','); }).join(' ') + \"</coordinates>\"","source":"$convertToGeoJSON.result.type.includes('Polygon') ? $geomtags.result['Polygon']['outer']['open'] + \"<coordinates>\"+$multi_poly_coord_outer.result.map(function(coords) { return coords.join(',');}).join(' ') + \"</coordinates>\" + $geomtags.result['Polygon']['outer']['close'] : \"<coordinates>\"+$multi_poly_coord_outer.result.map(function(coords) { return coords.join(',');}).join(' ') + \"</coordinates>\""}},"name":"multi_poly_outer_format","position":"-20,560","title":"Evaluate Expression","transitions":[{"id":169,"inputs":{},"position":"100,620 100,670","sourceConnector":"bottom","target":{"id":140}}]},{"action":"gcx:wf:core::AddItem","id":140,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$multi_poly_outer_format"],"annotations":[{"count":24,"index":0,"kind":"idref"}],"code":"$multi_poly_outer_format.result","source":"$multi_poly_outer_format.result"}},"position":"-20,670","title":"Add: Outer Polygon Coord","transitions":[{"id":171,"inputs":{},"position":"100,700 100,770","target":{"id":142}}]},{"action":"gcx:wf:core::If","description":"If multi_poly_coord_inner exists, return false","id":142,"inputs":{"condition":{"accessors":["$multi_poly_coord_inner"],"annotations":[{"count":23,"index":1,"kind":"idref"}],"code":"!$multi_poly_coord_inner.result.length","source":"!$multi_poly_coord_inner.result.length"}},"position":"-20,770","title":"If","transitions":[{"branch":"true","id":181,"inputs":{},"position":"-20,825 -40,825 -40,1155 -20,1155","sourceConnector":"left","target":{"id":148},"targetConnector":"left"},{"branch":"false","id":222,"inputs":{},"position":"220,825 410,825 410,880","sourceConnector":"right","target":{"id":217},"targetConnector":"top"}]},{"action":"gcx:wf:core::AddItem","id":148,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$geomtags","$convertToGeoJSON"],"annotations":[{"count":9,"index":0,"kind":"idref"},{"count":17,"index":17,"kind":"idref"}],"code":"$geomtags.result[$convertToGeoJSON.result.type]['close']","source":"$geomtags.result[$convertToGeoJSON.result.type]['close']"}},"position":"-20,1140","title":"Add: Item Closing Tag"},{"action":"gcx:wf:core::AddItem","id":179,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$multi_point_coord"],"annotations":[{"count":18,"index":0,"kind":"idref"}],"code":"$multi_point_coord.result","source":"$multi_point_coord.result"}},"position":"810,490","title":"Add: Point Coord","transitions":[{"id":161,"inputs":{},"position":"930,520 930,1155 220,1155","sourceConnector":"bottom","target":{"id":148},"targetConnector":"right"}]},{"action":"gcx:wf:core::Evaluate","id":182,"inputs":{"expression":{"accessors":["$geomtags","$convertToGeoJSON","$geomtags"],"annotations":[{"count":9,"index":0,"kind":"idref"},{"count":17,"index":50,"kind":"idref"},{"count":9,"index":118,"kind":"idref"}],"code":"$geomtags.result['Point']['open'] + \"<coordinates>\" + $convertToGeoJSON.result.coordinates.join(' ') + \"</coordinates>\" + $geomtags.result['Point']['close']","source":"$geomtags.result['Point']['open']+\"<coordinates>\"+$convertToGeoJSON.result.coordinates.join(' ') + \"</coordinates>\" + $geomtags.result['Point']['close']"}},"name":"multi_point_coord","position":"810,380","title":"Evaluate Expression","transitions":[{"id":186,"inputs":{},"position":"930,440 930,490","sourceConnector":"bottom","target":{"id":179}}]},{"action":"gcx:wf:core::AddItem","id":197,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$geomtags","$convertToGeoJSON"],"annotations":[{"count":9,"index":0,"kind":"idref"},{"count":17,"index":17,"kind":"idref"}],"code":"$geomtags.result[$convertToGeoJSON.result.type]['open']","source":"$geomtags.result[$convertToGeoJSON.result.type]['open']"}},"position":"-20,-10","title":"Add: Item Opening Tag","transitions":[{"id":137,"inputs":{},"position":"100,20 100,60","target":{"id":135}}]},{"action":"gcx:wf:core::AddItem","id":213,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$multi_polygon_inner_boundary","$geomtags"],"annotations":[{"count":29,"index":0,"kind":"idref"},{"count":9,"index":40,"kind":"idref"}],"code":"$multi_polygon_inner_boundary.result + $geomtags.result['Polygon']['inner']['close']","source":"$multi_polygon_inner_boundary.result + $geomtags.result['Polygon']['inner']['close']"}},"position":"290,1070","title":"Add: Inner Polygon Contents and Closing Tags","transitions":[{"id":223,"inputs":{},"position":"410,1100 410,1120 100,1120 100,1140","sourceConnector":"bottom","target":{"id":148},"targetConnector":"top"}]},{"action":"gcx:wf:core::Evaluate","id":215,"inputs":{"expression":{"accessors":["$multi_poly_coord_inner","$geomtags","$geomtags"],"annotations":[{"count":23,"index":0,"kind":"idref"},{"count":9,"index":56,"kind":"idref"},{"count":9,"index":209,"kind":"idref"}],"code":"$multi_poly_coord_inner.result.map(function (i) { return $geomtags.result['Polygon']['linearRing']['open'] + \"<coordinates>\" + i.map(function (coords) { return coords.join(','); }).join(' ') + \"</coordinates>\" + $geomtags.result['Polygon']['linearRing']['close']; })","source":"$multi_poly_coord_inner.result.map(function(i) { return $geomtags.result['Polygon']['linearRing']['open'] + \"<coordinates>\" + i.map(function(coords) { return coords.join(',');}).join(' ') + \"</coordinates>\" + $geomtags.result['Polygon']['linearRing']['close']})"}},"name":"multi_polygon_inner_boundary","position":"290,960","title":"Evaluate Expression","transitions":[{"id":219,"inputs":{},"position":"410,1020 410,1070","sourceConnector":"bottom","target":{"id":213}}]},{"action":"gcx:wf:core::AddItem","id":217,"inputs":{"collection":{"accessors":["$kml_components"],"annotations":[{"count":15,"index":0,"kind":"idref"}],"code":"$kml_components.result","source":"$kml_components.result"},"item":{"accessors":["$geomtags"],"annotations":[{"count":9,"index":0,"kind":"idref"}],"code":"$geomtags.result['Polygon']['inner']['open']","source":"$geomtags.result['Polygon']['inner']['open']"}},"position":"290,880","title":"Add: Inner Polygon Start Tag","transitions":[{"id":221,"inputs":{},"position":"410,910 410,960","target":{"id":215}}]}]},{"id":201,"steps":[{"id":203,"inputs":{},"position":"0,0","purpose":"start","title":"Event"}],"title":"submit-footer"}],"deploymentConfig":{"supportedApps":{"VSW":true}},"designerVersion":"5.45.1+3","forms":[{"defaults":{},"elements":{"fname_input":{"description":{"markdown":""},"enabled":true,"index":0,"rowIndex":0,"rowNumber":0,"title":{"markdown":"Enter a name for the exported file."},"titleLocation":"above","type":"TextBox","value":"ExportedFeatures"},"footer":{"enabled":true,"items":{"0":{"default":true,"index":0,"label":{"markdown":"OK"},"validates":true,"value":"ok"},"1":{"index":1,"label":{"markdown":"Cancel"},"validates":false,"value":"cancel"}},"section":"footer","type":"ButtonBar"},"header":{"section":"header","title":{"markdown":"Export to KML"},"type":"Header"}},"id":190}],"licenseInfo":{"licenseeId":"df10d07f-506a-c6aa-a546-afbf5c8980d1"},"references":[{"id":304,"path":"https://unpkg.com/@vertigis/workflow-activities-geometry-conversion@3.0.0","suite":"uuid:aef2d828-661e-44e4-861a-03371b3c7303"}],"start":{"id":3},"transitions":[{"branch":"loop","id":11,"inputs":{},"source":{"id":8},"target":{"id":10}},{"branch":"loop","id":125,"inputs":{},"source":{"id":122},"target":{"id":124}},{"branch":"submit$footer","id":207,"inputs":{},"source":{"id":187},"target":{"id":203}}]}Edit: Updated the workflow to fix an error when processing point geometry. Also added the ability to accept graphics as a context input.
-
Thanks Brandon for uploading your example - much appreciated. I'll give it a go. Export tools are next on the agenda!
0
Vous devez vous connecter pour laisser un commentaire.
Commentaires
1 commentaire