sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch master updated: Committing modified files -- formatting changes.
Date Fri, 17 Aug 2018 08:59:47 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/master by this push:
     new b2da143  Committing modified files -- formatting changes.
     new b82dcd9  Merge pull request #10 (https://github.com/apache/sis/pull/10) from https://github.com/kelseaflores/sis.
b2da143 is described below

commit b2da143bc5dd7c821645e6fcc3c656ed7767feab
Author: Kelsea Flores <kjflores2@usfca.edu>
AuthorDate: Fri Aug 17 01:42:34 2018 -0700

    Committing modified files -- formatting changes.
---
 .../java/org/apache/sis/index/tree/QuadTree.java   | 1120 ++++++++++----------
 .../org/apache/sis/index/tree/QuadTreeData.java    |   53 +-
 .../org/apache/sis/index/tree/QuadTreeNode.java    |  280 ++---
 .../org/apache/sis/index/tree/QuadTreeWriter.java  |  257 +++--
 4 files changed, 845 insertions(+), 865 deletions(-)

diff --git a/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTree.java b/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTree.java
index 1af0e16..5cb1b53 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTree.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTree.java
@@ -32,601 +32,591 @@ import org.apache.sis.distance.LatLonPointRadius;
  * design of quad tree index in H. Samet, The Design and Analysis of Spatial
  * Data Structures. Massachusetts: Addison Wesley Publishing Company, 1989.
  *
- * <div class="warning"><b>Note on future work:</b> this class may change in incompatible way
- * in a future Apache SIS release, or may be replaced by new API.</div>
+ * <div class="warning"><b>Note on future work:</b> this class may change in
+ * incompatible way in a future Apache SIS release, or may be replaced by new
+ * API.</div>
  */
 public class QuadTree {
 
-  // assume map is shifted to be in positive coordinate
-  private static final double EARTH_MIN_X = 0;
-  private static final double EARTH_MIN_Y = 0;
-  private static final double EARTH_MAX_X = 360;
-  private static final double EARTH_MAX_Y = 180;
-  private static final double EARTH_MID_X = (EARTH_MAX_X - EARTH_MIN_X) / 2;
-  private static final double EARTH_MID_Y = (EARTH_MAX_Y - EARTH_MIN_Y) / 2;
-  private static final double[] xf = new double[] { -0.25, 0.25, -0.25, 0.25 };
-  private static final double[] yf = new double[] { 0.25, 0.25, -0.25, -0.25 };
-
-  private QuadTreeNode root;
-  private int size;
-  private int nodeSize;
-
-  private int maxDepth;
-  private int capacity;
-
-  /**
-   * Creates a quad tree.
-   *
-   * @param capacity
-   *          the capacity of each node in the quad tree
-   * @param maxDepth
-   *          the maximum depth of the tree
-   */
-  public QuadTree(int capacity, int maxDepth) {
-    this.size = 0;
-    this.nodeSize = 0;
-    this.capacity = capacity;
-    this.maxDepth = maxDepth;
-    this.root = new QuadTreeNode(NodeType.GRAY, this.nodeSize);
-  }
-
-  /**
-   * Creates a quad tree with 0 capacity and depth. Useful when user wants to
-   * set the capacity and depth after quad tree construction.
-   */
-  public QuadTree() {
-    this.size = 0;
-    this.nodeSize = 0;
-    this.capacity = 0;
-    this.maxDepth = 0;
-    this.root = new QuadTreeNode(NodeType.GRAY, this.nodeSize);
-  }
-
-  /**
-   * Inserts the specified data into the quad tree.
-   *
-   * @param data
-   *          specified data to be inserted
-   * @return true if the data was inserted into the quad tree; false if data
-   *         cannot be inserted because the capacity of the node has been
-   *         exceeded and the depth of the tree will be exceeded if we insert
-   *         this data
-   */
-  public boolean insert(QuadTreeData data) {
-    if (insert(data, this.root)) {
-      this.size++;
-      return true;
-    } else {
-      return false;
+    // assume map is shifted to be in positive coordinate
+    private static final double EARTH_MIN_X = 0;
+    private static final double EARTH_MIN_Y = 0;
+    private static final double EARTH_MAX_X = 360;
+    private static final double EARTH_MAX_Y = 180;
+    private static final double EARTH_MID_X = (EARTH_MAX_X - EARTH_MIN_X) / 2;
+    private static final double EARTH_MID_Y = (EARTH_MAX_Y - EARTH_MIN_Y) / 2;
+    private static final double[] xf = new double[] { -0.25, 0.25, -0.25, 0.25 };
+    private static final double[] yf = new double[] { 0.25, 0.25, -0.25, -0.25 };
+
+    private QuadTreeNode root;
+    private int size;
+    private int nodeSize;
+
+    private int maxDepth;
+    private int capacity;
+
+    /**
+     * Creates a quad tree.
+     *
+     * @param capacity
+     *            the capacity of each node in the quad tree
+     * @param maxDepth
+     *            the maximum depth of the tree
+     */
+    public QuadTree(int capacity, int maxDepth) {
+        this.size = 0;
+        this.nodeSize = 0;
+        this.capacity = capacity;
+        this.maxDepth = maxDepth;
+        this.root = new QuadTreeNode(NodeType.GRAY, this.nodeSize);
     }
-  }
-
-  /**
-   * Calculates the quadrant that the data lies in.
-   *
-   * @param data
-   *          specifed data
-   * @param x
-   *          the x-midpoint of the current node
-   * @param y
-   *          the y-midpoint of the current node
-   * @return the quadrant that the data lies in
-   */
-  private Quadrant compare(final QuadTreeData data, final double x,
-      final double y) {
-    if (data.getX() < x)
-      if (data.getY() < y)
-        return Quadrant.SW;
-      else
-        return Quadrant.NW;
-    else if (data.getY() < y)
-      return Quadrant.SE;
-    else
-      return Quadrant.NE;
-  }
-
-  /**
-   * Inserts the data into the quad tree with the specified root.
-   *
-   * @param data
-   *          data to be inserted
-   * @param root
-   *          root of quadtree
-   * @return true if data was inserted, false otherwise
-   */
-  private boolean insert(final QuadTreeData data, final QuadTreeNode root) {
-    int currentDepth = 0;
-
-    QuadTreeNode r = root;
-    double x = EARTH_MID_X;
-    double y = EARTH_MID_Y;
-    double lx = EARTH_MAX_X;
-    double ly = EARTH_MAX_Y;
-
-    QuadTreeNode u;
-    QuadTreeNode t;
-    Quadrant q, uq;
-    t = r;
-    q = compare(data, x, y);
-    currentDepth++;
-    while (t.getChild(q) != null
-        && t.getChild(q).getNodeType() == NodeType.GRAY) {
-      t = t.getChild(q);
-      x = x + xf[q.index()] * lx;
-      lx = lx / 2.0;
-      y = y + yf[q.index()] * ly;
-      ly = ly / 2.0;
-      q = compare(data, x, y);
-      currentDepth++;
-
-      if (currentDepth > this.maxDepth)
-        return false;
+
+    /**
+     * Creates a quad tree with 0 capacity and depth. Useful when user wants to
+     * set the capacity and depth after quad tree construction.
+     */
+    public QuadTree() {
+        this.size = 0;
+        this.nodeSize = 0;
+        this.capacity = 0;
+        this.maxDepth = 0;
+        this.root = new QuadTreeNode(NodeType.GRAY, this.nodeSize);
     }
-    if (t.getChild(q) == null) {
-      QuadTreeNode newlyCreated = new QuadTreeNode(++this.nodeSize,
-          this.capacity);
-      newlyCreated.addData(data);
-      t.setChild(newlyCreated, q);
-    } else {
-      u = t.getChild(q);
-      if (u.getCount() < this.capacity) {
-        u.addData(data);
-        return true;
-      } else {
-        QuadTreeData[] originalData = u.getData();
-
-        if (!maxDepthExceeded(originalData, data, x, y, lx, ly, q, currentDepth)) {
-          t.setChild(new QuadTreeNode(NodeType.GRAY, u.getId()), q);
-          t = t.getChild(q);
-          x = x + xf[q.index()] * lx;
-          lx = lx / 2.0;
-
-          y = y + yf[q.index()] * ly;
-          ly = ly / 2.0;
-          q = compare(data, x, y);
-          currentDepth++;
-          if (currentDepth > this.maxDepth)
+
+    /**
+     * Inserts the specified data into the quad tree.
+     *
+     * @param data
+     *            specified data to be inserted
+     * @return true if the data was inserted into the quad tree; false if data
+     *         cannot be inserted because the capacity of the node has been
+     *         exceeded and the depth of the tree will be exceeded if we insert
+     *         this data
+     */
+    public boolean insert(QuadTreeData data) {
+        if (insert(data, this.root)) {
+            this.size++;
+            return true;
+        } else {
             return false;
-          while (isSimilarQuad(originalData, data, x, y, q)) {
-            t.setChild(new QuadTreeNode(NodeType.GRAY, ++this.nodeSize), q);
+        }
+    }
+
+    /**
+     * Calculates the quadrant that the data lies in.
+     *
+     * @param data
+     *            specifed data
+     * @param x
+     *            the x-midpoint of the current node
+     * @param y
+     *            the y-midpoint of the current node
+     * @return the quadrant that the data lies in
+     */
+    private Quadrant compare(final QuadTreeData data, final double x, final double y) {
+        if (data.getX() < x)
+            if (data.getY() < y)
+                return Quadrant.SW;
+            else
+                return Quadrant.NW;
+        else if (data.getY() < y)
+            return Quadrant.SE;
+        else
+            return Quadrant.NE;
+    }
+
+    /**
+     * Inserts the data into the quad tree with the specified root.
+     *
+     * @param data
+     *            data to be inserted
+     * @param root
+     *            root of quadtree
+     * @return true if data was inserted, false otherwise
+     */
+    private boolean insert(final QuadTreeData data, final QuadTreeNode root) {
+        int currentDepth = 0;
+
+        QuadTreeNode r = root;
+        double x = EARTH_MID_X;
+        double y = EARTH_MID_Y;
+        double lx = EARTH_MAX_X;
+        double ly = EARTH_MAX_Y;
+
+        QuadTreeNode u;
+        QuadTreeNode t;
+        Quadrant q, uq;
+        t = r;
+        q = compare(data, x, y);
+        currentDepth++;
+        while (t.getChild(q) != null && t.getChild(q).getNodeType() == NodeType.GRAY) {
             t = t.getChild(q);
             x = x + xf[q.index()] * lx;
             lx = lx / 2.0;
-
             y = y + yf[q.index()] * ly;
             ly = ly / 2.0;
             q = compare(data, x, y);
             currentDepth++;
-            if (currentDepth > this.maxDepth)
-              return false;
-          }
 
-          if (t.getChild(q) == null) {
-            QuadTreeNode newlyCreated = new QuadTreeNode(++this.nodeSize,
-                this.capacity);
+            if (currentDepth > this.maxDepth)
+                return false;
+        }
+        if (t.getChild(q) == null) {
+            QuadTreeNode newlyCreated = new QuadTreeNode(++this.nodeSize, this.capacity);
             newlyCreated.addData(data);
             t.setChild(newlyCreated, q);
-          } else {
-            t.getChild(q).addData(data);
-          }
-
-          for (int i = 0; i < originalData.length; i++) {
-            uq = compare(originalData[i], x, y);
-            if (t.getChild(uq) == null) {
-              QuadTreeNode newlyCreated = new QuadTreeNode(++this.nodeSize,
-                  this.capacity);
-              newlyCreated.addData(originalData[i]);
-              t.setChild(newlyCreated, uq);
+        } else {
+            u = t.getChild(q);
+            if (u.getCount() < this.capacity) {
+                u.addData(data);
+                return true;
             } else {
-              t.getChild(uq).addData(originalData[i]);
+                QuadTreeData[] originalData = u.getData();
+
+                if (!maxDepthExceeded(originalData, data, x, y, lx, ly, q, currentDepth)) {
+                    t.setChild(new QuadTreeNode(NodeType.GRAY, u.getId()), q);
+                    t = t.getChild(q);
+                    x = x + xf[q.index()] * lx;
+                    lx = lx / 2.0;
+
+                    y = y + yf[q.index()] * ly;
+                    ly = ly / 2.0;
+                    q = compare(data, x, y);
+                    currentDepth++;
+                    if (currentDepth > this.maxDepth)
+                        return false;
+                    while (isSimilarQuad(originalData, data, x, y, q)) {
+                        t.setChild(new QuadTreeNode(NodeType.GRAY, ++this.nodeSize), q);
+                        t = t.getChild(q);
+                        x = x + xf[q.index()] * lx;
+                        lx = lx / 2.0;
+
+                        y = y + yf[q.index()] * ly;
+                        ly = ly / 2.0;
+                        q = compare(data, x, y);
+                        currentDepth++;
+                        if (currentDepth > this.maxDepth)
+                            return false;
+                    }
+
+                    if (t.getChild(q) == null) {
+                        QuadTreeNode newlyCreated = new QuadTreeNode(++this.nodeSize, this.capacity);
+                        newlyCreated.addData(data);
+                        t.setChild(newlyCreated, q);
+                    } else {
+                        t.getChild(q).addData(data);
+                    }
+
+                    for (int i = 0; i < originalData.length; i++) {
+                        uq = compare(originalData[i], x, y);
+                        if (t.getChild(uq) == null) {
+                            QuadTreeNode newlyCreated = new QuadTreeNode(++this.nodeSize, this.capacity);
+                            newlyCreated.addData(originalData[i]);
+                            t.setChild(newlyCreated, uq);
+                        } else {
+                            t.getChild(uq).addData(originalData[i]);
+                        }
+                    }
+                } else {
+                    return false;
+                }
             }
-          }
-        } else {
-          return false;
         }
-      }
-    }
-    return true;
-  }
-
-  /**
-   * Determines if insertion of the data will cause the depth of the quad tree
-   * to be exceeded.
-   *
-   * @param originalData
-   *          array containing the data that is already stored in the node
-   * @param toBeAddedData
-   *          data to be added to the node
-   * @param originalX
-   *          the x-midpoint of the node
-   * @param originalY
-   *          the y-midpoint of the node
-   * @param originalLX
-   *          the width of the node
-   * @param originalLY
-   *          the height of the node
-   * @param originalQ
-   *          the quadrant that all data currently lies in
-   * @param depth
-   *          the current depth
-   * @return true if the depth will be exceeded, false otherwise
-   */
-  private boolean maxDepthExceeded(final QuadTreeData[] originalData,
-      final QuadTreeData toBeAddedData, final double originalX,
-      final double originalY, final double originalLX, final double originalLY,
-      final Quadrant originalQ, final int depth) {
-    int currentDepth = depth;
-    double x = originalX;
-    double lx = originalLX;
-    double y = originalY;
-    double ly = originalLY;
-    Quadrant q = originalQ;
-
-    x = x + xf[q.index()] * lx;
-    lx = lx / 2.0;
-
-    y = y + yf[q.index()] * ly;
-    ly = ly / 2.0;
-    q = compare(toBeAddedData, x, y);
-    currentDepth++;
-    if (currentDepth > this.maxDepth)
-      return true;
-    while (isSimilarQuad(originalData, toBeAddedData, x, y, q)) {
-      x = x + xf[q.index()] * lx;
-      lx = lx / 2.0;
-
-      y = y + yf[q.index()] * ly;
-      ly = ly / 2.0;
-      q = compare(toBeAddedData, x, y);
-      currentDepth++;
-      if (currentDepth > this.maxDepth)
         return true;
     }
-    return false;
-  }
-
-  /**
-   * Returns true if all data (new and old) have to be stored in the same
-   * quadrant of the node.
-   *
-   * @param originalData
-   *          array of data already stored in the node
-   * @param newNode
-   *          the node in which data is stored
-   * @param x
-   *          the x midpoint of the node
-   * @param y
-   *          the y midpoint of the node
-   * @param q
-   *          the quadrant that the new data lies in
-   * @return true if all data lies in the quadrant, false otherwise
-   */
-  private boolean isSimilarQuad(QuadTreeData[] originalData,
-      QuadTreeData newNode, double x, double y, Quadrant q) {
-    Quadrant quad = compare(originalData[0], x, y);
-    if (q != quad)
-      return false;
-    for (int i = 1; i < originalData.length; i++) {
-      if (compare(originalData[i], x, y) != quad)
+
+    /**
+     * Determines if insertion of the data will cause the depth of the quad tree
+     * to be exceeded.
+     *
+     * @param originalData
+     *            array containing the data that is already stored in the node
+     * @param toBeAddedData
+     *            data to be added to the node
+     * @param originalX
+     *            the x-midpoint of the node
+     * @param originalY
+     *            the y-midpoint of the node
+     * @param originalLX
+     *            the width of the node
+     * @param originalLY
+     *            the height of the node
+     * @param originalQ
+     *            the quadrant that all data currently lies in
+     * @param depth
+     *            the current depth
+     * @return true if the depth will be exceeded, false otherwise
+     */
+    private boolean maxDepthExceeded(final QuadTreeData[] originalData, final QuadTreeData toBeAddedData,
+            final double originalX, final double originalY, final double originalLX, final double originalLY,
+            final Quadrant originalQ, final int depth) {
+        int currentDepth = depth;
+        double x = originalX;
+        double lx = originalLX;
+        double y = originalY;
+        double ly = originalLY;
+        Quadrant q = originalQ;
+
+        x = x + xf[q.index()] * lx;
+        lx = lx / 2.0;
+
+        y = y + yf[q.index()] * ly;
+        ly = ly / 2.0;
+        q = compare(toBeAddedData, x, y);
+        currentDepth++;
+        if (currentDepth > this.maxDepth)
+            return true;
+        while (isSimilarQuad(originalData, toBeAddedData, x, y, q)) {
+            x = x + xf[q.index()] * lx;
+            lx = lx / 2.0;
+
+            y = y + yf[q.index()] * ly;
+            ly = ly / 2.0;
+            q = compare(toBeAddedData, x, y);
+            currentDepth++;
+            if (currentDepth > this.maxDepth)
+                return true;
+        }
         return false;
     }
-    return true;
-  }
-
-  /**
-   * Performs point radius search.
-   *
-   * @param point
-   *          the center of the circular region
-   * @param radiusKM
-   *          the radius in kilometers
-   * @return a list of QuadTreeData that are within the given radius from the
-   *         point
-   */
-  public List<QuadTreeData> queryByPointRadius(final DirectPosition2D point,
-      final double radiusKM) {
-    LatLonPointRadius pr = new LatLonPointRadius(point, radiusKM);
-    return queryByPointRadius(point, radiusKM, this.root,
-        new Rectangle2D.Double(EARTH_MIN_X, EARTH_MIN_Y, EARTH_MAX_X,
-            EARTH_MAX_Y), pr.getRectangularRegionApproximation(360));
-  }
-
-  /**
-   * Performs point radius search.
-   *
-   * @param point
-   *          the center of the circular region
-   * @param radiusKM
-   *          the radius in kilometers
-   * @param node
-   *          quad tree root node
-   * @param nodeRegion
-   *          Rectangle2D representing the circular node region
-   * @param searchRegion
-   *          Rectangle2D representing the circular search region
-   * @return a list of QuadTreeData that are within the given radius from the
-   *         point
-   */
-  private List<QuadTreeData> queryByPointRadius(final DirectPosition2D point,
-      final double radiusKM, final QuadTreeNode node,
-      final Rectangle2D nodeRegion, final Rectangle2D searchRegion) {
-    List<QuadTreeData> matches = new ArrayList<QuadTreeData>();
-    if (node == null) {
-      return matches;
-    } else if (node.getNodeType() != NodeType.GRAY) {
-      if (node.getNodeType() == NodeType.WHITE)
-        return matches;
-      else {
-        QuadTreeData[] data = node.getData();
-        for (int i = 0; i < node.getCount(); i++) {
-          if (DistanceUtils.getHaversineDistance(data[i].getLatLon().y, data[i]
-              .getLatLon().x, point.y, point.x) <= radiusKM) {
-            matches.add(data[i]);
-          }
-        }
-        return matches;
-      }
-
-    } else {
-      Rectangle2D swRectangle = new Rectangle2D.Double(nodeRegion.getX(),
-          nodeRegion.getY(), nodeRegion.getWidth() / 2,
-          nodeRegion.getHeight() / 2);
-      Rectangle2D seRectangle = new Rectangle2D.Double(nodeRegion.getX()
-          + nodeRegion.getWidth() / 2, nodeRegion.getY(),
-          nodeRegion.getWidth() / 2, nodeRegion.getHeight() / 2);
-      Rectangle2D nwRectangle = new Rectangle2D.Double(nodeRegion.getX(),
-          nodeRegion.getY() + nodeRegion.getHeight() / 2,
-          nodeRegion.getWidth() / 2, nodeRegion.getHeight() / 2);
-      Rectangle2D neRectangle = new Rectangle2D.Double(nodeRegion.getX()
-          + nodeRegion.getWidth() / 2, nodeRegion.getY()
-          + nodeRegion.getHeight() / 2, nodeRegion.getWidth() / 2, nodeRegion
-          .getHeight() / 2);
-
-      if (swRectangle.intersects(searchRegion)) {
-        List<QuadTreeData> swMatches = queryByPointRadius(point, radiusKM, node
-            .getChild(Quadrant.SW), swRectangle, searchRegion);
-        for (QuadTreeData q : swMatches) {
-          matches.add(q);
-        }
-      }
-      if (seRectangle.intersects(searchRegion)) {
-        List<QuadTreeData> seMatches = queryByPointRadius(point, radiusKM, node
-            .getChild(Quadrant.SE), seRectangle, searchRegion);
-        for (QuadTreeData q : seMatches) {
-          matches.add(q);
-        }
-      }
-      if (nwRectangle.intersects(searchRegion)) {
-        List<QuadTreeData> nwMatches = queryByPointRadius(point, radiusKM, node
-            .getChild(Quadrant.NW), nwRectangle, searchRegion);
-        for (QuadTreeData q : nwMatches) {
-          matches.add(q);
-        }
-      }
-      if (neRectangle.intersects(searchRegion)) {
-        List<QuadTreeData> neMatches = queryByPointRadius(point, radiusKM, node
-            .getChild(Quadrant.NE), neRectangle, searchRegion);
-        for (QuadTreeData q : neMatches) {
-          matches.add(q);
+
+    /**
+     * Returns true if all data (new and old) have to be stored in the same
+     * quadrant of the node.
+     *
+     * @param originalData
+     *            array of data already stored in the node
+     * @param newNode
+     *            the node in which data is stored
+     * @param x
+     *            the x midpoint of the node
+     * @param y
+     *            the y midpoint of the node
+     * @param q
+     *            the quadrant that the new data lies in
+     * @return true if all data lies in the quadrant, false otherwise
+     */
+    private boolean isSimilarQuad(QuadTreeData[] originalData, QuadTreeData newNode, double x, double y, Quadrant q) {
+        Quadrant quad = compare(originalData[0], x, y);
+        if (q != quad)
+            return false;
+        for (int i = 1; i < originalData.length; i++) {
+            if (compare(originalData[i], x, y) != quad)
+                return false;
         }
-      }
-    }
-    return matches;
-  }
-
-  /**
-   * Performs bounding box search.
-   *
-   * @param searchRegion
-   *          Envelope representing the rectangular search region
-   * @return a list of QuadTreeData that are within the given radius from the
-   *         point
-   */
-  public List<QuadTreeData> queryByBoundingBox(final Envelope2D searchRegion) {
-    Rectangle2D.Double[] rectArray = searchRegion.toRectangles();
-    for (final Rectangle2D.Double r : rectArray) {
-        r.x += 180;
-        r.y += 90;
+        return true;
     }
-    if (rectArray.length == 1) {
-      // traverse tree once because region does not cross dateline
-      return queryByBoundingBox(rectArray[0]);
-
-    } else if (rectArray.length == 2) {
-      // traverse tree twice since region crosses dateline
-      List<QuadTreeData> firstMatches = queryByBoundingBox(rectArray[0]);
-      List<QuadTreeData> secondMatches = queryByBoundingBox(rectArray[1]);
-
-      // merge two lists and return
-      for (QuadTreeData q : secondMatches) {
-        if (!firstMatches.contains(q)) {
-          firstMatches.add(q);
-        }
-      }
-      return firstMatches;
-    } else {
-      return null;
+
+    /**
+     * Performs point radius search.
+     *
+     * @param point
+     *            the center of the circular region
+     * @param radiusKM
+     *            the radius in kilometers
+     * @return a list of QuadTreeData that are within the given radius from the
+     *         point
+     */
+    public List<QuadTreeData> queryByPointRadius(final DirectPosition2D point, final double radiusKM) {
+        LatLonPointRadius pr = new LatLonPointRadius(point, radiusKM);
+        return queryByPointRadius(point, radiusKM, this.root,
+                new Rectangle2D.Double(EARTH_MIN_X, EARTH_MIN_Y, EARTH_MAX_X, EARTH_MAX_Y),
+                pr.getRectangularRegionApproximation(360));
     }
-  }
-
-  /**
-   * Performs bounding box search.
-   *
-   * @param searchRegion
-   *          Rectangle2D representing the rectangular search region
-   * @return a list of QuadTreeData that are within the given radius from the
-   *         point
-   */
-  private List<QuadTreeData> queryByBoundingBox(final Rectangle2D searchRegion) {
-    return queryByBoundingBox(this.root, new Rectangle2D.Double(EARTH_MIN_X,
-        EARTH_MIN_Y, EARTH_MAX_X, EARTH_MAX_Y), searchRegion);
-  }
-
-  /**
-   * Performs bounding box search.
-   *
-   * @param node
-   *          quad tree root node
-   * @param nodeRegion
-   *          Rectangle2D representing the rectangular node region
-   * @param searchRegion
-   *          Rectangle2D representing the rectangular search region
-   * @return a list of QuadTreeData that are within the given radius from the
-   *         point
-   */
-  private List<QuadTreeData> queryByBoundingBox(final QuadTreeNode node,
-      final Rectangle2D nodeRegion, final Rectangle2D searchRegion) {
-
-    List<QuadTreeData> matches = new ArrayList<QuadTreeData>();
-    if (node == null) {
-      return matches;
-    } else if (node.getNodeType() != NodeType.GRAY) {
-      if (node.getNodeType() == NodeType.WHITE)
-        return matches;
-      else {
-        QuadTreeData[] data = node.getData();
-        for (int i = 0; i < node.getCount(); i++) {
-          if (searchRegion.contains(data[i].getX(), data[i].getY())) {
-            matches.add(data[i]);
-          }
+
+    /**
+     * Performs point radius search.
+     *
+     * @param point
+     *            the center of the circular region
+     * @param radiusKM
+     *            the radius in kilometers
+     * @param node
+     *            quad tree root node
+     * @param nodeRegion
+     *            Rectangle2D representing the circular node region
+     * @param searchRegion
+     *            Rectangle2D representing the circular search region
+     * @return a list of QuadTreeData that are within the given radius from the
+     *         point
+     */
+    private List<QuadTreeData> queryByPointRadius(final DirectPosition2D point, final double radiusKM,
+            final QuadTreeNode node, final Rectangle2D nodeRegion, final Rectangle2D searchRegion) {
+        List<QuadTreeData> matches = new ArrayList<QuadTreeData>();
+        if (node == null) {
+            return matches;
+        } else if (node.getNodeType() != NodeType.GRAY) {
+            if (node.getNodeType() == NodeType.WHITE)
+                return matches;
+            else {
+                QuadTreeData[] data = node.getData();
+                for (int i = 0; i < node.getCount(); i++) {
+                    if (DistanceUtils.getHaversineDistance(data[i].getLatLon().y, data[i].getLatLon().x, point.y,
+                            point.x) <= radiusKM) {
+                        matches.add(data[i]);
+                    }
+                }
+                return matches;
+            }
+
+        } else {
+            Rectangle2D swRectangle = new Rectangle2D.Double(nodeRegion.getX(), nodeRegion.getY(),
+                    nodeRegion.getWidth() / 2, nodeRegion.getHeight() / 2);
+            Rectangle2D seRectangle = new Rectangle2D.Double(nodeRegion.getX() + nodeRegion.getWidth() / 2,
+                    nodeRegion.getY(), nodeRegion.getWidth() / 2, nodeRegion.getHeight() / 2);
+            Rectangle2D nwRectangle = new Rectangle2D.Double(nodeRegion.getX(),
+                    nodeRegion.getY() + nodeRegion.getHeight() / 2, nodeRegion.getWidth() / 2,
+                    nodeRegion.getHeight() / 2);
+            Rectangle2D neRectangle = new Rectangle2D.Double(nodeRegion.getX() + nodeRegion.getWidth() / 2,
+                    nodeRegion.getY() + nodeRegion.getHeight() / 2, nodeRegion.getWidth() / 2,
+                    nodeRegion.getHeight() / 2);
+
+            if (swRectangle.intersects(searchRegion)) {
+                List<QuadTreeData> swMatches = queryByPointRadius(point, radiusKM, node.getChild(Quadrant.SW),
+                        swRectangle, searchRegion);
+                for (QuadTreeData q : swMatches) {
+                    matches.add(q);
+                }
+            }
+            if (seRectangle.intersects(searchRegion)) {
+                List<QuadTreeData> seMatches = queryByPointRadius(point, radiusKM, node.getChild(Quadrant.SE),
+                        seRectangle, searchRegion);
+                for (QuadTreeData q : seMatches) {
+                    matches.add(q);
+                }
+            }
+            if (nwRectangle.intersects(searchRegion)) {
+                List<QuadTreeData> nwMatches = queryByPointRadius(point, radiusKM, node.getChild(Quadrant.NW),
+                        nwRectangle, searchRegion);
+                for (QuadTreeData q : nwMatches) {
+                    matches.add(q);
+                }
+            }
+            if (neRectangle.intersects(searchRegion)) {
+                List<QuadTreeData> neMatches = queryByPointRadius(point, radiusKM, node.getChild(Quadrant.NE),
+                        neRectangle, searchRegion);
+                for (QuadTreeData q : neMatches) {
+                    matches.add(q);
+                }
+            }
         }
         return matches;
-      }
-
-    } else {
-      Rectangle2D swRectangle = new Rectangle2D.Double(nodeRegion.getX(),
-          nodeRegion.getY(), nodeRegion.getWidth() / 2,
-          nodeRegion.getHeight() / 2);
-      Rectangle2D seRectangle = new Rectangle2D.Double(nodeRegion.getX()
-          + nodeRegion.getWidth() / 2, nodeRegion.getY(),
-          nodeRegion.getWidth() / 2, nodeRegion.getHeight() / 2);
-      Rectangle2D nwRectangle = new Rectangle2D.Double(nodeRegion.getX(),
-          nodeRegion.getY() + nodeRegion.getHeight() / 2,
-          nodeRegion.getWidth() / 2, nodeRegion.getHeight() / 2);
-      Rectangle2D neRectangle = new Rectangle2D.Double(nodeRegion.getX()
-          + nodeRegion.getWidth() / 2, nodeRegion.getY()
-          + nodeRegion.getHeight() / 2, nodeRegion.getWidth() / 2, nodeRegion
-          .getHeight() / 2);
-
-      if (swRectangle.intersects(searchRegion)) {
-        List<QuadTreeData> swMatches = queryByBoundingBox(node
-            .getChild(Quadrant.SW), swRectangle, searchRegion);
-        for (QuadTreeData q : swMatches) {
-          matches.add(q);
-        }
-      }
-      if (seRectangle.intersects(searchRegion)) {
-        List<QuadTreeData> seMatches = queryByBoundingBox(node
-            .getChild(Quadrant.SE), seRectangle, searchRegion);
-        for (QuadTreeData q : seMatches) {
-          matches.add(q);
+    }
+
+    /**
+     * Performs bounding box search.
+     *
+     * @param searchRegion
+     *            Envelope representing the rectangular search region
+     * @return a list of QuadTreeData that are within the given radius from the
+     *         point
+     */
+    public List<QuadTreeData> queryByBoundingBox(final Envelope2D searchRegion) {
+        Rectangle2D.Double[] rectArray = searchRegion.toRectangles();
+        for (final Rectangle2D.Double r : rectArray) {
+            r.x += 180;
+            r.y += 90;
         }
-      }
-      if (nwRectangle.intersects(searchRegion)) {
-        List<QuadTreeData> nwMatches = queryByBoundingBox(node
-            .getChild(Quadrant.NW), nwRectangle, searchRegion);
-        for (QuadTreeData q : nwMatches) {
-          matches.add(q);
+        if (rectArray.length == 1) {
+            // traverse tree once because region does not cross dateline
+            return queryByBoundingBox(rectArray[0]);
+
+        } else if (rectArray.length == 2) {
+            // traverse tree twice since region crosses dateline
+            List<QuadTreeData> firstMatches = queryByBoundingBox(rectArray[0]);
+            List<QuadTreeData> secondMatches = queryByBoundingBox(rectArray[1]);
+
+            // merge two lists and return
+            for (QuadTreeData q : secondMatches) {
+                if (!firstMatches.contains(q)) {
+                    firstMatches.add(q);
+                }
+            }
+            return firstMatches;
+        } else {
+            return null;
         }
-      }
-      if (neRectangle.intersects(searchRegion)) {
-        List<QuadTreeData> neMatches = queryByBoundingBox(node
-            .getChild(Quadrant.NE), neRectangle, searchRegion);
-        for (QuadTreeData q : neMatches) {
-          matches.add(q);
+    }
+
+    /**
+     * Performs bounding box search.
+     *
+     * @param searchRegion
+     *            Rectangle2D representing the rectangular search region
+     * @return a list of QuadTreeData that are within the given radius from the
+     *         point
+     */
+    private List<QuadTreeData> queryByBoundingBox(final Rectangle2D searchRegion) {
+        return queryByBoundingBox(this.root, new Rectangle2D.Double(EARTH_MIN_X, EARTH_MIN_Y, EARTH_MAX_X, EARTH_MAX_Y),
+                searchRegion);
+    }
+
+    /**
+     * Performs bounding box search.
+     *
+     * @param node
+     *            quad tree root node
+     * @param nodeRegion
+     *            Rectangle2D representing the rectangular node region
+     * @param searchRegion
+     *            Rectangle2D representing the rectangular search region
+     * @return a list of QuadTreeData that are within the given radius from the
+     *         point
+     */
+    private List<QuadTreeData> queryByBoundingBox(final QuadTreeNode node, final Rectangle2D nodeRegion,
+            final Rectangle2D searchRegion) {
+
+        List<QuadTreeData> matches = new ArrayList<QuadTreeData>();
+        if (node == null) {
+            return matches;
+        } else if (node.getNodeType() != NodeType.GRAY) {
+            if (node.getNodeType() == NodeType.WHITE)
+                return matches;
+            else {
+                QuadTreeData[] data = node.getData();
+                for (int i = 0; i < node.getCount(); i++) {
+                    if (searchRegion.contains(data[i].getX(), data[i].getY())) {
+                        matches.add(data[i]);
+                    }
+                }
+                return matches;
+            }
+
+        } else {
+            Rectangle2D swRectangle = new Rectangle2D.Double(nodeRegion.getX(), nodeRegion.getY(),
+                    nodeRegion.getWidth() / 2, nodeRegion.getHeight() / 2);
+            Rectangle2D seRectangle = new Rectangle2D.Double(nodeRegion.getX() + nodeRegion.getWidth() / 2,
+                    nodeRegion.getY(), nodeRegion.getWidth() / 2, nodeRegion.getHeight() / 2);
+            Rectangle2D nwRectangle = new Rectangle2D.Double(nodeRegion.getX(),
+                    nodeRegion.getY() + nodeRegion.getHeight() / 2, nodeRegion.getWidth() / 2,
+                    nodeRegion.getHeight() / 2);
+            Rectangle2D neRectangle = new Rectangle2D.Double(nodeRegion.getX() + nodeRegion.getWidth() / 2,
+                    nodeRegion.getY() + nodeRegion.getHeight() / 2, nodeRegion.getWidth() / 2,
+                    nodeRegion.getHeight() / 2);
+
+            if (swRectangle.intersects(searchRegion)) {
+                List<QuadTreeData> swMatches = queryByBoundingBox(node.getChild(Quadrant.SW), swRectangle,
+                        searchRegion);
+                for (QuadTreeData q : swMatches) {
+                    matches.add(q);
+                }
+            }
+            if (seRectangle.intersects(searchRegion)) {
+                List<QuadTreeData> seMatches = queryByBoundingBox(node.getChild(Quadrant.SE), seRectangle,
+                        searchRegion);
+                for (QuadTreeData q : seMatches) {
+                    matches.add(q);
+                }
+            }
+            if (nwRectangle.intersects(searchRegion)) {
+                List<QuadTreeData> nwMatches = queryByBoundingBox(node.getChild(Quadrant.NW), nwRectangle,
+                        searchRegion);
+                for (QuadTreeData q : nwMatches) {
+                    matches.add(q);
+                }
+            }
+            if (neRectangle.intersects(searchRegion)) {
+                List<QuadTreeData> neMatches = queryByBoundingBox(node.getChild(Quadrant.NE), neRectangle,
+                        searchRegion);
+                for (QuadTreeData q : neMatches) {
+                    matches.add(q);
+                }
+            }
         }
-      }
+        return matches;
+    }
+
+    /**
+     * Returns the size of the quad tree.
+     *
+     * @return size of the quad tree.
+     */
+    public int size() {
+        return this.size;
+    }
+
+    /**
+     * Returns the root node of the quad tree.
+     *
+     * @return root node of the quad tree.
+     */
+    final QuadTreeNode getRoot() {
+        return this.root;
+    }
+
+    /**
+     * Sets the size of the quad tree.
+     *
+     * @param size
+     *            The new quad tree size.
+     */
+    public void setSize(int size) {
+        this.size = size;
+    }
+
+    /**
+     * Returns the size of the quad tree.
+     *
+     * @return size of quad tree
+     */
+    public int getSize() {
+        return this.size;
+    }
+
+    /**
+     * Sets the node size of the quad tree.
+     *
+     * @param nodeSize
+     *            The new node size.
+     */
+    public void setNodeSize(int nodeSize) {
+        this.nodeSize = nodeSize;
+    }
+
+    /**
+     * Returns the node size of the quad tree.
+     *
+     * @return node size of the quad tree.
+     */
+    public int getNodeSize() {
+        return this.nodeSize;
+    }
+
+    /**
+     * Returns the capacity of node in the quad tree.
+     *
+     * @return capacity of node in the quad tree.
+     */
+    public int getCapacity() {
+        return this.capacity;
+    }
+
+    /**
+     * Returns the maximum depth of the quad tree.
+     *
+     * @return maximum depth of the quad tree.
+     */
+    public int getDepth() {
+        return this.maxDepth;
+    }
+
+    /**
+     * Sets the capacity of node in the quad tree.
+     *
+     * @param capacity
+     *            the capacity of node in the quad tree.
+     */
+    public void setCapacity(int capacity) {
+        this.capacity = capacity;
+    }
+
+    /**
+     * Sets the maximum depth of the quad tree.
+     *
+     * @param depth
+     *            the maximum depth of the quad tree.
+     */
+    public void setDepth(int depth) {
+        this.maxDepth = depth;
     }
-    return matches;
-  }
-
-  /**
-   * Returns the size of the quad tree.
-   *
-   * @return size of the quad tree.
-   */
-  public int size() {
-    return this.size;
-  }
-
-  /**
-   * Returns the root node of the quad tree.
-   *
-   * @return root node of the quad tree.
-   */
-  final QuadTreeNode getRoot() {
-    return this.root;
-  }
-
-  /**
-   * Sets the size of the quad tree.
-   *
-   * @param size The new quad tree size.
-   */
-  public void setSize(int size) {
-    this.size = size;
-  }
-
-  /**
-   * Returns the size of the quad tree.
-   *
-   * @return size of quad tree
-   */
-  public int getSize() {
-    return this.size;
-  }
-
-  /**
-   * Sets the node size of the quad tree.
-   *
-   * @param nodeSize The new node size.
-   */
-  public void setNodeSize(int nodeSize) {
-    this.nodeSize = nodeSize;
-  }
-
-  /**
-   * Returns the node size of the quad tree.
-   *
-   * @return node size of the quad tree.
-   */
-  public int getNodeSize() {
-    return this.nodeSize;
-  }
-
-  /**
-   * Returns the capacity of node in the quad tree.
-   *
-   * @return capacity of node in the quad tree.
-   */
-  public int getCapacity() {
-    return this.capacity;
-  }
-
-  /**
-   * Returns the maximum depth of the quad tree.
-   *
-   * @return maximum depth of the quad tree.
-   */
-  public int getDepth() {
-    return this.maxDepth;
-  }
-
-  /**
-   * Sets the capacity of node in the quad tree.
-   *
-   * @param capacity the capacity of node in the quad tree.
-   */
-  public void setCapacity(int capacity) {
-    this.capacity = capacity;
-  }
-
-  /**
-   * Sets the maximum depth of the quad tree.
-   *
-   * @param depth the maximum depth of the quad tree.
-   */
-  public void setDepth(int depth) {
-    this.maxDepth = depth;
-  }
 }
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTreeData.java b/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTreeData.java
index 507bada..3a37ae9 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTreeData.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTreeData.java
@@ -24,35 +24,36 @@ import org.apache.sis.geometry.DirectPosition2D;
  * quad tree must implement this interface, so that quad tree can access
  * location and store name of file in which data is saved.
  *
- * <div class="warning"><b>Note on future work:</b> this interface may change in incompatible way
- * in a future Apache SIS release, or may be replaced by new API.</div>
+ * <div class="warning"><b>Note on future work:</b> this interface may change in
+ * incompatible way in a future Apache SIS release, or may be replaced by new
+ * API.</div>
  */
 public interface QuadTreeData {
-  /**
-   * Returns the Java 2D x-coordinate for the longitude.
-   *
-   * @return the Java 2D x-coordinate
-   */
-  public double getX();
+    /**
+     * Returns the Java 2D x-coordinate for the longitude.
+     *
+     * @return the Java 2D x-coordinate
+     */
+    public double getX();
 
-  /**
-   * Returns the Java 2D y-coordinate for the latitude.
-   *
-   * @return the Java 2D y-coordinate
-   */
-  public double getY();
+    /**
+     * Returns the Java 2D y-coordinate for the latitude.
+     *
+     * @return the Java 2D y-coordinate
+     */
+    public double getY();
 
-  /**
-   * Returns the latitude/longitude pair.
-   *
-   * @return the latitude/longitude pair.
-   */
-  public DirectPosition2D getLatLon();
+    /**
+     * Returns the latitude/longitude pair.
+     *
+     * @return the latitude/longitude pair.
+     */
+    public DirectPosition2D getLatLon();
 
-  /**
-   * Returns the name of the file where the entry's info is saved.
-   *
-   * @return the name of the file where the entry's info is saved
-   */
-  public String getFileName();
+    /**
+     * Returns the name of the file where the entry's info is saved.
+     *
+     * @return the name of the file where the entry's info is saved
+     */
+    public String getFileName();
 }
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTreeNode.java b/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTreeNode.java
index ce8a7d4..5078deb 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTreeNode.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTreeNode.java
@@ -22,157 +22,157 @@ package org.apache.sis.index.tree;
  */
 final class QuadTreeNode {
 
-  private QuadTreeData[] data;
-  private QuadTreeNode nw;
-  private QuadTreeNode ne;
-  private QuadTreeNode se;
-  private QuadTreeNode sw;
-  private NodeType type;
-  private int id;
-  private int capacity;
-  private int dataCount;
-  private static final int MIN_CAPACITY = 10;
+    private QuadTreeData[] data;
+    private QuadTreeNode nw;
+    private QuadTreeNode ne;
+    private QuadTreeNode se;
+    private QuadTreeNode sw;
+    private NodeType type;
+    private int id;
+    private int capacity;
+    private int dataCount;
+    private static final int MIN_CAPACITY = 10;
 
-  /**
-   * Constructs a quad tree node that can store data
-   *
-   * @param id
-   *          node's id
-   * @param capacity
-   *          node's capcacity
-   */
-  public QuadTreeNode(int id, int capacity) {
-    this.capacity = capacity > 0 ? capacity : MIN_CAPACITY;
-    this.dataCount = 0;
-    this.data = new QuadTreeData[this.capacity];
-    this.type = NodeType.BLACK;
-    this.nw = null;
-    this.ne = null;
-    this.sw = null;
-    this.se = null;
-    this.id = id;
-  }
+    /**
+     * Constructs a quad tree node that can store data
+     *
+     * @param id
+     *            node's id
+     * @param capacity
+     *            node's capcacity
+     */
+    public QuadTreeNode(int id, int capacity) {
+        this.capacity = capacity > 0 ? capacity : MIN_CAPACITY;
+        this.dataCount = 0;
+        this.data = new QuadTreeData[this.capacity];
+        this.type = NodeType.BLACK;
+        this.nw = null;
+        this.ne = null;
+        this.sw = null;
+        this.se = null;
+        this.id = id;
+    }
 
-  /**
-   * Constructs a quad tree node that acts as a parent.
-   *
-   * @param type
-   *          node's type
-   * @param id
-   *          node's id
-   */
-  public QuadTreeNode(NodeType type, int id) {
-    this.type = type;
-    this.nw = null;
-    this.ne = null;
-    this.sw = null;
-    this.se = null;
-    this.data = null;
-    this.id = id;
-  }
+    /**
+     * Constructs a quad tree node that acts as a parent.
+     *
+     * @param type
+     *            node's type
+     * @param id
+     *            node's id
+     */
+    public QuadTreeNode(NodeType type, int id) {
+        this.type = type;
+        this.nw = null;
+        this.ne = null;
+        this.sw = null;
+        this.se = null;
+        this.data = null;
+        this.id = id;
+    }
 
-  /**
-   * Add data to the node.
-   *
-   * @param data
-   *          data to be added
-   */
-  public void addData(QuadTreeData data) {
-    if (this.dataCount < this.capacity) {
-      this.data[dataCount] = data;
-      this.dataCount++;
+    /**
+     * Add data to the node.
+     *
+     * @param data
+     *            data to be added
+     */
+    public void addData(QuadTreeData data) {
+        if (this.dataCount < this.capacity) {
+            this.data[dataCount] = data;
+            this.dataCount++;
+        }
     }
-  }
 
-  /**
-   * Gets the number of data stored in the node
-   *
-   * @return number of data stored in the node
-   */
-  public int getCount() {
-    return this.dataCount;
-  }
+    /**
+     * Gets the number of data stored in the node
+     *
+     * @return number of data stored in the node
+     */
+    public int getCount() {
+        return this.dataCount;
+    }
 
-  /**
-   * Gets the node type.
-   *
-   * @return node type
-   */
-  public NodeType getNodeType() {
-    return this.type;
-  }
+    /**
+     * Gets the node type.
+     *
+     * @return node type
+     */
+    public NodeType getNodeType() {
+        return this.type;
+    }
 
-  /**
-   * Sets the node's quadrant to point to the specified child.
-   *
-   * @param child
-   *          child of this node
-   * @param q
-   *          quadrant where the child resides
-   */
-  public void setChild(QuadTreeNode child, Quadrant q) {
-    switch (q) {
-    case NW:
-      this.nw = child;
-      break;
-    case NE:
-      this.ne = child;
-      break;
-    case SW:
-      this.sw = child;
-      break;
-    case SE:
-      this.se = child;
-      break;
+    /**
+     * Sets the node's quadrant to point to the specified child.
+     *
+     * @param child
+     *            child of this node
+     * @param q
+     *            quadrant where the child resides
+     */
+    public void setChild(QuadTreeNode child, Quadrant q) {
+        switch (q) {
+        case NW:
+            this.nw = child;
+            break;
+        case NE:
+            this.ne = child;
+            break;
+        case SW:
+            this.sw = child;
+            break;
+        case SE:
+            this.se = child;
+            break;
+        }
     }
-  }
 
-  /**
-   * Returns the child of this node that resides in the specified quadrant.
-   *
-   * @param q
-   *          specified quadrant
-   * @return child in the specified quadrant
-   */
-  public QuadTreeNode getChild(Quadrant q) {
-    switch (q) {
-    case NW:
-      return this.nw;
-    case NE:
-      return this.ne;
-    case SW:
-      return this.sw;
-    case SE:
-      return this.se;
-    default:
-      return null;
+    /**
+     * Returns the child of this node that resides in the specified quadrant.
+     *
+     * @param q
+     *            specified quadrant
+     * @return child in the specified quadrant
+     */
+    public QuadTreeNode getChild(Quadrant q) {
+        switch (q) {
+        case NW:
+            return this.nw;
+        case NE:
+            return this.ne;
+        case SW:
+            return this.sw;
+        case SE:
+            return this.se;
+        default:
+            return null;
+        }
     }
-  }
 
-  /**
-   * Returns the data stored in this node.
-   *
-   * @return data stored in this node
-   */
-  public QuadTreeData[] getData() {
-    return this.data;
-  }
+    /**
+     * Returns the data stored in this node.
+     *
+     * @return data stored in this node
+     */
+    public QuadTreeData[] getData() {
+        return this.data;
+    }
 
-  /**
-   * Returns node's id.
-   *
-   * @return node's id
-   */
-  public int getId() {
-    return this.id;
-  }
+    /**
+     * Returns node's id.
+     *
+     * @return node's id
+     */
+    public int getId() {
+        return this.id;
+    }
 
-  /**
-   * Returns node's capacity.
-   *
-   * @return node's capacity
-   */
-  public int getCapacity() {
-    return this.capacity;
-  }
+    /**
+     * Returns node's capacity.
+     *
+     * @return node's capacity
+     */
+    public int getCapacity() {
+        return this.capacity;
+    }
 }
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTreeWriter.java b/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTreeWriter.java
index ceaa228..4b7c9f4 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTreeWriter.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/index/tree/QuadTreeWriter.java
@@ -24,157 +24,146 @@ import java.io.IOException;
 /**
  * Class to save the quad tree index from file.
  *
- * <div class="warning"><b>Note on future work:</b> this class may change in incompatible way
- * in a future Apache SIS release, or may be replaced by new API.</div>
+ * <div class="warning"><b>Note on future work:</b> this class may change in
+ * incompatible way in a future Apache SIS release, or may be replaced by new
+ * API.</div>
  */
 public final class QuadTreeWriter {
-  private QuadTreeWriter() {
-  }
+    private QuadTreeWriter() {
+    }
 
-  /**
-   * Writes the entire quad tree index to file with each node in saved in a
-   * separate file.
-   *
-   * @param tree
-   *          the quad tree
-   * @param directory
-   *          the directory where the index file is located
-   */
-  public static void writeTreeToFile(QuadTree tree, String directory) {
-    createIdxDir(directory);
-    writeTreeConfigsToFile(tree, directory);
-    writeNodeToFile(tree.getRoot(), directory);
-  }
+    /**
+     * Writes the entire quad tree index to file with each node in saved in a
+     * separate file.
+     *
+     * @param tree
+     *            the quad tree
+     * @param directory
+     *            the directory where the index file is located
+     */
+    public static void writeTreeToFile(QuadTree tree, String directory) {
+        createIdxDir(directory);
+        writeTreeConfigsToFile(tree, directory);
+        writeNodeToFile(tree.getRoot(), directory);
+    }
 
-  /**
-   * Creating quad tree index file.
-   *
-   * @param directory
-   *          the directory where the index file is located
-   */
-  private static void createIdxDir(String directory) {
-    File dir = new File(directory);
-    if (!dir.exists()) {
-      System.out.println("[INFO] Creating qtree idx dir: [" + directory + "]");
-      new File(directory).mkdirs();
+    /**
+     * Creating quad tree index file.
+     *
+     * @param directory
+     *            the directory where the index file is located
+     */
+    private static void createIdxDir(String directory) {
+        File dir = new File(directory);
+        if (!dir.exists()) {
+            System.out.println("[INFO] Creating qtree idx dir: [" + directory + "]");
+            new File(directory).mkdirs();
+        }
     }
-  }
 
-  /**
-   * Write quad tree configerations to file.
-   *
-   * @param tree
-   *          the quad tree
-   * @param directory
-   *          the directory where the configerations file is located
-   */
-  private static void writeTreeConfigsToFile(QuadTree tree, String directory) {
-    try {
-      BufferedWriter writer = new BufferedWriter(new FileWriter(directory
-          + "tree_config.txt"));
-      writer.write("capacity;" + tree.getCapacity() + ";depth;"
-          + tree.getDepth());
-      writer.newLine();
-      writer.close();
-    } catch (IOException e) {
-      e.printStackTrace();
+    /**
+     * Write quad tree configerations to file.
+     *
+     * @param tree
+     *            the quad tree
+     * @param directory
+     *            the directory where the configerations file is located
+     */
+    private static void writeTreeConfigsToFile(QuadTree tree, String directory) {
+        try {
+            BufferedWriter writer = new BufferedWriter(new FileWriter(directory + "tree_config.txt"));
+            writer.write("capacity;" + tree.getCapacity() + ";depth;" + tree.getDepth());
+            writer.newLine();
+            writer.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
     }
-  }
 
-  /**
-   * Write quad tree node to index file.
-   *
-   * @param node
-   *          the quad tree node
-   * @param directory
-   *          the directory where the index file is located
-   */
-  private static void writeNodeToFile(QuadTreeNode node, String directory) {
-    try {
-      BufferedWriter writer = new BufferedWriter(new FileWriter(directory
-          + "node_" + node.getId() + ".txt"));
+    /**
+     * Write quad tree node to index file.
+     *
+     * @param node
+     *            the quad tree node
+     * @param directory
+     *            the directory where the index file is located
+     */
+    private static void writeNodeToFile(QuadTreeNode node, String directory) {
+        try {
+            BufferedWriter writer = new BufferedWriter(new FileWriter(directory + "node_" + node.getId() + ".txt"));
 
-      if (node.getNodeType() == NodeType.GRAY) {
-        if (node.getChild(Quadrant.NW) != null) {
-          writer.write(getQuadTreeDataString(Quadrant.NW, node
-              .getChild(Quadrant.NW)));
-          writer.newLine();
-        }
+            if (node.getNodeType() == NodeType.GRAY) {
+                if (node.getChild(Quadrant.NW) != null) {
+                    writer.write(getQuadTreeDataString(Quadrant.NW, node.getChild(Quadrant.NW)));
+                    writer.newLine();
+                }
 
-        if (node.getChild(Quadrant.NE) != null) {
-          writer.write(getQuadTreeDataString(Quadrant.NE, node
-              .getChild(Quadrant.NE)));
-          writer.newLine();
-        }
+                if (node.getChild(Quadrant.NE) != null) {
+                    writer.write(getQuadTreeDataString(Quadrant.NE, node.getChild(Quadrant.NE)));
+                    writer.newLine();
+                }
 
-        if (node.getChild(Quadrant.SW) != null) {
-          writer.write(getQuadTreeDataString(Quadrant.SW, node
-              .getChild(Quadrant.SW)));
-          writer.newLine();
-        }
+                if (node.getChild(Quadrant.SW) != null) {
+                    writer.write(getQuadTreeDataString(Quadrant.SW, node.getChild(Quadrant.SW)));
+                    writer.newLine();
+                }
 
-        if (node.getChild(Quadrant.SE) != null) {
-          writer.write(getQuadTreeDataString(Quadrant.SE, node
-              .getChild(Quadrant.SE)));
-          writer.newLine();
+                if (node.getChild(Quadrant.SE) != null) {
+                    writer.write(getQuadTreeDataString(Quadrant.SE, node.getChild(Quadrant.SE)));
+                    writer.newLine();
+                }
+            }
+            writer.close();
+        } catch (IOException e) {
+            e.printStackTrace();
         }
-      }
-      writer.close();
-    } catch (IOException e) {
-      e.printStackTrace();
-    }
-    if (node.getNodeType() == NodeType.GRAY) {
-      if (node.getChild(Quadrant.NW) != null
-          && node.getChild(Quadrant.NW).getNodeType() == NodeType.GRAY) {
-        writeNodeToFile(node.getChild(Quadrant.NW), directory);
-      }
+        if (node.getNodeType() == NodeType.GRAY) {
+            if (node.getChild(Quadrant.NW) != null && node.getChild(Quadrant.NW).getNodeType() == NodeType.GRAY) {
+                writeNodeToFile(node.getChild(Quadrant.NW), directory);
+            }
 
-      if (node.getChild(Quadrant.NE) != null
-          && node.getChild(Quadrant.NE).getNodeType() == NodeType.GRAY) {
-        writeNodeToFile(node.getChild(Quadrant.NE), directory);
-      }
+            if (node.getChild(Quadrant.NE) != null && node.getChild(Quadrant.NE).getNodeType() == NodeType.GRAY) {
+                writeNodeToFile(node.getChild(Quadrant.NE), directory);
+            }
 
-      if (node.getChild(Quadrant.SW) != null
-          && node.getChild(Quadrant.SW).getNodeType() == NodeType.GRAY) {
-        writeNodeToFile(node.getChild(Quadrant.SW), directory);
-      }
+            if (node.getChild(Quadrant.SW) != null && node.getChild(Quadrant.SW).getNodeType() == NodeType.GRAY) {
+                writeNodeToFile(node.getChild(Quadrant.SW), directory);
+            }
 
-      if (node.getChild(Quadrant.SE) != null
-          && node.getChild(Quadrant.SE).getNodeType() == NodeType.GRAY) {
-        writeNodeToFile(node.getChild(Quadrant.SE), directory);
-      }
+            if (node.getChild(Quadrant.SE) != null && node.getChild(Quadrant.SE).getNodeType() == NodeType.GRAY) {
+                writeNodeToFile(node.getChild(Quadrant.SE), directory);
+            }
+        }
     }
-  }
 
-  /**
-   * Get the quad tree data string
-   *
-   * @param quadrant
-   *          specified quadrant
-   * @param node
-   *          the quad tree node
-   * @return quad tree data string
-   */
-  private static String getQuadTreeDataString(Quadrant quadrant,
-      final QuadTreeNode node) {
-    StringBuffer str = new StringBuffer();
-    str.append(quadrant.index());
-    str.append(':');
-    str.append(node.getNodeType().toString());
-    str.append(':');
-    str.append(node.getId());
-    str.append(':');
-    str.append(node.getCapacity());
-    str.append(':');
-    QuadTreeData[] data = node.getData();
-    for (int i = 0; i < node.getCount(); i++) {
-      str.append(data[i].getLatLon().y);
-      str.append(';');
-      str.append(data[i].getLatLon().x);
-      str.append(';');
-      str.append(data[i].getFileName());
-      str.append(':');
+    /**
+     * Get the quad tree data string
+     *
+     * @param quadrant
+     *            specified quadrant
+     * @param node
+     *            the quad tree node
+     * @return quad tree data string
+     */
+    private static String getQuadTreeDataString(Quadrant quadrant, final QuadTreeNode node) {
+        StringBuffer str = new StringBuffer();
+        str.append(quadrant.index());
+        str.append(':');
+        str.append(node.getNodeType().toString());
+        str.append(':');
+        str.append(node.getId());
+        str.append(':');
+        str.append(node.getCapacity());
+        str.append(':');
+        QuadTreeData[] data = node.getData();
+        for (int i = 0; i < node.getCount(); i++) {
+            str.append(data[i].getLatLon().y);
+            str.append(';');
+            str.append(data[i].getLatLon().x);
+            str.append(';');
+            str.append(data[i].getFileName());
+            str.append(':');
+        }
+        return str.substring(0, str.length() - 1);
     }
-    return str.substring(0, str.length() - 1);
-  }
 }


Mime
View raw message