문제

I've just been trying to draw some lines on Google Earth using point coordinates and everything works but for a tiny detail. The lines go through the earth and don't follow the surface so they are usually invisible as I've got points all arround the globe. Any ideas?

line = kml.newlinestring(coords=[firstcoord, secondcoord])

Thanks in advance :)

도움이 되었습니까?

해결책

You need to enable tesselate on the line geometry to follow the curvature of the earth.

Very large lines should enable tessellation so that they follow the curvature of the earth (otherwise, they may go underground and be hidden).

To enable tessellation, the value for <altitudeMode> must be clampToGround or clampToSeaFloor otherwise tessellation flag will be ignored.

Make sure the generated KML output looks something like this:

  <Placemark>
    <name>line with tessellation</name>
    <LineString>
      <tessellate>1</tessellate>
      <altitudeMode>clampToGround</altitudeMode>
      <coordinates>
        -122.383103,37.617112 -73.782201,40.643612 
      </coordinates>
    </LineString>
  </Placemark>

Python code to do this:

import simplekml

kml = simplekml.Kml()
firstcoord = (-122.383103, 37.617112)
secondcoord = (-73.782201, 40.643612)
line = kml.newlinestring(tessellate=1,
                         altitudemode=simplekml.AltitudeMode.clamptoground,
                         coords=[firstcoord, secondcoord])

print("Output: line.kml")
kml.save("line.kml")
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top