Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opt-out Z interpolation #715

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -25,7 +26,6 @@
public class RobustLineIntersector
extends LineIntersector
{

public RobustLineIntersector() {
}

Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
bjornharrtell marked this conversation as resolved.
Show resolved Hide resolved

/**
* Internal class which encapsulates the runtime switch to Z-interpolate when applicable.
* <p>
* <ul>
* <li><code>jts.zinterpolating=false</code> - (default) do not Z-interpolate
* <li><code>jts.zinterpolating=true</code> - Z-interpolate
* </ul>
*
* @author bjornharrtell
*
*/
public class ZInterpolating {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a lot of boilerplate to hold a boolean value decision, can this class take on more responsibility and swap between interpolation approaches as a stratagy object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it feel like boilerplate. I have difficulties properly understanding/interpreting what you mean with "take on more responsibility and swap between interpolation approaches as a stratagy object". In either case it's intentionally done this way because it is modeled after the other existing system property option jts.overlay and broken out into a self contained class because it is affecting two very separate things (RobustLineIntersector and ElevationModel), and I wanted to do it in a way that is as non intrusive as possible on the existing source.

I suppose system wide settings could be done with smarter and nicer desig but I don't think this is the place to do such general improvement and restructuring.

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down