Class: GeoScript::Projection

Inherits:
Object
  • Object
show all
Defined in:
lib/geoscript/projection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proj) ⇒ Projection

Returns a new instance of Projection.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/geoscript/projection.rb', line 10

def initialize(proj)
  if proj.kind_of? CoordinateReferenceSystem
    @crs = proj
  elsif proj.kind_of? GeoScript::Projection
    @crs = proj.crs
  elsif proj.kind_of? String
    @crs = CRS.decode proj
    
    if @crs.nil?
      @crs = CRS.parseWKT proj
      
      if @crs.nil?
        raise "Unable to determine projection from #{proj}"
      end
    end
  end
end

Instance Attribute Details

#crsObject

Returns the value of attribute crs.



8
9
10
# File 'lib/geoscript/projection.rb', line 8

def crs
  @crs
end

Class Method Details

.reproject(obj, from_crs, to_crs) ⇒ Object



82
83
84
# File 'lib/geoscript/projection.rb', line 82

def self.reproject(obj, from_crs, to_crs)
  Projection.new(from_crs).transform obj, to_crs
end

Instance Method Details

#get_boundsObject



36
37
38
39
40
41
42
43
# File 'lib/geoscript/projection.rb', line 36

def get_bounds
  env = CRS.get_envelope @crs
  if env
    min = env.get_minimum
    max = env.get_maximum
    GeoScript::Geom::Bounds.create min.first, min.last, max.first, max.last
  end
end

#get_geoboundsObject



45
46
47
48
49
50
# File 'lib/geoscript/projection.rb', line 45

def get_geobounds
  box = CRS.get_geographic_bounding_box @crs
  if box
    GeoScript::Geom::Bounds.create box.west_bound_longitude, box.south_bound_latitude, box.east_bound_longitude, box.north_bound_latitude, 'epsg:4326'
  end
end

#get_idObject



28
29
30
# File 'lib/geoscript/projection.rb', line 28

def get_id
  CRS.lookup_identifier(@crs, true).to_s
end

#get_wktObject



32
33
34
# File 'lib/geoscript/projection.rb', line 32

def get_wkt
  @crs.to_s
end

#transform(obj, dest) ⇒ Object



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/geoscript/projection.rb', line 52

def transform(obj, dest)
  from_crs = @crs
  to_crs = Projection.new(dest).crs
  transform = CRS.find_math_transform(from_crs, to_crs)

  if obj.kind_of? Array
  else
    geometry_transform = GeometryCoordinateSequenceTransformer.new
    geometry_transform.math_transform = transform
    new_geom = geometry_transform.transform obj
    # not entirely comfortable with this
    case new_geom.class.to_s
    when 'Java::ComVividsolutionsJtsGeom::Point'
      GeoScript::Geom::Point.new new_geom
    when 'Java::ComVividsolutionsJtsGeom::Polygon'
      GeoScript::Geom::Polygon.new new_geom
    when 'Java::ComVividsolutionsJtsGeom::MultiPoint'
      GeoScript::Geom::MultiPoint.create new_geom
    when 'Java::ComVividsolutionsJtsGeom::MultiPolygon'
      GeoScript::Geom::MultiPolygon.create new_geom
    when 'Java::ComVividsolutionsJtsGeom::LineString'
      GeoScript::Geom::LineString.create new_geom
    when 'Java::ComVividsolutionsJtsGeom::MultiLineString'
      GeoScript::Geom::MultiLineString.create new_geom
    when 'Java::ComVividsolutionsJtsGeom::LinearRing'
      GeoScript::Geom::LinearRing.create new_geom
    end  
  end
end