我有一組使用kml.linestring連接的點。但是,我想根據這些行的速度對這些行進行顏色編碼(我可以使用這些行)>問題是,我的kml文件在Google地圖上呈現時,根本沒有渲染線條:(線條在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生成的(它首先生成很多linestyles,然後將它們逐一分配給這些點。 )
它將幫助,如果你也將包括生成的KML在你的問題。或者至少是它的一小部分,說明問題。 –
當然。讓我這樣做。 – crazyaboutliv