gpt4 book ai didi

java - KML 文件中不可见的线条

转载 作者:行者123 更新时间:2023-11-30 09:45:22 24 4
gpt4 key购买 nike

我有一组使用 kml.linestring 连接的点。但是,我想根据这些线路的速度(我可用)对这些线路进行颜色编码> 问题是我的 kml 文件在谷歌地图上呈现时根本不呈现这些线路:(

如果我对一组不同的坐标(多边形)执行相同的操作,则完全可以正常工作。事实上,如果我不对线条进行颜色编码而只使用默认颜色,它会完美地呈现线条。但是,我需要颜色编码。我附上下面的代码:

public static void drawKML(File f) throws IOException
{
final Kml kml= KmlFactory.createKml();
final Document document = kml.createAndSetDocument().withName("Document.kml").withOpen(true);

final LineStyle style1=document.createAndAddStyle().withId("linestyleExample1").createAndSetLineStyle().withColor("ff000000");
final LineStyle style2=document.createAndAddStyle().withId("linestyleExample2").createAndSetLineStyle().withColor("ff008cff");

final LineStyle style3=document.createAndAddStyle().withId("linestyleExample3").createAndSetLineStyle().withColor("ff008000");
FileInputStream fstream=new FileInputStream(f);
DataInputStream in=new DataInputStream(fstream);
BufferedReader br=new BufferedReader(new InputStreamReader(in));
String line=br.readLine();
Placemark placemark1;

while(line!=null)
{
String[] alpha=line.split(" ");
double speed=Double.parseDouble(alpha[4])*3.6;
String description="";
description=description+"Speed="+speed+"\n";

if(speed>=0 && speed<=15) {
document.createAndAddPlacemark().withStyleUrl("#linestyleExample1").withDescription(description).createAndSetLineString().withExtrude(true).withTessellate(true).addToCoordinates(Double.parseDouble(alpha[1]), Double.parseDouble(alpha[0])).addToCoordinates(Double.parseDouble(alpha[3]),Double.parseDouble(alpha[2]));
logger.error("In black range");
}
else if(speed>15 && speed<=35) {
document.createAndAddPlacemark().withStyleUrl("#linestyleExample2").withDescription(description).createAndSetLineString().withExtrude(true).withTessellate(true).addToCoordinates(Double.parseDouble(alpha[1]), Double.parseDouble(alpha[0])).addToCoordinates(Double.parseDouble(alpha[3]),Double.parseDouble(alpha[2]));
logger.error("In orange range");
}
else {
document.createAndAddPlacemark().withStyleUrl("#linestyleExample3").withDescription(description).createAndSetLineString().withExtrude(true).withTessellate(true).addToCoordinates(Double.parseDouble(alpha[1]), Double.parseDouble(alpha[0])).addToCoordinates(Double.parseDouble(alpha[3]),Double.parseDouble(alpha[2]));
logger.error("In green");
}
//placemark1.createAndSetLineString().withExtrude(true).withTessellate(true).addToCoordinates(Double.parseDouble(alpha[1]), Double.parseDouble(alpha[0])).addToCoordinates(Double.parseDouble(alpha[3]),Double.parseDouble(alpha[2]));
line=br.readLine();

}
kml.marshal(new File(path/to/file));
}

它是这样的:

The lines are missing

它应该是这样的:

Did this using Python

来自错误 kml 文件的片段(不代表任何点):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
<Document>
<name>Document.kml</name>
<open>1</open>
<Style id="linestyleExample1">
<LineStyle>
<color>ff000234</color>
<width>0.0</width>
</LineStyle>
</Style>
<Style id="linestyleExample2">
<LineStyle>
<color>ff008cff</color>
<width>0.0</width>
</LineStyle>
</Style>
<Style id="linestyleExample3">
<LineStyle>
<color>ff006400</color>
<width>0.0</width>
</LineStyle>
</Style>
<Placemark>
<description>Speed=0.0
</description>
<styleUrl>#linestyleExample1</styleUrl>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>
<coordinates>78.48419,17.38463 78.48302,17.38328</coordinates>
</LineString>
</Placemark>
<Placemark>
<description>Speed=0.0
</description>
<styleUrl>#linestyleExample1</styleUrl>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>
<coordinates>78.48302,17.38328 78.48244,17.38264</coordinates>
</LineString>
</Placemark>
<Placemark>
<description>Speed=0.0
</description>
<styleUrl>#linestyleExample1</styleUrl>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>
<coordinates>78.48244,17.38264 78.48173,17.38204</coordinates>
</LineString>
</Placemark>
<Placemark>
<description>Speed=51.4415867904
</description>
<styleUrl>#linestyleExample3</styleUrl>
<LineString>
<coordinates>78.48173,17.38204 78.48068,17.38264</coordinates>
</LineString>
</Placemark>
<Placemark>
<description>Speed=51.4415867904
</description>
<styleUrl>#linestyleExample3</styleUrl>
<LineString>
<coordinates>78.48068,17.38264 78.47993,17.3829</coordinates>
</LineString>
</Placemark>
<Placemark>
<description>Speed=90.72
</description>
<styleUrl>#linestyleExample3</styleUrl>
<LineString>
<coordinates>78.47993,17.3829 78.47677,17.38331</coordinates>
</LineString>
</Placemark>
<Placemark>
<description>Speed=76.46400000000001
</description>
<styleUrl>#linestyleExample3</styleUrl>
<LineString>
<coordinates>78.47677,17.38331 78.47521,17.38359</coordinates>
</LineString>
</Placemark>
<Placemark>
<description>Speed=61.56000000000001
</description>
<styleUrl>#linestyleExample3</styleUrl>
<LineString>
<coordinates>78.47521,17.38359 78.47506,17.38353</coordinates>
</LineString>
</Placemark>
<Placemark>
<description>Speed=0.0
</description>
<styleUrl>#linestyleExample1</styleUrl>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>

来自一个确实正确表示它的片段:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
<Document id="feat_1">
<Style id="stylesel_0">
<LineStyle>
<color>ff000000</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_1">
<LineStyle>
<color>ff008cff</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_2">
<LineStyle>
<color>ff008cff</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_3">
<LineStyle>
<color>ff008cff</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_4">
<LineStyle>
<color>ff008cff</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_5">
<LineStyle>
<color>ff008000</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_6">
<LineStyle>
<color>ff008cff</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_7">
<LineStyle>
<color>ff008cff</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_8">
<LineStyle>
<color>ff008cff</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_9">
<LineStyle>
<color>ff008cff</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_10">
<LineStyle>
<color>ff008cff</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_11">
<LineStyle>
<color>ff008cff</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_12">
<LineStyle>
<color>ff008cff</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_13">
<LineStyle>
<color>ff008000</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_14">
<LineStyle>
<color>ff008000</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_15">
<LineStyle>
<color>ff008cff</color>
<colorMode>normal</colorMode>
</LineStyle>
</Style>
<Style id="stylesel_16">

它们是不同的,因为第二个是使用 Python 生成的(它首先生成很多线型,然后将它们一个一个地分配给点。)

最佳答案

原因是在“错误的”kml 中,您的线型有明确的宽度定义 0.0 将其更改为正数(5.0 左右),您将看到您的线条或完全删除它以使用默认宽度

Codewise 我不知道你正在使用的库,但我猜这样的东西应该可以解决问题

final LineStyle style2=
document.createAndAddStyle()
.withId("linestyleExample2")
.createAndSetLineStyle()
.withColor("ff008cff")
.withWidth(5.0d);

关于java - KML 文件中不可见的线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7555278/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com