无法覆盖 kml 文件

发布于 2024-12-07 12:12:08 字数 7251 浏览 0 评论 0 原文

我即时生成 KML 文件。生成后,我像这样调用 Google 地图:

http://maps.google.com/maps?q=http://:8081/< ;位置>/<名称>.kml 。我使用的文件的名称基于用户输入的起始位置的纬度/经度。显然,当位置相同时,会从同一位置开始生成新的kml文件。在这种情况下,旧的应该被覆盖,确实如此。但是,当它提供给谷歌地图时,谷歌地图显示旧文件。我附加了两个示例文件和 python 代码的片段来说明情况:

import sys
import simplekml
kml=simplekml.Kml()
data=open(sys.argv[1],'r')
for line in data:
    points=line.split(' ')
    #speed=float(points[9])*3.6
    poly=kml.newpolygon(description=("Segment number"+str(points[0])),outerboundaryis=[(float(points[2]),float(points[1])),(float(points[4]),float(points[3])),(float(points[6]),float(points[5])),(float(points[8]),float(points[7]))])
        poly.polystyle.outline=0
kml.save("overwrite1.kml")

我使用两个不同的文件调用此代码示例两次,其片段发布在下面。 文件1:

90 17.44868272235051 78.35992655187812 17.448697277638573 78.35983344811831 17.448738277640214 78.35984044810797 17.44872372234887 78.35993355188845 
91 17.4486465880062 78.35986774305402 17.448733411989906 78.35989225695096 17.448203411899485 78.36194225741018 17.448116588096628 78.36191774259473 
92 17.44811737513277 78.36191508602762 17.44820262486316 78.3619449139783 17.447872624807378 78.36297491419779 17.447787375188554 78.36294508580814 
93 17.44778593144203 78.36295056347981 17.447874068554235 78.36296943652408 17.44777406853705 78.36347943664289 17.44768593145922 78.36346056336097 
94 17.447725298386487 78.3635168529482 17.44773470160246 78.36342314704976 17.448464701620733 78.36350314686737 17.448455298368216 78.36359685313049 
95 17.44844964150418 78.36359591532924 17.44847035848529 78.36350408466528 17.44916035852647 78.36367408449023 17.449139641463 78.36376591550432 
96 17.44914388953053 78.36376671292972 17.44915611045848 78.36367328706736 17.450066110488546 78.36380328683892 17.45005388950045 78.36389671315817 
97 17.45007148384362 78.36389560619496 17.450048516146023 78.36380439381118 17.45084851609243 78.36358439360971 17.450871483897217 78.36367560639643 
98 17.4508625677922 78.36367697298195 17.450857432196702 78.3635830270191 17.451527432187646 78.36354302685181 17.451532567801255 78.36363697314921 
99 17.45152818002525 78.3636369943884 17.45153181996366 78.36354300561091 17.454841819995337 78.36368300478371 17.45483817999356 78.36377699521559 

文件2:

17473 17.44436514856338 78.47057386682884 17.444454851433058 78.47056613316957 17.444460851434094 78.470642133188 17.444371148562336 78.4706498668104 
17474 17.496817749620345 78.3936639958953 17.496902250375502 78.39369600411102 17.496642250331544 78.39444600426742 17.49655774966431 78.39441399573903 
17475 17.471726433843678 78.56706897439275 17.471793566150335 78.5671310256177 17.471353566083877 78.56765102565059 17.47128643391013 78.5675889743598 
17476 17.47585253344295 78.56776331893766 17.47588746654784 78.56767668105347 17.476727466633236 78.56804668087453 17.476692533357554 78.56813331911657 
17477 17.47712250351409 78.56712330514262 17.477157496476696 78.56703669484854 17.47860749662435 78.56767669454003 17.47857250336645 78.5677633054511 
17478 17.478630673594786 78.56773989598412 17.47854932640072 78.56770010402349 17.478849326351025 78.5670301041477 17.478930673644467 78.56706989586 
17479 17.478886419731488 78.56709693560659 17.478893580257395 78.56700306439186 17.479253580264213 78.56703306430197 17.479246419724667 78.56712693569652 
17480 17.47929464334328 78.56708587636851 17.47920535665311 78.56707412363394 17.479505356601035 78.5645841242342 17.479594643395355 78.5645958757682 
17481 17.48534674355407 78.56693717788423 17.485433256442004 78.56696282212097 17.485083256382193 78.56825282240784 17.484996743613884 78.56822717759738 
17482 17.485021447069396 78.56828279163804 17.485058552921615 78.56819720835271 17.485248552941915 78.56828720831444 17.4852114470491 78.56837279167631 

第一个kml文件的片段:

<tessellate>0</tessellate>
                        <extrude>0</extrude>
                        <coordinates>78.363676973,17.4508625678,0.0 78.363583027,17.4508574322,0.0 78.3635430269,17.4515274322,0.0 78.3636369731,17.4515325678,0.0</coordinates>
                    </LinearRing>
                </outerBoundaryIs>
            </Polygon>
            <styleUrl>#stylesel_98</styleUrl>
            <visibility>1</visibility>
            <open>0</open>
            <description>Segment number98</description>
        </Placemark>
        <Placemark id="feat_200">
            <Polygon id="geom_198">
                <tessellate>0</tessellate>
                <extrude>0</extrude>
                <outerBoundaryIs>
                    <LinearRing>
                        <tessellate>0</tessellate>
                        <extrude>0</extrude>
                        <coordinates>78.3636369944,17.45152818,0.0 78.3635430056,17.45153182,0.0 78.3636830048,17.45484182,0.0 78.3637769952,17.45483818,0.0</coordinates>
                    </LinearRing>
                </outerBoundaryIs>
            </Polygon>
            <styleUrl>#stylesel_99</styleUrl>
            <visibility>1</visibility>
            <open>0</open>
            <description>Segment number99</description>
        </Placemark>
    </Document>
</kml>

第二个kml文件的片段:

<tessellate>0</tessellate>
                        <extrude>0</extrude>
                        <coordinates>78.5669371779,17.4853467436,0.0 78.5669628221,17.4854332564,0.0 78.5682528224,17.4850832564,0.0 78.5682271776,17.4849967436,0.0</coordinates>
                    </LinearRing>
                </outerBoundaryIs>
            </Polygon>
            <styleUrl>#stylesel_98</styleUrl>
            <visibility>1</visibility>
            <open>0</open>
            <description>Segment number17481</description>
        </Placemark>
        <Placemark id="feat_200">
            <Polygon id="geom_198">
                <tessellate>0</tessellate>
                <extrude>0</extrude>
                <outerBoundaryIs>
                    <LinearRing>
                        <tessellate>0</tessellate>
                        <extrude>0</extrude>
                        <coordinates>78.5682827916,17.4850214471,0.0 78.5681972084,17.4850585529,0.0 78.5682872083,17.4852485529,0.0 78.5683727917,17.485211447,0.0</coordinates>
                    </LinearRing>
                </outerBoundaryIs>
            </Polygon>
            <styleUrl>#stylesel_99</styleUrl>
            <visibility>1</visibility>
            <open>0</open>
            <description>Segment number17482</description>
        </Placemark>
    </Document>
</kml>

生成的kml文件的快照,两种情况相同:(:[我什至在发出第二个请求之前清除了缓存]:

谢谢。(抱歉但是,我希望他们能把事情说清楚)

I generate KML files on-the-fly.After generating, I call Google maps like this :

http://maps.google.com/maps?q=http://<my ip>:8081/<location>/<name>.kml . The name of the file I use is based on the lat/long of the starting location entered by the user. Obviously, when the location is same, a new kml file is generated starting from the same location. Under such circumstances, the old one should be overwritten, which it is. But, when its given to google maps, Google maps shows the old file . Am attaching snippets from two sample files and python code to illustrate the situation :

import sys
import simplekml
kml=simplekml.Kml()
data=open(sys.argv[1],'r')
for line in data:
    points=line.split(' ')
    #speed=float(points[9])*3.6
    poly=kml.newpolygon(description=("Segment number"+str(points[0])),outerboundaryis=[(float(points[2]),float(points[1])),(float(points[4]),float(points[3])),(float(points[6]),float(points[5])),(float(points[8]),float(points[7]))])
        poly.polystyle.outline=0
kml.save("overwrite1.kml")

I call this code sample twice, with two different files, snippets of which are posted below.
File 1:

90 17.44868272235051 78.35992655187812 17.448697277638573 78.35983344811831 17.448738277640214 78.35984044810797 17.44872372234887 78.35993355188845 
91 17.4486465880062 78.35986774305402 17.448733411989906 78.35989225695096 17.448203411899485 78.36194225741018 17.448116588096628 78.36191774259473 
92 17.44811737513277 78.36191508602762 17.44820262486316 78.3619449139783 17.447872624807378 78.36297491419779 17.447787375188554 78.36294508580814 
93 17.44778593144203 78.36295056347981 17.447874068554235 78.36296943652408 17.44777406853705 78.36347943664289 17.44768593145922 78.36346056336097 
94 17.447725298386487 78.3635168529482 17.44773470160246 78.36342314704976 17.448464701620733 78.36350314686737 17.448455298368216 78.36359685313049 
95 17.44844964150418 78.36359591532924 17.44847035848529 78.36350408466528 17.44916035852647 78.36367408449023 17.449139641463 78.36376591550432 
96 17.44914388953053 78.36376671292972 17.44915611045848 78.36367328706736 17.450066110488546 78.36380328683892 17.45005388950045 78.36389671315817 
97 17.45007148384362 78.36389560619496 17.450048516146023 78.36380439381118 17.45084851609243 78.36358439360971 17.450871483897217 78.36367560639643 
98 17.4508625677922 78.36367697298195 17.450857432196702 78.3635830270191 17.451527432187646 78.36354302685181 17.451532567801255 78.36363697314921 
99 17.45152818002525 78.3636369943884 17.45153181996366 78.36354300561091 17.454841819995337 78.36368300478371 17.45483817999356 78.36377699521559 

File 2:

17473 17.44436514856338 78.47057386682884 17.444454851433058 78.47056613316957 17.444460851434094 78.470642133188 17.444371148562336 78.4706498668104 
17474 17.496817749620345 78.3936639958953 17.496902250375502 78.39369600411102 17.496642250331544 78.39444600426742 17.49655774966431 78.39441399573903 
17475 17.471726433843678 78.56706897439275 17.471793566150335 78.5671310256177 17.471353566083877 78.56765102565059 17.47128643391013 78.5675889743598 
17476 17.47585253344295 78.56776331893766 17.47588746654784 78.56767668105347 17.476727466633236 78.56804668087453 17.476692533357554 78.56813331911657 
17477 17.47712250351409 78.56712330514262 17.477157496476696 78.56703669484854 17.47860749662435 78.56767669454003 17.47857250336645 78.5677633054511 
17478 17.478630673594786 78.56773989598412 17.47854932640072 78.56770010402349 17.478849326351025 78.5670301041477 17.478930673644467 78.56706989586 
17479 17.478886419731488 78.56709693560659 17.478893580257395 78.56700306439186 17.479253580264213 78.56703306430197 17.479246419724667 78.56712693569652 
17480 17.47929464334328 78.56708587636851 17.47920535665311 78.56707412363394 17.479505356601035 78.5645841242342 17.479594643395355 78.5645958757682 
17481 17.48534674355407 78.56693717788423 17.485433256442004 78.56696282212097 17.485083256382193 78.56825282240784 17.484996743613884 78.56822717759738 
17482 17.485021447069396 78.56828279163804 17.485058552921615 78.56819720835271 17.485248552941915 78.56828720831444 17.4852114470491 78.56837279167631 

Snippet from first kml file:

<tessellate>0</tessellate>
                        <extrude>0</extrude>
                        <coordinates>78.363676973,17.4508625678,0.0 78.363583027,17.4508574322,0.0 78.3635430269,17.4515274322,0.0 78.3636369731,17.4515325678,0.0</coordinates>
                    </LinearRing>
                </outerBoundaryIs>
            </Polygon>
            <styleUrl>#stylesel_98</styleUrl>
            <visibility>1</visibility>
            <open>0</open>
            <description>Segment number98</description>
        </Placemark>
        <Placemark id="feat_200">
            <Polygon id="geom_198">
                <tessellate>0</tessellate>
                <extrude>0</extrude>
                <outerBoundaryIs>
                    <LinearRing>
                        <tessellate>0</tessellate>
                        <extrude>0</extrude>
                        <coordinates>78.3636369944,17.45152818,0.0 78.3635430056,17.45153182,0.0 78.3636830048,17.45484182,0.0 78.3637769952,17.45483818,0.0</coordinates>
                    </LinearRing>
                </outerBoundaryIs>
            </Polygon>
            <styleUrl>#stylesel_99</styleUrl>
            <visibility>1</visibility>
            <open>0</open>
            <description>Segment number99</description>
        </Placemark>
    </Document>
</kml>

Snippet from 2nd kml file:

<tessellate>0</tessellate>
                        <extrude>0</extrude>
                        <coordinates>78.5669371779,17.4853467436,0.0 78.5669628221,17.4854332564,0.0 78.5682528224,17.4850832564,0.0 78.5682271776,17.4849967436,0.0</coordinates>
                    </LinearRing>
                </outerBoundaryIs>
            </Polygon>
            <styleUrl>#stylesel_98</styleUrl>
            <visibility>1</visibility>
            <open>0</open>
            <description>Segment number17481</description>
        </Placemark>
        <Placemark id="feat_200">
            <Polygon id="geom_198">
                <tessellate>0</tessellate>
                <extrude>0</extrude>
                <outerBoundaryIs>
                    <LinearRing>
                        <tessellate>0</tessellate>
                        <extrude>0</extrude>
                        <coordinates>78.5682827916,17.4850214471,0.0 78.5681972084,17.4850585529,0.0 78.5682872083,17.4852485529,0.0 78.5683727917,17.485211447,0.0</coordinates>
                    </LinearRing>
                </outerBoundaryIs>
            </Polygon>
            <styleUrl>#stylesel_99</styleUrl>
            <visibility>1</visibility>
            <open>0</open>
            <description>Segment number17482</description>
        </Placemark>
    </Document>
</kml>

Snapshot of the kml file generated , same in both cases :( : [I cleared the cache even,before making the 2nd request]:

Thanks . ( sorry for the long description. But, I hope they make things clear)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜肉鲜肉永远不皱 2024-12-14 12:12:08

关于 Google 地图缓存 KML 的 Google 查询似乎表明Google 正在缓存 KML 文件大约 5 分钟。

一个简单的解决方案是向您的网址添加随机查询,而不是链接到 http://maps.google.com/maps?q=http://:8081/.kml,您将链接到 http://maps.google.com/maps?q=http://:8081//.kml?rnd=

您的网络服务器会忽略它,但 Google 会认为这是一个新 URL 并重新获取它。

A google query on Google Maps Caching KML seems to indicate that Google are caching KML files for about 5 minutes.

A simple solution is to add a random query to your URL, so instead of linking to http://maps.google.com/maps?q=http://<my ip>:8081/<location>/<name>.kml, you would link to http://maps.google.com/maps?q=http://<my ip>:8081/<location>/<name>.kml?rnd=<somerandomvalue>

Your web server will ignore it, but Google will think it's a new URL and refetch it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文