Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

How to add a custom attribute to an existing .kml file

TR
8 - Asteroid

I have a proof-of-concept I'm trying to put together but am flailing a bit.

 

Here's what I want to achieve:

 

  1. Input tool: reading an existing .kml file
  2. Formula tool: add <color></color> attribute
  3. Formula tool: set color to green
  4. Output tool: save as .kml

I've created a .kml file with the following schema:

 

<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document><Folder><name>TestLocations</name>
<Schema name="TestLocations" id="TestLocations">
<SimpleField name="Name" type="string"></SimpleField>
<SimpleField name="Address" type="string"></SimpleField>
<SimpleField name="City" type="string"></SimpleField>
<SimpleField name="ST" type="string"></SimpleField>
<SimpleField name="Latitude" type="float"></SimpleField>
<SimpleField name="Longitude" type="float"></SimpleField>
<SimpleField name="Comments" type="string"></SimpleField>
</Schema>
<Placemark>
<name>ABC123</name>
<description>123 MAIN AVE</description>
<ExtendedData><SchemaData schemaUrl="#TestLocations">
<SimpleData name="Name">ABC123</SimpleData>
<SimpleData name="Address">123 MAIN AVE</SimpleData>
<SimpleData name="City">NEW YORK</SimpleData>
<SimpleData name="ST">NY</SimpleData>
<SimpleData name="Latitude">45.4133</SimpleData>
<SimpleData name="Longitude">-74.0794</SimpleData>
<SimpleData name="Comments"></SimpleData>
</SchemaData></ExtendedData>
<Point><coordinates>-74.0794,45.4133,0</coordinates></Point>
</Placemark>

I recognize there needs to be a <color>green</color> attribute added after the <Placemark>. Before I get to this step, I've tried to read the file using a .csv format but get an error saying there are too many fields. So here's where I'm flailing. How do I read it, edit it, then save it?

 

My end goal is a .kml file which will be used in ESRI's ArcExplorer.

 

For reference, this is a sample Google .kml file:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Placemark>
  <Style id="WhateverYouWantHere">
<BalloonStyle>
<color>ff007db3</color>
</BalloonStyle>
</Style>
  <name>The Great Sphinx of Egypt</name>
  <description>The Great Sphinx of Egypt</description>
  <LookAt>
    <longitude>31.1376421035748</longitude>
    <latitude>29.97531730109229</latitude>
    <range>197.0202883013975</range>
    <tilt>27.35354524205621</tilt>
    <heading>-140.3945943869927</heading>
  </LookAt>
  <styleUrl>#WhateverYouWantHere</styleUrl>
    <styleUrl>root://styleMaps#default+nicon=0x307+hicon=0x317</styleUrl>
  <Point>
    <coordinates>31.13764210357481,29.97531730109229,0</coordinates>
  </Point>
</Placemark>
</kml>

 

Thanks for the input in advance!

Todd

 

2 REPLIES 2
patrick_digan
17 - Castor
17 - Castor

Hi @TR! I would try several things (in no particular order):

1) For the delimiters, use \0 (\0 means no delimiters)

2) For the field length, use a really big number (In case things are getting truncated)

3) Check the treat errors as warnings box (to at least try to read in as much as possible and allow debugging if there are still issues)

 

Untitled.png

 

Once you get the data in, you could use a formula tool to add in the color attribute. For your output, you would use the same setup as the input. I'd be happy to help more, but I think you're on the right track!

Patrick Digan

TR
8 - Asteroid

Ahh, I overlooked my delimiter which was set as a comma. That one change worked perfectly, thanks!

Read .kml as .csv

Labels