Class: Proj::Domain

Inherits:
Object
  • Object
show all
Defined in:
lib/proj/domain.rb

Overview

Represents a usage domain of a PjObject. Each domain has a scope describing the purpose and a geographic area of use. Objects can have multiple domains.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope:, area_of_use:) ⇒ Domain

Returns a new instance of Domain.

Parameters:

  • scope (String)

    The scope describing the purpose of this domain

  • area_of_use (Area)

    The geographic area of use



16
17
18
19
# File 'lib/proj/domain.rb', line 16

def initialize(scope:, area_of_use:)
  @scope = scope
  @area_of_use = area_of_use
end

Instance Attribute Details

#area_of_useArea (readonly)

Returns The geographic area of use for this domain.

Returns:

  • (Area)

    The geographic area of use for this domain



12
13
14
# File 'lib/proj/domain.rb', line 12

def area_of_use
  @area_of_use
end

#scopeString (readonly)

Returns The scope of this domain.

Returns:

  • (String)

    The scope of this domain



9
10
11
# File 'lib/proj/domain.rb', line 9

def scope
  @scope
end

Class Method Details

.count(pj_object) ⇒ Integer

Returns the number of usage domains for an object. Requires PROJ 9.2+. Returns 1 on older versions for backward compatibility.

Parameters:

  • pj_object (PjObject)

    The object to query

Returns:

  • (Integer)

See Also:



29
30
31
32
33
34
35
# File 'lib/proj/domain.rb', line 29

def self.count(pj_object)
  if Api.method_defined?(:proj_get_domain_count)
    Api.proj_get_domain_count(pj_object)
  else
    1
  end
end

.domains(pj_object) ⇒ Array<Domain>

Returns all usage domains for an object. On PROJ < 9.2, falls back to Api.proj_get_scope and Api.proj_get_area_of_use and returns a single domain.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/proj/domain.rb', line 47

def self.domains(pj_object)
  use_ex = Api.method_defined?(:proj_get_domain_count)
  domain_count = use_ex ? Api.proj_get_domain_count(pj_object) : 1

  domain_count.times.map do |index|
    scope = use_ex ? Api.proj_get_scope_ex(pj_object, index) : Api.proj_get_scope(pj_object)

    p_name = FFI::MemoryPointer.new(:pointer)
    p_west = FFI::MemoryPointer.new(:double)
    p_south = FFI::MemoryPointer.new(:double)
    p_east = FFI::MemoryPointer.new(:double)
    p_north = FFI::MemoryPointer.new(:double)

    if use_ex
      result = Api.proj_get_area_of_use_ex(pj_object.context, pj_object, index,
                                            p_west, p_south, p_east, p_north, p_name)
    else
      result = Api.proj_get_area_of_use(pj_object.context, pj_object,
                                         p_west, p_south, p_east, p_north, p_name)
    end
    unless result
      Error.check_object(pj_object)
    end

    name = p_name.read_pointer.read_string_to_null.force_encoding('utf-8')
    area = Area.new(west_lon_degree: p_west.read_double,
                    south_lat_degree: p_south.read_double,
                    east_lon_degree: p_east.read_double,
                    north_lat_degree: p_north.read_double,
                    name: name)

    new(scope: scope, area_of_use: area)
  end
end