Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gk
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
micro_app
gk
Commits
fd7d4d7c
Commit
fd7d4d7c
authored
May 07, 2020
by
sunyuhua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
部分kml文件导入不成功
parent
a7f0e7a2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
4 deletions
+25
-4
KmlParserUtil.java
...m/dlbridge/jadp/plugins/cmpt/utils/gps/KmlParserUtil.java
+25
-4
No files found.
src/main/java/com/dlbridge/jadp/plugins/cmpt/utils/gps/KmlParserUtil.java
View file @
fd7d4d7c
...
@@ -14,9 +14,15 @@ import java.util.HashMap;
...
@@ -14,9 +14,15 @@ import java.util.HashMap;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* KML格式的经纬度的转化方案
*/
public
class
KmlParserUtil
{
public
class
KmlParserUtil
{
public
static
String
parseKml
(
InputStream
input
)
{
public
static
String
parseKml
(
InputStream
input
)
{
Route
route
=
new
Route
();
Route
route
=
new
Route
();
SAXReader
reader
=
new
SAXReader
();
SAXReader
reader
=
new
SAXReader
();
...
@@ -36,7 +42,14 @@ public class KmlParserUtil {
...
@@ -36,7 +42,14 @@ public class KmlParserUtil {
placeMark
=
doc
.
selectNodes
(
"//default:Folder/default:Placemark"
);
placeMark
=
doc
.
selectNodes
(
"//default:Folder/default:Placemark"
);
for
(
Node
node
:
selectNodes
)
{
for
(
Node
node
:
selectNodes
)
{
String
lineString
=
node
.
getText
();
String
lineString
=
node
.
getText
();
String
[]
array
=
lineString
.
split
(
"\n"
);
Pattern
CRLF
=
Pattern
.
compile
(
"(\r\n|\r|\n|\n\r)"
);
Matcher
m
=
CRLF
.
matcher
(
lineString
);
String
[]
array
=
null
;
if
(
m
.
find
())
{
array
=
lineString
.
split
(
"\n"
);
}
else
{
array
=
lineString
.
split
(
" "
);
}
TracePoint
tracePoint
;
TracePoint
tracePoint
;
for
(
String
string
:
array
)
{
for
(
String
string
:
array
)
{
if
(
string
.
trim
().
length
()
==
0
)
{
if
(
string
.
trim
().
length
()
==
0
)
{
...
@@ -46,12 +59,13 @@ public class KmlParserUtil {
...
@@ -46,12 +59,13 @@ public class KmlParserUtil {
String
[]
location
=
string
.
split
(
","
);
String
[]
location
=
string
.
split
(
","
);
tracePoint
.
setLongitude
(
Double
.
parseDouble
(
location
[
0
].
trim
()));
tracePoint
.
setLongitude
(
Double
.
parseDouble
(
location
[
0
].
trim
()));
tracePoint
.
setLatitude
(
Double
.
parseDouble
(
location
[
1
].
trim
()));
tracePoint
.
setLatitude
(
Double
.
parseDouble
(
location
[
1
].
trim
()));
if
(
location
.
length
>=
3
)
{
if
(
location
.
length
>=
3
&&
"0.0"
.
equals
(
location
[
2
].
trim
())
)
{
tracePoint
.
setAltitude
(
Float
.
parseFloat
(
location
[
2
].
trim
()));
tracePoint
.
setAltitude
(
Float
.
parseFloat
(
location
[
2
].
trim
()));
}
else
{
}
else
{
tracePoint
.
setAltitude
(
0
);
tracePoint
.
setAltitude
(
0
);
}
}
route
.
getTracePoint
().
add
(
tracePoint
);
route
.
getTracePoint
().
add
(
tracePoint
);
}
}
}
}
}
else
{
}
else
{
...
@@ -60,7 +74,14 @@ public class KmlParserUtil {
...
@@ -60,7 +74,14 @@ public class KmlParserUtil {
placeMark
=
doc
.
selectNodes
(
"//default:Folder/default:Placemark"
);
placeMark
=
doc
.
selectNodes
(
"//default:Folder/default:Placemark"
);
for
(
Node
node
:
nodeList
)
{
for
(
Node
node
:
nodeList
)
{
String
lineString
=
node
.
getText
();
String
lineString
=
node
.
getText
();
String
[]
array
=
lineString
.
split
(
" "
);
Pattern
CRLF
=
Pattern
.
compile
(
"(\r\n|\r|\n|\n\r)"
);
Matcher
m
=
CRLF
.
matcher
(
lineString
);
String
[]
array
=
null
;
if
(
m
.
find
())
{
array
=
lineString
.
split
(
"\n"
);
}
else
{
array
=
lineString
.
split
(
" "
);
}
TracePoint
tracePoint
;
TracePoint
tracePoint
;
if
(
array
.
length
==
0
)
{
if
(
array
.
length
==
0
)
{
continue
;
continue
;
...
@@ -68,7 +89,7 @@ public class KmlParserUtil {
...
@@ -68,7 +89,7 @@ public class KmlParserUtil {
tracePoint
=
new
TracePoint
();
tracePoint
=
new
TracePoint
();
tracePoint
.
setLongitude
(
Double
.
parseDouble
(
array
[
0
].
trim
()));
tracePoint
.
setLongitude
(
Double
.
parseDouble
(
array
[
0
].
trim
()));
tracePoint
.
setLatitude
(
Double
.
parseDouble
(
array
[
1
].
trim
()));
tracePoint
.
setLatitude
(
Double
.
parseDouble
(
array
[
1
].
trim
()));
if
(
array
.
length
>=
3
)
{
if
(
array
.
length
>=
3
&&
"0.0"
.
equals
(
array
[
2
].
trim
())
)
{
tracePoint
.
setAltitude
(
Float
.
parseFloat
(
array
[
2
].
trim
()));
tracePoint
.
setAltitude
(
Float
.
parseFloat
(
array
[
2
].
trim
()));
}
else
{
}
else
{
tracePoint
.
setAltitude
(
0
);
tracePoint
.
setAltitude
(
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment