I use the latlong_to_point to draw a latlong grid and find that: if the latitudes include both north and south, it will appear like this:
instead of:
So if my site is exactly stand on the equator and I need to use LatLong data, how can I deal with this problem?
Here is my script:
model=Sketchup.active_model
p=[]
max_lng=117+2
min_lng=117-2
max_lat=10
min_lat=-10
for lat in min_lat..max_lat do
p<<(min_lng..max_lng).to_a.collect{|lng|
Geom::LatLong.new(lat,lng)
}
end
pt=p.collect{|arr|
arr.collect{|latlong|
model.latlong_to_point(latlong.to_a.reverse)
}
}
for i in 0..(max_lat-min_lat) do
for j in 0..(max_lng-min_lng-1) do
model.entities.add_line(pt[i][j],pt[i][j+1])
end
end
for i in 0..(max_lat-min_lat-1) do
for j in 0..(max_lng-min_lng) do
model.entities.add_line(pt[i][j],pt[i+1][j])
end
end
Finally, I create a method to move a Point3d 10000km south if its latitude is negative.
def latlong2point(latlong)
if latlong.is_a?(Array) then
lat=latlong[1]
lng=latlong[0]
elsif latlong.is_a?(Geom::LatLong) then
lat=latlong.latitude
lng=latlong.longitude
else
return(nil)
end
pt=Sketchup.active_model.latlong_to_point([lng,lat])
if lat<0 then pt[1]-=10000.km end
return pt
end
and get this: