Commit 52c81885a5f3ef263466edd430b8d41865bb46b7

Authored by 王通
1 parent b070e462

1.

src/main/java/com/bsth/util/GeoConverter.java
... ... @@ -27,7 +27,7 @@ public class GeoConverter {
27 27 StringBuilder sb = new StringBuilder("POLYGON((");
28 28 wkt = wkt.substring(9, wkt.length() - 2);
29 29 for (String point : wkt.split(",")) {
30   - CoordinateConverter.Location location = CoordinateConverter.LocationMake(point);
  30 + CoordinateConverter.Location location = CoordinateConverter.LocationMake(point.trim());
31 31 location = CoordinateConverter.transformFromBDToWGS(location);
32 32 sb.append(location.toString()).append(",");
33 33 }
... ... @@ -43,7 +43,7 @@ public class GeoConverter {
43 43 StringBuilder sb = new StringBuilder("LINESTRING(");
44 44 wkt = wkt.substring(11, wkt.length() - 1);
45 45 for (String coordinate : wkt.split(",")) {
46   - CoordinateConverter.Location location = CoordinateConverter.LocationMake(coordinate);
  46 + CoordinateConverter.Location location = CoordinateConverter.LocationMake(coordinate.trim());
47 47 location = CoordinateConverter.transformFromBDToWGS(location);
48 48 sb.append(location.toString()).append(",");
49 49 }
... ... @@ -51,4 +51,20 @@ public class GeoConverter {
51 51  
52 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 }
... ...