Skip to content

Commit 6bb193e

Browse files
authored
Fixed error in interswect function. Issue 91155
- Intersect between line and polygon fails when not optimized. Fixed. (#456)
1 parent f36fab9 commit 6bb193e

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

gxgeospatial/src/main/java/com/genexus/GXGeospatial.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.locationtech.spatial4j.distance.GeodesicSphereDistCalc;
2020
import org.locationtech.spatial4j.io.*;
2121
import org.locationtech.spatial4j.shape.*;
22-
import org.locationtech.spatial4j.shape.*;
22+
import org.locationtech.spatial4j.shape.impl.BufferedLineString;
2323
import org.locationtech.spatial4j.shape.jts.*;
2424

2525
import net.sf.geographiclib.PolygonArea;
@@ -231,6 +231,7 @@ public void fromWKT(String wktString)
231231
}
232232
ShapeReader rdr = ctx.getFormats().getWktReader();
233233
readShape(rdr, wkText);
234+
234235
if (lastErrorCode != 0 && wktString.contains(",")) {
235236
String[] coords = wktString.split(",", 2);
236237
double dlat = Double.parseDouble(coords[0].trim());
@@ -351,12 +352,44 @@ public double area()
351352
return 0;
352353
}
353354

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+
}
354373

355374
public boolean intersect(GXGeospatial geowith)
356375
{
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());
360393
}
361394
else {
362395
return false;

0 commit comments

Comments
 (0)