|
19 | 19 | import org.locationtech.spatial4j.distance.GeodesicSphereDistCalc; |
20 | 20 | import org.locationtech.spatial4j.io.*; |
21 | 21 | import org.locationtech.spatial4j.shape.*; |
22 | | -import org.locationtech.spatial4j.shape.*; |
| 22 | +import org.locationtech.spatial4j.shape.impl.BufferedLineString; |
23 | 23 | import org.locationtech.spatial4j.shape.jts.*; |
24 | 24 |
|
25 | 25 | import net.sf.geographiclib.PolygonArea; |
@@ -231,6 +231,7 @@ public void fromWKT(String wktString) |
231 | 231 | } |
232 | 232 | ShapeReader rdr = ctx.getFormats().getWktReader(); |
233 | 233 | readShape(rdr, wkText); |
| 234 | + |
234 | 235 | if (lastErrorCode != 0 && wktString.contains(",")) { |
235 | 236 | String[] coords = wktString.split(",", 2); |
236 | 237 | double dlat = Double.parseDouble(coords[0].trim()); |
@@ -351,12 +352,44 @@ public double area() |
351 | 352 | return 0; |
352 | 353 | } |
353 | 354 |
|
| 355 | + public Shape lineStringToJTS(GXGeospatial geowith) |
| 356 | + { |
| 357 | + String wText = geowith.toWKT(); |
| 358 | + SpatialContextFactory euclidean = new JtsSpatialContextFactory(); |
| 359 | + euclidean.shapeFactoryClass = org.locationtech.spatial4j.shape.jts.JtsShapeFactory.class; |
| 360 | + euclidean.geo = false; |
| 361 | + SpatialContext context = euclidean.newSpatialContext(); |
| 362 | + ShapeReader rdr = context.getFormats().getWktReader(); |
| 363 | + try{ |
| 364 | + Shape cShape = rdr.read(wText); |
| 365 | + return cShape; |
| 366 | + } |
| 367 | + catch (Exception ex) |
| 368 | + { |
| 369 | + GXutil.writeLogError("Error: GXGeospatial " + ex.toString()); |
| 370 | + return null; |
| 371 | + } |
| 372 | + } |
354 | 373 |
|
355 | 374 | public boolean intersect(GXGeospatial geowith) |
356 | 375 | { |
357 | | - if (this.innerValue() != null && geowith.innerValue() != null) { |
358 | | - SpatialRelation rel = this.innerValue().relate(geowith.innerValue()); |
359 | | - return (rel.intersects()); |
| 376 | + if (this.innerValue() != null && geowith.innerValue() != null) { |
| 377 | + Shape cShape2 = geowith.innerValue(); |
| 378 | + Shape cShape = this.innerValue(); |
| 379 | + if (this.innerValue() instanceof BufferedLineString) { |
| 380 | + cShape = lineStringToJTS(this); |
| 381 | + if (cShape == null) |
| 382 | + return false; |
| 383 | + } |
| 384 | + if (geowith.innerValue() instanceof BufferedLineString) |
| 385 | + { |
| 386 | + cShape2 = lineStringToJTS(geowith); |
| 387 | + if (cShape2 == null) |
| 388 | + return false; |
| 389 | + } |
| 390 | + |
| 391 | + SpatialRelation rel = cShape.relate(cShape2); |
| 392 | + return (rel.intersects()); |
360 | 393 | } |
361 | 394 | else { |
362 | 395 | return false; |
|
0 commit comments