I have a MapBasic script that divides an irregular polygon into smaller polygons of 1 hectare each.
Would anyone help me to convert the following into an ArcPy script.
' This program requires an open MapInfo Table named woodlots with fields lot (integer) and area (dec or float)
Declare Sub Main
Declare Function Calc_height(stand1 as object) as float
Declare Sub CookieVarH(ByVal width1, height1 as float, sliver1 As Object, cookiecutter As Object)
Declare Sub setWoodlot()
Declare Sub setTimberlot()
Declare sub checker
global gs_last_band, gs_project as string
Sub Main
INCLUDE "C:\program files\MAPINFO\MAPBASIC\MAPBASIC.DEF"
INCLUDE "C:\program files\MAPINFO\MAPBASIC\MENU.DEF"
Include "icons.def"
Set CoordSys Earth
Projection 8,33,"m",141,0,0.9996, 500000, 10000000
Dim stand1, rectangle1, band1, band2, sliver1, cookie1, sliver2 As Object
Dim woodlot1, leftover1, cookie2, right_end1, left_end1 As Object
Dim minX, maxX, minY, maxY, area1, width1, height1, widthend, widthstart As Float
Dim diff_y, row_id As Float
Dim band_no, woodlot_no, max_band, i, lots as Integer
Dim sliver_area As Float
Dim mnX, mnY, mxX, mxY As Float
stand1 = selection.obj
band_no = 1
woodlot_no = 1
gs_last_band = "false"
while CartesianArea(stand1, "hectare") > 1
minX = ObjectGeography(stand1, OBJ_GEO_MINX)
minY = ObjectGeography(stand1, OBJ_GEO_MINY)
maxX = ObjectGeography(stand1, OBJ_GEO_MAXX)
maxY = ObjectGeography(stand1, OBJ_GEO_MAXY)
width1 = 1
area1 = 0
height1 = 0
create Rect into variable rectangle1 (minX, minY) (maxX, maxY)
height1 = calc_height(stand1) '****** call height
create Rect into variable band1 (minX, (maxY - height1)) (maxX, maxY)
sliver1 = overlap(stand1, band1)
sliver_area = CartesianArea(sliver1, "hectare")
lots = round((sliver_area/1),1)
' note " height1 = " + str$(height1) + " sliver_area = " + str$(sliver_area) + " lots = " + str$(lots)
for i = 1 to lots
width1 = 10
area1 = 0
if i < lots then
mnX = ObjectGeography(sliver1, OBJ_GEO_MINX)
mnY = ObjectGeography(sliver1, OBJ_GEO_MINY)
mxX = ObjectGeography(sliver1, OBJ_GEO_MAXX)
mxY = ObjectGeography(sliver1, OBJ_GEO_MAXY)
do
create Rect into variable cookie1 ((mnX) , (mnY)) ((mnX + width1), mxY)
woodlot1 = overlap(sliver1, cookie1)
area1 = CartesianArea(woodlot1, "hectare")
width1 = width1 + 0.1
loop while Area1 < 1 ' if area is > 1 put woodlot in layer and remove from sliver
insert into Woodlots (obj,area)
values (woodlot1, area1)
woodlot_no = woodlot_no + 1
else 'last lot in sliver cut out all
woodlot1 = sliver1
area1 = CartesianArea(woodlot1, "hectare")
if gs_last_band = "false" then
insert into Woodlots (obj,area)
values (woodlot1, area1)
woodlot_no = woodlot_no + 1
else
insert into Woodlots (obj,lot,area)
values (woodlot1, 9999, area1)
call CookieVarH(width1,height1, sliver1, cookie1)
end if
end if
if lots = 1 then
call CookieVarH(500,height1, sliver1, cookie1)
end if
sliver1 = Erase( sliver1, cookie1 )
sliver_area = CartesianArea(sliver1, "hectare")
next
create Rect into variable band2 (minX, (maxY - height1)) (maxX, (maxY + 1))
leftover1 = erase( stand1, band2 )
stand1 = leftover1
wend
' insert remeinder into table
if gs_last_band = "false" then ' only do if there is a remeinder
insert into Woodlots (obj,lot, area)
values (leftover1, 9999, CartesianArea(stand1, "hectare"))
stand1 = selection.obj
end if
' clean objects
select * from woodlots
' Objects Snap From Selection Tolerance Vector 1 Units "m"
commit table woodlots
End Sub 'Main
function Calc_height (stand1 as object) As Float
Dim sliver_area, trunc, height, stand_area, stand_trunc As Float
dim bandx, sliver1 as object
dim lots as float
Dim mnX, mxX, mnY, mxY As Float
stand_area = CartesianArea(stand1, "hectare")
stand_trunc = int(stand_area)
height = 65
mnX = ObjectGeography(stand1, OBJ_GEO_MINX)
mnY = ObjectGeography(stand1, OBJ_GEO_MINY)
mxX = ObjectGeography(stand1, OBJ_GEO_MAXX)
mxY = ObjectGeography(stand1, OBJ_GEO_MAXY)
create Rect into variable bandx (mnX, (mxY - height)) (mxX, mxY)
sliver1 = overlap(stand1, bandx)
sliver_area = CartesianArea(sliver1, "hectare")
lots = Round((sliver_area/1), 1)
trunc = int((sliver_area/1))
' note "sliver_area = " + str$(sliver_area) + "lots = " + str$(lots) + " trunc = " + str$(trunc)
if (lots = trunc and trunc <> 0 ) then
' note "height getting smaller"
mnX = ObjectGeography(stand1, OBJ_GEO_MINX)
mnY = ObjectGeography(stand1, OBJ_GEO_MINY)
mxX = ObjectGeography(stand1, OBJ_GEO_MAXX)
mxY = ObjectGeography(stand1, OBJ_GEO_MAXY)
while CartesianArea((sliver1), "hectare")/1 > trunc
height = height -0.05
create Rect into variable bandx (mnX, (mxY - height)) (mxX, mxY)
sliver1 = overlap(stand1, bandx)
wend
gs_last_band = "false"
elseif (stand_area < 1) or (stand_area < (lots*1)) then ' last band
' note " stand_area = " + str$(stand_area) + " lots = " + str$(lots)
height = 300
gs_last_band = "true"
else
' note "height getting larger"
' if (lots > stand_area) and (lots >1) then
' lots = lots -1
' end if
if lots = 0 then lots = 1 end if
gs_last_band = "false"
mnX = ObjectGeography(stand1, OBJ_GEO_MINX)
mnY = ObjectGeography(stand1, OBJ_GEO_MINY)
mxX = ObjectGeography(stand1, OBJ_GEO_MAXX)
mxY = ObjectGeography(stand1, OBJ_GEO_MAXY)
while CartesianArea(sliver1, "hectare")/1 < lots
height = height + 0.05
create Rect into variable bandx (mnX, (mxY - height)) (mxX, mxY)
sliver1 = overlap(stand1, bandx)
wend
end if
Calc_height = height
height = 65
' note " calc_height = " + str$(height)
End Function
Sub CookieVarH (ByVal width1, height1 as float, sliver1 As Object, cookiecutter As Object)
Dim mnX1, mnY1, mxX1, mxY1 As Float
mnX1 = ObjectGeography(sliver1, OBJ_GEO_MINX)
mnY1 = ObjectGeography(sliver1, OBJ_GEO_MINY)
mxX1 = ObjectGeography(sliver1, OBJ_GEO_MAXX)
mxY1 = ObjectGeography(sliver1, OBJ_GEO_MAXY)
create Rect into variable cookiecutter ((mnX1) , (mnY1)) ((mnX1 + width1), mxY1)
End Sub