see FOSS4G 開発者の為の、図形演算ライブラリガイド - Qiita [キータ]
注)gist/github で図形演算ができるわけではないので、あしからず
see FOSS4G 開発者の為の、図形演算ライブラリガイド - Qiita [キータ]
注)gist/github で図形演算ができるわけではないので、あしからず
using System; | |
using GeoAPI.Geometries; | |
using NetTopologySuite; | |
namespace TopologyTest | |
{ | |
class MainClass | |
{ | |
public static void Main(string[] args) | |
{ | |
var service = NtsGeometryServices.Instance; | |
var gf = service.CreateGeometryFactory(); | |
var polygonA = gf.CreatePolygon(new Coordinate[] | |
{ | |
new Coordinate(34.0, 136.0), | |
new Coordinate(34.0, 138.0), | |
new Coordinate(37.0, 138.0), | |
new Coordinate(37.0, 136.0), | |
new Coordinate(34.0, 136.0) | |
}); | |
var polygonB = gf.CreatePolygon(new Coordinate[] | |
{ | |
new Coordinate(36.0, 137.0), | |
new Coordinate(35.0, 137.0), | |
new Coordinate(35.0, 140.0), | |
new Coordinate(36.0, 137.0) | |
}); | |
polygonA.Intersection(polygonB).ToConsole("Intersection"); | |
polygonA.Union(polygonB).ToConsole("Union"); | |
polygonA.SymmetricDifference(polygonB).ToConsole("SymmetricDifference"); | |
polygonA.Difference(polygonB).ToConsole("Difference"); | |
polygonB.Buffer(0.5).ToConsole("Buffer"); | |
} | |
} | |
public static class GeomExtensions | |
{ | |
public static void ToConsole(this IGeometry geom, string tag) { | |
Console.WriteLine(tag + " - " + geom.ToString()); | |
} | |
} | |
} |