Polygonize a Multipolygon

Recently I ran into this issue where I needed to write code for finding holes in a Polygon. I mentioned an ‘n’ time solution in my previous post and although that solution is correct if the Geometry is correct, it may not work as expected if the Geometry is represented differently. To explain the use-case a little better, I picked Puerto Rico which contains 6 holes. However, if the geometry is read from a WKT and the small islands (refer to the image) is mentioned at the end rather than with the polygons, JTS considers them as holes. So instead of 5, it would show 308 holes. Naturally this is incorrect.

pr_openlayers

A solution to this would be to use the Polygonizer class in JTS which re-creates the entire geometry polygon by polygon. Below is a piece of code for doing that.

Find holes in a Polygon using JTS

There is no published method in JTS to recognize holes from whole Polygons or in other words find the holes in a Polygon. You can of course run a n-squared loop with contains to check whether a polygon contains the other and thus proving its a hole. However, here’s a n time solution to the problem using JTS.

My adventures in the aftermarket car stereo land – tryst with CarToys

Last week I delved into the aftermarket car stereo world. Sure my OEM stereo worked just fine but I wanted more – bluetooth, big capacitive screen, Apple CarPlay and the works. I knew it would cost me a handsome amount and I was ready to shell it out. All I wanted was a painless process and a good install job. So there starts my story.

CarToys has done a brilliant job marketing its stores and to be fair they have more than one good stereos. They carry the Pioneer NEX models and I am sure they can get you the Alpine models in a jiffy as well. So my first obvious choice was CarToys at Irving.  So one fine day I took off a little early from work and made the journey. I was shown all their stock. I was impressed and selected a model. The sales rep wanted to set up an appointment the day after, as they had to bring in some parts for the installation, and I was over the moon with joy.

Along came the day of the installation, I called up the sales rep and he confirmed the parts would be in by the time I got there. I re-confirmed and even offered a later time if there was a chance that the parts would not arrive on time for the appointment. As any good sales rep would do, he assured me that all would be great. I just needed to get my car to the store. And I was over the moon with joy once more.

I got a few weekend chores out of the way and drove to the store. I got in and got out in less than a minute. Apparently the carrier doesn’t deliver on weekends. I wonder how much trouble it would have been to make a phone call and let me know. Anyways I re-scheduled the appointment on Monday and Mr Sales Rep confirmed that Monday would be the day. I was a little skeptical but happy. Hey, mistakes do happen although I do not appreciate people who cannot respect other people’s time.

Along came Monday, I called up half an hour before the scheduled appointment time. Mr Sales Rep wasn’t in that day. I gave my details and asked whether the appointment was still on. And lo behold, to my surprise neither my name, nor my number, nor my car details even existed in their roster. So for five days straight I had been sitting around for nothing. The person on the phone, I am going to call him Mr Rep II, let me in on their secret sauce for keeping appointments – I had to make a deposit. I wonder why Mr Rep – the first didn’t mention it on Day 1. I wasn’t asking them to do it for free.

Mr Rep II then offered to do it the day after if I came in and made a deposit that day. No apologies, no discounts, nothing for the trouble and confusion caused by Mr Rep – the first. Of course I denied and went to BestBuy. So far my experience with BestBuy had been good. They were realistic about their timelines. Although I do not want to wait but I do realize these things take time and its good to know an approximate ETA. But more on that in the second part of this post. Till then, stay tuned!

Accessing classes across classloaders in Pentaho Kettle

Recently, while working on some Kettle steps, I came across an issue where I had a custom data type that needed to be cast across class loaders. In a previous post, I have written about a solution where you can imbibe the class in the jar so it is loaded by the same classloader. That works fine if you don’t have multiple steps in multiple jars. In this post, I am going to talk about the later scenario.

First of all, as I had mentioned earlier, there is no easy way to cast across classloaders. Even the same class is treated differently in each classloader. So I went on to look for a solution that didn’t involve reflection or serialization aka a cleaner solution, if you will. What I ended up with is this: an interface that is inherited by the datatype class and which contains method declarations used in the steps. That way, while casting, you don’t cast to the datatype class, instead to the interface, which in turn can pickup any instance of the data type class from any of the classloaders and still work just great.

Remember though to have only one instance of your interface.

Image courtesy: java-forums.com

PK – The movie

I usually don’t review movies but couldn’t let go reviewing this one. There are those times (read Dabangg, Kick, Happy new year, etc) when I feel sad about the condition of Bollywood movies but PK is definitely not one of those moments. Matter of fact, its quite the contrary. So here goes my review. I have tried to be as objective as possible without letting go of any spoilers.

First I would like to talk about the central theme and its comparison with the movie Oh My God (OMG). I have read and heard from several sources that many people think the movie is very similar to OMG (read copy of OMG). I have to agree that the central theme remains the same or should I say similar, but that’s about all the similarity you would get between the two. Sure both the movies focussed on religion, the intricacies of religious practices and the transparency (or lack thereof) with which it is practiced but both digress from each other on one simple point: OMG showed how frustrating it can be for the common man whereas PK displayed how “silly” and superficial our ways are to an outsider, in fact, silly to the point of destroying civil harmony.

PK, in my opinion, is not a movie about setting things right. It’s not a movie about the triumph of good over evil and it’s not a movie on everlasting love. It’s a mirror, a reflection of our society, a reflection of who we are and a subtle message to all of us that we could be better and stronger. I don’t think PK attacks any religion. To be factually fair, it covered all the major religions in India. I believe it took religion as an example to prove its point. It might have been anything else but religion is a topic that hits almost everybody’s nerve so I guess that’s why the writer chose it.

Rajkumar Hirani did a great job as the director of the movie. There are no back stories or intricate romantic plots. The primary story covered almost the entire movie. The only thing that hit me a little unnecessary was Anushka Sharma’s tryst with Sushant Singh Rajput at the end. The movie could have done just fine without a happy romantic ending but then again we all love happy romantic endings, don’t we!

In conclusion, after a year full of fluff and buff, Bollywood produced a gem that can’t be easily forgotten.

Happy new year 2015

A new year is a great time to look back in retrospection and forward in resolutions. But before all that, its time to party. This year I went to the Big D NYE event at the American Airlines Center, Dallas and it was just awesome. The fireworks were amazing and whole ambience was simply enticing. Here's a video of yesterday's countdown and ushering in of 2015.

 

The AA Center hosts the Big D NYE event every year in association with its partners especially SouthWest Airlines. This year they sponsored the fireworks and its was a treat for the eyes. If you are planning to attend this event next year, here are a few bits of information that you may find helpful:

  • The Big D NYE event sees a footfall in the range of 30000-40000 and people pour in at an increased rate usually after 9PM, so plan accordingly.
  • The AA center has a parking capacity of approximately 8000 which is never enough. However, there are other parking options especially near Victory station that are at a walking distance from it.
  • The Big D NYE event also hosts a private red carpet party and I hear Rowan Atkinson was present this year. 

 

Classloader issues while trying to cast different instances of the same class to itself

I was working on a part of code today where I needed to cast an instance of a class to itself. Usually that should work like a breeze but it failed with a ClassCastException in my case. With a little effort I figured out that the issue was thus:

The instances of the class were loaded by two different class loaders and since instances of the same class cannot be cast into one another without explicit serialization/deserialization protocols, the cast, obviously failed.

Naturally the fix was to enable the instances to be loaded by the same class loader. Another fix would have been to write serialization and deserialization protocols. The latter is especially handy if you are not sure whether there is a chance of an instance of the class to be loaded, by say, using reflection and thus a different classloader.

Some food for thought!

On the Saradha scandal

Our great country has seen a lot of scandals but perhaps never a Ponzi scheme as the Saradha scandal. How authorities can allow such a scheme to be run for so long is beyond me but here's a timeline of what happened and key figures from West Bengal. What you draw from it is totally up to you but on a very personal note when I finished writing this timeline, it did change a lot of my perceptions.

  • Sudipto Sen, the chairman and MD of Saradha Group earlier known as Sankaraditya Sen and was part of the Naxalite movement.
  • He changed his name and may have undergone plastic surgery in 1990's.
  • Sudipto Sen started the Ponzi scheme in 2000. By then he had acquired land and was part of land development projects, which became a catalyst for his Ponzi scheme.
  • In 2006, Saradha Group incorporated the companies that formed the group.
  • Initially, the Group collected money from investors using the frontline companies by issuing secured debentures and redeemable preferential bonds.
  • Agents were paid hefty commissions of 25%-40% which made this a very lucrative job.
  • In 2009 SEBI first confronted the Saradha Group. By then Saradha Group had more than 200 companies to create more cross-holdings.
  • SEBI started putting pressure and in 2010 the Group changed its modus operandi to investment on tourism, hotels etc.
  • Saradha Group also started selling chit funds.
  • SEBI warned the State Government of West Bengal in 2011 prompting the group to change its method yet again. It started selling shares of listed companies and embezzled the funds to untraceable offshore accounts.
  • At the time, since Saradha Group sold chit funds, it came under the jurisdiction of the State Government and not SEBI.
  • In 2011, Saradha Group bought Global Automobiles, shut down the factory and put it up as a face to gullible investors. It also bought similar shell companies to show off to agents and investors.
  • On 7th Dec, 2012 RBI told the WB Government to initiate a suo motu.
  • By the end of the year, SEBI was able to classify the Group's activities as a collective investment scheme rather than a chit fund and put a stop to all investments. The Group didn't comply.
  • In January 2013, the Group's cash inflow was less than its outflow for the first time.
  • On 6th April, 2013 Sen wrote a confessional letter to the CBI and disappeared.
  • On 18th April 2013, an arrest warrant was issued on Sen's name and he was arrested on the 23rd of April in Kashmir.
  • Saradha Group  was thus shut in April 2013.

Key figures

  • Sudipto Sen – chairman and MD
  • Debjani Mukherjee – one of the executive directors with check signing authority
  • Satabdi Roy, TMC MP and actress – Brand Ambassador
  • Mithun Chakraborty, TMC MP and actor – Brand Ambassador of media platform
  • Kunal Ghosh, TMC MP – CEO of media group (drew a salary of US$26000 per month)
  • Srinjoy Bose, TMC MP – Directly involved with the Group's media operations
  • Madan Mitra, TMC MLA – Headed the employee's union
  • Shyamapada Mukherjee, TMC – Saradha Group bought his failing company Landmark Cement
  • Mamata Banerjee, TMC, CM – Sold paintings worth US$300,000 to the Group

 

Pentaho Kettle plugin code generator v0.1 released

Recently I released a snapshot of my Pentaho boiler plate code generator application. Today after a significant amount of work, I am releasing the first RC version of it – 0.1. The changelog is as follows:

  • Major bug fixes to generated code where the generated code didn't compile out of the box.
  • The generator now adds the imports to the generated classes.
  • Adds Eclipse nature to the generated project.
  • Has the ability for dependency management using S3.
  • Adds dependent jars to classpath.
  • The generator now runs on an auxiliary thread.
  • Progress update feature added.

Let me know what you think of the new version and don't forget to register issues and features requests.
As always, here's the link to the project.