Unexpected utm_to_point behaviour

geolocation
ruby

#1

I am struggling a bit with placing some construction points based on some UTM32 coordinates I pulled from a public provider.

The points are all placed correctly relative to each other, but when overlayed over a geolocation snapshot the figure looks mirrored, rotated and squashed.

The model is geolocated:

I tried to run the following code in a model geolocated near the point:

point = [6116763.558, 519305.906]
utm_zone_number = 32
utm_zone_letter = "U"
model = Sketchup.active_model
pointutm = Geom::UTM.new utm_zone_number, utm_zone_letter, point[1], point[0]
point3Dutm = model::utm_to_point(pointutm)
utm_from_point = model::point_to_utm(point3Dutm)

For some reason the coordinates from the source are y, x it looks like.

The UTM object:

pointutm
UTM(32 U 519305.90600 6116763.55800)

but the conversion to a point3D seems to be wrong, because if I convert the point3D back into UTM the coordinates are not the same:

utm_from_point
UTM(32 U 519495.01108 6116192.84162)

What gives? They are off, but not by that much.

model.get_datum gives me “WGS 84” if that has any significance.


#2

There are some quirks and errors in the API, ie, here’s one reported just the other day:


#3

So it’s ok to assume that utm_to_point is also expecting the coordinates reversed. But utm_to_point takes a UTM object, and not an array.

Anyway, I converted UTM to latlong and then from latlong to point:

pointll = pointutm.to_latlong
point3D = model::latlong_to_point([pointll.longitude, pointll.latitude])

and it worked! Also on the complete set, and it matched perfectly.

Thank you for the help, and it sure looks like there is room for improvement in these methods.


#4

HA! What a brain fart. I can of course just make the UTM from the y, x order from the source and everything works without converting to latlong.


#5

No, I didn’t mean this. Just that there have long been errors in the API documentation. (So do not be surprised if you find some errors.)

You said, …

You did not tell what the source was (or give us a link.)

In my quick test, I did:

pointutm = Geom::UTM.new utm_zone_number, utm_zone_letter, point.x, point.y

And then tested that pointutm.x and pointutm.y returned that same values that were passed to the object constructor.
They did.

Again, if the “source” is non-standard, how could the SketchUp API know this ?

Correct.