4

我的问题很简单:是否可以用图像文件(bmp、jpeg、gif、...)而不是颜色来填充 Google 地球中的多边形?

谢谢!

4

4 回答 4

3

我遇到了同样的问题,发现 Pablo Reyes 建议的模型解决方案是最好的。Ground Overlays 的问题是他们希望图像是一个板carrée 投影。如果您的图像是正交投影,则尝试使用补偿<gx:LatLonQuad>会使图像失真,因为它应用了非仿射变换。加上<gx:LatLonQuad>无论如何都会忽略高度坐标,因此地球保持恒定高度的图像曲线。

Pablo Reyes 提供的 KML 示例很好。在不需要 SketchUp 的情况下,平面的 model.dae 文件如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
<asset>
    <unit meter="1" name="meter" />
    <up_axis>Z_UP</up_axis>
</asset>
<library_visual_scenes>
    <visual_scene id="ID1">
        <node>
            <instance_geometry url="#ID2">
                <bind_material>
                    <technique_common>
                        <instance_material symbol="Material2" target="#ID3">
                            <bind_vertex_input semantic="UVSET0" input_semantic="TEXCOORD" input_set="0" />
                        </instance_material>
                    </technique_common>
                </bind_material>
            </instance_geometry>
        </node>
    </visual_scene>
</library_visual_scenes>
<library_geometries>
    <geometry id="ID2">
        <mesh>
            <source id="ID8">
                <float_array id="ID12" count="24">500.0 500.0 0 -500.0 -500.0 0 -500.0 500.0 0 500.0 -500.0 0 500.0 -500.0 0 500.0 500.0 0 -500.0 -500.0 0 -500.0 500.0 0</float_array>
                <technique_common>
                    <accessor count="8" source="#ID12" stride="3">
                        <param name="X" type="float" />
                        <param name="Y" type="float" />
                        <param name="Z" type="float" />
                    </accessor>
                </technique_common>
            </source>
            <source id="ID9">
                <float_array id="ID13" count="24">0 0 -1 0 0 -1 0 0 -1 0 0 -1 -0 -0 1 -0 -0 1 -0 -0 1 -0 -0 1</float_array>
                <technique_common>
                    <accessor count="8" source="#ID13" stride="3">
                        <param name="X" type="float" />
                        <param name="Y" type="float" />
                        <param name="Z" type="float" />
                    </accessor>
                </technique_common>
            </source>
            <source id="ID11">
                <float_array id="ID14" count="8">1 1 0 0 0 1 1 0</float_array>
                <technique_common>
                    <accessor count="4" source="#ID14" stride="2">
                        <param name="S" type="float" />
                        <param name="T" type="float" />
                    </accessor>
                </technique_common>
            </source>
            <vertices id="ID10">
                <input semantic="POSITION" source="#ID8" />
                <input semantic="NORMAL" source="#ID9" />
            </vertices>
            <triangles count="4" material="Material2">
                <input offset="0" semantic="VERTEX" source="#ID10" />
                <input offset="1" semantic="TEXCOORD" source="#ID11" />
                <p>0 0 1 1 2 2 1 1 0 0 3 3 4 3 5 0 6 1 7 2 6 1 5 0</p>
            </triangles>
        </mesh>
    </geometry>
</library_geometries>
<library_materials>
    <material id="ID3" name="MaterialName">
        <instance_effect url="#ID4" />
    </material>
</library_materials>
<library_effects>
    <effect id="ID4">
        <profile_COMMON>
            <newparam sid="ID6">
                <surface type="2D">
                    <init_from>ID5</init_from>
                </surface>
            </newparam>
            <newparam sid="ID7">
                <sampler2D>
                    <source>ID6</source>
                </sampler2D>
            </newparam>
            <technique sid="COMMON">
                <lambert>
                    <diffuse>
                        <texture texture="ID7" texcoord="UVSET0" />
                    </diffuse>
                    <transparent opaque="RGB_ZERO">
                        <color>0.3 0.3 0.3 1</color>
                    </transparent>
                    <transparency>
                        <float>1</float>
                    </transparency>
                </lambert>
            </technique>
        </profile_COMMON>
    </effect>
</library_effects>
<library_images>
    <image id="ID5">
        <init_from>images/2Dimage.png</init_from>
    </image>
</library_images>
<scene>
    <instance_visual_scene url="#ID1" />
</scene>

其中平面为 1000 平方米,以模型坐标系原点为中心。这是由以下定义的:

<float_array id="ID12" count="24">500.0 500.0 0 -500.0 -500.0 0 -500.0 500.0 0 500.0 -500.0 0 500.0 -500.0 0 500.0 500.0 0 -500.0 -500.0 0 -500.0 500.0 0</float_array>

图像将被应用到平面边缘到边缘。如果图像不是正方形,则必须相应地修改平面的尺寸。可以使用<Scale><Orientation>KML 设置在 GE 中调整平面大小和旋转。图像的不透明度由以下方式设置:

<color>0.3 0.3 0.3 1</color>

这使我可以使用具有不同大小、位置和方向的多个图像的相同模型文件(只要它们都具有相同的形状:在这种情况下为正方形)。它可以正确渲染与中心地球相切的正交投影。

于 2014-03-27T16:35:01.203 回答
2

您可以创建一个collada 3D 对象,您可以在其中定义例如具有图像作为平面纹理的平面。创建后,您可以将其用作模型在您的 kml 文件中,您可以将其放置在特定的位置(经度、纬度、高度)以及您想要的比例和方向。执行此操作的最简单方法是使用软件 SketchUp 以图像作为纹理创建平面,然后导出 collada *.dae 文件。然后你进入谷歌地球的菜单并添加你刚刚创建的模型并放置它。您可以将其保存为 *.kmz 文件。该文件将包含压缩的 collada *.dae 文件和纹理图像。使用 python pycollada 库创建 collada *.dae 文件可以实现更详细的方法。也有一些工具可以使用 python 创建 *.kml 文件[例如 pyKML、simplekml 或 fastkml],或者您可以自己编写它,就像我在此处发布的 kml 文件一样。在此代码中,collada 模型文件名为“model.dae”,

...
<Placemark>
<styleUrl>#default0</styleUrl>
<Model id="ID">
<altitudeMode>relativeToGround</altitudeMode>
<Location>
    <longitude>167.469167</longitude>
    <latitude>9.397944000000001</latitude>
    <altitude>12</altitude>
</Location>
<Orientation>
    <heading>0</heading>
    <tilt>0</tilt>
    <roll>0</roll>
</Orientation>
<Scale>
    <x>1</x>
    <y>1</y>
    <z>1</z>
</Scale>
<Link>
    <href>model.dae</href>
</Link>
<ResourceMap>
<Alias>
    <targetHref>2Dimage.png</targetHref>
    <sourceHref>images/2Dimage.png</sourceHref>
    </Alias>
</ResourceMap>
</Model>
</Placemark>
于 2013-10-31T03:50:50.647 回答
1

您不能用图像填充多边形,但可以使用地面叠加层(又名图像叠加层)。

正常的地面覆盖仅允许您可以旋转的方形边界。

<kml xmlns="http://www.opengis.net/kml/2.2">
<GroundOverlay>
   <name>GroundOverlay.kml</name>
   <Icon>
      <href>http://www.google.com/intl/en/images/logo.gif</href>
   </Icon>
   <LatLonBox>
      <north>37.83234</north>
      <south>37.832122</south>
      <east>-122.373033</east>
      <west>-122.373724</west>
      <rotation>45</rotation>
   </LatLonBox>
</GroundOverlay>
</kml>

但是,如果您想完全控制图像叠加,则可以使用 Google 地球扩展<gx:LatLonQuad>。LatLonQuad 指定定义覆盖区域的四边形的四个角点的坐标,而不仅仅是定义北、南、东和西边界的两个点。

<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<GroundOverlay>
    <name>Quad Image Overlay</name>
    <Icon>
        <href>http://www.google.com/intl/en/images/logo.gif</href>
        <viewBoundScale>0.75</viewBoundScale>
    </Icon>
    <gx:LatLonQuad>
        <coordinates>
            31.13309787341621,29.97820855337135,0 31.13521972695729,29.97822570382352,0 31.13414174103354,29.97910121868758,0 31.13378951869572,29.97910728214542,0 
        </coordinates>
    </gx:LatLonQuad>
</GroundOverlay>
</kml>

参考:

于 2013-10-07T14:13:33.353 回答
0

是的你可以。请参阅 Google KML 交互式采样器提供的此程序。

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Placemark>
    <name>SketchUp Model of Macky Auditorium</name>
    <description>University of Colorado, Boulder; model created by Noël Nemcik.</description>
    <LookAt>
      <longitude>-105.2727379358738</longitude>
      <latitude>40.01000594412381</latitude>
      <altitude>0</altitude>
      <heading>-27.70337734057933</heading>
      <tilt>65.74454495876547</tilt>
      <range>127.2393107680517</range>
    </LookAt>
    <Model id="model_4">
      <altitudeMode>relativeToGround</altitudeMode>
      <Location>
        <longitude>-105.272774533734</longitude>
        <latitude>40.009993372683</latitude>
        <altitude>0</altitude>
      </Location>
      <Orientation>
        <heading>0</heading>
        <tilt>0</tilt>
        <roll>0</roll>
      </Orientation>
      <Scale>
        <x>1</x>
        <y>1</y>
        <z>1</z>
      </Scale>
      <Link>
        <href>http://kml-samples.googlecode.com/svn/trunk/resources/CU-Macky.dae</href>
      </Link>
      <ResourceMap>
        <Alias>
          <targetHref>textures/CU-Macky---Center-StairsnoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky---Center-StairsnoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-4sideturretnoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-4sideturretnoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-Back-NorthnoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-Back-NorthnoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-BrickwallnoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-BrickwallnoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-East-WingnoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-East-WingnoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-EastdetaildoornoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-EastdetaildoornoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-EastnoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-EastnoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-EntrancenoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-EntrancenoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-Front--TurretnoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-Front--TurretnoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-FrontbrickwallnoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-FrontbrickwallnoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-FrontnoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-FrontnoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-FrontofTowernoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-FrontofTowernoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-NortheastUnivnoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-NortheastUnivnoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-NorthnoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-NorthnoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-RoofnoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-RoofnoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-Tower-SidenoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-Tower-SidenoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-TowerBasenoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-TowerBasenoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-TowernoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-TowernoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/CU-Macky-_Side_BrickwallnoCulling.jpg</targetHref>
          <sourceHref>../files/CU-Macky-_Side_BrickwallnoCulling.jpg</sourceHref>
        </Alias>
        <Alias>
          <targetHref>textures/roofnoCulling.jpg</targetHref>
          <sourceHref>../files/roofnoCulling.jpg</sourceHref>
        </Alias>
      </ResourceMap>
    </Model>
  </Placemark>
</kml>
​
于 2015-04-06T11:57:19.377 回答