diff --git a/modules/core/src/main/java/org/locationtech/jts/algorithm/RobustLineIntersector.java b/modules/core/src/main/java/org/locationtech/jts/algorithm/RobustLineIntersector.java index 8f35de6947..70fff839cf 100644 --- a/modules/core/src/main/java/org/locationtech/jts/algorithm/RobustLineIntersector.java +++ b/modules/core/src/main/java/org/locationtech/jts/algorithm/RobustLineIntersector.java @@ -16,6 +16,7 @@ */ import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Envelope; +import org.locationtech.jts.geom.ZInterpolating; /** * A robust version of {@link LineIntersector}. @@ -25,7 +26,6 @@ public class RobustLineIntersector extends LineIntersector { - public RobustLineIntersector() { } @@ -414,6 +414,8 @@ private static double zGetOrInterpolate(Coordinate p, Coordinate p1, Coordinate * @return the interpolated Z value (may be NaN) */ private static double zInterpolate(Coordinate p, Coordinate p1, Coordinate p2) { + if (!ZInterpolating.getZInterpolating()) + return Double.NaN; double p1z = p1.getZ(); double p2z = p2.getZ(); if (Double.isNaN(p1z)) { diff --git a/modules/core/src/main/java/org/locationtech/jts/geom/ZInterpolating.java b/modules/core/src/main/java/org/locationtech/jts/geom/ZInterpolating.java new file mode 100644 index 0000000000..d148a5fced --- /dev/null +++ b/modules/core/src/main/java/org/locationtech/jts/geom/ZInterpolating.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016 Vivid Solutions. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * and Eclipse Distribution License v. 1.0 which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html + * and the Eclipse Distribution License is available at + * + * http://www.eclipse.org/org/documents/edl-v10.php. + */ +package org.locationtech.jts.geom; + +/** + * Internal class which encapsulates the runtime switch to Z-interpolate when applicable. + *

+ *

+ * + * @author bjornharrtell + * + */ +public class ZInterpolating { + public static String ZINTERPOLATING_PROPERTY_NAME = "jts.zinterpolating"; + public static String ZINTERPOLATING_PROPERTY_VALUE_TRUE = "true"; + public static String ZINTERPOLATING_PROPERTY_VALUE_FALSE = "false"; + public static boolean ZINTERPOLATING_DEFAULT = true; + private static boolean isZInterpolating = ZINTERPOLATING_DEFAULT; + + static { + setZInterpolatingImpl(System.getProperty(ZINTERPOLATING_PROPERTY_NAME)); + } + + public static boolean getZInterpolating() { + return isZInterpolating; + } + + public static void setZInterpolating(boolean zInterpolating) { + isZInterpolating = zInterpolating; + } + + private static void setZInterpolatingImpl(String isZInterpolatingCode) { + if (isZInterpolatingCode == null) + return; + isZInterpolating = ZINTERPOLATING_DEFAULT; + if (ZINTERPOLATING_PROPERTY_VALUE_TRUE.equalsIgnoreCase(isZInterpolatingCode)) + isZInterpolating = true; + } +} diff --git a/modules/core/src/main/java/org/locationtech/jts/operation/overlayng/ElevationModel.java b/modules/core/src/main/java/org/locationtech/jts/operation/overlayng/ElevationModel.java index 653a1c0317..0f88b085c6 100644 --- a/modules/core/src/main/java/org/locationtech/jts/operation/overlayng/ElevationModel.java +++ b/modules/core/src/main/java/org/locationtech/jts/operation/overlayng/ElevationModel.java @@ -16,6 +16,7 @@ import org.locationtech.jts.geom.CoordinateSequenceFilter; import org.locationtech.jts.geom.Envelope; import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.ZInterpolating; import org.locationtech.jts.math.MathUtil; /** @@ -192,6 +193,10 @@ public double getZ(double x, double y) { * @param geom the geometry to populate Z values for */ public void populateZ(Geometry geom) { + // short-circuit if ZInterpolation is globally turned off + if (!ZInterpolating.getZInterpolating()) + return; + // short-circuit if no Zs are present in model if (! hasZValue) return; diff --git a/modules/core/src/main/java/org/locationtech/jts/operation/overlayng/OverlayNG.java b/modules/core/src/main/java/org/locationtech/jts/operation/overlayng/OverlayNG.java index 8152a286e7..baccd583d1 100644 --- a/modules/core/src/main/java/org/locationtech/jts/operation/overlayng/OverlayNG.java +++ b/modules/core/src/main/java/org/locationtech/jts/operation/overlayng/OverlayNG.java @@ -486,7 +486,7 @@ else if (! inputGeom.isSingle() && inputGeom.hasPoints()) { result = computeEdgeOverlay(); } /** - * This is a no-op if the elevation model was not computed due to Z not present + * This is a no-op if the elevation model was not computed due to Z not present or if Z interpolation is turned off */ elevModel.populateZ(result); return result;