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()); | |
| } | |
| } | |
| } |
| { | |
| "crs": { | |
| "properties": { | |
| "name": "urn:ogc:def:crs:OGC:1.3:CRS84" | |
| }, | |
| "type": "name" | |
| }, | |
| "features": [ | |
| { | |
| "geometry": { | |
| "coordinates": [ | |
| [ | |
| [137.0, 36.0], | |
| [137.0, 35.0], | |
| [140.0, 35.0], | |
| [137.0, 36.0] | |
| ] | |
| ], | |
| "type": "Polygon" | |
| }, | |
| "type": "Feature" | |
| }, | |
| { | |
| "geometry": { | |
| "coordinates": [ | |
| [ | |
| [137.1581139, 36.47434165], | |
| [137.0660543, 36.49561763], | |
| [136.9716358, 36.49919483], | |
| [136.8782303, 36.4849455], | |
| [136.7891732, 36.45337849], | |
| [136.7076449, 36.40562109], | |
| [136.6365567, 36.34337874], | |
| [136.5784473, 36.26887413], | |
| [136.5353917, 36.18476788], | |
| [136.5089276, 36.09406347], | |
| [136.5, 36], | |
| [136.5, 35], | |
| [136.5096074, 34.90245484], | |
| [136.5380602, 34.80865828], | |
| [136.5842652, 34.72221488], | |
| [136.6464466, 34.64644661], | |
| [136.7222149, 34.58426519], | |
| [136.8086583, 34.53806023], | |
| [136.9024548, 34.50960736], | |
| [137, 34.5], | |
| [140, 34.5], | |
| [140.1000291, 34.51010799], | |
| [140.1960138, 34.54002327], | |
| [140.2840733, 34.58853631], | |
| [140.3606471, 34.65368564], | |
| [140.4226393, 34.73283713], | |
| [140.4675434, 34.82279054], | |
| [140.4935437, 34.91990888], | |
| [140.4995891, 35.02026546], | |
| [140.4854352, 35.11980266], | |
| [140.4516541, 35.21449601], | |
| [140.3996118, 35.30051686], | |
| [140.3314124, 35.37438723], | |
| [140.2498134, 35.43312039], | |
| [140.1581139, 35.47434165], | |
| [137.1581139, 36.47434165] | |
| ] | |
| ], | |
| "type": "Polygon" | |
| }, | |
| "type": "Feature" | |
| }, | |
| { | |
| "geometry": { | |
| "coordinates": [ | |
| [135.0, 33.0], | |
| [140.0, 33.0], | |
| [140.0, 38.0], | |
| [135.0, 38.0], | |
| [135.0, 33.0] | |
| ], | |
| "type": "LineString" | |
| }, | |
| "type": "Feature" | |
| } | |
| ], | |
| "type": "FeatureCollection" | |
| } |