ThinkGeo.com    |     Documentation    |     Premium Support

Parallel line tool

Hi, I was wondering if there is an existing method to generate parallel lines using MapSuite? we have a requirement to be allow users to select any given line, could have many vertices and change direction randomly, and generate one or more lines parallel to the selected one.

Thanks,
Jonathan

Hey @Jonathan3,

So, I think you are just looking to copy the selected line shape and then performing the LineShape.TranslateByOffset or LineShape.TranslateByDegree function on it. But you might have other requirements for this that I’m not aware of.

Thanks,
Kyle

Hi Kyle, I do not think that would work - possibly down to how we think of a parallel line. In the image below, the black line is the original, the dotted grey a copy moved by an offset and the red a hand drawn effort of what I think would be a parallel line on the original. More like concentric circles are parallel, copied and translated circles would not be parallel.

Thanks,
Jonathan

Hey @Jonathan3,

Ahh, yes, that does make a lot more sense. So, we don’t have an API like that in ThinkGeo, but that doesn’t mean that it can’t be done. NetTopologySuite has a way to get what’s called an offset curve that basically creates a parallel of a line that you describe. We have to do some simple converting between our LineShape and their Coordinate[], but it works with a limiting factor being the distance to sharp angle:

image

private LineShape GetOffsetCurve(LineShape lineShape, double offsetDistance)
{
    OffsetCurveBuilder ocb = new OffsetCurveBuilder(new PrecisionModel(), new BufferParameters(8, EndCapStyle.Round, JoinStyle.Mitre, 4));
    Coordinate[] coordinates = new Coordinate[lineShape.Vertices.Count];
    for (int i = 0; i < lineShape.Vertices.Count; i++)
    {
        coordinates[i] = new Coordinate(lineShape.Vertices[i].X, lineShape.Vertices[i].Y);
    }

    var offsetCurve = ocb.GetOffsetCurve(coordinates, offsetDistance);
    LineShape result = new LineShape();
    foreach (var coordinate in offsetCurve)
    {
        result.Vertices.Add(new Vertex(coordinate.X, coordinate.Y));
    }

    return result;
}

Thanks,
Kyle