3
$\begingroup$

I have a KML file with a bunch of (lat,lon) pairs. I can retrieve the pairs by importing the KML file as "Data" and drilling down into it:

Import["mykml.kml","Data"][[1,2,2,1,1]]

enter image description here

This yields a GeoPosition object with the (lat,lon) points. Passing this to GeoDistance calculates the length of the path, which is what I'm after.

Now I want to CloudDeploy a FormFunction so other folks can run GeoDistance on their own KML files; something like

form = FormFunction["yourfile" -> "KML", GeoDistance[#yourfile] &]
CloudDeploy[form, Permissions -> "Public"]

The problem is that the FormFunction imports the KML file without the extra "Data" specifier, so that #yourfile is some map object instead of a data structure I can drill down into.

How can I tell FormFunction to import the "Data" in the KML file, and not perform the default importing action?

$\endgroup$
2
  • $\begingroup$ Does my answer fit your needs? $\endgroup$
    – Kuba
    Commented Jun 15, 2017 at 7:02
  • $\begingroup$ Yes, it works like a charm. Many thanks! $\endgroup$ Commented Jun 15, 2017 at 13:56

1 Answer 1

4
$\begingroup$

You can import plain text and then ImportString:

form = FormFunction[
    "yourfile" -> "Text"
  , GeoDistance[ImportString[#yourfile, {"KML", "Data"}][[1, 2, 2, 1, 1]]] &
];

CloudDeploy[form, Permissions -> "Public"]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.