1

I want to ask about how to fix my mapbasic code to become faster

Actually, I made a program with mapbasic that worked normally but it takes long time to run and sometimes not responding

I already try to modified the code but nothing changes :(

This is my code

Sub ProsesBuffer
Create Table "Buffer2" 
    (Block_no Char(15),Remark Char(10),Type_Palm Char(10),Ha Decimal(6,2))
    File "D:\Buffer2.TAB" 
    TYPE NATIVE Charset "WindowsLatin1"
Create Map For Buffer2 CoordSys Earth Projection 1, 104

Set Table Buffer2 FastEdit On Undo Off
Create Object As Buffer From sensus Width 5 Units "m" Type Spherical Resolution 100 Into Table Buffer2 Group by Rowid

Update Buffer2 Set Ha = Area(obj, "sq m")
Commit Table Buffer2

Create Index On Buffer2 (Block_no)
Add Map Layer Buffer2


Create Table "Check_Region" 
    (Block_no Char(15),Remark Char(10),Type_Palm Char(10),Ha Decimal(6,2))
    File "D:\Check_Region.TAB" 
    TYPE NATIVE Charset "WindowsLatin1"


Create Map For Check_Region CoordSys Earth Projection 1, 104

Create Index On Check_Region (Block_no)
Add Map Layer Check_Region

Set Map Layer 1 Editable On
Set Table Buffer2 FastEdit On Undo Off
Objects Check From Buffer2 Into Table Check_Region Overlap Pen (1,2,0)  Brush (2,16776960,0) 
Commit Table Buffer2

Update Check_Region Set Ha = Area(obj, "sq m")
Commit Table Check_Region
Browse * From Check_Region

Set Map Layer 1 Editable Off Layer 2 Editable On
Add Column "Buffer2" (Ha) From Check_Region Set To sum(Ha) Where within
Browse * From Buffer2

'function stdev
Select count(*) "NL", sum(Ha) "Jlh_Ha",sum(Ha*Ha) "Sum_Sq", avg(Ha) "Mean" from Buffer2 into tbl_stdev
Browse * From tbl_stdev
dim numlines as integer
dim _sum_sq as float
dim _mean as float
dim _jlh_ha as float
fetch first from tbl_stdev
numlines=tbl_stdev.nl
_jlh_ha=tbl_stdev.jlh_ha
_sum_sq=tbl_stdev.sum_sq
_mean=tbl_stdev.mean
dim stdev as float
stdev= (_sum_sq - (_jlh_ha^2)/numlines)/(numlines-1)
print "stdev " + stdev
dim sd as float
sd=sqr(stdev)
dim stdev1 as float
dim stdev2 as float
dim stdev3 as float
stdev = _mean + 1 * sd
stdev2 = _mean + 2 * sd
stdev3 = _mean + 3 * sd
print "SD " + sd
print "STDEV1 " + stdev
print "STDEV2 " + stdev2
print "STDEV3 " + stdev3

Set Layer 1 Editable Off Layer 3 Editable On
select * from Buffer2 where Ha > stdev3 into Selection
browse * from Selection
Create Table "stdev3" (Block_no Char(15),Remark Char(10),Type_Palm Char(10),Ha Decimal(6,2)) file "D:\Buffer\stdev3.tab" 
TYPE NATIVE Charset "WindowsLatin1"
Create Map For stdev3 CoordSys Earth Projection 1, 104
drop index stdev3 (Block_no)
Create Index On stdev3 (Block_no)
Add Map Layer stdev3

End Sub
Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
Junita
  • 11
  • 6
  • What is it that you have tried to modify? Do you know where the bottleneck in your code is? If you are unsure why it's so slow, the first thing to do is to identify what step(s) are taking a long time. You can do this by using some thoughtfully positioned 'Print...' statements which include a timestamp. Once you've worked out what is running slowly then it should be a bit easier to work out how to speed it up. – T_Bacon Oct 08 '15 at 08:59
  • Why do you create a new table from tab file? Can you open the tab files directly (`Open Table ... as `)? Skip the `Browse * From ...` commands. MapInfo can do everything on a "blank screen", it is not required to have the maps visible and refreshed all the time. – Wernfried Domscheit Dec 14 '15 at 07:36

0 Answers0