[GIS] Split a polygon using SqlServer geometry type

geometrysqlsql server

I have a polygon geometry in SqlServer and i want to split that single polygon into two features via a line that i draw through it.
How can i do that with sql?
I don't want to lose ANY portion of the original polygon. So buffering the line and doing a difference is not going to get it done. Unless there is a way i can "put back" the lost edges from the diff.

SqlGeometry splitLineGeom = SqlGeometry.STGeomFromText(new SqlChars(splitLineWKT.ToCharArray()), Srid);
// buffer line and get the difference from the input
SqlGeometry bufferedSplitLine = splitLineGeom.STBuffer(0.001);
SqlGeometry resultGeom = inputGeom.STDifference(bufferedSplitLine);

Best Answer

We need to determine where the line intersects the edges of the polygon. We then need to edit the GEOM string to Add the split line in at the location determined. To do so, you will accept the beginning line segments until you get to the split location. When you get to the first intersected segment, you will alter that segment to end at the intersection point. Add the intersect segment. Edit the next segment to use the line intersection close point as the start point and then use the remaining line segments to close out the first polygon.

Rather than programatically generating the second polygon, clip the larger polygon with the newly created polygon and retain the external portion.

I will add diagrams later when I have time.

Related Question