0

I am new to this part, so I hope someone who has experienced this could give some advices.

I have a shape file document, which contains many shapes. The data needed to be processed is large number of points. I try to generate a quadtree index for the shapefile and then locate these points. And I find a class which is suitable for it.

http://docs.geotools.org/latest/javadocs/org/geotools/data/shapefile/index/quadtree/QuadTree.html#insert-org.geotools.data.shapefile.index.quadtree.Node-int-com.vividsolutions.jts.geom.Envelope-int-

Below is my code

    ShpFiles shpFile = new ShpFiles(shpFileName);
    IndexFile indexShapeFile = new IndexFile(shpFile,true);
    int numShapes = indexShapeFile.getRecordCount();
    com.vividsolutions.jts.geom.Envelope eRoot = new com.vividsolutions.jts.geom.Envelope(-85,85,-180,180);
    QuadTree t1 = new QuadTree(numShapes,eRoot,indexShapeFile);

The problem is that, how do I need to do next? Do I need to insert all polygons manually? And how could I search points with this tree?

1 Answers1

0

A quad-tree is a member of a class of data structures referred to as bounding volume hierarchies (BVH). Specifically a quad-tree recursively subdivides a finite 2-dimensional space into 4 quadrants. In your case it looks like you either have to do this manually, by creating a hierarchy of Node objects and adding shapes to them, or it'll do it for you by inserting shapes into the tree via insert(). Unfortunately the documentation isn't very clear on the proper usage.

One thing you need to be aware of is how that QuadTree class handles shapes that are intersected by multiple quad-tree nodes. At first glance it isn't clear as to whether or not this library splits shapes for you so you may need to come up with your own solution.

Corillian
  • 907
  • 7
  • 12
  • Thank you for your reply. The document of this library is hard to understand for me and I have been trying to read it for a long time. I am not sure how to add shapes to cooresponding node after these node is created. So if I try to use `insert(int recno, Envelope bounds)` to insert shapes, what is the meaning of bounds from your point of view? – Mengyu Li Apr 26 '17 at 03:13
  • It looks like an Envelope represents the bounding box of a shape: http://docs.geotools.org/latest/javadocs/org/geotools/geometry/Envelope2D.html – Corillian Apr 26 '17 at 03:19
  • Got it. If I have successfully generated the index quadtree, how could I use it to locate points? I mean, it only has a function `search(Envelope bounds) `, which might be useful for finding shapes(?) in bounds. Is it useful for finding points? – Mengyu Li Apr 26 '17 at 03:30
  • Yes it's useful for locating points. You locate points the same way you'd locate shapes - by providing an `Envelope` specifying the bounds. – Corillian Apr 26 '17 at 22:26