9

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.

8

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.

2

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;
    }
  • 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
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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