KML 文件上不可见的线条
我有一组使用 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 生成的(其中生成一个首先有很多线型,然后将它们一一分配给点)。
I have a set of points that are joined by using kml.linestring . But, I want to colour code those lines based on the speeds at those lines ( which I have available)> The problem is that my kml file, when rendered on google maps, doesn't render the lines at all :(
If I do the same thing for a different set of co-ordinates, which are polygons, it works totally fine. Infact, if I do not colour code the lines and just use the default colour, it renders the lines perfectly. But, I need the colour coding. I am attaching the code below:
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));
}
This is how it looks:
This is how it should look:
Fragment from the faulty kml file ( which doesn't represent any points ) :
<?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>
Fragment from one which does represent it correctly :
<?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">
They are different as the second one has been generated using Python ( which generates a lot of linestyles first and then assigns them one by one to the points . )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原因是在“错误”kml 中,您的线条样式有明确的宽度定义 0.0 将其更改为正数(5.0 左右),您将看到您的线条或完全删除它以使用默认宽度
Codewise 我不'不知道你正在使用的库,但我想这样的东西应该可以解决问题
The reason is that in the 'faulty' kml your linestyles have a explicit width definition of 0.0 Change it to a positive number (5.0 or so) and you'll see your lines or remove it completly to use the default width
Codewise I don't know the lib you are using but I would guess something like this should do the trick