github.com/altipla-consulting/ravendb-go-client@v0.1.3/spatial_options_factory.go (about)

     1  package ravendb
     2  
     3  // NewGeographyDefaultOptions returns default geography SpatialOptions
     4  func NewGeographyDefaultOptions() *SpatialOptions {
     5  	return NewGeographyDefaultOptionsWithRadius(SpatialUnitsKilometers)
     6  }
     7  
     8  // NewGeographyDefaultOptionsWithRadius returns default geography SpatialOptions
     9  // with a a given radius
    10  func NewGeographyDefaultOptionsWithRadius(circleRadiusUnits SpatialUnits) *SpatialOptions {
    11  	return NewGeographyGeohashPrefixTreeIndexWithRadius(0, circleRadiusUnits)
    12  }
    13  
    14  // NewGeograpyboundingBoxIndex returns geography SpatialOptions for a bounding box
    15  func NewGeograpyboundingBoxIndex() *SpatialOptions {
    16  	return NewGeographyBoundingBoxIndexWithRadius(SpatialUnitsKilometers)
    17  }
    18  
    19  // NewGeographyBoundingBoxIndexWithRadius return geography SpatialOptions
    20  // for a bounding box with a given radius
    21  func NewGeographyBoundingBoxIndexWithRadius(circleRadiusUnits SpatialUnits) *SpatialOptions {
    22  	opts := NewSpatialOptions()
    23  	opts.Type = SpatialFieldGeography
    24  	opts.Strategy = SpatialSearchStrategyBoundingBox
    25  	opts.Units = circleRadiusUnits
    26  	return opts
    27  }
    28  
    29  // NewGeographyGeohashPrefixTreeIndex returns geography SpatialOptions for
    30  // using geography geohash prefix tree index
    31  func NewGeographyGeohashPrefixTreeIndex(maxTreeLevel int) *SpatialOptions {
    32  	return NewGeographyGeohashPrefixTreeIndexWithRadius(maxTreeLevel, SpatialUnitsKilometers)
    33  }
    34  
    35  // NewGeographyGeohashPrefixTreeIndexWithRadius returns geography SpatialOptions for
    36  //// using geography geohash prefix tree index with a given circle radius
    37  func NewGeographyGeohashPrefixTreeIndexWithRadius(maxTreeLevel int, circleRadiusUnits SpatialUnits) *SpatialOptions {
    38  	if maxTreeLevel == 0 {
    39  		maxTreeLevel = SpatialOptionsDefaultGeohashLevel
    40  	}
    41  
    42  	opts := NewSpatialOptions()
    43  	opts.Type = SpatialFieldGeography
    44  	opts.MaxTreeLevel = maxTreeLevel
    45  	opts.Strategy = SpatialSearchStrategyGeohashPrefixTree
    46  	opts.Units = circleRadiusUnits
    47  	return opts
    48  }
    49  
    50  // NewGeographyQuadPrefixTreeIndex returns geography SpatialOptions
    51  // for quad prefix tree
    52  func NewGeographyQuadPrefixTreeIndex(maxTreeLevel int) *SpatialOptions {
    53  	return NewGeographyQuadPrefixTreeIndexWithRadius(maxTreeLevel, SpatialUnitsKilometers)
    54  }
    55  
    56  // NewGeographyQuadPrefixTreeIndex returns geography SpatialOptions
    57  // for quad prefix tree with a given radius
    58  func NewGeographyQuadPrefixTreeIndexWithRadius(maxTreeLevel int, circleRadiusUnits SpatialUnits) *SpatialOptions {
    59  	if maxTreeLevel == 0 {
    60  		maxTreeLevel = SpatialOptionsDefaultQuadTreeLevel
    61  	}
    62  
    63  	opts := NewSpatialOptions()
    64  	opts.Type = SpatialFieldGeography
    65  	opts.MaxTreeLevel = maxTreeLevel
    66  	opts.Strategy = SpatialSearchStrategyQuadPrefixTree
    67  	opts.Units = circleRadiusUnits
    68  	return opts
    69  }
    70  
    71  // NewCartesianBoundingBoxIndex returns cartesian SpatialOptions
    72  func NewCartesianBoundingBoxIndex() *SpatialOptions {
    73  	opts := NewSpatialOptions()
    74  	opts.Type = SpatialFieldCartesian
    75  	opts.Strategy = SpatialSearchStrategyBoundingBox
    76  	return opts
    77  }
    78  
    79  // NewCartesianQuadPrefixTreeIndex returns cartesian SpatialOptions for
    80  // quad prefix tree index
    81  func NewCartesianQuadPrefixTreeIndex(maxTreeLevel int, bounds *SpatialBounds) *SpatialOptions {
    82  	panicIf(maxTreeLevel <= 0, "maxTreeLevel must be > 0")
    83  	opts := NewSpatialOptions()
    84  	opts.Type = SpatialFieldCartesian
    85  	opts.MaxTreeLevel = maxTreeLevel
    86  	opts.Strategy = SpatialSearchStrategyQuadPrefixTree
    87  	opts.MinX = bounds.MinX
    88  	opts.MinY = bounds.MinY
    89  	opts.MaxX = bounds.MaxX
    90  	opts.MaxY = bounds.MaxY
    91  	return opts
    92  }
    93  
    94  // SpatialBounds describes bounds of a region
    95  type SpatialBounds struct {
    96  	MinX float64
    97  	MaxX float64
    98  	MinY float64
    99  	MaxY float64
   100  }
   101  
   102  // NewSpatialBounds returns new SpatialBounds
   103  func NewSpatialBounds(minX float64, minY float64, maxX float64, maxY float64) *SpatialBounds {
   104  	return &SpatialBounds{
   105  		MinX: minX,
   106  		MaxX: maxX,
   107  		MinY: minY,
   108  		MaxY: maxY,
   109  	}
   110  }