Commit 52c81885a5f3ef263466edd430b8d41865bb46b7
1 parent
b070e462
1.
Showing
1 changed file
with
18 additions
and
2 deletions
src/main/java/com/bsth/util/GeoConverter.java
| @@ -27,7 +27,7 @@ public class GeoConverter { | @@ -27,7 +27,7 @@ public class GeoConverter { | ||
| 27 | StringBuilder sb = new StringBuilder("POLYGON(("); | 27 | StringBuilder sb = new StringBuilder("POLYGON(("); |
| 28 | wkt = wkt.substring(9, wkt.length() - 2); | 28 | wkt = wkt.substring(9, wkt.length() - 2); |
| 29 | for (String point : wkt.split(",")) { | 29 | for (String point : wkt.split(",")) { |
| 30 | - CoordinateConverter.Location location = CoordinateConverter.LocationMake(point); | 30 | + CoordinateConverter.Location location = CoordinateConverter.LocationMake(point.trim()); |
| 31 | location = CoordinateConverter.transformFromBDToWGS(location); | 31 | location = CoordinateConverter.transformFromBDToWGS(location); |
| 32 | sb.append(location.toString()).append(","); | 32 | sb.append(location.toString()).append(","); |
| 33 | } | 33 | } |
| @@ -43,7 +43,7 @@ public class GeoConverter { | @@ -43,7 +43,7 @@ public class GeoConverter { | ||
| 43 | StringBuilder sb = new StringBuilder("LINESTRING("); | 43 | StringBuilder sb = new StringBuilder("LINESTRING("); |
| 44 | wkt = wkt.substring(11, wkt.length() - 1); | 44 | wkt = wkt.substring(11, wkt.length() - 1); |
| 45 | for (String coordinate : wkt.split(",")) { | 45 | for (String coordinate : wkt.split(",")) { |
| 46 | - CoordinateConverter.Location location = CoordinateConverter.LocationMake(coordinate); | 46 | + CoordinateConverter.Location location = CoordinateConverter.LocationMake(coordinate.trim()); |
| 47 | location = CoordinateConverter.transformFromBDToWGS(location); | 47 | location = CoordinateConverter.transformFromBDToWGS(location); |
| 48 | sb.append(location.toString()).append(","); | 48 | sb.append(location.toString()).append(","); |
| 49 | } | 49 | } |
| @@ -51,4 +51,20 @@ public class GeoConverter { | @@ -51,4 +51,20 @@ public class GeoConverter { | ||
| 51 | 51 | ||
| 52 | return (LineString) Wkt.fromWkt(sb.toString()); | 52 | return (LineString) Wkt.fromWkt(sb.toString()); |
| 53 | } | 53 | } |
| 54 | + | ||
| 55 | + public static LineString lineStringWgs2bd(String wkt) { | ||
| 56 | + if (wkt.indexOf("LINESTRING") != 0) { | ||
| 57 | + throw new IllegalArgumentException("异常的LineString wkt数据"); | ||
| 58 | + } | ||
| 59 | + StringBuilder sb = new StringBuilder("LINESTRING("); | ||
| 60 | + wkt = wkt.substring(11, wkt.length() - 1); | ||
| 61 | + for (String coordinate : wkt.split(",")) { | ||
| 62 | + CoordinateConverter.Location location = CoordinateConverter.LocationMake(coordinate.trim()); | ||
| 63 | + location = CoordinateConverter.transformFromWGSToBD(location); | ||
| 64 | + sb.append(location.toString()).append(","); | ||
| 65 | + } | ||
| 66 | + sb.deleteCharAt(sb.length() - 1).append(")"); | ||
| 67 | + | ||
| 68 | + return (LineString) Wkt.fromWkt(sb.toString()); | ||
| 69 | + } | ||
| 54 | } | 70 | } |