Monday, January 14, 2008

Reverse Geocoding Using GeoName Data

I have be using GeoNames data for implementing reverse geocoding.

It took me a while to get it working and thought of sharing the steps that I followed ( Postgres + Postgis ) to get the reverse geocoding work ( and it is fast! )
1) Created and loaded the table by following link or link.

2) Created a geometry column
SELECT AddGeometryColumn( 'public', 'geoname', 'latlon_point', 2163, 'POINT', 2 );
Note that I am using 2163 as SRID ( the unit is meter )

3) Populated the column
update geoname set latlon_point =
transform(GeomFromText('POINT(' || longitude || ' ' || latitude || ')',4326),2163)

4) Created a clustered gist index
CREATE INDEX geoname _latlon_place_index
ON geoname
USING gist
(latlon_point);
ALTER TABLE geoname CLUSTER ON geoname _latlon_place_index;

5) To find nearest 5 records (within 5 kms) for the given lat/long ( 12.97199/77.60483)

SELECT * FROM geoname
WHERE feature_class = 'P'
and st_dwithin(latlon_point, transform(GeomFromText('POINT(77.60483 12.97199)',4326),2163),5000)
order by ST_Distance(latlon_point, transform(GeomFromText('POINT(77.60483 12.97199)',4326),2163))
limit 5

The above query should be extremely fast if the gist index is created properly. One way to confirm whether is it using the index or not, is by looking at the query planner output :

"Limit (cost=9.82..9.82 rows=1 width=175)"
" -> Sort (cost=9.82..9.82 rows=1 width=175)"
" Sort Key: st_distance(latlon_point, '...'::geometry)"
" -> Index Scan using geoname1_latlon_place_index on geoname1 (cost=0.00..9.81 rows=1 width=175)"
" Index Cond: (latlon_point && '..'::geometry)"
" Filter: ((feature_class = 'P'::bpchar) AND (latlon_point && '..'::geometry) AND ('..'::geometry && st_expand(latlon_point, 5000::double precision))

As with any user generated data, there are dirty data present in this dump like duplicate place record, empty place name etc. Also since I am interested only in cities, I added a filter on feature_code = 'PPL' and feature_class = 'P'.

This is just the first pass, and I still need to do couple more processing for cases where the place name contains punctuation, duplicate places across state/country etc. I'm calling it a night! The alarm clock is going to go off in just six hours.

-XP

Wednesday, November 14, 2007

I'll be there @ BCB5

Friday, October 19, 2007

LifeBlob is Live !!!

We are feature complete and passed out invites to our first set of users!

My Timeline
-XP

Tuesday, September 18, 2007

Running Memcached on Windows

I was trying to run memcached server on windows as that is my current development OS. Unfortunately the memcached's windows port has given only source code for libevent ( a dependency) and it needs VC to compile :P. With obvious lack ( read: interest ) in VC tools, I set on a big google hunt for finding the windows build of libevent.

I was finally able to get some luck from this site. Thanks to them, I was able to get memcached running successfully.

I have attached the memcached ( 1.2.1 ) setup here

Sets to run the server
1) Unzip the folder to any directory
2) Within the folder, run memcached.exe -d install ( One time )
3) For
starting the server: memcached.exe -d start
stopping the server: memcached.exe -d stop
4) To uninstall the service, run memcached.exe -d uninstall

You can also run memcached.exe -h to find all the properties that can be configured.

-XP

Friday, August 31, 2007

Comic

Thursday, August 23, 2007

Comic



Wednesday, August 22, 2007

Excellent Y! Support

The closure Y! photo's was indeed a bad news. I was totally in love with their interface and obviously unlimited storage:P The day the news came in, I decided to move my photos ( > 2 GB ) quickly ( read: bad judgment ) to flickr. The decision was pretty much based on Flickr's brand name over other options. After the image transfer, I realized that I would have been better off using either Shutterfly/SnapFish service which offers unlimited storage.

But as expected, after doing the photo transfer to Flickr, my Y! photo account got locked. ( It was mentioned in their FAQ that the transfer is a one time only operation). I shot a mail to Y! support ( with the least expectation ) on whether it is possible for them to reactivate my Y! account so that I could migrate to another photo service.

I received a mail from their support within 2 days and was a positive reply :)


Hello,

Thank you for writing to Yahoo! Photos.

Thank you for contacting us regarding your attempted move of your Yahoo! Photos to another service. We are very sorry to hear that you are having problems moving to the affiliate of your choice.

We have released your Yahoo! Photos account so that you can attempt the move again. If you are having continuing problems moving to the same affiliate, you may want to try moving to a different affiliate or simply downloading your images to your computer yourself and then manually uploading them to the affiliate of your choice.

If you have any additional questions or concerns please let us know as soon as possible as we'd be more than happy to help!

- http://help.yahoo.com/l/us/yahoo/photos/

We appreciate your time in writing to us -- your input helps us to identify ways to help make this the easiest and most hassle-free way to transition all of your favorite photos to one of these great services above!

Thank you again for contacting Yahoo! Photos.

Regards,

Jamie Lynn

Yahoo! Photos Customer Care



This kind of support is truly amazing and very much appreciated!

PS: I moved my photos to ShutterFly. My new preference is Google Photos but sadly they don't provide "free" unlimited storage :(

Friday, August 17, 2007

Struts2 + Custom URLs

For the web application that I was building using Struts, I needed custom ( read: cool ) URLs.

Traditionally, struts URL would be of the format
http://www.myapp.com/login.do
where do is the action extension.

But rather, I wanted a clean URL like http://www.myapp.com/login

To achieve this, I had to do the following

-> In my custom struts.xml, I added a line which overrides the default ActionMapper class

->
Write the custom class which should extend ActionMapper

With a custom Mapper Class, the scope of formats of URL is limited only by imagination :P
To take up an example, lets say we want to have a "clean" search URL
http://www.myapp.com/search/abc+xyz
To achieve the above, we need the following

  • Action class called Search and corresponding function called getResults(). This class also needs to implement ServletRequestAware to get hold of the ServletRequest ( which would contain the search parameters )
  • In the custom Action Mapper Class, we would need to use regex ( split on "/" ) to understand the URL and if we find the first token is "search", we could set
actionMapping.setNamespace(namespace);
actionMapping.setName("search");
actionMapping.setMethod("getResults");
request.setAttribute(SEARCH_KEY, searchParameters);


-XP

Tuesday, April 03, 2007

MS Live Search WTF

Check out the results for "how long does it take to get a patent" on MS Live Search ( roftl ).

Looks like the live team is doing a great job in catching up google :P

Wednesday, February 21, 2007

Funny Traffic Signal

Encountered a weired traffic signal near RajajiNagar Entrance. Was wondering what to do next: "Jump" the signal or face the wrath of the vehicles behind me :P



PS: I had taken the pic using my phone ( Nokia 6270 ) without flash and while moving and hence the bad quality ;)

-XP

Family Tree

I am very bad at remembering detailed family relations and for that matter even names :P When ever I visit my native place (which is very rare) with my parents, my parents/I make sure that I get a "crash" course on all the relations again ;). So being a tech guy, I wanted a tech solution and hence entered the domain of family tree. For long I had be wanting to find a site that would really simplify creation of the family tree. I had tried various sites like Ancestry, TribalPages etc, but none of them allowed me an "easy" or "flexible" way to create a family tree :( Couple of hrs back, Pavan ( Friend and Colleague ), pinged me with the URL to this brand new "web 2.0 family tree"!

It is called Geni( That is one short name!). The first thing that strike me was with the ease it allowed me to create an account ( No email validation to start off! But then we need to validate later). The UI is flash based and mind blowing. The whole experience of creating family tree is taken to the next level. It was so much of fun that within 30 mins or so, I had added over 20+ members to my tree. The product is still in "beta" and has couple of privacy issues to be answered ( Like mother's maiden name being shown, access control etc). But in all, I really liked the whole user experience. I recommend that you take a shot at this.

A sample tree


I also manage to find couple of other new Family Tree service
  1. Famster
  2. Zooof
But none the above has an UI that is as intuitive as the Geni's one

Update
  • Check out the way they incite users to complete the profile.
-XP