Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions gxgeospatial/src/main/java/com/genexus/GXGeospatial.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.locationtech.spatial4j.distance.GeodesicSphereDistCalc;
import org.locationtech.spatial4j.io.*;
import org.locationtech.spatial4j.shape.*;
import org.locationtech.spatial4j.shape.*;
import org.locationtech.spatial4j.shape.impl.BufferedLineString;
import org.locationtech.spatial4j.shape.jts.*;

import net.sf.geographiclib.PolygonArea;
Expand Down Expand Up @@ -231,6 +231,7 @@ public void fromWKT(String wktString)
}
ShapeReader rdr = ctx.getFormats().getWktReader();
readShape(rdr, wkText);

if (lastErrorCode != 0 && wktString.contains(",")) {
String[] coords = wktString.split(",", 2);
double dlat = Double.parseDouble(coords[0].trim());
Expand Down Expand Up @@ -351,12 +352,44 @@ public double area()
return 0;
}

public Shape lineStringToJTS(GXGeospatial geowith)
{
String wText = geowith.toWKT();
SpatialContextFactory euclidean = new JtsSpatialContextFactory();
euclidean.shapeFactoryClass = org.locationtech.spatial4j.shape.jts.JtsShapeFactory.class;
euclidean.geo = false;
SpatialContext context = euclidean.newSpatialContext();
ShapeReader rdr = context.getFormats().getWktReader();
try{
Shape cShape = rdr.read(wText);
return cShape;
}
catch (Exception ex)
{
GXutil.writeLogError("Error: GXGeospatial " + ex.toString());
return null;
}
}

public boolean intersect(GXGeospatial geowith)
{
if (this.innerValue() != null && geowith.innerValue() != null) {
SpatialRelation rel = this.innerValue().relate(geowith.innerValue());
return (rel.intersects());
if (this.innerValue() != null && geowith.innerValue() != null) {
Shape cShape2 = geowith.innerValue();
Shape cShape = this.innerValue();
if (this.innerValue() instanceof BufferedLineString) {
cShape = lineStringToJTS(this);
if (cShape == null)
return false;
}
if (geowith.innerValue() instanceof BufferedLineString)
{
cShape2 = lineStringToJTS(geowith);
if (cShape2 == null)
return false;
}

SpatialRelation rel = cShape.relate(cShape2);
return (rel.intersects());
}
else {
return false;
Expand Down