Skip to content

Instantly share code, notes, and snippets.

@kiichi
Last active November 29, 2018 19:16
Show Gist options
  • Save kiichi/540a72171ae24c3cb5da to your computer and use it in GitHub Desktop.
Save kiichi/540a72171ae24c3cb5da to your computer and use it in GitHub Desktop.
C# GIS Intersact Example using NetTopologySuite
using System;
using NetTopologySuite.Geometries;
using GeoAPI.Geometries;
// Not sure SRID is respected or not. because their doc says obsolete
namespace NetTopologySuiteTest {
class MainClass {
public static void Main (string[] args) {
// Check Intersection of Brooklyn Street or not
// https://www.google.com/maps/@40.6888907,-73.9459579,14z
GeometryFactory factory = new GeometryFactory (new PrecisionModel(), 4326);
// Flagbush
LineString ls1 = (LineString)factory.CreateLineString(new Coordinate[]{
new Coordinate(-73.984238,40.695317),
new Coordinate(-73.974282,40.678949)
});
// Atlantic
LineString ls2= (LineString)factory.CreateLineString(new Coordinate[]{
new Coordinate(-73.997928,40.691575),
new Coordinate(-73.959562,40.679567)
});
bool doesIntersects = ls1.Intersects (ls2);
Console.WriteLine ("Does Flatbush and Atlantic intersect? : " + doesIntersects);
// Broadway - around wburg
LineString ls3 = (LineString)factory.CreateLineString(new Coordinate[]{
new Coordinate(-73.956000,40.707469),
new Coordinate(-73.915402,40.685929)
});
doesIntersects = ls1.Intersects (ls3);
Console.WriteLine ("Does Flatbush and Broadway intersect? : " + doesIntersects);
}
}
}
@kiichi
Copy link
Author

kiichi commented Aug 4, 2015

map_small

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment