net.refractions.udig.tools.edit.support
Class EditUtils

java.lang.Object
  extended by net.refractions.udig.tools.edit.support.EditUtils

public class EditUtils
extends java.lang.Object

Methods for determining spatial relationships between points.

Since:
1.1.0
Author:
Jesse

Nested Class Summary
static class EditUtils.EditToolHandlerShapeProvider
           
static class EditUtils.MinFinder
          Keeps track of the point that is the minimum distance to the center point.
static class EditUtils.StaticEditGeomProvider
          Provider for EditGeoms
static class EditUtils.StaticShapeProvider
           
 
Field Summary
static EditUtils instance
           
static int NO_INTERSECTION
           
static int OVER_EDGE
           
 
Constructor Summary
EditUtils()
           
 
Method Summary
 UndoableComposite appendPathToShape(EditToolHandler handler, java.awt.geom.PathIterator iter, PrimitiveShape shape)
          Appends the points defined in the PathIterator to the shape.
 UndoableComposite appendPathToShape(java.awt.geom.PathIterator iter, ShapeType shapeType, EditToolHandler handler, EditBlackboard bb,  currentProvider2)
          Appends the points defined in the PathIterator to the shape.
 void cancelHideSelection(ILayer selectedLayer)
          When an edit is canceled the selected layer must be re-rendered because they were hidden by refreshLayer(ILayer, Feature, Envelope, boolean, boolean) This method must be called in order to efficiently do that.
 void clearLayerStateShapeCache(java.util.Collection<ILayer> layers)
          The framework stores the current shape and state on a layer when the currently selected layer changes.
 Coordinate closestCoordinateOnEdge(Coordinate endPoint1, Coordinate endPoint2, Coordinate src)
          Returns the closest point on the line between vertex1 and vertex2 to coordinate src
 Point closestPointOnEdge(Point endPoint1, Point endPoint2, Point src)
          Returns the closest point on the line between vertex1 and vertex2 to coordinate src
 int getClosest(Geometry geometry, Coordinate click, Coordinate[] result)
          Returns the index of the coordinate closest to the click.
 Coordinate getClosestSnapPoint(EditToolHandler handler, EditBlackboard editBlackboard, Point centerPoint, boolean includeVerticesInCurrent, SnapBehaviour snapBehaviour, EditState stateAfterSearch)
          Searches all the layers in the map and the EditBlackboard for the closest vertex to center point
 EditGeom getGeomWithMouseOver(java.util.Collection<EditGeom> geoms, Point location, boolean treatUnknownAsPolygon)
          Returns the Geometry from the collection that the mouse is over/intersects
 java.util.List<EditGeom> getIntersectingGeom(EditBlackboard editBlackboard, Point point, boolean treatUnknownAsPolygons)
          Finds and returns the EditGeoms that intersect the point.
 Coordinate getTransformedClick(Coordinate click, ILayer layer)
          Convenience method; transforms the click from the viewportModel CRS to the layer's CRS.
 void hideSelectedFeatures(EditToolHandler handler, ILayer selectedLayer)
          Triggers a re-render that hides the features on the EditBlackboard.
 Coordinate intersectingLines(Coordinate line1P1, Coordinate line1P2, Coordinate line2P1, Coordinate line2P2)
          Returns the intersection where the two lines meet
 boolean intersection(Point point1, Point point2, PrimitiveShape shape, int startIndex, int endIndex)
          Checks whether the edge from point1 to point2 intersects any edge in the shape from startIndex to the endIndex
static Coordinate midPointOnLine(Coordinate coord, Coordinate coord2)
           
 boolean overEdge(Coordinate endPoint1, Coordinate endPoint2, Envelope env)
          Returns true if the envelope overlaps some part of the edge
 boolean overEdgeCoordinatePrecision(PrimitiveShape shape, Envelope env)
          Return true if the envelope overlaps at least one edge of the shape.
 boolean overEdgePixelPrecision(PrimitiveShape shape, Envelope env)
          Return true if the envelope overlaps at least one edge of the shape.
 int overVertext(Coordinate[] coords, Envelope env)
           
 void refreshLayer(ILayer selectedLayer, Feature feature, Envelope refreshBounds, boolean forceRefresh, boolean hidefeature)
          Sets the rendering hint on the layer so that the feature is hidden if hidefeature is true.
 void reverseOrder(PrimitiveShape shape)
          Reverse the order of the vertices in a Shape.
 boolean selfIntersection(PrimitiveShape shape)
          Returns true if the shape has a self intersection.
 Coordinate snapToGrid(Point centerPoint, IMap map)
          Returns the coordinate that is on the grid intersection closest to the coordinate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OVER_EDGE

public static final int OVER_EDGE
See Also:
Constant Field Values

NO_INTERSECTION

public static final int NO_INTERSECTION
See Also:
Constant Field Values

instance

public static EditUtils instance
Constructor Detail

EditUtils

public EditUtils()
Method Detail

overVertext

public int overVertext(Coordinate[] coords,
                       Envelope env)

overEdgeCoordinatePrecision

public boolean overEdgeCoordinatePrecision(PrimitiveShape shape,
                                           Envelope env)
Return true if the envelope overlaps at least one edge of the shape. This checks all the Coordinates in the shape so the envelope must be in the "world" space (same projection as coordinates).

Parameters:
shape - to search
env - envelope used to see if it overlaps an edge
Returns:
true if the envelope overlaps at least one edge of the shape.

overEdgePixelPrecision

public boolean overEdgePixelPrecision(PrimitiveShape shape,
                                      Envelope env)
Return true if the envelope overlaps at least one edge of the shape. This only checks the Points in the shape so the envelope must be in pixel space. This also means that it is not completely accurate but it is sufficient for interactive purposes.

Parameters:
shape - to search
env - envelope used to see if it overlaps an edge
Returns:
true if the envelope overlaps at least one edge of the shape.

overEdge

public boolean overEdge(Coordinate endPoint1,
                        Coordinate endPoint2,
                        Envelope env)
Returns true if the envelope overlaps some part of the edge

Parameters:
endPoint1 - one end point of the edge
endPoint2 - the other end point of the edge
env - the reference envelope.
Returns:
true if the envelope overlaps some part of the edge

getClosest

public int getClosest(Geometry geometry,
                      Coordinate click,
                      Coordinate[] result)
Returns the index of the coordinate closest to the click.

Parameters:
geometry - the geometry to search for the closest coordinate; The default geometry is searched.
click - the closest coordinate in coordinates will be found with respect to click
result - the first position will be fill with the closest coordinate in geometry.
Returns:
the index of the coordinate closest to the click.

closestCoordinateOnEdge

public Coordinate closestCoordinateOnEdge(Coordinate endPoint1,
                                          Coordinate endPoint2,
                                          Coordinate src)
Returns the closest point on the line between vertex1 and vertex2 to coordinate src

All Coordinates must be in the same CRS

Parameters:
endPoint1 - first vertex of a line.
endPoint2 - second vertex of a line.
src - the closes coordinate is found with respect to src.
Returns:
the closest point on the line between vertex1 and vertex2 to coordinate src

closestPointOnEdge

public Point closestPointOnEdge(Point endPoint1,
                                Point endPoint2,
                                Point src)
Returns the closest point on the line between vertex1 and vertex2 to coordinate src

All Coordinates must be in the same CRS

Parameters:
endPoint1 - first vertex of a line.
endPoint2 - second vertex of a line.
src - the closes coordinate is found with respect to src.
Returns:
the closest point on the line between vertex1 and vertex2 to coordinate src

getTransformedClick

public Coordinate getTransformedClick(Coordinate click,
                                      ILayer layer)
Convenience method; transforms the click from the viewportModel CRS to the layer's CRS.

Parameters:
click -
Returns:

getIntersectingGeom

public java.util.List<EditGeom> getIntersectingGeom(EditBlackboard editBlackboard,
                                                    Point point,
                                                    boolean treatUnknownAsPolygons)
Finds and returns the EditGeoms that intersect the point. This maybe an expensive operation if there are a large number of EditGeoms each with many points. The calculation is done in screen space, however, so the number of coordinates in the shapes do not matter so much.

Parameters:
editBlackboard -
point -
treatUnknownAsPolygons -
Returns:

snapToGrid

public Coordinate snapToGrid(Point centerPoint,
                             IMap map)
Returns the coordinate that is on the grid intersection closest to the coordinate.


getClosestSnapPoint

public Coordinate getClosestSnapPoint(EditToolHandler handler,
                                      EditBlackboard editBlackboard,
                                      Point centerPoint,
                                      boolean includeVerticesInCurrent,
                                      SnapBehaviour snapBehaviour,
                                      EditState stateAfterSearch)
Searches all the layers in the map and the EditBlackboard for the closest vertex to center point

Parameters:
includeVerticesInCurrent - indicates whether the vertices of the current feature should be considered.
stateAfterSearch -
Returns:
the Point that is the closest vertex.

intersectingLines

public Coordinate intersectingLines(Coordinate line1P1,
                                    Coordinate line1P2,
                                    Coordinate line2P1,
                                    Coordinate line2P2)
Returns the intersection where the two lines meet


reverseOrder

public void reverseOrder(PrimitiveShape shape)
Reverse the order of the vertices in a Shape. Used because the holes and shells in polygons have to be in a particular order.

Parameters:
shape -

appendPathToShape

public UndoableComposite appendPathToShape(EditToolHandler handler,
                                           java.awt.geom.PathIterator iter,
                                           PrimitiveShape shape)
Appends the points defined in the PathIterator to the shape. Currently curve segments are not supported and if there is a moveto in the middle of the iterator a hole will be created in the shape. If the GeomType is line or point then an exception will be thrown but otherwise the client code must ensure that the request makes sense.

Parameters:
iter - The iterator to append
shape - the shape to append to.
Returns:
Commands that will append the points to the shape. Nothing is done until commands are run.

appendPathToShape

public UndoableComposite appendPathToShape(java.awt.geom.PathIterator iter,
                                           ShapeType shapeType,
                                           EditToolHandler handler,
                                           EditBlackboard bb,
                                            currentProvider2)
Appends the points defined in the PathIterator to the shape. Currently curve segments are not supported and if there is a move to in the middle of the iterator a hole will be created in the shape. If the GeomType is line or point then an exception will be thrown but otherwise the client code must ensure that the request makes sense.

Parameters:
iter - The iterator to append
bb - the editblackboard used to add coordinates
currentProvider2 - the shape provider that provides the shape to append the coordinates to
shapeType - the type of geometry that is expected from currentProvider.
Returns:
Commands that will append the points to the shape. Nothing is done until commands are run.

midPointOnLine

public static Coordinate midPointOnLine(Coordinate coord,
                                        Coordinate coord2)

clearLayerStateShapeCache

public void clearLayerStateShapeCache(java.util.Collection<ILayer> layers)
The framework stores the current shape and state on a layer when the currently selected layer changes. This method clears that cache on the layers passed in. This should be called when the tool is de-actived and when a cancel and accept is run. This is so that the shapes can be garbage collected.

Parameters:
layers -

cancelHideSelection

public void cancelHideSelection(ILayer selectedLayer)
When an edit is canceled the selected layer must be re-rendered because they were hidden by refreshLayer(ILayer, Feature, Envelope, boolean, boolean) This method must be called in order to efficiently do that.

Parameters:
selectedLayer -
See Also:
refreshLayer(ILayer, Feature, Envelope, boolean, boolean)

hideSelectedFeatures

public void hideSelectedFeatures(EditToolHandler handler,
                                 ILayer selectedLayer)
Triggers a re-render that hides the features on the EditBlackboard.


refreshLayer

public void refreshLayer(ILayer selectedLayer,
                         Feature feature,
                         Envelope refreshBounds,
                         boolean forceRefresh,
                         boolean hidefeature)
Sets the rendering hint on the layer so that the feature is hidden if hidefeature is true. If hidefeature is false then the hint is reset all features are shown

cancelHideSelection(ILayer) should be called if the edit is canceled.

Parameters:
selectedLayer -
feature -
refreshBounds - the area to refresh (should be the the area of the feature). May be null to refresh entire area. Envelope should be in Layer coordinates.
hidefeature -
See Also:
cancelHideSelection(ILayer)

getGeomWithMouseOver

public EditGeom getGeomWithMouseOver(java.util.Collection<EditGeom> geoms,
                                     Point location,
                                     boolean treatUnknownAsPolygon)
Returns the Geometry from the collection that the mouse is over/intersects

Parameters:
geoms - Geoms to search through
location - the location
Returns:
the first geom that the location is over/intersects

selfIntersection

public boolean selfIntersection(PrimitiveShape shape)
Returns true if the shape has a self intersection. Only checks the points not the coordinates there for it is quicker but less accurate.

Parameters:
shape - shape to test.
Returns:
true if the shape has a self intersection.

intersection

public boolean intersection(Point point1,
                            Point point2,
                            PrimitiveShape shape,
                            int startIndex,
                            int endIndex)
Checks whether the edge from point1 to point2 intersects any edge in the shape from startIndex to the endIndex

Parameters:
point1 - the first point in the reference edge
point2 - the second point in the reference edge
shape - the shape that is searched for intersections
startIndex - the index in the shape of the point at which to start searching. The point indicated will be the first point in the edge.
endIndex - the index to stop the search. It is the index of the end point of the last edge to compare
Returns:
true if there is an intersection between the edge indicated by last,current and the shape