ThinkGeo.com    |     Documentation    |     Premium Support

MBTilesExtractorSample for WPF .net framework

Hi,

I downloaded the sample at https://github.com/ThinkGeo/MBTilesExtractorSample-ForWpf and was able to build and run on my computer.

Then I copied the whole project to another computer. It’s able to run but each time I tried to extract a new map, it stucked at 44KB. Any ideas?

Thanks,

Liang

Hi Liang,

I tested to copy the project to a new machine, after login my account and activate WPF license, it works well.

If each time it generate a 44kb result for different data, I think maybe there is an exception when it run.

I think you can open the “Common Language Runtime Exceptions” in exception settings and see what’s the exception in the new machine.

image

You can also debug the code to see what happened in the function “ExtractTiles”.

Any information please let us know.

Regards,

Ethan

Hi Ethan,

Can you try click the copied exe on the other machine?
My other machines don’t have visual studio installed. So I copied the project but click the exe to run the extractor. I activated and added WPF license. How do I login to my account?

Thanks,

Liang

If you build the solution, there is an exe file copied to the output called ThinkGeo.ProductCenter.exe. You can also find this exe by looking through your packages. If you start this exe, you can log into your account and activate any licenses.

Additionally, I have tried this sample recently myself, and I have been able to get it to load and run correctly. You can’t just copy the exe to another machine. You will need to copy the entire output and ensure any prerequisites are installed on the new machine (things like the appropriate .Net Framework/Core, etc). If you do copy the files, I recommend that you build in release mode, or you will have to ensure that you have the debug versions of the Framework if you are using it.

Good luck! :smiley:

Hi Brandon,

I copied the whole project folder, including bin, Data, obj, Properties and Shared to the other machine. I logged in to Thinkgeo product center on the other machine. I tried both release and debug mode. The extracted map still stuck at 44 KB on the other machine.

I added exception handling in function ExtractTiles() but did not see any.

Interestingly, I added debug MessageBox after
targetDB.Metadata.Insert(sourceDB.Metadata.Entries);
Whenever the message pops up, my other machine has extracted file size of 44 KB while my working machine shows 56 KB.

After that, it seems the function never comes out from while ( ! isEnd). In fact, it never passes the line "var entries = sourceDB.Map.Query(quersql);

Any suggestions that why that’s the case?

Thanks,
Liang

Liang_lu,

I wish I could help you more, but without looking at your code exactly and working with your system, I am not sure why you are having issues. I can only tell you that I have generated tiles on multiple machines from the sample and code based on the sample. I did generate the database, but I main generated Raster tiles.

I am having an issue with databases in another application. I wonder if the two are related. My code was working but when I changed to .Core, it would not insert features into a database. I have a support ticket submitted for my issue. I’ll watch your issue, and if my solution can help, I’ll be sure to post it.

Hi Brandon,

Thank you! I am using the extractor sample for .NET framework.

I tried .NET core version of the sample but it stuck somewhere as well. Here is the link to the issue I submitted: MBTilesExtractor for .net core goes into infinite loop

Thanks,
Liang

Hi Liang,

Brandon’s reply is helpful if the reason is generally, but from your reply it looks that’s not related with account reason etc.

The most direct solution is install a IDE for example VS or other to catch what’s the detail exception.

If your environment is not allowed to install IDE, you can add some code in the sample code, for example:
this.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);

AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

Then print the exception into a log file. You can also try to check system log to see whether any exception caught by windows.

If you think the logic loop in any function for example ExtractTiles, you can also dump some text in log file to trace what’s the status when it’s run.

Before that, you should want to find another machine, copy entire folder and run product center first, login your account, activate the product and try again, this is for make sure whether it’s a special environment problem.

In fact we found some new machines to test and it still works well.

Any news about your test please let us know.

Regards,

Ethan

Hi Ethan,

I tried yesterday. There was no exception. It seemed sourceDB.Map.Query did not come back in ExtractTiles().

I added debug MessageBox after
targetDB.Metadata.Insert(sourceDB.Metadata.Entries);
Whenever the message pops up, my other machine has extracted file size of 44 KB while my working machine shows 56 KB.
After that, it seems the function never comes out from while ( ! isEnd). In fact, it never passes the line "var entries = sourceDB.Map.Query(quersql);GeneratedMaps.zip (3.4 KB)

I attached the 44KB and 56 KB map files.

Thanks,
Liang

Hi Liang,

Thanks for your test, if the code never comes out from while loop, but the file generated succeed, that means some exception happened inner but hadn’t been caught by your test code.

I think you can add the try catch code in while logic, and print offset value to see whether it’s running. In fact you can print the values after each line, the while block only 9 lines, so that’s possible to do that.

You can add the “Debug.WriteLine” and watch them by the third part utility for example debugview.

Regards,

Ethan

Hi Ethan,

It seems I didn’t describe it clearly.
On my machine, everything is fine. Extracted MBTiles map for Wyoming is around 100 MB.
On the other machine, extracted MBTiles map is stuck at 44KB. I found that for the other machine, it doesn’t go pass the first call of var entries = sourceDB.Map.Query(querySql);
In another word, program is stuck at the first call of sourceDB.Map.Query(querySql).

private void ExtractTiles(RectangleShape bbox, string targetFilePath)
{

targetDB.Metadata.Insert(sourceDB.Metadata.Entries);

foreach (var tileRange in tileRanges)
{
long offset = 0;
bool isEnd = false;
while (!isEnd)
{
string querySql = $“SELECT * FROM {sourceDB.Map.TableName} WHERE " + ConvetToSqlString(tileRange) + $” LIMIT {offset},{recordLimit}";
var entries = sourceDB.Map.Query(querySql);
targetDB.Map.Insert(entries);

}

Thanks,

Liang

Hi Liang,

Thanks for your description, that make sense now, it looks in the other machine code run into var entries = sourceDB.Map.Query(querySql) and stop there or start loop.

Could you please watch the memory usage and CPU usage when program stop to make sure whether it’s still running or be stopped background?

And we want to know have you tried to run it in one third machine? You can test that in virtual machine or cloud server if possible. A same OS and a different OS for compare test should be helpful.

We also want to know your OS environment include OS version, dotnet framework version etc. So we can build a same VM to reproduce it.

Regards,

Ethan

Hi Ethan,

My machine has Windows 10.0.18362. The project was built on dot net framework 4.6.1. I have 4.6.1, 4.7.1, 4.7.2 and 4.8 on this machine.

The other machines have 10.0.18383. The other machine has 4.6.1 and 4.8 dot net framework. It has windows 10 10.0.18363 with 4GB memory. Memory usage is 73%. CPU 12%. It is running, not in background.

Thanks,

Liang

Hi Liang,

Thanks for your information.

We will did more test based on the same environment.

If we can reproduce that we will try to solve it.

Any good news about it we will let you know.

Regards,

Ethan