18
18
* <a href="http://en.wikipedia.org/wiki/Geohash">geohashing</a>.
19
19
* </p>
20
20
*
21
- * @author dave
22
- *
23
21
*/
24
22
public final class GeoHash {
25
23
@@ -134,7 +132,10 @@ private static void addOddParityEntries(Map<Direction, Map<Parity, String>> m) {
134
132
* borders too (at the poles and the -180,180 longitude boundaries).
135
133
*
136
134
* @param hash
135
+ * string hash relative to which the adjacent is returned
137
136
* @param direction
137
+ * direction relative to {@code hash} for which the adjacent is
138
+ * returned
138
139
* @return hash of adjacent hash
139
140
*/
140
141
public static String adjacentHash (String hash , Direction direction ) {
@@ -413,6 +414,7 @@ static long encodeHashToLong(double latitude, double longitude, int length) {
413
414
* Latitude will be between -90 and 90 and longitude between -180 and 180.
414
415
*
415
416
* @param geohash
417
+ * hash to decode
416
418
* @return lat long point
417
419
*/
418
420
// Translated to java from:
@@ -471,10 +473,14 @@ private static void refineInterval(double[] interval, int cd, int mask) {
471
473
* hash can enclose the bounding box then 0 is returned.
472
474
*
473
475
* @param topLeftLat
476
+ * latitude of top left point (north west)
474
477
* @param topLeftLon
478
+ * longitude of top left point (north west)
475
479
* @param bottomRightLat
480
+ * latitude of bottom right point (south east)
476
481
* @param bottomRightLon
477
- * @return
482
+ * longitude of bottom right point (south east)
483
+ * @return length of the hash
478
484
*/
479
485
public static int hashLengthToCoverBoundingBox (double topLeftLat , double topLeftLon ,
480
486
double bottomRightLat , double bottomRightLon ) {
@@ -517,9 +523,12 @@ public static int hashLengthToCoverBoundingBox(double topLeftLat, double topLeft
517
523
* contains the given lat and long.
518
524
*
519
525
* @param hash
526
+ * hash to test containment in
520
527
* @param lat
528
+ * latitude
521
529
* @param lon
522
- * @return
530
+ * longitude
531
+ * @return true if and only if the hash contains the given lat and long
523
532
*/
524
533
public static boolean hashContains (String hash , double lat , double lon ) {
525
534
LatLong centre = decodeHash (hash );
@@ -532,10 +541,14 @@ public static boolean hashContains(String hash, double lat, double lon) {
532
541
* {@link GeoHash}.DEFAULT_MAX_HASHES.
533
542
*
534
543
* @param topLeftLat
544
+ * latitude of top left point (north west)
535
545
* @param topLeftLon
546
+ * longitude of top left point (north west)
536
547
* @param bottomRightLat
548
+ * latitude of bottom right point (south east)
537
549
* @param bottomRightLon
538
- * @return
550
+ * longitude of bottom right point (south east)
551
+ * @return coverage
539
552
*/
540
553
public static Coverage coverBoundingBox (double topLeftLat , final double topLeftLon ,
541
554
final double bottomRightLat , final double bottomRightLon ) {
@@ -552,11 +565,16 @@ public static Coverage coverBoundingBox(double topLeftLat, final double topLeftL
552
565
* will be {@link GeoHash}.MAX_HASH_LENGTH.
553
566
*
554
567
* @param topLeftLat
568
+ * latitude of top left point (north west)
555
569
* @param topLeftLon
570
+ * longitude of top left point (north west)
556
571
* @param bottomRightLat
572
+ * latitude of bottom right point (south east)
557
573
* @param bottomRightLon
574
+ * longitude of bottom right point (south east)
558
575
* @param maxHashes
559
- * @return
576
+ * maximum number of hashes to use to cover the box
577
+ * @return coverage
560
578
*/
561
579
public static Coverage coverBoundingBoxMaxHashes (double topLeftLat , final double topLeftLon ,
562
580
final double bottomRightLat , final double bottomRightLon , int maxHashes ) {
@@ -582,11 +600,17 @@ public static Coverage coverBoundingBoxMaxHashes(double topLeftLat, final double
582
600
* bounding box.
583
601
*
584
602
* @param topLeftLat
603
+ * latitude of top left point (north west)
585
604
* @param topLeftLon
605
+ * longitude of top left point (north west)
586
606
* @param bottomRightLat
607
+ * latitude of bottom right point (south east)
587
608
* @param bottomRightLon
609
+ * longitude of bottom right point (south east)
588
610
* @param length
589
- * @return
611
+ * of hash
612
+ * @return number of hashes of given length required to cover the given
613
+ * bounding box
590
614
*/
591
615
public static Coverage coverBoundingBox (double topLeftLat , final double topLeftLon ,
592
616
final double bottomRightLat , final double bottomRightLon , final int length ) {
@@ -649,11 +673,12 @@ static CoverageLongs coverBoundingBoxLongs(double topLeftLat, final double topLe
649
673
}
650
674
651
675
/**
652
- * Returns height in degrees of all geohashes of length n . Results are
676
+ * Returns height in degrees of all geohashes of length {@code n} . Results are
653
677
* deterministic and cached to increase performance.
654
678
*
655
679
* @param n
656
- * @return
680
+ * length of geohash
681
+ * @return height in degrees of the geohash with length {@code n}
657
682
*/
658
683
public static double heightDegrees (int n ) {
659
684
if (n > MAX_HASH_LENGTH )
@@ -677,10 +702,10 @@ private static double[] createValues() {
677
702
678
703
/**
679
704
* Returns the height in degrees of the region represented by a geohash of
680
- * length n .
705
+ * length {@code n} .
681
706
*
682
- * @param n
683
- * @return
707
+ * @param n length of hash
708
+ * @return height in degrees of the region represented by a geohash of length {@code n}
684
709
*/
685
710
private static double calculateHeightDegrees (int n ) {
686
711
double a ;
@@ -710,8 +735,8 @@ private static double[] createValues() {
710
735
* deterministic and cached to increase performance (might be unnecessary,
711
736
* have not benchmarked).
712
737
*
713
- * @param n
714
- * @return
738
+ * @param n length of hash
739
+ * @return width in degrees
715
740
*/
716
741
public static double widthDegrees (int n ) {
717
742
if (n > MAX_HASH_LENGTH )
@@ -724,8 +749,8 @@ public static double widthDegrees(int n) {
724
749
* Returns the width in degrees of the region represented by a geohash of
725
750
* length n.
726
751
*
727
- * @param n
728
- * @return
752
+ * @param n length of geohash
753
+ * @return width in degrees
729
754
*/
730
755
private static double calculateWidthDegrees (int n ) {
731
756
double a ;
@@ -742,7 +767,7 @@ private static double calculateWidthDegrees(int n) {
742
767
* Returns a String of lines of hashes to represent the relative positions
743
768
* of hashes on a map. The grid is of height and width 2*size centred around
744
769
* the given hash. Highlighted hashes are displayed in upper case. For
745
- * example, gridToString("dr",1,Collections.< String> emptySet()) returns:
770
+ * example, gridToString("dr",1,Collections.< String> emptySet()) returns:
746
771
* </p>
747
772
*
748
773
* <pre>
@@ -751,10 +776,10 @@ private static double calculateWidthDegrees(int n) {
751
776
* dn dq dw
752
777
* </pre>
753
778
*
754
- * @param hash
755
- * @param size
756
- * @param highlightThese
757
- * @return
779
+ * @param hash central hash
780
+ * @param size size of square grid in hashes
781
+ * @param highlightThese hashes to highlight
782
+ * @return String representation of grid
758
783
*/
759
784
public static String gridAsString (String hash , int size , Set <String > highlightThese ) {
760
785
return gridAsString (hash , -size , -size , size , size , highlightThese );
@@ -764,7 +789,7 @@ public static String gridAsString(String hash, int size, Set<String> highlightTh
764
789
* Returns a String of lines of hashes to represent the relative positions
765
790
* of hashes on a map.
766
791
*
767
- * @param hash
792
+ * @param hash reference hash
768
793
* @param fromRight
769
794
* top left of the grid in hashes to the right (can be negative).
770
795
* @param fromBottom
@@ -776,7 +801,7 @@ public static String gridAsString(String hash, int size, Set<String> highlightTh
776
801
* @param toBottom
777
802
* bottom right of the grid in hashes to the bottom (can be
778
803
* negative).
779
- * @return
804
+ * @return string representation of grid
780
805
*/
781
806
public static String gridAsString (String hash , int fromRight , int fromBottom , int toRight ,
782
807
int toBottom ) {
@@ -785,7 +810,7 @@ public static String gridAsString(String hash, int fromRight, int fromBottom, in
785
810
}
786
811
787
812
/**
788
- * Returns a String of lines of hashes to represent the relative positions
813
+ * <p> Returns a String of lines of hashes to represent the relative positions
789
814
* of hashes on a map. Highlighted hashes are displayed in upper case. For
790
815
* example, gridToString("dr",-1,-1,1,1,Sets.newHashSet("f2","f8")) returns:
791
816
* </p>
@@ -796,7 +821,7 @@ public static String gridAsString(String hash, int fromRight, int fromBottom, in
796
821
* dn dq dw
797
822
* </pre>
798
823
*
799
- * @param hash
824
+ * @param hash reference hash
800
825
* @param fromRight
801
826
* top left of the grid in hashes to the right (can be negative).
802
827
* @param fromBottom
@@ -808,8 +833,8 @@ public static String gridAsString(String hash, int fromRight, int fromBottom, in
808
833
* @param toBottom
809
834
* bottom right of the grid in hashes to the bottom (can be
810
835
* negative).
811
- * @param highlightThese
812
- * @return
836
+ * @param highlightThese hashes to highlight
837
+ * @return String representation of grid
813
838
*/
814
839
public static String gridAsString (String hash , int fromRight , int fromBottom , int toRight ,
815
840
int toBottom , Set <String > highlightThese ) {
0 commit comments