2

I have a Sketchup 3d model that is geo-located. I can get the geo-location of the model as follows :-

latitude = Sketchup.active_model.attribute_dictionaries["GeoReference"]["Latitude"]

longitude = Sketchup.active_model.attribute_dictionaries["GeoReference"]["Longitude"]

Now i want to render this model on a 3D globe. So i need the location bounds of the 3d model.

Basically i need bounding box of the model on 2d map.

Right now i am extracting the same from the corners of a model(8 corner).

// This will return left-front-bottom corner.
lowerCorner = Sketchup.active_model.bounds.corner(0)
// This will return right-back-top corner.
upperCorner = Skectup.active_model.bounds.corner(6)

But it returns simple geometrical points in meters, inches depending upon the model.

For example i uploaded this model in sketchup. Following are the values of geo-location, lowerCorner and upperCorner respectively that i'm getting by using the above code for the above model.

geoLocation : 25.141407985864, 55.18563969191 //lat,long
lowerCorner : (-9483.01089", -6412.376053", -162.609524") // In inches
upperCorner : (-9483.01089", 6479.387909", 12882.651999") // In inches

So my first question is what i'm doing is correct or not ? Second question is If yes for the first how can i get the values of lowerCorner and upperCorner in lat long format.

Neelesh
  • 666
  • 6
  • 17

1 Answers1

1

But it returns simple geometrical points in meters, inches depending upon the model.

Geom::BoundingBox.corner returns a Geom::Point3d. The x, y and z members of that is a Length. That is always returning the internal value of SketchUp which is inches.

However, when you use Length.to_s it will use the current model's unit settings and format the values into that. When you call Geom::Point3d.to_s it will use Length.to_s. On the other hand, if you call Geom::Point3d.inspect it will print the internal units (inches) without formatting.

Instead of tapping into the attributes of the model directly like that I recommend you use the API methods of geo-location: Sketchup::Model.georeferenced?

By the sound of it you might find Sketchup::Model.point_to_latlong useful.

Example - I geolocated a SketchUp model to the town square of Trondheim, Norway (Geolocation: 63°25′47″N 10°23′36″E):

model = Sketchup.active_model
bounds = model.bounds
# Get the base of the boundingbox. No need to get the top - as the
# result doesn't contain altiture information.
(0..3).each { |i|
  pt = bounds.corner(i)
  latlong = model.point_to_latlong(pt)
  latitude = latlong.x.to_f
  longitude = latlong.y.to_f
  puts "#{pt.inspect} => #{longitude}, #{latitude}"
}

showing a localised su model getting world coordinates from model coordinates

akmozo
  • 9,829
  • 3
  • 28
  • 44
thomthom
  • 2,854
  • 1
  • 23
  • 53