How to draw land using its UTM coordinates (WGS84) via Ruby Console?

I have following coordinates in UTM format:

Zone: 35U
382094.220, 6049129.846
382117.199, 6049110.658
382094.616, 6049085.305
382105.314, 6049076.344
382094.655, 6049064.374
382059.400, 6049094.012
382068.312, 6049103.466

And found this example:

# zone_number, zone_letter, x, y
lon_lat = Geom::UTM.new(13, "T", 475849.37521, 4429682.73749).to_latlong.to_a.reverse
model.latlong_to_point(lon_lat)

But cannot figure out, how to draw land using all points.
Thanks!

Do you have a geo-located model to follow with this?

1 Like

The Ruby API documents don’t mention it, but doesn’t a model need to already be geolocated for model#latlong_to_point to work? Without geolocation there is no relationship between lat, long and model coordinates!

1 Like

Yes, I did that.

Can you share a sample model to go along with your snippet? Makes it a lot easier to debug when we all have the same information/data.

test.skp (531.0 KB)
Here you are. I hope, I did it right.

model = Sketchup.active_model

puts "Origin Lat-Long"
p model.point_to_latlong(ORIGIN)
puts

# Zone: 35U
coords = [
  [382094.220, 6049129.846],
  [382117.199, 6049110.658],
  [382094.616, 6049085.305],
  [382105.314, 6049076.344],
  [382094.655, 6049064.374],
  [382059.400, 6049094.012],
  [382068.312, 6049103.466],
]

model.start_operation('Mark UTM Points', true)
coords.each { |coord|
  utm = Geom::UTM.new(35, "U", coord.x, coord.y)
  lat_long = utm.to_latlong
  # Geom::LatLong's to_a method return Long,Lat - so the array must be reversed.
  model_point = model.latlong_to_point(lat_long.to_a.reverse)
  model.entities.add_cpoint(model_point)
}
model.commit_operation

1 Like