Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have parcel data intersecting line data. In the parcel data there are some parcels that don't intersect the line. How could I programmatically figure out if the non-intersecting parcel is on the Right side or the Left side of the line? Thanks.

share|improve this question
add comment

3 Answers 3

up vote 7 down vote accepted

Use the IHitTest interface. Your query point will be the polygon centroid and the input geometry will be the line. One of the outputs will be a boolean (bRightSide) which will tell you what side of the line you're on.

share|improve this answer
add comment

You can use the dot product for this

/// <summary>
/// Used to indicate the orientation of an object in space 
/// with respect to another object
/// </summary>
public enum OrientationType
{
    Left,
    Right,
    Coincident,
    Unknown
}


/// <summary>
    /// Determines if a point is oriented left, right or coincident with
    /// a directed line. 
    /// Line direction is determined by its From and To points.
    /// </summary>
    /// <param name="p">The point to test.</param>
    /// <param name="segment">The line dividing the space</param>
    /// <returns>An OrientationType indicating the orientation.</returns>
    public static OrientationType GetPointOrientation(IPoint p, ISegment segment)
    {

        OrientationType result = OrientationType.Unknown;

        double Ax = segment.FromPoint.X;
        double Ay = segment.FromPoint.Y;
        double Bx = segment.ToPoint.X;
        double By = segment.ToPoint.Y;
        double Px = p.X;
        double Py = p.Y;

        double nDotV = ((Ay - By) * (Px - Ax)) + ((Bx - Ax) * (Py - Ay));

        if (nDotV < 0)
        {
            result = OrientationType.Right;//opposite direction to normal vector
        }
        else if (nDotV > 0)
        {
            result = OrientationType.Left;
        }
        else if (nDotV == 0)
        {
            result = OrientationType.Coincident;
        }

        return result;
    }
share|improve this answer
1  
I think it's worth pointing out that this technique requires the input line to be a line composed of only 2 vertices as it is accepting an ISegment object. –  Hornbydd Nov 10 '11 at 23:06
    
This works fine for a proper Euclidean line (the whole thing, not just a segment or ray), but I'm pretty sure the OP used "line" and "line data" as loose synonyms for polylines, where the dot product approach fails. –  whuber Nov 10 '11 at 23:08
add comment

Algorithm to get desired result:

  1. Take the Line in focus
  2. Add some buffer (0.0000005) at Right (or Left) side of the Line geometry.
  3. Check whether buffer geometry is ‘Inside’ the Polygon geometry or ‘Overlap’ with Polygon geometry.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.