Tag Archives: open source

GMap.NET component : Moving Marker

WTH is GMap.NET?

Simply put: it’s an open source .net component that can show online mapping service (such as Google Map, Bing Map, OpenStreetMap) in your .NET app.
Download the binary here: http://greatmaps.codeplex.com/
Extract it. You’ll get the .net 2.0 and .net 4.0 version, since I’m using VS 2015, we’ll use the .net 4.0 version.

What will we do now is about how to move a marker inside the map (for tracking/visualizing object movement, etc). We’ll just move the marker randomly in this tutorial.

  • Create new VB Windows Form project
  • Add GMap.NET component into your project reference
GMap.NET component reference

GMap.NET component reference

  • Add GMap.NET component into your toolbar.
Add GMap.NET component step 1

Add GMap.NET component step 1

Add GMap.NET component step 2

Add GMap.NET component step 2

  • Now drag and drop the GMap.NET control into your Form, I name it myMap
  • We’ll also add another controls: 1 Button (name: btnMove), 1 Timer (name: tmr1), 1 Label (name: lblInfo)
List of components

List of components

I also add new bitmap resource into our project properties. This will be used as our marker symbol.

Resource for marker symbol

Resource for marker symbol

You can see the Form’s full source code at the bottom of this post. I’ll just point out some important parts:

  • Map initialization is on Form1_Load event code (zoom level, initial position, provider used, marker type, etc)
  • When you click on the btnMove, it’ll start generating new random position for our marker. The random change is happened in the timer event (tmr1_Tick)
  • The process to update the map visual is delegated into function update_map(), so it will run in different thread and the form still responsive
  • In this tutorial, we are using BingSatelliteMapProvider, you can use another provider such as GoogleMapProvider or OviSatelliteMapProvider. Just see MapProviders namespace to see all supported providers.

Running the app

Running the app


Here’s the full source code:

Imports GMap.NET
Imports GMap.NET.WindowsForms

Public Class Form1
    Private Delegate Sub UpdateFormDelegate()
    Private UpdateFormDelegate1 As UpdateFormDelegate

    Private copter_lat, copter_lon As Double
    Private WithEvents copter_marker As Markers.GMarkerGoogle
    Private WithEvents copter_layer As GMapOverlay

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        copter_lat = -7.076275
        copter_lon = 110.428952

        myMap.MinZoom = 5
        myMap.MaxZoom = 20
        myMap.Zoom = 17
        myMap.Position = New PointLatLng(-7.076275, 110.428952)
        myMap.MapProvider = MapProviders.BingSatelliteMapProvider.Instance
        myMap.Manager.Mode = AccessMode.ServerAndCache
        copter_layer = New GMapOverlay("copter_layer")
        copter_marker = New Markers.GMarkerGoogle(New PointLatLng(-7.076275, 110.428952), My.Resources.purple_drone)
        copter_layer.Markers.Add(copter_marker)
        myMap.Overlays.Add(copter_layer)
        myMap.UpdateMarkerLocalPosition(copter_marker)
        myMap.Invalidate()
        update_map()
    End Sub

    Private Sub tmr1_Tick(sender As Object, e As EventArgs) Handles tmr1.Tick
        Randomize()
        Dim delta_lat As Double = ((100 * Rnd()) + 20) / 10000000.0
        Dim delta_lon As Double = ((100 * Rnd()) + 20) / 10000000.0
        Dim not_lat As Single = Rnd()
        Dim not_lon As Single = Rnd()

        If not_lat >= 0.5 Then
            copter_lat += delta_lat
        Else
            copter_lat -= delta_lat
        End If
        If not_lon >= 0.5 Then
            copter_lon += delta_lon
        Else
            copter_lon -= delta_lon
        End If

        UpdateFormDelegate1 = New UpdateFormDelegate(AddressOf update_map)
        Invoke(UpdateFormDelegate1)
    End Sub

    Private Sub btnMove_Click(sender As Object, e As EventArgs) Handles btnMove.Click
        If tmr1.Enabled Then
            tmr1.Enabled = False
            MsgBox("Random Move stop")
        Else
            tmr1.Enabled = True
            MsgBox("Random Move start")
        End If
    End Sub

    Private Sub myMap_OnMapZoomChanged() Handles myMap.OnMapZoomChanged
        lblInfo.Text = "Info : Lat= " + CStr(copter_lat) + ", Lon= " + CStr(copter_lon) + ", Zoom Level= " + CStr(myMap.Zoom)
    End Sub

    Private Sub update_map()
        copter_marker.Position = New PointLatLng(copter_lat, copter_lon)
        myMap.UpdateMarkerLocalPosition(copter_marker)
        myMap.Invalidate()
        lblInfo.Text = "Info : Lat= " + CStr(copter_lat) + ", Lon= " + CStr(copter_lon) + ", Zoom Level= " + CStr(myMap.Zoom)
    End Sub
End Class

CEntos 6.7 Migrating from mysql-server/mysql-community-server into latest MariaDB

Ok, first you should install yum-replace plugin if you haven’t already have it.

yum install yum-plugin-replace

Get MariaDB packages repo from MariaDB repos builder here
MariaDB repo builder
You’ll get some repo config text that you can save to /etc/yum.repos.d/MariaDb.repo like these:

# MariaDB 10.1 CentOS repository list - created 2016-04-17 23:39 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Do update your repo chache

yum update

If you’re installing mysql-server from CentOS 6.7 default repo, you should do this:

yum replace mysql-libs --replace-with=MariaDB-common

If you’re installing mysql server from webtatic repo (mysql55w-server), you should do this:

yum replace mysql55w-libs --replace-with=MariaDB-common

If you’re installing from MySQL Community repository, do this:

yum replace mysql-community-common --replace-with=MariaDB-common

Just answer with ‘Y’ if the yum replace command show you some conflicts.
Next, just install all MariaDB related packages:

yum install MariaDB-*

Start MariaDB:

/etc/init.d/mysql start

Confirm that you’re using MariaDB:

[root@www ~]# mysql --version
mysql  Ver 15.1 Distrib 10.1.13-MariaDB, for Linux (x86_64) using readline 5.1

Don’t worry, if you have successfully installing MariaDB over MySQL:

  1. your web app that use MySQL will not broken, no need to change anything
  2. your data will stay intact (no data loss)
  3. use MySQL commands as usual (such as: mysql -u root -p)
  4. the MariaDB config is still in /etc/my.cnf

In short, business as usual!

Exporting high resolution image from QGIS project

qgis_hasil_resolusi

Problem:

You want to export your QGIS project into high resolution image. QGIS desktop “Project” –> “Save as Image” only save/export the project into a low resolution image (i.e. your desktop resolution).

qgis_banyumanik

Solution:

1. Finish your project in QGIS

Finish your GIS project in QGIS Desktop, choose which layers to be shown, what style should it use, etc.

2. Choose your extent that will be exported into image

For myself, I choose the full-extent, but you may choose the extent as you wish. You my use “Vector” –> “Coordinate Capture” to help copying the coordinates. You will need to write down the coordinates for [xMin, yMin] (top-left coordinate) and for [xMax, yMax] (bottom-right coordinate). Save and close your QGIS project.

3. Execute the export command via command line of QGIS

Open your command prompt/console (preferably as Administrator/root). Go to your QGIS binary folder, where you install QGIS +”bin” folder, for example C:\Program Files\QGIS Brighton\bin. Use this command template:

qgis --project "c:\where\you\save\your\qgis\project\file.qgs" --snapshot "c:\where\you\want\to\save\your\image.png" --height result_image_height --width result_image_width --extent xmin,ymin,xmax,ymax

For example:

C:\Program Files\QGIS Brighton\bin>qgis --project "D:\work\dita s1\pmapper\Semarang\Kec_Banyumanik\banyumanik.qgs" --snapshot "c:\users\achmadz\documents\padangsari.png" --height 5000 --width 5000 --extent 435825.86153,9218725.47861,438150.22840,9217277.65534

That command will open QGIS Desktop for a moment then close itself. The command will produce padangsari.png in c:\users\achmadz\documents\. Open the image, and you’ll see the image in high resolution (5000×5000 pixels).

qgis_hasil_resolusi

Windows Installer Cleaner

Some background:

My SSD drive is almost full, after checking with TreeSize Free, it seems a lot of space is taken by files inside c:\windows\installer\. Searching around, I conclude that some of files is safe to be deleted from that particular place. There is a VB script in http://blogs.msdn.com/b/heaths/archive/2007/01/31/how-to-safely-delete-orphaned-patches.aspx that detect which files that shouldn’t be deleted from c:\windows\installer.

I also know an application named WiCleanup from KZTechs that detect and delete the “safe” files but after I tried it, the confirmation of deletion for files one-by-one makes me uncomfortable. So, I decide, why not programming the application by myself? And this application is born!

Implementation:

I programmed the application in VB .NET language using the free Microsoft Visual Studio 2013 Community Edition. Without further a do, you can download the application here:

[button link=”http://www.ahowto.net/wp-content/uploads/2015/03/Release.zip”]Windows Installer Cleaner Binary Only[/button]
(Of course you need .NET framework 4.5 installed if you want to run this application)
[button link=”http://www.ahowto.net/wp-content/uploads/2015/03/wic_winform.zip”]Windows Installer Cleaner Full Source Code[/button]

How to use:

It’s quite straight forward. There are three buttons there, you just need to click on them sequentially.

  1. Click “Get Kept List” to see which files that you should keep on c:\windows\installer
  2. Click “Get Delete List” to get the files that should be safe to be deleted and their size.
  3. Click “Delete Files” to delete the detected files.

What I learn from building this application:

  • how to create .NET application that need Administrator privilege (UAC things) when executed
  • how to use COM object in .NET application
  • how to use/import .dll from MS Windows in .NET
  • some file operation in .NET (FileInfo, deleting files, file’s attribute)
Windows Installer Cleaner Screenshot in Windows 7 64-bit

Windows Installer Cleaner Screenshot in Windows 7 64-bit

The application is already tested on Windows 8.1 64-bit and Windows 7 SP1 64-bit. Both systems is running fine until now. 😀

Matrix operation library for CodeIgniter

This tips is useful if you someday handling web-based project that involving Matrix handling and you want to implement it using CodeIgniter. We’ll use PHPMath library for this.

  • Download the latest version of phpmath library from here: http://www.phpmath.com/build02/downloads/
  • Open the archive (build02.tar.gz) and see the content, you’ll see “build02” folder, go inside, you’ll see more folders there:
phpmath archive content

phpmath archive content

  • Because we only need the matrix handling and operation library, we just need the “JAMA” folder inside.
  • Extract this “JAMA” folder into your CodeIgniter’s application/third_party/ library, rename it to more meaningful folder, I prefer “phpmath”. Your third_party library will be look like this:
phpmath inside third_party folder

phpmath inside third_party folder

  • Go inside “phpmath” folder, you’ll see more folders there. We don’t need “docs”, “examples” and “tests” folder, we can delete them, your phpmath folder will be like this:
phpmath after deleting unnecessary folders

phpmath after deleting unnecessary folders

And you are done! (In this tips: not like mPDF and PHPExcel library, we don’t need to create a new file/class in the application/libraries folder)

How to use it?

Quite simple, check and test these code samples inside your controller:

 
// load the phpmath library
require_once(APPPATH."/third_party/phpmath/Matrix.php");

// define new matrix
$raw_matrix_a=array(
     array(1,2,3,4),
     array(5,6,7,8)
);
$raw_matrix_b=array(
     array(1,2),
     array(3,4),
     array(5,6),
     array(7,8)
);
$raw_matrix_c=array(
     array(9, 10),
     array(11, 12)
);
$raw_matrix_d=array(
     array(13, 14),
     array(15, 16)
);
// build the Matrix class
$mA=new Matrix($raw_matrix_a);
$mB=new Matrix($raw_matrix_b);
$mC=new Matrix($raw_matrix_c);
$mD=new Matrix($raw_matrix_d);

//get the matrix element
var_dump($mA->get(1,1));
//set value
$mA->set(1,1, 0);
//get matrix dimension
var_dump($mA->getRowDimension());
var_dump($mA->getColumnDimension());

//addition
$mE=$mD->plus($mC); //must have same dimension
//subtraction
$mE=$mD->minus($mC);
//multiplication
$mE=$mA->times($mB);
//inverse
$mE=$mD->inverse(); // must be square matrix
//transpose
$mE=$mB->transpose();