Skip to content

Commit

Permalink
Make some instances reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Dec 12, 2024
1 parent bf32f91 commit 7097105
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

public class RetainUpFromPolygon implements GtfsTransformStrategy {

private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory();
private final WKTReader wktReader = new WKTReader(GEOMETRY_FACTORY);

@CsvField(optional = false)
private String polygon;

Expand Down Expand Up @@ -73,9 +76,8 @@ public void run(TransformContext transformContext, GtfsMutableRelationalDao gtfs
* @throws IllegalArgumentException if the WKT string is invalid or cannot be parsed.
*/
private Geometry buildPolygon(String polygonWKT) {
WKTReader reader = new WKTReader();
try{
return reader.read(polygonWKT);
return wktReader.read(polygonWKT);
} catch (ParseException e){
throw new IllegalArgumentException(
String.format("Error parsing WKT string: %s", e.getMessage()), e
Expand All @@ -91,8 +93,7 @@ private Geometry buildPolygon(String polygonWKT) {
* @return true if the point is within the boundaries of the geometry; false otherwise.
*/
private boolean insidePolygon(Geometry geometry, double lon, double lat) {
GeometryFactory geometryFactory = new GeometryFactory();
Point point = geometryFactory.createPoint(new Coordinate(lon, lat));
Point point = GEOMETRY_FACTORY.createPoint(new Coordinate(lon, lat));
return geometry.contains(point);
}

Expand Down

0 comments on commit 7097105

Please sign in to comment.