/** * Unwrap a coordinate {@link Point} from a Feature with a Point geometry. * * @param obj any value * @return a coordinate * @see <a href="http://turfjs.org/docs/#getcoord">Turf getCoord documentation</a> * @since 3.2.0 */ public static Point getCoord(Feature obj) { if (obj.geometry() instanceof Point) { return (Point) obj.geometry(); } throw new TurfException("A Feature with a Point geometry is required."); } }
/** * Enforce expectations about types of GeoJson objects for Turf. * * @param value any GeoJson object * @param type expected GeoJson type * @param name name of calling function * @see <a href="http://turfjs.org/docs/#geojsontype">Turf geojsonType documentation</a> * @since 1.2.0 */ public static void geojsonType(GeoJson value, String type, String name) { if (TextUtils.isEmpty(type) || TextUtils.isEmpty(name)) { throw new TurfException("Type and name required"); } if (value == null || !value.type().equals(type)) { throw new TurfException("Invalid input to " + name + ": must be a " + type + ", given " + (value != null ? value.type() : " null")); } }
/** * Enforce expectations about types of {@link Feature} inputs for Turf. Internally this uses * {@link Feature#type()} to judge geometry types. * * @param feature with an expected geometry type * @param type type expected GeoJson type * @param name name of calling function * @see <a href="http://turfjs.org/docs/#featureof">Turf featureOf documentation</a> * @since 1.2.0 */ public static void featureOf(Feature feature, String type, String name) { if (TextUtils.isEmpty(name)) { throw new TurfException(".featureOf() requires a name"); } if (feature == null || !feature.type().equals("Feature") || feature.geometry() == null) { throw new TurfException(String.format( "Invalid input to %s, Feature with geometry required", name)); } if (feature.geometry() == null || !feature.geometry().type().equals(type)) { throw new TurfException(String.format( "Invalid input to %s: must be a %s, given %s", name, type, feature.geometry().type())); } }
throw new TurfException("Turf lineSlice requires a LineString made up of at least 2 " + "coordinates."); } else if (startPt.equals(stopPt)) { throw new TurfException("Start and stop points in Turf lineSlice cannot equal each other.");
throw new TurfException("collectionOf() requires a name"); throw new TurfException(String.format( "Invalid input to %s, FeatureCollection required", name)); throw new TurfException(String.format( "Invalid input to %s, Feature with geometry required", name)); throw new TurfException(String.format( "Invalid input to %s: must be a %s, given %s", name, type, feature.geometry().type()));
/** * Takes a line, a start {@link Point}, and a stop point and returns the line in between those * points. * * @param startPt Starting point. * @param stopPt Stopping point. * @param line Line to slice. * @return Sliced line. * @throws TurfException signals that a Turf exception of some sort has occurred. * @see <a href="http://turfjs.org/docs/#lineslice">Turf Line slice documentation</a> * @since 1.2.0 */ @NonNull public static LineString lineSlice(@NonNull Point startPt, @NonNull Point stopPt, @NonNull Feature line) { checkNotNull(line.geometry(), "Feature.geometry() == null"); if (!line.geometry().type().equals("LineString")) { throw new TurfException("input must be a LineString Feature or Geometry"); } return lineSlice(startPt, stopPt, (LineString) line.geometry()); }
throw new TurfException("Turf lineSlice requires a LineString Geometry made up of " + "at least 2 coordinates. The LineString passed in only contains " + coords.size() + "."); } else if (startDist == stopDist) { throw new TurfException("Start and stop distance in Turf lineSliceAlong " + "cannot equal each other."); throw new TurfException("Start position is beyond line");
/** * Takes a {@link LineString}, a specified distance along the line to a start {@link Point}, * and a specified distance along the line to a stop point * and returns a subsection of the line in-between those points. * * This can be useful for extracting only the part of a route between two distances. * * @param line input line * @param startDist distance along the line to starting point * @param stopDist distance along the line to ending point * @param units one of the units found inside {@link TurfConstants.TurfUnitCriteria} * can be degrees, radians, miles, or kilometers * @return sliced line * @throws TurfException signals that a Turf exception of some sort has occurred. * @see <a href="http://turfjs.org/docs/#lineslicealong">Turf Line slice documentation</a> * @since 3.1.0 */ @NonNull public static LineString lineSliceAlong(@NonNull Feature line, @FloatRange(from = 0) double startDist, @FloatRange(from = 0) double stopDist, @NonNull @TurfConstants.TurfUnitCriteria String units) { checkNotNull(line.geometry(), "Feature.geometry() == null"); if (!line.geometry().type().equals("LineString")) { throw new TurfException("input must be a LineString Feature or Geometry"); } return lineSliceAlong((LineString)line.geometry(), startDist, stopDist, units); }
throw new TurfException("Turf nearestPointOnLine requires a List of Points " + "made up of at least 2 coordinates.");