Package oracle.spatial.network.nfe.util
Class SpatialUtils
- java.lang.Object
-
- oracle.spatial.network.nfe.util.SpatialUtils
-
public class SpatialUtils extends java.lang.Object
This class provides multiple static methods for performing different spatial-related tasks
-
-
Constructor Summary
Constructors Constructor Description SpatialUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static oracle.sdovis.edit.util.JGeometrySegmentPoint
createSegmentPoint(double pointX, double pointY, double[] lineOrdinates, int segmentIndex)
Creates a JGeometrySegmentPoint for the given line ordinates.static double
distToLine(java.awt.geom.Point2D point, JGeometry line)
Gets the distance from the given point to the nearest point at the given linestatic double
getDataSRSTolerance(java.awt.geom.AffineTransform affineTransform, double pxTolerance)
Gets a tolerance in the data coordinate system given a tolerance in pixelsstatic double
getDistance(double x1, double y1, double x2, double y2)
Gets the distance between two pointsstatic double
getDistance(java.awt.geom.Point2D point1, java.awt.geom.Point2D point2)
Gets the distance between two pointsstatic double
getLineLength(double[] lineOrdinates)
Gets the length of a line.static oracle.sdovis.edit.util.JGeometrySegment
getLineNearestSegment(double[] ordinates, java.awt.geom.Point2D targetPoint, double tolerance)
Gets the line's segment nearest to the given point as long as it is not farer than the given tolerancestatic oracle.sdovis.edit.util.JGeometrySegment
getLineNearestSegment(JGeometry line, java.awt.geom.Point2D targetPoint, double tolerance)
Gets the line's segment nearest to the given point as long as it is not farer than the given tolerancestatic oracle.sdovis.edit.util.JGeometrySegmentPoint
getLineSegmentPoint(double[] ordinates, java.awt.geom.Point2D targetPoint, double tolerance)
Gets the nearest segment point in the line to the given point as long as it is not farer than the given tolerance.static oracle.sdovis.edit.util.JGeometrySegmentPoint
getLineSegmentPoint(JGeometry line, java.awt.geom.Point2D point)
Gets the nearest segment point in the line to the given point.static oracle.sdovis.edit.util.JGeometrySegmentPoint
getLineSegmentPoint(JGeometry line, java.awt.geom.Point2D targetPoint, double tolerance)
Gets the nearest segment point in the line to the given point as long as it is not farer than the given tolerance.static java.awt.geom.Rectangle2D
getMBR(JGeometry geom, double threshold)
Gets the MBR of the given geometry containing the given thresholdstatic java.awt.geom.Point2D
getPointOnLine(double[] lineOrdinates, double positionPercentage)
Gets the spatial location of a point in the line given a percentage of the line's lengthstatic double
getPositionPercentage(JGeometry lineGeom, java.awt.geom.Point2D point, double tolerance)
Given a line and a point, gives the corresponding percentage of that point relative to the line's length.static double
getPositionPercentage(JGeometry lineGeom, oracle.sdovis.edit.util.JGeometrySegmentPoint segmentPoint)
Given a line and a line's segment point, gives the corresponding percentage of that point relative to the line's length.static oracle.sdovis.edit.util.JGeometrySegmentPoint
getSegmentPoint(double[] lineOrdinates, double positionPercentage)
Gets the line segment point information corresponding to a position in the line given as a percentage of the line's lengthstatic JGeometry
getSubLine(JGeometry line, double startPos, double endPos)
Gets the geometry of a portion of the given linestatic JGeometry
getSubLine(JGeometry line, java.awt.geom.Point2D startPoint, java.awt.geom.Point2D endPoint, double tolerance)
Gets the geometry of a portion of the given linestatic JGeometry
getSubLine(JGeometry line, oracle.sdovis.edit.util.JGeometrySegmentPoint startSegPoint, oracle.sdovis.edit.util.JGeometrySegmentPoint endSegPoint)
Gets the geometry of a portion of the given linestatic double
getSubLineLength(JGeometry lineGeom, java.awt.geom.Point2D point, double tolerance)
Gets the length from the line's start point to the given point in the line.static double
getSubLineLength(JGeometry lineGeom, oracle.sdovis.edit.util.JGeometrySegmentPoint segmentPoint)
Gets the length from the line's start point to the given point in the line.static boolean
isSamePoint(double[] point1, double[] point2)
Tells whether the given points are located at the same positionstatic JGeometry
joinAdjacentLines(JGeometry srcLine, JGeometry endLine)
Joins two lines into one single linestatic JGeometry
moveLinePoint(JGeometry line, int pointIndex, java.awt.geom.Point2D newPoint)
Replaces line's point by anotherstatic JGeometry
translate(JGeometry geom, double transX, double transY)
Translates a geometry
-
-
-
Method Detail
-
getDataSRSTolerance
public static double getDataSRSTolerance(java.awt.geom.AffineTransform affineTransform, double pxTolerance) throws java.awt.geom.NoninvertibleTransformException
Gets a tolerance in the data coordinate system given a tolerance in pixels- Parameters:
affineTransform
- the affine transform used for converting between coordinate systemspxTolerance
- a tolerance in pixels- Returns:
- a tolerance in the data coordinate system
- Throws:
java.awt.geom.NoninvertibleTransformException
-
getDistance
public static double getDistance(java.awt.geom.Point2D point1, java.awt.geom.Point2D point2)
Gets the distance between two points- Parameters:
point1
- a point objectpoint2
- a point object- Returns:
- the distance between two points
-
getDistance
public static double getDistance(double x1, double y1, double x2, double y2)
Gets the distance between two points- Parameters:
x1
- the first point's x ordinatey1
- the first point's y ordinatex2
- the second point's x ordinatey2
- the second point's y ordinate- Returns:
- the distance between two points
-
distToLine
public static double distToLine(java.awt.geom.Point2D point, JGeometry line)
Gets the distance from the given point to the nearest point at the given line- Parameters:
point
- a point objectline
- a line string geometry object- Returns:
- the distance from the point to the nearest point at the line
-
isSamePoint
public static boolean isSamePoint(double[] point1, double[] point2)
Tells whether the given points are located at the same position- Parameters:
point1
- a two-valued array containing the coordinates of a pointpoint2
- a two-valued array containing the coordinates of a point- Returns:
- true if both points are equals
-
moveLinePoint
public static JGeometry moveLinePoint(JGeometry line, int pointIndex, java.awt.geom.Point2D newPoint)
Replaces line's point by another- Parameters:
line
- a line string geometry objectpointIndex
- the index of the point to be replaced. Given the line's ordinate array, the index corresponds to the position por the x ordinate of the point that is going to be replaced.newPoint
- a point object that will be the new line's point- Returns:
- the line after replacing the point
-
getLineLength
public static double getLineLength(double[] lineOrdinates)
Gets the length of a line. The length is the sum of the length of each line segment.- Parameters:
lineOrdinates
- the line ordinates- Returns:
- the length of the line
-
getPointOnLine
public static java.awt.geom.Point2D getPointOnLine(double[] lineOrdinates, double positionPercentage)
Gets the spatial location of a point in the line given a percentage of the line's length- Parameters:
lineOrdinates
- the line ordinatespositionPercentage
- a percentage of the line's length- Returns:
- a point object
-
getSegmentPoint
public static oracle.sdovis.edit.util.JGeometrySegmentPoint getSegmentPoint(double[] lineOrdinates, double positionPercentage)
Gets the line segment point information corresponding to a position in the line given as a percentage of the line's length- Parameters:
lineOrdinates
- the line ordinatespositionPercentage
- a percentage of the line's length- Returns:
- the segment point information
-
createSegmentPoint
public static oracle.sdovis.edit.util.JGeometrySegmentPoint createSegmentPoint(double pointX, double pointY, double[] lineOrdinates, int segmentIndex)
Creates a JGeometrySegmentPoint for the given line ordinates. This method is meant to help on avoiding boilerplate code regarding to the creation of a JGeometrySegment point but does not perform any verification.- Parameters:
pointX
- the x ordinate of the segment pointpointY
- the y ordinate of the segment pointlineOrdinates
- a line ordinatessegmentIndex
- the index of the line segment. The index is based on the number of segments in the line, not the ordinates, and it is zero based.- Returns:
-
getLineSegmentPoint
public static oracle.sdovis.edit.util.JGeometrySegmentPoint getLineSegmentPoint(JGeometry line, java.awt.geom.Point2D targetPoint, double tolerance)
Gets the nearest segment point in the line to the given point as long as it is not farer than the given tolerance.- Parameters:
line
- a line stringtargetPoint
- a point objecttolerance
- the maximum distance between the given point and the line's point- Returns:
- the segment point object for the line's point
-
getLineSegmentPoint
public static oracle.sdovis.edit.util.JGeometrySegmentPoint getLineSegmentPoint(double[] ordinates, java.awt.geom.Point2D targetPoint, double tolerance)
Gets the nearest segment point in the line to the given point as long as it is not farer than the given tolerance.- Parameters:
ordinates
- a line string ordinatestargetPoint
- a point objecttolerance
- the maximum distance between the given point and the line's point- Returns:
- the segment point object for the line's point
-
getLineSegmentPoint
public static oracle.sdovis.edit.util.JGeometrySegmentPoint getLineSegmentPoint(JGeometry line, java.awt.geom.Point2D point)
Gets the nearest segment point in the line to the given point.- Parameters:
line
- a line stringpoint
- a point object- Returns:
- the segment point object for the line's point
-
getLineNearestSegment
public static oracle.sdovis.edit.util.JGeometrySegment getLineNearestSegment(JGeometry line, java.awt.geom.Point2D targetPoint, double tolerance)
Gets the line's segment nearest to the given point as long as it is not farer than the given tolerance- Parameters:
line
- a line stringtargetPoint
- a point objecttolerance
- the value bounding the distance- Returns:
- the line's segment information
-
getLineNearestSegment
public static oracle.sdovis.edit.util.JGeometrySegment getLineNearestSegment(double[] ordinates, java.awt.geom.Point2D targetPoint, double tolerance)
Gets the line's segment nearest to the given point as long as it is not farer than the given tolerance- Parameters:
ordinates
- a line string ordinatestargetPoint
- a point objecttolerance
- the value bounding the distance- Returns:
- the line's segment information
-
getSubLine
public static JGeometry getSubLine(JGeometry line, java.awt.geom.Point2D startPoint, java.awt.geom.Point2D endPoint, double tolerance)
Gets the geometry of a portion of the given line- Parameters:
line
- a line stringstartPoint
- a point of the original line that will be the start point of the sub lineendPoint
- a point of the original line that will be the end point of the sub linetolerance
- tells how far can be the given start and end points to be considered as points in the line- Returns:
- a line string geometry or null if the given start and end points are outside the tolerance
-
getSubLine
public static JGeometry getSubLine(JGeometry line, double startPos, double endPos)
Gets the geometry of a portion of the given line- Parameters:
line
- a line stringstartPoint
- a point of the original line that will be the start point of the sub lineendPoint
- a point of the original line that will be the end point of the sub line- Returns:
- a line string geometry
-
getSubLine
public static JGeometry getSubLine(JGeometry line, oracle.sdovis.edit.util.JGeometrySegmentPoint startSegPoint, oracle.sdovis.edit.util.JGeometrySegmentPoint endSegPoint)
Gets the geometry of a portion of the given line- Parameters:
line
- a line stringstartSegPoint
- a segment point of the original line that will be the start point of the sub lineendSegPoint
- a segment point of the original line that will be the end point of the sub line- Returns:
- a line string geometry
-
getPositionPercentage
public static double getPositionPercentage(JGeometry lineGeom, java.awt.geom.Point2D point, double tolerance)
Given a line and a point, gives the corresponding percentage of that point relative to the line's length.- Parameters:
lineGeom
- a line stringpoint
- a point objecttolerance
- the maximum distance from the point to the line to be considered as a point on the line- Returns:
- a percentage of the line length. A value between 0 and 1 inclusive.
-
getPositionPercentage
public static double getPositionPercentage(JGeometry lineGeom, oracle.sdovis.edit.util.JGeometrySegmentPoint segmentPoint)
Given a line and a line's segment point, gives the corresponding percentage of that point relative to the line's length.- Parameters:
lineGeom
- a line stringsegmentPoint
- the line's segment point- Returns:
- a percentage of the line length. A value between 0 and 1 inclusive.
-
getSubLineLength
public static double getSubLineLength(JGeometry lineGeom, java.awt.geom.Point2D point, double tolerance)
Gets the length from the line's start point to the given point in the line.- Parameters:
lineGeom
- a line stringpoint
- a point objecttolerance
- the maximum distance from the point to the line- Returns:
- the length of the sub line described or an invalid number if the given point does not lay on the line.
-
getSubLineLength
public static double getSubLineLength(JGeometry lineGeom, oracle.sdovis.edit.util.JGeometrySegmentPoint segmentPoint)
Gets the length from the line's start point to the given point in the line.- Parameters:
lineGeom
- a line stringsegmentPoint
- a line's segment point- Returns:
- the length of the sub line described
-
translate
public static JGeometry translate(JGeometry geom, double transX, double transY)
Translates a geometry- Parameters:
geom
- a geometry objecttransX
- the distance the geometry will be moved in the x dimensiontransY
- the distance the geometry will be moved in the y dimension- Returns:
- the translated geometry
-
getMBR
public static java.awt.geom.Rectangle2D getMBR(JGeometry geom, double threshold)
Gets the MBR of the given geometry containing the given threshold- Parameters:
geom
- a geometry objectthreshold
- an additional distance added to each side of the resulting MBR- Returns:
- the geometry's MBR as a rectangle object
-
joinAdjacentLines
public static JGeometry joinAdjacentLines(JGeometry srcLine, JGeometry endLine)
Joins two lines into one single line- Parameters:
srcLine
- a line string which will be the initial line segments of the resulting linesendLine
- a line string which will be the last line segments of the resulting lines- Returns:
- a new line string geometry
-
-