KML을 구문 분석 할 수있는 라이브러리가 있습니까?자바에서 KML 읽기 및 구문 분석
답변
자신의 라이브러리를 만들지 만 코드를 작성하지 않아도됩니다.
나는 http://code.google.com/apis/kml/documentation/kmlreference.html을 제안합니다. 거기에서 XML Schema을 얻을 수 있습니다. 스키마를 얻었 으면 JAXB을 사용하여 KML을 쉽게 파싱하고 쓰는 객체 트리를 생성 할 수 있습니다.
This may also be a good resource 다른 누군가가 이미 완료 한 것처럼 보입니다.
약간의 연습을 위해이 길을갔습니다. 스키마가 컴파일러를 통해 실행될 때 충돌하는 몇 가지 요소가 있다는 점에서 약간의 문제가 있습니다. 주요한 것은 없지만 몇 가지 맞춤 바인딩을 작성할 준비가되어 있어야합니다. – CurtainDog
는 XML 당신이 라이브러리뿐만 아니라 유망 보인다 ++
을 파서와 데이터를 읽을 수 있지만 아직 거기에 자바에 대한 바인딩을 가지고 http://code.google.com/p/libkml/에서 사용할 수있는 lib 디렉토리하지만 lib 디렉토리가 C에 할 수 있기 때문에 :
http://code.google.com/p/javaapiforkml/
라이브러리는 지금까지 지원을 제공합니다.
여기 내 JSOUP 구현이가 KML 데이터를 처리하는 경우에 정말 잘
public ArrayList<ArrayList<LatLng>> getCoordinateArrays() {
ArrayList<ArrayList<LatLng>> allTracks = new ArrayList<ArrayList<LatLng>>();
try {
StringBuilder buf = new StringBuilder();
InputStream json = MyApplication.getInstance().getAssets().open("track.kml");
BufferedReader in = new BufferedReader(new InputStreamReader(json));
String str;
String buffer;
while ((str = in.readLine()) != null) {
buf.append(str);
}
in.close();
String html = buf.toString();
Document doc = Jsoup.parse(html, "", Parser.xmlParser());
ArrayList<String> tracksString = new ArrayList<String>();
for (Element e : doc.select("coordinates")) {
tracksString.add(e.toString().replace("<coordinates>", "").replace("</coordinates>", ""));
}
for (int i = 0; i < tracksString.size(); i++) {
ArrayList<LatLng> oneTrack = new ArrayList<LatLng>();
ArrayList<String> oneTrackString = new ArrayList<String>(Arrays.asList(tracksString.get(i).split("\\s+")));
for (int k = 1; k < oneTrackString.size(); k++) {
LatLng latLng = new LatLng(Double.parseDouble(oneTrackString.get(k).split(",")[0]),
Double.parseDouble(oneTrackString.get(k).split(",")[1]));
oneTrack.add(latLng);
}
allTracks.add(oneTrack);
}}
} catch (Exception e) {
e.printStackTrace();
}
return allTracks;
}
osmbonuspack 일을하는 데 도움이 희망입니다.
당신은 여러 선택() 메서드 호출을 할 수 있습니다 안드로이드 스튜디오 :
dependencies {
compile 'org.jsoup:jsoup:1.8.1'
}
// find a way to read the file and store it in a string
String inputFileContents = "";
String xmlContent = inputFileContents;
Document doc = Jsoup.parse(xml, "", Parser.xmlParser());
for(Element e : doc.select("LineString").select("coordinates")) {
// the contents
System.out.println(e.text());
}
를 사용하는 경우. 나는에 코드를 단순화 :
Element e = doc.select("LineString").select("coordinates").first();
오류 : (20, 29) java : parse (org.jsoup.nodes.Document.OutputSettings.Syntax, java.lang.String, org.jsoup.parser.Parser)에 적합한 메소드가 없습니다. method org.jsoup.Jsoup .parse (java.lang.String, java.lang.String, org.jsoup.parser.Parser) 해당 사항 없음 (인수 불일치 : org.jsoup.nodes.Document.OutputSettings.Syntax는 java.lang으로 변환 될 수 없습니다. 문자열) 메서드 – user3871754
내 수입 : import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.parser.Parser; import static org.jsoup.nodes.Document.OutputSettings.Syntax.xml; – user3871754
이 구조를 XML 파일을 포함하는 다른 옵션은 KML 파일이 정상 파일입니다. 이 파일에서 검색을 하나 개의 특정 장소에 대한
private static void readKML(InputStream fileKML, String nameCoordinates) {
String column = null;
Boolean folder = Boolean.TRUE;
Boolean placemark = Boolean.FALSE;
Boolean placeCorrect = Boolean.FALSE;
BufferedReader br = new BufferedReader(new InputStreamReader(fileKML));
try {
while ((column = br.readLine()) != null) {
if (folder) {
int ifolder = column.indexOf("<Folder>");
if (ifolder != -1) {
folder = Boolean.FALSE;
placemark = Boolean.TRUE;
continue;
}
}
if (placemark) {
String tmpLine = nameCoordinates;
tmpLine = tmpLine.replaceAll("\t", "");
tmpLine = tmpLine.replaceAll(" ", "");
String tmpColumn = column;
tmpColumn = tmpColumn.replaceAll("\t", "");
tmpColumn = tmpColumn.replaceAll(" ", "");
int name = tmpColumn.indexOf(tmpLine);
if (name != -1) {
placemark = Boolean.FALSE;
placeCorrect = Boolean.TRUE;
continue;
}
}
if (placeCorrect) {
int coordin = column.indexOf("<coordinates>");
if (coordin != -1) {
String tmpCoordin = column;
tmpCoordin = tmpCoordin.replaceAll(" ", "");
tmpCoordin = tmpCoordin.replaceAll("\t", "");
tmpCoordin = tmpCoordin.replaceAll("<coordinates>", "");
tmpCoordin = tmpCoordin
.replaceAll("</coordinates>", "");
String[] coo = tmpCoordin.split(",");
System.out.println("LONG: "+coo[0]);
System.out.println("LATI: "+coo[1])
break;
}
}
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
return cresp;
}
여기에 세미콜론이 없습니다 : System.out.println ("LATI :"+ coo [1]) – user3871754
- 1. 쿠키 읽기 및 구문 분석
- 2. 자바에서 문자열을 HTML로 구문 분석
- 3. 자바에서 XML 파일 구문 분석
- 4. C에서 구문 분석 및 데이터 프레임 읽기?
- 5. QML XmlListModel 및 car2go xml 구문 분석
- 6. 안드로이드에서 KMF 구문 분석
- 7. KML 파일에서 일부 요소를 구문 분석 할 때의 문제
- 8. MKMapView 및 addOverlay - kml에서 오버레이 구문 분석
- 9. C#에서 Excel 파일 읽기 및 구문 분석
- 10. C# 멀티 스레딩 파일 읽기 및 페이지 구문 분석
- 11. 자바에서 텍스트 파일 읽기
- 12. 자바에서 형태소 분석 라이브러리
- 13. PHP URL 구문 분석 및
- 14. jQuery를 - 구문 분석 및 jQuery로
- 15. PHP 및 XML 구문 분석
- 16. XML 구문 분석 및 사용
- 17. 오라클 구문 분석 및 대체
- 18. XML 검색 및 구문 분석
- 19. 구문 분석 날짜 및 시간
- 20. Sax 구문 분석 및 인코딩
- 21. wsdl 및 xsd 구문 분석
- 22. 템플릿 구문 분석 및 반영
- 23. PHP에서 구문 분석 및 편집
- 24. 문자열 구문 분석 및 문자열
- 25. 분할 및 구문 분석 window.location.hash
- 26. Java에서 동영상 구문 분석
- 27. Java 날짜 구문 분석
- 28. 자바에서 바코드 읽기
- 29. 는 자바에서 고정 된 형식의 텍스트 파일을 구문 분석
- 30. ASIHTTPRequest 및 ASINetworkQueue 및 JSON 구문 분석
여기 Jsoup 내 구현의 여러 장소 표시 다른 예입니다 http://stackoverflow.com/questions/1140144/read-and-parse-kml- in-java/21283827 # 21283827 – alexandrius