2011-09-26 7 views
2

kml.linestring을 사용하여 결합 된 점 집합이 있습니다. 그러나, 나는 그 라인에서 속도를 기반으로 그 라인들을 색칠하고 싶다. (나는 사용할 수있다.)> 문제는 나의 kml 파일이 구글 맵에서 렌더링 될 때 라인을 전혀 렌더링하지 않는다는 것이다. (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

이 보이게하는 방법입니다 : 결함이있는 KML 파일에서

Did this using Python

조각 (어떤 점을 표현하지 않는) : 하나에서

<?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"> 

두 번째와 다릅니다. 하나는 파이썬을 사용하여 생성되었습니다 (많은 선 스타일을 먼저 생성 한 다음 점에 하나씩 할당합니다).)

+0

에게해야 할 거라 생각

Codewise 폭입니다. 또는 적어도 그 작은 조각, 문제를 보여줍니다. –

+0

예. 내가 해줄거야. – crazyaboutliv

답변

2

'faulty'kml에서 선 스타일의 너비는 0.0으로 명시 적으로 정의되어 있기 때문에 양수로 변경하면 (5.0 정도) 선이 표시되거나 기본값을 사용하도록 완료됩니다. 내가 사용하는 lib 디렉토리를 모르는하지만이 같은 귀하의 질문에 당신은 또한 생성 된 KML을 포함 할 경우이, 도움이 될 트릭

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

감사합니다.이 트릭을했습니다. 그러나, 나는 약간 놀랐다. 파이썬을 사용할 때 너비를 지정하지 않으면 자동으로 기본 너비가 사용됩니다. API가 너비가 0 인 행을 어떻게 가정 할 수 있습니까? - / – crazyaboutliv

관련 문제