Created
January 16, 2016 15:12
-
-
Save airbreather/72a044104a4d44014235 to your computer and use it in GitHub Desktop.
Testing ground for union optimization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.IO; | |
using System.Linq; | |
using GeoAPI.Geometries; | |
using NetTopologySuite; | |
using NetTopologySuite.IO; | |
using NetTopologySuite.Operation.Union; | |
namespace TestingGround | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// functionally equivalent to a redux version of PackedCoordinateSequenceFactory that | |
// can only create 2-dimensional x/y sequences... it also uses a custom struct instead | |
// of paired doubles, which seems to be a benefit. | |
ICoordinateSequenceFactory csf = new SuperCoordSeqFactory(); | |
IGeometryFactory fac = NtsGeometryServices.Instance.CreateGeometryFactory(csf); | |
// Data originally grabbed from ftp://ftp2.census.gov/geo/tiger/TIGER2015/TRACT/ | |
const string BiggestState = @"N:\media\datasets\TIGER\2015\tl_2015_48_tract"; | |
const string BigState = @"N:\media\datasets\TIGER\2015\tl_2015_23_tract"; | |
const string WholeCountry = @"N:\media\datasets\TIGER\2015"; | |
var geoms = Directory.EnumerateFiles(BigState, "*.shp", SearchOption.AllDirectories) | |
.AsParallel() | |
.SelectMany(path => new ShapefileReader(path, fac).Cast<IGeometry>()) | |
.ToList(); | |
Stopwatch sw = Stopwatch.StartNew(); | |
var unionResult = UnaryUnionOp.Union(geoms); | |
sw.Stop(); | |
Console.WriteLine("Took {0} seconds.", sw.ElapsedTicks / (double)Stopwatch.Frequency); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment