Skip to content

Commit

Permalink
Merge pull request #68 from BIM-Tools/develop
Browse files Browse the repository at this point in the history
Fix map scaling
  • Loading branch information
janbrouwer authored Nov 1, 2024
2 parents 4298104 + 9be459e commit a27eb65
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
12 changes: 7 additions & 5 deletions src/bt_ifcmanager/lib/lib_ifc/IfcUnitAssignment_su.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

module BimTools
module IfcUnitAssignment_su
attr_reader :length_unit, :area_unit, :volume_unit
attr_reader :length_unit, :area_unit, :volume_unit, :length_unit_entity, :area_unit_entity, :volume_unit_entity

LENGTH_UNITS = %i[
Inches
Expand Down Expand Up @@ -88,10 +88,12 @@ def initialize(ifc_model)
@ifc_model = ifc_model
@su_model = ifc_model.su_model
set_units
@units = IfcManager::Types::Set.new
@units.add(ifc_unit(@length_unit))
@units.add(ifc_unit(@area_unit))
@units.add(ifc_unit(@volume_unit))

@length_unit_entity = ifc_unit(@length_unit)
@area_unit_entity = ifc_unit(@area_unit)
@volume_unit_entity = ifc_unit(@volume_unit)

@units = IfcManager::Types::Set.new([@length_unit_entity, @area_unit_entity, @volume_unit_entity])
end

def set_units
Expand Down
10 changes: 6 additions & 4 deletions src/bt_ifcmanager/lib/lib_ifc/ifc_map_conversion_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def set_scale(scale)
#
# @param ifc_model [Object] The IFC model to calculate the scale factor for.
# @return [Numeric] The scale factor calculated for the given `ifc_model`.
def calculate_scale(ifc_model)
def calculate_utm_scale_factor(ifc_model)
length_measure = IfcManager::Types::IfcLengthMeasure.new(ifc_model, 1.0.m)

length_measure.convert
Expand All @@ -108,14 +108,16 @@ def set_from_utm(representationcontext, projected_crs, utm_point, world_transfor
# Adjust the y value if the hemisphere is south
y = 2 * equator_height - y if hemisphere == 'S'

model_scale = calculate_utm_scale_factor(@ifc_model)

set_source_crs(representationcontext)
set_target_crs(projected_crs)
set_eastings(x)
set_northings(y)
set_eastings(x * model_scale)
set_northings(y * model_scale)
set_orthogonalheight(0.0)
set_xaxisabscissa(world_transformation.xaxis.x)
set_xaxisordinate(world_transformation.xaxis.y)
set_scale(calculate_scale(@ifc_model))
set_scale(1.0)
end
end
end
Expand Down
11 changes: 3 additions & 8 deletions src/bt_ifcmanager/lib/lib_ifc/ifc_projected_crs_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,8 @@ def set_geodeticdatum(geodeticdatum)
@ifc_projected_crs.geodeticdatum = Types::IfcIdentifier.new(@ifc_model, geodeticdatum)
end

def set_mapunit(unit = :METRE)
mapunit = @ifc::IfcSIUnit.new(@ifc_model)
mapunit.dimensions = '*'
mapunit.unittype = :LENGTHUNIT
mapunit.prefix = nil
mapunit.name = unit
@ifc_projected_crs.mapunit = mapunit
def set_mapunit(map_unit)
@ifc_projected_crs.mapunit = map_unit
end

# Calculates the EPSG code based on the UTM point.
Expand Down Expand Up @@ -92,7 +87,7 @@ def set_from_utm(utm_point)
set_name(epsg_name)
set_description(epsg_description)
set_geodeticdatum('WGS 84')
set_mapunit(:METRE)
set_mapunit(@ifc_model.units.length_unit_entity)
end
end
end
Expand Down

0 comments on commit a27eb65

Please sign in to comment.