我有一组使用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));
}
它的外观如下:
这应该是它的样子:
来自故障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生成的(它首先生成许多线条样式,然后逐个分配给它们。)
答案 0 :(得分:2)
原因是在'错误'kml中你的线条明确的宽度定义为0.0将它改为正数(5.0左右)你会看到你的线条或完全删除它以使用默认宽度< / p>
Codewise我不知道你正在使用的lib,但我猜这样的东西应该可以解决这个问题
final LineStyle style2=
document.createAndAddStyle()
.withId("linestyleExample2")
.createAndSetLineStyle()
.withColor("ff008cff")
.withWidth(5.0d);