在 Mathematica 中处理 KMZ
我被困在转换中。
我有一个包含一些坐标的 KMZ 文件。我像这样阅读该文件:
m=Import["~/Desktop/locations.kmz","Data"]
我得到这样的信息:
{{LayerName->Point Features,
Geometry->{
Point[{-120.934,49.3321,372}],
Point[{-120.935,49.3275,375}],
Point[{-120.935,49.323,371}]},
Labels->{},LabeledData->{},ExtendedData->{},
PlacemarkNames->{1,2,3},
Overlays->{},NetworkLinks->{}
}}
我想从每个点中提取 {x,y,z} 以及与这些点关联的地标名称 {1,2,3}。即使我可以从 Geometry->{} 中获取点,那也很好,因为我可以使用 List@@@ 将它们提取到列表中,但我迷失在无法提取的基本部分中几何“规则”。
感谢您的帮助,
罗恩
I'm stuck on a conversion.
I have a KMZ file with some coordinates. I read the file like this:
m=Import["~/Desktop/locations.kmz","Data"]
I get something like this:
{{LayerName->Point Features,
Geometry->{
Point[{-120.934,49.3321,372}],
Point[{-120.935,49.3275,375}],
Point[{-120.935,49.323,371}]},
Labels->{},LabeledData->{},ExtendedData->{},
PlacemarkNames->{1,2,3},
Overlays->{},NetworkLinks->{}
}}
I want to extract the {x,y,z} from each of the points and also the placemark names {1,2,3} associated with the points. Even if I can just get the points out of Geometry->{} that would be fine because I can extract them into a list with List@@@, but I'm lost at the fundamental part where I can't extract the Geometry "Rule".
Thanks for any help,
Ron
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
虽然 Leonid 的答案是正确的,但您可能会发现它不适用于您的代码。原因是
Import
命令的输出包含字符串(例如"LayerNames"
),而不是符号(例如LayerNames
)。我已将 KML 文件上传到我的网站空间,因此我们可以使用实际的Import
命令来尝试此操作。尝试如下操作:再次注意,
"Geometry"
是一个字符串。事实上,in
的内容看起来像这样(在InputForm
中):上下文:KML 指的是 Keyhole 标记语言。 Keyhole 是一家开发工具的公司,最终被 Google 收购后成为 Google Earth。 KMZ 是 KML 的压缩版本。
While Leonid's answer is correct, you will likely find that it does not work with your code. The reason is that the output of your
Import
command contains strings, such as"LayerNames"
, rather than symbols, such asLayerNames
. I've uploaded a KML file to my webspace so we can try this using an actualImport
command. Try something like the following:Again, note that
"Geometry"
is a string. In fact, the contents ofin
look like so (inInputForm
):Context: KML refers to Keyhole Markup Language. Keyhole was a company that developed tools that ultimately became Google Earth, after they were acquired by Google. KMZ is a zipped version of KML.
我认为可以安全地对 Leonid 和 Mark 的答案进行简化,即删除花哨的
Verbatim
构造。也就是说:Leonid 的第一个操作可以写成:
Leonid 的第二个操作:
我在导入 Mark 的数据时遇到了麻烦,但据我猜测,可以写成:
我会让这个答案的投票告诉我我是否正确。
A simplification to Leonid and Mark's answers that I believe can be made safely is to remove the fancy
Verbatim
construct. That is:Leonid's first operation can be written:
Leonid's second operation:
I had trouble importing Mark's data, but from what I can guess, one could write:
I'll let the votes on this answer tell me if I am correct.
给定你的表达式
这将提取点:
这将提取地标:
这是一个更优雅的方法,利用我们正在寻找的规则,它将提取两者:
Given your expression
This will extract the points:
And this will extract the placemarks:
Here is a more elegant method exploiting that we are looking for rules, that will extract both:
Transpose[{"PlacemarkNames", "Geometry"} / 怎么样。 m[[1]]] ?
How about
Transpose[{"PlacemarkNames", "Geometry"} /. m[[1]]]
?