MapWindow 4 - Plugins : MapWindow Discussion Forum
Hello everyone, I am relatively new to MapWindow development and am writing a function for reclassifying a grid file based on a lookup table (code attached below). I'm finding it to be a little slow so was wondering if there are any ways of speeding it up? Any suggestions will be gre
Speeding up grid reclassification from lookup table
Posted by:
sschung ()
Date: December 18, 2009 08:56AM
Hello everyone,
I am relatively new to MapWindow development and am writing a function for reclassifying a grid file based on a lookup table (code attached below). I'm finding it to be a little slow so was wondering if there are any ways of speeding it up? Any suggestions will be greatly appreciated.
Thanks,
Sang
[Edit:] Added code tags for better reading
Edited 1 time(s). Last edit at 12/18/2009 09:17AM by pmeems.
I am relatively new to MapWindow development and am writing a function for reclassifying a grid file based on a lookup table (code attached below). I'm finding it to be a little slow so was wondering if there are any ways of speeding it up? Any suggestions will be greatly appreciated.
Thanks,
Sang
Dim dset As New DataSet
Dim con As New OleDb.OleDbConnection
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
dset.Clear()
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FILEPATH + ";Extended Properties=DBase IV"
con.Open()
sql = "SELECT * from FILENAME"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(dset, "table")
con.Close()
Dim soiltexturegrid As New MapWinGIS.Grid
Dim conductivitygrid As New MapWinGIS.Grid
Dim row As Integer
Dim col As Integer
Dim rownum As Integer
Dim colnum As Integer
Dim soiltype As Integer
soiltexturegrid.Open(SOILTEXTURE)
If conductivitygrid.CreateNew(CONDUCTIVITY, soiltexturegrid.Header, soiltexturegrid.DataType, 0, True, MapWinGIS.GridFileType.Ascii, Me) = True Then
rownum = conductivitygrid.Header.NumberRows - 1
colnum = conductivitygrid.Header.NumberCols - 1
For row = 0 To rownum
For col = 0 To colnum
conductivitygrid.Value(col, row) = soiltexturegrid.Value(col, row)
Next
Next
For soiltype = 0 To dset.Tables("table").Rows.Count -1
utils.GridReplace(conductivitygrid, soiltype + 1, dset.Tables("table").Rows(soiltype).Item("KS") / 100)
Next
conductivitygrid.Save()
conductivitygrid.Close()
soiltexturegrid.Close()
[Edit:] Added code tags for better reading
Edited 1 time(s). Last edit at 12/18/2009 09:17AM by pmeems.
Re: Speeding up grid reclassification from lookup table
Posted by:
pmeems ()
Date: December 18, 2009 09:25AM
You could add some timing to see what is so slow. But I think your first loop is slow:
You might consider copying the file instead of creating a new one and adding the values one by one.
Copying can be done using CopyGrid()
Hope it helps,
Paul
--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group
Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.
---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS
Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl
*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn
For row = 0 To rownum
For col = 0 To colnum
conductivitygrid.Value(col, row) = soiltexturegrid.Value(col, row)
Next
Next
You might consider copying the file instead of creating a new one and adding the values one by one.
Copying can be done using CopyGrid()
Hope it helps,
Paul
--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group
Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.
---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS
Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl
*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn
Re: Speeding up grid reclassification from lookup table
Posted by:
sschung ()
Date: December 18, 2009 10:55AM
Thank you for the suggestion Paul. I've modified my code to use the copygrid function but now I encounter an error that says "Writing to this format is not allowed". Would you know why that is? Thanks again.
Re: Speeding up grid reclassification from lookup table
Posted by:
sschung ()
Date: December 18, 2009 12:06PM
FYI:
it seems like the error occurs when I try to edit the grid that has been copied. (the copying procedure itself works fine)
it seems like the error occurs when I try to edit the grid that has been copied. (the copying procedure itself works fine)
Re: Speeding up grid reclassification from lookup table
Posted by:
pmeems ()
Date: December 18, 2009 04:12PM
If you close MW, can you open the copied grid in MW?
If not the file is not copied right, if so the CopyGrid() method is not correctly finishing the grid.
Either way it is best to submit a bug report in Mantis, refer to this post and add the grid file you want to copy.
If I understand it correctly you're copying an ASCII grid. You could open the copied file in a text editor and have a look at the header.
--
Paul
--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group
Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.
---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS
Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl
*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn
If not the file is not copied right, if so the CopyGrid() method is not correctly finishing the grid.
Either way it is best to submit a bug report in Mantis, refer to this post and add the grid file you want to copy.
If I understand it correctly you're copying an ASCII grid. You could open the copied file in a text editor and have a look at the header.
--
Paul
--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group
Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.
---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS
Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl
*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn
Re: Speeding up grid reclassification from lookup table
Posted by:
enrico chiaradia ()
Date: December 21, 2009 01:01AM
I found that Grid.value() method is very slow when you have to manage large dataset. I suggest to use getfloatwindow() instead because it uses pointers to loop in grid data array. Than, using .net array loop, it makes user compatible time (it's necessary only if you have to modify the array value).
Use/modify this function to copy your grid: [www.mapwindow.org]
enrico
Use/modify this function to copy your grid: [www.mapwindow.org]
enrico
Sorry, only registered users may post in this forum.


