Monday, 16 March 2015

Synchronizing zoom and pan among multiple map tiles using OpenLayers

What can you do if you have more than two or more maps in a html page and you want to synchronize their pan and zoom, so they all show the same location, at the same scale, each time you look at them?
Such a thing is useful if you want to compare two map sources or you want to display a street map and the aerial photo of the same location. Here is a tip on how to do this using openlayers. I have tested it in Geoserver.
At first it has to be defined where the maps will be shown. A way to do this is to divide the screen equally and give a piece to each map. A simple way to do this is for two maps is to add the following code in the html body

<div style="width:100%; height:50%" id="map"></div>

Then, two (or more) maps have to be defined as variables; one for each map source. The variables need to be initialized as usually (with or without additional options) and the layers for each map must be added.

var map1;
var map2;
map1 = new OpenLayers.Map('map', options);
map2 = new OpenLayers.Map('map', options);
map1.addLayer(myfirstlayer);
map2.addLayer(mysecondlayer);


For the two maps to appear simultaneously in the html page, it is necessary to add controls and define the map center or extend for each one separately. Somehow like this

map1.addControl(new OpenLayers.Control.Navigation());
map1.setCenter( new OpenLayers.LonLat(35.000000,27.00000).transform( new OpenLayers.Projection("EPSG:4326"),map1.getProjectionObject()), 17);

map2.addControl(new OpenLayers.Control.Navigation());
map2.setCenter( new OpenLayers.LonLat(35.000000,27.00000).transform( new OpenLayers.Projection("EPSG:4326"),map2.getProjectionObject()), 17);


In order to achieve synchronization in each map there must be registered listeners for the pan and zoom events and some functions that create new zoom and pan events. For the pan events the “moveend” listener should be used and for the zoom events the “zoomend”  listener.

//Register Listeners
map1.events.register("moveend", null, mapEventM);
map1.events.register("zoomend", null, mapEventZ);
               
map2.events.register("moveend", null, mapEventM2);
map2.events.register("zoomend", null, mapEventZ2);


Each listener registered in map1 is associated with a function that manipulates the appearance of map2 and vice versa. So on a zoom event on map1, function mapEventZ passes the zoom to map2 and on a zoom event on map2 function mapEventZ2 passes the zoom parameters to map1. On a similar ways the pan events are handled.

//Functions that manipulate pan events

function mapEventM(event) {
    map2.setCenter(map1.getCenter());
}
               
function mapEventM2(event) {
    map1.setCenter(map2.getCenter());
}

               
//Functions that manipulate zoom events

function mapEventZ(event) {
    map2.zoomTo(map1.getZoom());
}
               
function mapEventZ2(event) {
map1.zoomTo(map2.getZoom());
}



http://wmsviewer-rodis.rhcloud.com/

Saturday, 31 January 2015

Information entropy as an anthropomorphic concept

After this post I wrote a paper on this subject, find it in arxiv.org

One of the most interesting opinions that I have heard about entropy has been formed by E.T. Jaynes and E.P. Wigner (link). According to them, entropy is an anthropomorphic concept in the sense that in a physical system there can be found many thermodynamic systems. The physical system can be examined from many points of view examining different variables each time and calculating entropy differently. In this post and in the paper in arxiv.org that followed it (link), I discuss how I think that we may apply this concept in information entropy, how Shannon’s definition of entropy can fit in Jayne’s and Bank’s opinion. I also present a case in which I have used this combination of ideas in the past in an Android application.
Information entropy has been defined by Claude Shannon (link). It quantifies the amount of information that is transmitted by a channel or more generally the information content that there is in a message M. Message M consists of a set of n symbols, let P(i) be the probability of appearance of any symbol i in M then for all n symbols stands that entropy H = -ΣP(i)logP(i). Probability P(i) equals to the frequency of appearance of i in M.
Let’s generalize this idea. Let S be a set of objects that we may describe their properties using v variables for each one. Let each variable take values from a range [a, b] of discrete values. Now we have a lot of information about S and we can use entropy in order to analyze it. Exactly as Jaynes describes the examination of physical systems we may choose any subset v’ of v in order to examine the information content of S. The choice of v’ depends on how we care to examine S and this provides the anthropomorphic characteristic to our analysis. Using information entropy we can examine the distribution of the properties described by v’ in the objects of S.
For simplicity reasons let us examine S considering two properties for its objects described by variables X and Y. For variable X and for probability P(x) in the appearance of any value x entropy is H(X)=-ΣP(x)logP(x). Same for Y, it stands that H(Y)=-ΣP(y)logP(y). In order to combine these two entropies we have to consider if they are dependent.
As it is known for independent X and Y stands that H(X,Y) = H(X) + H(Y).
For joint probability P(x, y) stands H(X,Y) = -ΣΣ P(x, y)log P(x, y).
For conditional entropy H(X | Y) which stands for the probability P(y, x) when X depends on Y entropy is H(X | Y) = -ΣP(y, x)log(P(y)/P(y, x)).
These considerations about entropy variables are different from the classical definitions of Shannon. Shannon defines conditional probability P(x, y) as the probability of appearance of symbol x which depends on the appearance of symbol y. While the above probabilities consider properties x and y of one discrete object.
Unconsciously I had used in the past all the above for the development of an android application; you may find it here or here. The goal of the application was to rate the strength of passwords for handheld devices. A strong password M must be complex but as we focus in handheld devices the frequency of appearance of each character in M is not the only property we may consider. The user of each device has to change the keyboard appearance of the device in order to write upper case characters, lower case, symbols or numbers. This makes the input of M more complex than in desktop computers and we may consider this property when rating the complexity of M.
The rating of password strength still regards characters of a simple string M but let us look into them as discrete objects of more than one property. Variable X is defined on the set of characters available to the user and P(x) is the frequency of appearance of each character x in M. Variable Y is the property of each symbol of being an upper case character, lower case, symbol or a number. Then P(y) is the probability of y being upper case character, lower case, symbol or number. The two variables are independent; X does not depend on Y. As a result H(X,Y)=H(X) + H(Y). Calculating entropy using the last equation provides a more accurate analysis of the information content of M.
For a more detailed presentation see my paper currently published in arxiv.org.

Friday, 30 January 2015

The illegal and misleading practices of mobogenie.com

Lately I found out that that there is site called mobogenie.com in which two of my Android apps are published. I have not submitted them to this site and I don’t really want them published there. But this didn’t stop them from presenting the apps in the site and putting a download button.
When you press the download button you get an .apk file that it is supposed to be the app that you are seeing in the site it has the same name. In reality it is the “mobogenie” app that tricks you to install it in your device. Then, perhaps you will have the chance do get the app that you actually want. In their disclaimer they admit that they have no control over the app submissions, they don’t really know if the app that you submit is really yours. A few days ago there was a link in the main page with directions on how to claim your own app from mobogenie if you find it there without having submitted it yourself.
Of course I send an e-mail, they respond that they will look at it, two weeks later no answer.
It turns out that they have built a whole market in which is not clear if they have the right to distribute the apps that they distribute. This practice is illegal, at least in my case it is clear in the EULA of my apps that they may be distributed only be authorized distributors; mobogenie is not one of them.
It is also misleading. The app that they let first to download is not the one you asked for.
Most of the app stores and markets have an app that they ask you to install before start downloading apps. But it is quite clear when you download the app of the appstore and when you download the app that you want. Before submitting an app to legitimate appstores like Amazon and Google Play you go through an extensive check of your ID, they even cross-check the information you provide with IRS. In mobogenie they could do something like this, but they don’t seem to care as their location is in Asia and you will probably won’t bother to form an international law complaint.
Besides, my apps that I saw in mobogenie are distributed from Amazon and Play for free, the mobogenies probably think that I should not mind having in their site my free apps. They could ask first.

Sunday, 28 December 2014

Open a file with default application in Android

Here is a technique to program an Android application to open files using the default application that it is associated with them. A part of this technique can be found in many other sites on the internet. The advantage of this technique is that you don’t need to specify the type of the files or the application that is associated with them.
At first you create a method and you input in it a file object pointing to the  desired file (let’s call it testfile), then it is only necessary to create an intent setting setAction(android.content.Intent.ACTION_VIEW) and intentview.setData(Uri.fromFile(testfile)) and then start an activity with this intent. When this method is executed the application associated with the testfile is executed and it opens testfile without closing your application.
The only problem with this technique is that there might be the case where there is no application associated with testfile. This can happen when there is no suitable application or the testfile has no extension. In this case there is an exception “android.content.ActivityNotFoundException” that must be handled. A convenient technique is to enclose the code in a try-catch structure so as to catch the exception and execute some other code that will direct the program to do something else, like opening the file in a text viewer or display some message.
Here is the code

File testfile = new File(//path of testfile);

 public void openfile(File testfile){
        try{
        Intent intent1=new Intent();
        intent1.setAction(android.content.Intent.ACTION_VIEW);
        intent1.setData(Uri.fromFile(testfile));
        startActivity(intent1);
        }
        catch(android.content.ActivityNotFoundException exception){

            //Do something else
+
        }
}

Wednesday, 15 October 2014

If Android was like an ordinary Linux distribution.

When Android was initially developed, it was design to work in devices with little processing capabilities; not much memory, slow processors, very low power consumption. So, the developing team of android took Linux, removed all the not so necessary features and Android became light and not very demanding; more like an embedded system.
Nowadays, Android enabled devices are equipped with a lot of memory big screens and multicore processors which make them powerful enough to carry complicated and demanding tasks. Still, the philosophy and architecture of android hasn’t changed much. Although I like Android very much, I can’t stop wondering how would it be if android was like an ordinary Linux distribution?

If Android could handle multiple user accounts like Linux 

 

While Linux is a real multiuser system, Android is mainly designed to handle Google accounts rather multiple user accounts. If Android was a multiuser OS like Linux each user would have his own desktop, home directory and settings. Each user would be able to do anything in his home directory like running a script or change permissions in a file, while the rest of the system would be protected. Currently, if you want to do these things you have to Root your device exposing the whole system. Also, each user could have installed his own private applications. To put it in a simple way, when children are coming to my house I could just log in to my tablet as a guest user and give it to them to play without worrying that they will mess up my e-mail application.

Android could have a fully featured console


There are many terminal emulators you may install in android. But if you do so, you find out that most of Unix commands do not work as they are either not installed or they require administrator user rights. As there is no home directory for you this situation affects the whole system; there is no directory in which you can do whatever you want. If you are an advanced user and you want to carry out more advanced procedures you have to install Busy Box a collection of Unix applications compiled for Android but you still need administrators rights; administrator accounts are not accessible. So you buy a high-tech device and you have to hack it so as to get the most of it. How sensible can this be?

Network transparency and remote system administration


With Linux things are simple. Using the console of your computer you can log in to some distant system and operate it like if it is right next to you. This feature is quite useful when you want to administrate some distant system without physical access to its hardware.  This is a very advance feature of Unix. You don’t just get the control of the desktop of the distant system, as it happens with most distant administration applications of Windows. In Unix you actually log in to the system itself.
If such a feature was easily accessible in Android, then we could talk about the support of distant system administration on the move. You could be in an island in the middle of the ocean and check the network traffic of you server in New York. Currently, if you care to do this it is necessary to install an application in your server and a corresponding one in your tablet and then set up a connection and you will probably end up being in control only of the desktop of your server ...... boring.
It is my belief that Android should gradually adopt the traditional features of Linux that are now hidden or ignored. Such an approach would benefit advanced users a lot.