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$
  • $\begingroup$ Does my answer fit your needs? $\endgroup$ – Kuba Jun 15 '17 at 7:02
  • $\begingroup$ Yes, it works like a charm. Many thanks! $\endgroup$ – ConvexMartian Jun 15 '17 at 13:56
3
$\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, privacy policy and cookie policy

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