Thursday, 15 September 2016

how to create RTree index on LineString geometry


I'm working with NTS(NetTopologySuite), then I get some geometries with type of LineString, and I want to create the IntervalRTree Index on them.


Here are some codes:


SortedPackedIntervalRTree tree = new SortedPackedIntervalRTree();

and the Insert Method looks like:


public void Insert(double min, double max, T item)

so, how can I get the "min" and "max" Value of LineString?



also, the Query Method of the tree looks like


public void Query(double min, double max, IItemVisitor visitor)

and how to query the tree index?



Answer



You can create an STRtree, which is a query-only R-tree created using the Sort-Tile-Recursive (STR) algorithm for two-dimensional spatial data. More details are at the documentation page of JTS.


To create a STRtree index in NTS,


 ISpatialIndex spatialIndex = new STRtree();

You would insert geometries into the index using the geometry's envelope,



 IGeometry geometry = WktReader.Read(//linestring WKT);
spatialIndex.Insert(geometry.EnvelopeInternal, geometry);

Now you can retrieve the items whos bounds intersect an envelope using,


 IGeometry boundaryGeom = WktReader.Read(//polygon Wkt);
Envelope envelope = inProcessGeometry.EnvelopeInternal;
IList intersectingObjects = spatialIndex.Query(envelope);

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...