Geographic Information Systems Asked on June 17, 2021
I’ve built some code to take multiple geometries and merge them into one envelope, but now I need to convert that envelope into a polygon/IGeometry shape that represents that area. Is there a way to do this?
For others, I ended up just doing the following and it seems to work well. Feel free to comment if anyone has any opinions:
public static IGeometry ToGeometry(this Envelope env)
{
if (env != null && env.MinX <= env.MaxX && env.MinY <= env.MaxY)
{
List<Coordinate> bounds = new List<Coordinate>()
{
new Coordinate(env.MinX,env.MinY),
new Coordinate(env.MaxX, env.MinY),
new Coordinate(env.MaxX, env.MaxY),
new Coordinate(env.MinX, env.MaxY),
new Coordinate(env.MinX,env.MinY),
};
NetTopologySuite.Geometries.LinearRing ring= new NetTopologySuite.Geometries.LinearRing(bounds.ToArray());
if (ring != null)
{
NetTopologySuite.Geometries.Polygon poly = new NetTopologySuite.Geometries.Polygon(ring);
return poly;
}
}
return null;
}
Answered by Phil on June 17, 2021
There is a simpler option:
Envelope envelope = new(95473, 101283, 435552, 445442);
GeometryFactory factory = new();
Geometry geometry = factory.ToGeometry(envelope);
Answered by Lev on June 17, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP