Hi Gary,
The code example you are asking about is the part splitting large polygons. It is a process where I calculate the size of the polygon (by generating a bounding box and measuring it). If the polygon is definitely present in less than two by two (4) cells (<800x1200m), the code draws the four relevant LOD 13 cells. If the polygon is wide enough to span more than two LOD cells, the same calculation is done but on the basis of three by three (9) cells.
This is done to optimize performance, since most polygons are never spanning more than two by two cells.
The generation of the LOD rectangles is done by calling a function (def Lod13Location). This calculates the precise corners of the LOD cell.
Here is a part of that code:
<CODE>
while i < 15:
#Get the lat/long values for centre of the current lat/long bounds
centerLong = ( leftLong + rightLong ) / 2
centerLat = ( topLat + bottomLat ) / 2
</CODE>
This defines the LOD corners very precise, by evaluating in which lodquadrant a point is and from that returning the four corners. This is done in 15 iterations, from LOD -2 down to LOD 13. The function also generate the name of the LOD cell. (the quad number, 0,1,2 or 3, is returned for each iteration)
Then, in SplitByLodCells, the polygon is intersected with these cells, creating between one and four new polygons, each inside one cell only.
Here is a little test i did that might better explain what is going on:
I made some points across Denmark, some 600 meters apart, in an UTM coordinate system.
Then i made a small script that draws the LOD13 cells, of which each point is part.
Here is the code:
<CODE>
import rhinoscriptsyntax as rs
import math as m
#get a number of points
points = rs.GetObjects("points for which you want to draw the LOD13, they are part of: ", rs.filter.point)
#run the LOD13 cell calculation
for point in points:
Lod13Location(GetLatLon(rs.PointCoordinates(point)))
</CODE>
Note that each point is converted to LatLon, then fed to the Lod13Location-function. It happens in this line: Lod13Location(GetLatLon(rs.PointCoordinates(point)))
I used three functions in the script: GetUtm(lat, lon), GetLatLon(point), and Lod13Location(latLon). I did not put the functions in this code example, as they would make it hard to read this forum entry.
and here are four pictures showing the process. The pictures show:
a) the area
b) the points
c) the generated LOD cells after the script has run. Note how the rotation of the LOD cells increases as the points are more and more to the east.
d) a zoom in showing the cells and the points.
Unfortunately Rhino does not handle .shp files, but deals with a wide range of file formats, here is a list:
regards, Ole
The code example you are asking about is the part splitting large polygons. It is a process where I calculate the size of the polygon (by generating a bounding box and measuring it). If the polygon is definitely present in less than two by two (4) cells (<800x1200m), the code draws the four relevant LOD 13 cells. If the polygon is wide enough to span more than two LOD cells, the same calculation is done but on the basis of three by three (9) cells.
This is done to optimize performance, since most polygons are never spanning more than two by two cells.
The generation of the LOD rectangles is done by calling a function (def Lod13Location). This calculates the precise corners of the LOD cell.
Here is a part of that code:
<CODE>
while i < 15:
#Get the lat/long values for centre of the current lat/long bounds
centerLong = ( leftLong + rightLong ) / 2
centerLat = ( topLat + bottomLat ) / 2
</CODE>
This defines the LOD corners very precise, by evaluating in which lodquadrant a point is and from that returning the four corners. This is done in 15 iterations, from LOD -2 down to LOD 13. The function also generate the name of the LOD cell. (the quad number, 0,1,2 or 3, is returned for each iteration)
Then, in SplitByLodCells, the polygon is intersected with these cells, creating between one and four new polygons, each inside one cell only.
Here is a little test i did that might better explain what is going on:
I made some points across Denmark, some 600 meters apart, in an UTM coordinate system.
Then i made a small script that draws the LOD13 cells, of which each point is part.
Here is the code:
<CODE>
import rhinoscriptsyntax as rs
import math as m
#get a number of points
points = rs.GetObjects("points for which you want to draw the LOD13, they are part of: ", rs.filter.point)
#run the LOD13 cell calculation
for point in points:
Lod13Location(GetLatLon(rs.PointCoordinates(point)))
</CODE>
Note that each point is converted to LatLon, then fed to the Lod13Location-function. It happens in this line: Lod13Location(GetLatLon(rs.PointCoordinates(point)))
I used three functions in the script: GetUtm(lat, lon), GetLatLon(point), and Lod13Location(latLon). I did not put the functions in this code example, as they would make it hard to read this forum entry.
and here are four pictures showing the process. The pictures show:
a) the area
b) the points
c) the generated LOD cells after the script has run. Note how the rotation of the LOD cells increases as the points are more and more to the east.
d) a zoom in showing the cells and the points.
Unfortunately Rhino does not handle .shp files, but deals with a wide range of file formats, here is a list:
regards, Ole
Last edited:



