<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Questions &#039;n&#039; Answers - Technology</title>
	<atom:link href="http://qnatech.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://qnatech.wordpress.com</link>
	<description>Q&#38;A - Java, J2EE, Tomcat, Apache, Linux, Blaze-DS, LCDS, BPM, MySQL, Performance, Deployment, Scaling</description>
	<lastBuildDate>Thu, 22 Dec 2011 08:13:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='qnatech.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Questions &#039;n&#039; Answers - Technology</title>
		<link>http://qnatech.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://qnatech.wordpress.com/osd.xml" title="Questions &#039;n&#039; Answers - Technology" />
	<atom:link rel='hub' href='http://qnatech.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Useful Maven Commands</title>
		<link>http://qnatech.wordpress.com/2011/12/22/useful-maven-commands/</link>
		<comments>http://qnatech.wordpress.com/2011/12/22/useful-maven-commands/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 08:13:48 +0000</pubDate>
		<dc:creator>qnaguru</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://qnatech.wordpress.com/?p=291</guid>
		<description><![CDATA[To run a unit test using maven from commandline: mvn -Dtest=ActualTestName test<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=291&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>To run a unit test using maven from commandline:<br />
mvn -Dtest=ActualTestName test</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/qnatech.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/qnatech.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/qnatech.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/qnatech.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/qnatech.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/qnatech.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/qnatech.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/qnatech.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/qnatech.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/qnatech.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/qnatech.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/qnatech.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/qnatech.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/qnatech.wordpress.com/291/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=291&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://qnatech.wordpress.com/2011/12/22/useful-maven-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2c5a6b33a6c910ba95351d8afb0a2a2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">qnaguru</media:title>
		</media:content>
	</item>
		<item>
		<title>Eclipse gets stuck at &#8216;Refreshing Maven Model&#8217; endlessly. How to resolve?</title>
		<link>http://qnatech.wordpress.com/2011/08/03/eclipse-gets-stuck-at-refreshing-maven-model-endlessly-how-to-resolve/</link>
		<comments>http://qnatech.wordpress.com/2011/08/03/eclipse-gets-stuck-at-refreshing-maven-model-endlessly-how-to-resolve/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 11:03:34 +0000</pubDate>
		<dc:creator>qnaguru</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://qnatech.wordpress.com/?p=285</guid>
		<description><![CDATA[Problem Statement On my Eclipse / STS IDE, when i open a (maven) project, it often gets stuck trying to resolve dependencies with &#8216;refreshing maven model&#8217; message endlessly. Solution Not sure why this happens. But the following resolves the problem - 1. Close your Eclipse / STS IDE. 2. Go to your workspace project directory <a href="http://qnatech.wordpress.com/2011/08/03/eclipse-gets-stuck-at-refreshing-maven-model-endlessly-how-to-resolve/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=285&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Problem Statement</strong><br />
On my Eclipse / STS IDE, when i open a (maven) project, it often gets stuck trying to resolve dependencies with &#8216;refreshing maven model&#8217; message endlessly.</p>
<p><strong>Solution</strong><br />
Not sure why this happens. But the following resolves the problem -<br />
1. Close your Eclipse / STS IDE.<br />
2. Go to your workspace project directory on command line (where the pom.xml exists)<br />
3. From command-line run: mvn dependency:resolve<br />
This will resolve all dependencies outside of Eclipse / STS IDE.<br />
For all projects that have large number of dependencies, this may be the thing to do!</p>
<p>Thats It. Now when you open your IDE, there are no dependencies to resolve, and you will not see the refreshing maven model problem.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/qnatech.wordpress.com/285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/qnatech.wordpress.com/285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/qnatech.wordpress.com/285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/qnatech.wordpress.com/285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/qnatech.wordpress.com/285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/qnatech.wordpress.com/285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/qnatech.wordpress.com/285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/qnatech.wordpress.com/285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/qnatech.wordpress.com/285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/qnatech.wordpress.com/285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/qnatech.wordpress.com/285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/qnatech.wordpress.com/285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/qnatech.wordpress.com/285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/qnatech.wordpress.com/285/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=285&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://qnatech.wordpress.com/2011/08/03/eclipse-gets-stuck-at-refreshing-maven-model-endlessly-how-to-resolve/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2c5a6b33a6c910ba95351d8afb0a2a2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">qnaguru</media:title>
		</media:content>
	</item>
		<item>
		<title>How to install a jar manually in local maven repository?</title>
		<link>http://qnatech.wordpress.com/2011/07/26/how-to-install-a-jar-manually-in-local-maven-repository/</link>
		<comments>http://qnatech.wordpress.com/2011/07/26/how-to-install-a-jar-manually-in-local-maven-repository/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 11:56:21 +0000</pubDate>
		<dc:creator>qnaguru</dc:creator>
				<category><![CDATA[maven]]></category>
		<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://qnatech.wordpress.com/?p=277</guid>
		<description><![CDATA[Problem Statement: Your pom.xml dependencies is not able to download a certain jar from the repository. Solution: You can manually download the jar and add it to your local maven repository. Assuming this dependency (mentioned in pom.xml) fails (because the jar fails to download): &#60;dependency&#62; &#60;groupId&#62;org.hibernate&#60;/groupId&#62; &#60;artifactId&#62;hibernate-entitymanager&#60;/artifactId&#62; &#60;version&#62;3.3.2.GA&#60;/version&#62; &#60;/dependency&#62; Then download hibernate-entitymanager-3.3.2.GA manually, and run <a href="http://qnatech.wordpress.com/2011/07/26/how-to-install-a-jar-manually-in-local-maven-repository/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=277&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Problem Statement: Your pom.xml dependencies is not able to download a certain jar from the repository.</p>
<p>Solution:<br />
You can manually download the jar and add it to your local maven repository.</p>
<p>Assuming this dependency (mentioned in pom.xml) fails (because the jar fails to download):</p>
<p><code>&lt;dependency&gt;<br />
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;<br />
      &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;<br />
      &lt;version&gt;3.3.2.GA&lt;/version&gt;<br />
&lt;/dependency&gt;<br />
</code><br />
Then download hibernate-entitymanager-3.3.2.GA manually, and run the command:<br />
<code>mvn install:install-file -DgroupId=org.hibernate -DartifactId=hibernate-entitymanager -Dversion=3.3.2.GA -Dpackaging=jar -Dfile=./hibernate-entitymanager-3.3.2.GA.jar </code></p>
<p>Thats it, you are all set.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/qnatech.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/qnatech.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/qnatech.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/qnatech.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/qnatech.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/qnatech.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/qnatech.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/qnatech.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/qnatech.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/qnatech.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/qnatech.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/qnatech.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/qnatech.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/qnatech.wordpress.com/277/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=277&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://qnatech.wordpress.com/2011/07/26/how-to-install-a-jar-manually-in-local-maven-repository/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2c5a6b33a6c910ba95351d8afb0a2a2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">qnaguru</media:title>
		</media:content>
	</item>
		<item>
		<title>How to use geo spatial with MongoDB?</title>
		<link>http://qnatech.wordpress.com/2011/07/07/how-to-use-geo-spatial-with-mongodb/</link>
		<comments>http://qnatech.wordpress.com/2011/07/07/how-to-use-geo-spatial-with-mongodb/#comments</comments>
		<pubDate>Thu, 07 Jul 2011 06:13:07 +0000</pubDate>
		<dc:creator>qnaguru</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://qnatech.wordpress.com/?p=261</guid>
		<description><![CDATA[Problem Statement Find all locations that are within a certain radius of a particular location. Solution Approach We will demonstrate this with pseudo-code. Let us insert lots of location specific data in MongoDB. We will search this very data later. static Mongo m; static DB db; static DBCollection coll; m = new Mongo("localhost"); db = <a href="http://qnatech.wordpress.com/2011/07/07/how-to-use-geo-spatial-with-mongodb/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=261&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Problem Statement</strong><br />
Find all locations that are within a certain radius of a particular location.</p>
<p><strong>Solution Approach</strong><br />
We will demonstrate this with pseudo-code.</p>
<p><strong>Let us insert lots of location specific data in MongoDB.</strong></p>
<p>We will search this very data later.</p>
<pre>
<code>
static Mongo m;
static DB db;
static DBCollection coll;

m = new Mongo("localhost");
db = m.getDB("mydb");
coll = db.getCollection("people");
coll.ensureIndex((DBObject) JSON.parse("{ 'loc' : '2d' }"));

Random rand = new Random();
long startTime = Calendar.getInstance().getTimeInMillis();

for (int i = 0; i &lt; 100000; i++)
{
    double lat = rand.nextDouble() * 180 - 90;
    BigDecimal bd1 = new BigDecimal(lat).setScale(2,RoundingMode.HALF_EVEN);
    lat = bd1.doubleValue();

    if (lat = 90)
         lat = lat - 0.5;
         double lon = rand.nextDouble() * 360 - 180;
         BigDecimal bd = new BigDecimal(lon).setScale(2, RoundingMode.HALF_EVEN);
         lon = bd.doubleValue();

    if (lon = 90)
         lon = lon - 0.5;

    // System.out.println("lon / lat = " + lon + " / " + lat);
    // lat=1; lon=1;
    coll.insert((DBObject) JSON.parse("{'loc' : [ " + lon + " , " + lat	+ " ]}"), WriteConcern.SAFE);
}

long timeTaken = Calendar.getInstance().getTimeInMillis() - startTime;
System.out.println("Total Time Taken to Insert (milliseconds): " + timeTaken);
</code>
</pre>
<p><strong>Now we want to do a geo spatial search on the above inserted data.</strong><br />
i.e find all documents(rows) whose location is within a certain miles(radius) from a particular location(lat,lon):</p>
<p>There are several ways to do this search.<br />
Lets look at them one by one.</p>
<pre>
<code>
//Using $nearSphere to find all locations that are within 1000 miles from location 78,10

static void <strong>searchWithNearSphere</strong>()
{
    // 1 radian = 3959 miles (6371 km).
    // So, 100 miles = 100/3959 = 0.0253 radians.
    // So, 1000 miles = 1000/3959 = 0.253 radians.
    System.out.println("searchWithNearSphere: Query to run: "
    + "{'$nearSphere' : [ 78 , 10 ] , '$maxDistance' : 0.253}");

    long startTime = Calendar.getInstance().getTimeInMillis();

    // Must use long/lat format, and not lat/long.
    // Valid bounds for latitude is -90/90.
    // Valid bounds for longitude is -180/180
    DBCursor cur = coll.find(new BasicDBObject("loc", JSON.parse("{'$nearSphere' : [ 78 , 10 ] , '$maxDistance' : 0.253}"))).limit(100000);
    long timeTaken = Calendar.getInstance().getTimeInMillis() - startTime;
    System.out.println("Total Time Taken for 'searchWithNearSphere(milliseconds): " + timeTaken);

    System.out.println("Total Documents Found: " + cur.count());
    System.out.println("Total Documents Found: " + cur.length());
    System.out.println("Total Documents Found: " + cur.size());

    /*
    * while (cur.hasNext()) { System.out.println(cur.next()); }
    *
    * System.out.println("Total Documents Found: " + cur.size());
    */
}

// Using geoNear command to find all locations that are within 1000 miles from location 78,10
static void <strong>searchWithGeoNear</strong>()
{
    BasicDBObject cmd = new BasicDBObject();
    cmd.put("geoNear", "people");
    int coord[] = { 78, 10 };
    cmd.put("near", coord);
    cmd.put("num", 1000);
    cmd.put("maxDistance", 0.253);
    cmd.put("spherical", true);

    long startTime = Calendar.getInstance().getTimeInMillis();
    CommandResult r = db.command(cmd);
    long timeTaken = Calendar.getInstance().getTimeInMillis() - startTime;
    System.out.println("Total Time Taken for 'searchWithGeoNear(milliseconds): " + timeTaken);
    System.out.println(r.ok());
    System.out.println(r.getErrorMessage());
    // System.out.println(r.toString());

    // print(r);//Print all the returned data.

    com.mongodb.BasicDBList resultsBasicDBList = (BasicDBList) r.get("results");
    System.out.println("Total Results: " + resultsBasicDBList.size());

    // System.out.println("Results: " + resultsBasicDBList); //This will
    // print the value of 'results' key.

    // print(resultsBasicDBList);//This will print individual values.
}

//The print function to print a DBObject:
public static void <strong>print</strong>(DBObject doc)
{
    Set allKeys = doc.keySet();
    Iterator it = allKeys.iterator();
    while (it.hasNext())
    {
        Object o = it.next();
        String temp = (String) o; // it.next();
        // System.out.println("K CLASS: " + o);
        // System.out.println("V CLASS: " + doc.get(temp).getClass());
        System.out.print(temp + "-");

        if (doc.get(temp) instanceof BasicDBObject)
        {
            System.out.println("\n");
	    print((DBObject) doc.get(temp));
        }
        else
        {
            System.out.println(doc.get(temp));
	    if (temp.toString().equalsIgnoreCase("loc"))
	        System.out.println("-------------");
        }
    }//end of while
}

// To clean up a collection completely

static void <strong>clean</strong>()
{
    // clear records if any
    DBCursor cur = coll.find();

    while (cur.hasNext())
        coll.remove(cur.next());
}
</code>
</pre>
<p><strong>Thats It!</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/qnatech.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/qnatech.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/qnatech.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/qnatech.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/qnatech.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/qnatech.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/qnatech.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/qnatech.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/qnatech.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/qnatech.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/qnatech.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/qnatech.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/qnatech.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/qnatech.wordpress.com/261/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=261&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://qnatech.wordpress.com/2011/07/07/how-to-use-geo-spatial-with-mongodb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2c5a6b33a6c910ba95351d8afb0a2a2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">qnaguru</media:title>
		</media:content>
	</item>
		<item>
		<title>How to use geo spatial with PostGres (PostGIS)?</title>
		<link>http://qnatech.wordpress.com/2011/07/06/how-to-use-geo-spatial-with-postgres-postgis/</link>
		<comments>http://qnatech.wordpress.com/2011/07/06/how-to-use-geo-spatial-with-postgres-postgis/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 13:11:12 +0000</pubDate>
		<dc:creator>qnaguru</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://qnatech.wordpress.com/?p=254</guid>
		<description><![CDATA[Problem Statement Find all locations that are within a certain radius of a particular location. Solution Approach We will demonstrate this with pseudo-code. Lets create a table in MySQL that will store geo information: CREATE TABLE geoinfo ( id bigserial NOT NULL, latitude numeric(9,4), longitude numeric(9,4), "location" geometry, CONSTRAINT enforce_dims_geom CHECK (st_ndims(location) = 2), CONSTRAINT <a href="http://qnatech.wordpress.com/2011/07/06/how-to-use-geo-spatial-with-postgres-postgis/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=254&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Problem Statement</strong><br />
Find all locations that are within a certain radius of a particular location.</p>
<p><strong>Solution Approach</strong><br />
We will demonstrate this with pseudo-code.</p>
<p><strong>Lets create a table in MySQL that will store geo information:</strong></p>
<pre>
<code>CREATE TABLE geoinfo
(
  id bigserial NOT NULL,
  latitude numeric(9,4),
  longitude numeric(9,4),
  "location" geometry,
  CONSTRAINT enforce_dims_geom CHECK (st_ndims(location) = 2),
  CONSTRAINT enforce_geotype_geom CHECK (geometrytype(location) = 'POINT'::text OR location IS NULL),
  CONSTRAINT enforce_srid_geom CHECK (st_srid(location) = (-1))
)
WITH (
  OIDS=FALSE
);
</code>
</pre>
<p>NOTE the use of the geometry datatype above.</p>
<p><strong>Now, what we want to do is insert lots of data in this table:</strong><br />
The following code inserts 100,000 random records into geoinfo table. We will do a search on this very data later.<br />
The code is same as what we saw in: <a href="http://qnatech.wordpress.com/2011/07/06/how-to-use-geo-spatial-with-mysql/" title="How to use Geo Spatial with MySQL?"></a>, only difference being this line:<br />
geomFunc=&#8221;st_pointfromtext&#8221;;// we are using a PostGIS specific function to insert data in location column.</p>
<pre>
<code>
static String dbUrl = "jdbc:postgresql://localhost:5432/postgis?";
static String dbClass = "org.postgresql.Driver";
static String schemaPrefix="";
static String DB_USERNAME="whatever";
static String DB_PASSWD="whatever";

Class.forName(dbClass);
Connection con = DriverManager.getConnection(dbUrl, DB_USERNAME, DB_PASSWD);
Statement stmt = con.createStatement();

String query1;
long startTime = Calendar.getInstance().getTimeInMillis();
//Randomize the lat, long inputs
Random rand = new Random();
String geomFunc="";

geomFunc="st_pointfromtext";

for (int i = 0; i &lt; 100000; i++)
{
    double lat = rand.nextDouble() * 180 - 90;
    BigDecimal bd1 = new BigDecimal(lat).setScale(2, RoundingMode.HALF_EVEN);
    lat = bd1.doubleValue();
    double lon = rand.nextDouble() * 360 - 180;
    BigDecimal bd = new BigDecimal(lon).setScale(2, RoundingMode.HALF_EVEN);
    lon = bd.doubleValue();
    query1 = &quot;INSERT INTO &quot; + schemaPrefix + &quot;geoinfo(latitude, longitude, location) VALUES (&quot; + lat + &quot;,&quot; + lon +             &quot;, &quot; + geomFunc + &quot;(&#039;POINT(&quot; + lat + &quot; &quot; + lon + &quot;)&#039;) )&quot;;
    System.out.println(query1);
    int res = stmt.executeUpdate(query1);
    // System.out.println(&quot;res: &quot; + res);
}

long timeTaken = Calendar.getInstance().getTimeInMillis() - startTime;
System.out.println(&quot;Total Time Taken to insert data : &quot; + timeTaken + &quot; milliseconds&quot;);
</code>

<strong>Now we want to do a geo spatial search on geoinfo table
i.e find all rows from the geoinfo table whose location is within a certain miles(radius) from a particular location(lat,lon):</strong>

We will write a findGeoLocations function that will print all records that meet this criteria:

<code>
public void findGeoLocations(double lat, double lon, double radiusInMiles)
{

Connection con = null;
try {
    //get DB Connection from somewhere.
    con = getConnection();

    //Statement stmt = con.createStatement();
    String query="";
    double radius=radiusInMiles/69;

    query="SELECT id, latitude, longitude, ST_DISTANCE(location, 'POINT(" + lat + " " + lon + ")') as distance FROM geoinfo WHERE ST_DWithin(location, 'POINT(" + lat + " " + lon + ")', " + radius + ")";
    //IMPORTANT:
    //If : geography suffix is used against POINT in SQL - then the order should be - lon lat and not - lat lon.
    //And the data too should have been inserted as lon lat for geocode location column. Geography suffix uses distances in meters.
    //If geography suffix is not used - then we can simply use - lat lon format.

    System.out.println("Query to use: " + query);

    PreparedStatement pStmt = con.prepareStatement(query);
    ResultSet rs;
    long startTime = Calendar.getInstance().getTimeInMillis();
    rs = pStmt.executeQuery();
    long timeTaken = Calendar.getInstance().getTimeInMillis() - startTime;

    int rows = 0;
    while (rs.next())
    {
        rows++;
        System.out.println ("RS: Id: " + rs.getInt("id") + " Lat: " + rs.getDouble("latitude") + " Lon: " + 		rs.getDouble("longitude") + " Dist: " +					rs.getDouble("distance"));
    }
    System.out.println("Total Rows: " + rows);
} // end try
catch (SQLException e)
{
    e.printStackTrace();
}
finally {
    con=null;
}
}</code>
</pre>
<p><strong>Thats It!</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/qnatech.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/qnatech.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/qnatech.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/qnatech.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/qnatech.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/qnatech.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/qnatech.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/qnatech.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/qnatech.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/qnatech.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/qnatech.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/qnatech.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/qnatech.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/qnatech.wordpress.com/254/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=254&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://qnatech.wordpress.com/2011/07/06/how-to-use-geo-spatial-with-postgres-postgis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2c5a6b33a6c910ba95351d8afb0a2a2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">qnaguru</media:title>
		</media:content>
	</item>
		<item>
		<title>How to use Haversine Formula for location (distance) searches with MySQL?</title>
		<link>http://qnatech.wordpress.com/2011/07/06/how-to-use-haversine-formula-for-location-distance-searches-with-mysql/</link>
		<comments>http://qnatech.wordpress.com/2011/07/06/how-to-use-haversine-formula-for-location-distance-searches-with-mysql/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 12:59:04 +0000</pubDate>
		<dc:creator>qnaguru</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://qnatech.wordpress.com/?p=249</guid>
		<description><![CDATA[Problem Statement Find all locations that are within a certain radius from a particular location(point). Solution Approach We will demonstrate that with pseudo-code. Refer the post titled: How to use Geo Spatial with MySQL Everything else remains same we will modify the function findGeoLocations(&#8230;) and call it findGeoLocationsWithHaversine(&#8230;). NOTE that it does not use geo <a href="http://qnatech.wordpress.com/2011/07/06/how-to-use-haversine-formula-for-location-distance-searches-with-mysql/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=249&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Problem Statement</strong><br />
Find all locations that are within a certain radius from a particular location(point).</p>
<p><strong>Solution Approach</strong><br />
We will demonstrate that with pseudo-code.<br />
Refer the post titled: 	<a href="http://qnatech.wordpress.com/2011/07/06/how-to-use-geo-spatial-with-mysql/" title="How to use Geo Spatial with MySQL?">How to use Geo Spatial with MySQL</a><br />
Everything else remains same we will modify the function findGeoLocations(&#8230;) and call it findGeoLocationsWithHaversine(&#8230;).<br />
NOTE that it does not use geo spatial capabilities of MySQL at all.</p>
<p><strong>This is what the function looks like:</strong></p>
<pre>
<code>
public void findGeoLocationsWithHaversine(double lat, double lon,
double radiusInMiles)
{

Connection con = null;

try {
    con = Constants.getConnection();

    //Statement stmt = con.createStatement();
    String query="";
    double radius=radiusInMiles/69;

    double x1 = lat - radius; double y1 = lon - radius;
    double x2 = lat + radius; double y2 = lon - radius;
    double x3 = lat + radius; double y3 = lon + radius;
    double x4 = lat - radius; double y4 = lon + radius;
    String polygonStr = x1 + " " + y1 + "," + x2 + " " + y2 + "," +
    x3 + " " + y3 + "," + x4 + " " + y4 + "," + x1 + " " + y1;
    String pointStr = lat + " " + lon;

    query = "select g.id, g.latitude, g.longitude, (3956 * 2 *
    ASIN ( SQRT ( POWER(SIN(("+lat+" - g.latitude)*pi()/180 / 2),";
    query = query + " 2) + COS(" + lat + "* pi()/180) *
    COS(g.latitude * pi()/180) * POWER(SIN((" + lon +
    "- g.longitude)     *";
    query = query + " pi()/180 / 2), 2) ) ))/69 as distance" ;
    query = query + " from geoinfo g";
    query = query + " where g.longitude between (" + lon +
    " - " + radius + "/abs(cos(radians(" + lat + "))))";
    query = query + " and (" + lon + " + " + radius +
    "/abs(cos(radians(" + lat + ")))";
    query = query + " ) and g.latitude between (" + lat +
    " - " + radius + ") and (" + lat + "+" + radius + ")";
    query = query + " having distance &lt; &quot; + radius;
    query = query + &quot; order by distance&quot;;

    System.out.println(&quot;Query to use: &quot; + query);
    PreparedStatement pStmt = con.prepareStatement(query);
    ResultSet rs;

    long startTime = Calendar.getInstance().getTimeInMillis();
    rs = pStmt.executeQuery();
    long timeTaken = Calendar.getInstance().getTimeInMillis()
    - startTime;

    System.out.println(&quot;Time Taken: &quot; + timeTaken + &quot; milliseconds&quot;);

    int rows = 0;
    while (rs.next())
    {
        rows++;
        /*
        System.out.println (&quot;RS: Id: &quot; + rs.getInt(&quot;id&quot;) +
        &quot; Lat: &quot; + rs.getDouble(&quot;latitude&quot;) + &quot; Lon: &quot; +
        rs.getDouble(&quot;longitude&quot;) + &quot; Dist: &quot; +
        rs.getDouble(&quot;distance&quot;));
        */
    }
    System.out.println(&quot;Total Rows: &quot; + rows);

} // end try

catch (SQLException e)
{
    e.printStackTrace();
}
finally
{
    con=null;
}
}</code>
</pre>
<p><strong>Thats It!</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/qnatech.wordpress.com/249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/qnatech.wordpress.com/249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/qnatech.wordpress.com/249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/qnatech.wordpress.com/249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/qnatech.wordpress.com/249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/qnatech.wordpress.com/249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/qnatech.wordpress.com/249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/qnatech.wordpress.com/249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/qnatech.wordpress.com/249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/qnatech.wordpress.com/249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/qnatech.wordpress.com/249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/qnatech.wordpress.com/249/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/qnatech.wordpress.com/249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/qnatech.wordpress.com/249/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=249&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://qnatech.wordpress.com/2011/07/06/how-to-use-haversine-formula-for-location-distance-searches-with-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2c5a6b33a6c910ba95351d8afb0a2a2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">qnaguru</media:title>
		</media:content>
	</item>
		<item>
		<title>How to use Geo Spatial with MySQL?</title>
		<link>http://qnatech.wordpress.com/2011/07/06/how-to-use-geo-spatial-with-mysql/</link>
		<comments>http://qnatech.wordpress.com/2011/07/06/how-to-use-geo-spatial-with-mysql/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 12:08:04 +0000</pubDate>
		<dc:creator>qnaguru</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://qnatech.wordpress.com/?p=237</guid>
		<description><![CDATA[Problem Statement Find all locations that are within a certain radius of a particular location. Solution Approach We will demonstrate this with pseudo-code. Lets create a table in MySQL that will store geo information: create table geoinfo ( id bigint(20) NOT NULL AUTO_INCREMENT, latitude DECIMAL(9,4) NULL , longitude DECIMAL(9,4) NULL , location POINT NOT NULL <a href="http://qnatech.wordpress.com/2011/07/06/how-to-use-geo-spatial-with-mysql/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=237&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Problem Statement</strong><br />
Find all locations that are within a certain radius of a particular location.</p>
<p><strong>Solution Approach</strong><br />
We will demonstrate this with pseudo-code.</p>
<p><strong>Lets create a table in MySQL that will store geo information:</strong></p>
<p><code>create table geoinfo (<br />
 id bigint(20) NOT NULL AUTO_INCREMENT,<br />
 latitude DECIMAL(9,4) NULL ,<br />
 longitude DECIMAL(9,4) NULL ,<br />
 location POINT NOT NULL ,<br />
 PRIMARY KEY (ID) )<br />
ENGINE = MyISAM DEFAULT CHARSET=utf8</p>
<p>-- Note the use of POINT data type against the location column above.<br />
-- Spatial Indexes cannot be created on InnoDB tables.<br />
create spatial index sp_index ON geocode(location);</code></p>
<p><strong>Now, what we want to do is insert lots of data in this table:</strong></p>
<p><code>static String dbUrl = "jdbc:mysql://localhost:3306/test?";<br />
static String dbClass = "com.mysql.jdbc.Driver";<br />
static String schemaPrefix="test."<br />
static String DB_USERNAME="whatever";<br />
static String DB_PASSWD="whatever";</p>
<p>Class.forName(dbClass);<br />
Connection con = DriverManager.getConnection(dbUrl, DB_USERNAME, DB_PASSWD);<br />
Statement stmt = con.createStatement();</p>
<p>String query1;<br />
long startTime = Calendar.getInstance().getTimeInMillis();<br />
//Randomize the lat, long inputs<br />
Random rand = new Random();<br />
String geomFunc="";</p>
<p>geomFunc="GeomFromText";</p>
<p>for (int i = 0; i &lt; 100000; i++) {<br />
  double lat = rand.nextDouble() * 180 - 90;<br />
  BigDecimal bd1 = new BigDecimal(lat).setScale(2, RoundingMode.HALF_EVEN);<br />
  lat = bd1.doubleValue();<br />
  double lon = rand.nextDouble() * 360 - 180;<br />
  BigDecimal bd = new BigDecimal(lon).setScale(2, RoundingMode.HALF_EVEN);<br />
  lon = bd.doubleValue();<br />
  query1 = &quot;INSERT INTO &quot; + schemaPrefix + &quot;geoinfo(latitude, longitude, location) VALUES (&quot; + lat + &quot;,&quot; + lon + &quot;, &quot; + geomFunc + &quot;(&#039;POINT(&quot; + lat + &quot; &quot; + lon + &quot;)&#039;) )&quot;;<br />
  System.out.println(query1);<br />
  int res = stmt.executeUpdate(query1);<br />
  // System.out.println(&quot;res: &quot; + res);<br />
}</p>
<p>long timeTaken = Calendar.getInstance().getTimeInMillis() - startTime;<br />
System.out.println(&quot;Total Time Taken to insert data : &quot; + timeTaken + &quot; milliseconds&quot;);</code></p>
<p><strong>Now we want to do a geo spatial search on geoinfo table<br />
i.e find all rows from the geoinfo table whose location is within a certain miles(radius) from a particular location(lat,lon):</strong></p>
<p>We will write a findGeoLocations function that will print all records that meet this criteria.</p>
<p><code>public void findGeoLocations(double lat, double lon, double radiusInMiles) {</p>
<p>Connection con = null;</p>
<p>		try {<br />
			con = Constants.getConnection();</p>
<p>			//Statement stmt = con.createStatement();<br />
			String query="";<br />
			double radius=radiusInMiles/69;</p>
<p>				double x1 = lat - radius; double y1 = lon - radius;<br />
				double x2 = lat + radius; double y2 = lon - radius;<br />
				double x3 = lat + radius; double y3 = lon + radius;<br />
				double x4 = lat - radius; double y4 = lon + radius;<br />
				String polygonStr = x1 + " " + y1 + "," + x2 + " " + y2 + "," + x3 + " " + y3 + "," + x4 + " " + y4 + "," + x1 + " " + y1;<br />
				String pointStr = lat + " " + lon;</p>
<p>				query = "SELECT id, latitude, longitude, AsText(location),";<br />
				query = query + " SQRT(POW( ABS( X(location) - " +  lat + "), 2) +";<br />
				query = query + " POW( ABS(Y(location) - " + lon + "), 2 )) AS distance";<br />
				query = query + " FROM geoinfo ";<br />
				query = query + " WHERE Intersects( location, GeomFromText('POLYGON((" + polygonStr + "))'))";<br />
				query = query + " AND (SQRT(POW( ABS( X(location) - X(GeomFromText('POINT(" + pointStr + ")'))), 2) +";<br />
				query = query + " POW( ABS(Y(location) - Y(GeomFromText('POINT(" + pointStr + ")'))), 2 ))) &lt; &quot; + radius ;<br />
				query = query + &quot; order by distance&quot;;</p>
<p>			System.out.println(&quot;Query to use: &quot; + query);</p>
<p>			PreparedStatement pStmt = con.prepareStatement(query);<br />
			ResultSet rs;</p>
<p>				long startTime = Calendar.getInstance().getTimeInMillis();<br />
				 rs = pStmt.executeQuery();<br />
				 long timeTaken = Calendar.getInstance().getTimeInMillis() - startTime;</p>
<p>				 System.out.println("Time Taken: &quot; + timeTaken + &quot; milliseconds&quot;);</p>
<p>				int rows = 0;<br />
				while (rs.next()) {<br />
					rows++;<br />
					/*<br />
					System.out.println (&quot;RS: Id: &quot; + rs.getInt(&quot;id&quot;) +<br />
					&quot; Lat: &quot; + rs.getDouble(&quot;latitude&quot;) + &quot; Lon: &quot; +<br />
					rs.getDouble(&quot;longitude&quot;) + &quot; Dist: &quot; +<br />
					rs.getDouble(&quot;distance&quot;));<br />
					*/<br />
				}<br />
				System.out.println(&quot;Total Rows: &quot; + rows);</p>
<p>		} // end try</p>
<p>		catch (SQLException e) {<br />
			e.printStackTrace();<br />
		} finally {<br />
			con=null;<br />
		}<br />
	}</code></p>
<p><strong>So Thats It!</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/qnatech.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/qnatech.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/qnatech.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/qnatech.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/qnatech.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/qnatech.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/qnatech.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/qnatech.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/qnatech.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/qnatech.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/qnatech.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/qnatech.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/qnatech.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/qnatech.wordpress.com/237/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=237&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://qnatech.wordpress.com/2011/07/06/how-to-use-geo-spatial-with-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2c5a6b33a6c910ba95351d8afb0a2a2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">qnaguru</media:title>
		</media:content>
	</item>
		<item>
		<title>How do i set Proxy for Maven (in Eclipse)?</title>
		<link>http://qnatech.wordpress.com/2011/06/22/how-do-i-set-proxy-for-maven-in-eclipse/</link>
		<comments>http://qnatech.wordpress.com/2011/06/22/how-do-i-set-proxy-for-maven-in-eclipse/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 09:33:32 +0000</pubDate>
		<dc:creator>qnaguru</dc:creator>
				<category><![CDATA[Build Tools]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://qnatech.wordpress.com/?p=215</guid>
		<description><![CDATA[Problem Statement: (1) I am behind a firewall, therefore Maven is unable to connect to repositories to download jars etc. Solution: In MAVEN_HOME\apache-maven-3.0.3\conf dir you have settings.xml. Open it and update the following: &#60;proxies&#62; &#60;!-- proxy &#124; Specification for one proxy, to be used in connecting to the network. --&#62; &#60;proxy&#62; &#60;id&#62;optional&#60;/id&#62; &#60;active&#62;true&#60;/active&#62; &#60;protocol&#62;http&#60;/protocol&#62; &#60;host&#62;&#60;/host&#62; <a href="http://qnatech.wordpress.com/2011/06/22/how-do-i-set-proxy-for-maven-in-eclipse/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=215&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Problem Statement: </strong><br />
(1) I am behind a firewall, therefore Maven is unable to connect to repositories to download jars etc.</p>
<p>Solution:<br />
In MAVEN_HOME\apache-maven-3.0.3\conf dir you have settings.xml. Open it and update the following:</p>
<p><code>&lt;proxies&gt;<br />
    &lt;!-- proxy<br />
     | Specification for one proxy, to be used in connecting to the network. --&gt;<br />
    &lt;proxy&gt;<br />
      &lt;id&gt;optional&lt;/id&gt;<br />
      &lt;active&gt;true&lt;/active&gt;<br />
      &lt;protocol&gt;http&lt;/protocol&gt;<br />
      &lt;host&gt;&lt;/host&gt;<br />
      &lt;port&gt;&lt;/port&gt;<br />
	  &lt;username&gt;&lt;/username&gt;<br />
	  &lt;password&gt;&lt;/password&gt;<br />
      &lt;nonProxyHosts&gt;&lt;/nonProxyHosts&gt;<br />
    &lt;/proxy&gt;<br />
  &lt;/proxies&gt;</code></p>
<p>Also check the following dir on windows:<br />
C:\Documents and Settings\useName\.m2<br />
If this has settings.xml &#8211; update that too.</p>
<p>Remember that username may require to be prefixed with domain name eg: mycorp/myuser</p>
<p><strong>Problem Statement:</strong><br />
(2) I am behind a firewall, using Eclipse IDE and have a Maven Plugin. But it is unable to connect to repositories.</p>
<p>Solution:<br />
Menu&gt; Windows &gt; Preferences &gt; General &gt; Network Connections.</p>
<p>Update the Proxy entries there.<br />
In case this does not work, try doing the Step 1 solution as well.</p>
<p>NOTE:<br />
1. Many Corporate Proxies will block you (temporarily?) on repeated authentication failures. Therefore be aware of this possibility.<br />
2. Try to authenticate yourself against your network say by logging off and logging into your system to ensure that your login credentials are still valid.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/qnatech.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/qnatech.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/qnatech.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/qnatech.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/qnatech.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/qnatech.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/qnatech.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/qnatech.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/qnatech.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/qnatech.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/qnatech.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/qnatech.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/qnatech.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/qnatech.wordpress.com/215/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=215&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://qnatech.wordpress.com/2011/06/22/how-do-i-set-proxy-for-maven-in-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2c5a6b33a6c910ba95351d8afb0a2a2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">qnaguru</media:title>
		</media:content>
	</item>
		<item>
		<title>How can i measure CPU and Memory utilization on a Linux?</title>
		<link>http://qnatech.wordpress.com/2011/06/10/how-can-i-measure-cpu-and-memory-utilization-on-a-linux/</link>
		<comments>http://qnatech.wordpress.com/2011/06/10/how-can-i-measure-cpu-and-memory-utilization-on-a-linux/#comments</comments>
		<pubDate>Fri, 10 Jun 2011 12:09:55 +0000</pubDate>
		<dc:creator>qnaguru</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://qnatech.wordpress.com/?p=209</guid>
		<description><![CDATA[CPU Utilization Commands: CPU utilization; measured every 2 seconds; 5 times: $ sar -u 2 5 Processor related stats: $ mpstat $ mpstat -P ALL Top 10 CPU users/processes on the Linux system: $ ps -eo pcpu,pid,user,args &#124; sort -k 1 -r &#124; head -10 Memory Utilization Commands ps aux ps aux &#124; awk &#8216;{print <a href="http://qnatech.wordpress.com/2011/06/10/how-can-i-measure-cpu-and-memory-utilization-on-a-linux/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=209&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>CPU Utilization Commands:</strong></p>
<p>CPU utilization; measured every 2 seconds; 5 times:<br />
$ sar -u 2 5</p>
<p>Processor related stats:<br />
$ mpstat<br />
$ mpstat -P ALL</p>
<p>Top 10 CPU users/processes on the Linux system:<br />
$ ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10</p>
<p><strong>Memory Utilization Commands</strong></p>
<p>ps aux<br />
ps aux | awk &#8216;{print $4&#8243;\t&#8221;$11}&#8217; | sort | uniq -c | awk &#8216;{print $2&#8243; &#8220;$1&#8243; &#8220;$3}&#8217; | sort -nr</p>
<p><strong>Overall</strong></p>
<p>To see lots of stats with a single command in real-time<br />
$ top</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/qnatech.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/qnatech.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/qnatech.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/qnatech.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/qnatech.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/qnatech.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/qnatech.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/qnatech.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/qnatech.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/qnatech.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/qnatech.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/qnatech.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/qnatech.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/qnatech.wordpress.com/209/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=209&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://qnatech.wordpress.com/2011/06/10/how-can-i-measure-cpu-and-memory-utilization-on-a-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2c5a6b33a6c910ba95351d8afb0a2a2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">qnaguru</media:title>
		</media:content>
	</item>
		<item>
		<title>How to do a Proximity Search using Haversine Formula?</title>
		<link>http://qnatech.wordpress.com/2011/06/08/how-to-do-a-proximity-search-using-haversine-formula/</link>
		<comments>http://qnatech.wordpress.com/2011/06/08/how-to-do-a-proximity-search-using-haversine-formula/#comments</comments>
		<pubDate>Wed, 08 Jun 2011 11:10:36 +0000</pubDate>
		<dc:creator>qnaguru</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://qnatech.wordpress.com/?p=205</guid>
		<description><![CDATA[Let us consider a table: create table `geoaddress` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `latitude` DECIMAL(9,4) NULL , `longitude` DECIMAL(9,4) NULL, &#8216;address&#8217; VARCHAR(1000) NULL, PRIMARY KEY (`ID`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8 The above table must ofcourse be populated with appropriate data. Here is a simple java code snippet to insert some random data: <a href="http://qnatech.wordpress.com/2011/06/08/how-to-do-a-proximity-search-using-haversine-formula/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=205&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Let us consider a table:</p>
<p>create table `geoaddress` (<br />
 `id` bigint(20) NOT NULL AUTO_INCREMENT,<br />
 `latitude` DECIMAL(9,4) NULL ,<br />
 `longitude` DECIMAL(9,4) NULL,<br />
 &#8216;address&#8217; VARCHAR(1000) NULL,<br />
 PRIMARY KEY (`ID`) )<br />
ENGINE = InnoDB DEFAULT CHARSET=utf8</p>
<p>The above table must ofcourse be populated with appropriate data.<br />
Here is a simple java code snippet to insert some random data:</p>
<p><code>...<br />
Statement stmt = con.createStatement();<br />
Random rand = new Random();<br />
for (int i = 0; i &lt; 100000; i++) {<br />
    double lat = rand.nextDouble() * 180 - 90;<br />
    BigDecimal bd1 = new BigDecimal(lat).setScale(2, RoundingMode.HALF_EVEN);<br />
    lat = bd1.doubleValue(); </p>
<p>    double lon = rand.nextDouble() * 360 - 180;<br />
    BigDecimal bd = new BigDecimal(lon).setScale(2, RoundingMode.HALF_EVEN);<br />
    lon = bd.doubleValue(); </p>
<p>    String query = &quot;INSERT INTO test.geocode(latitude, longitude, address)<br />
    VALUES (&quot; + lat + &quot;,&quot; + lon + &quot;, &#039;some addr&#039;)&quot;;<br />
    System.out.println(query);<br />
    int res = stmt.executeUpdate(query1);<br />
    // System.out.println(&quot;res: &quot; + res);<br />
}<br />
....<br />
</code></p>
<p>Given a latitude/longitude, we want to find all records from geoaddress table that are within a certain radius from a given latitude/longitude.</p>
<p>Here is java code snippet for that:</p>
<p><code></p>
<p>//Update lat, lon, radius variables with whatever values you want! The lat/lon together form the point from where search is performed.<br />
double lat=20;<br />
double lon=55;<br />
double radius=1; //Note: 1 unit (or degree) is equivalent to 69 miles. So for a 100 mile search, this should be set to 1.45</p>
<p>String query;</p>
<p>//The query below is implementation of Haversine Formula!<br />
query = "select g.id, g.latitude, g.longitude, (3956 * 2 * ASIN ( SQRT ( POWER(SIN(("+lat+" - g.latitude)*pi()/180 / 2),";<br />
query = query + " 2) + COS(" + lat + "* pi()/180) * COS(g.latitude * pi()/180) * POWER(SIN((" + lon + "- g.longitude) *";<br />
query = query + " pi()/180 / 2), 2) ) ))/69 as distance" ;<br />
query = query + " from geocode g";<br />
query = query + " where g.longitude between (" + lon + " - " + radius + "/abs(cos(radians(" + lat + "))))";<br />
query = query + " and (" + lon + " + " + radius + "/abs(cos(radians(" + lat + ")))";<br />
query = query + " ) and g.latitude between (" + lat + " - " + radius + ") and (" + lat + "+" + radius + ")";<br />
query = query + " having distance &lt; &quot; + radius;<br />
query = query + &quot; order by distance&quot;;</p>
<p>....<br />
PreparedStatement pStmt = con.prepareStatement(query);<br />
ResultSet rs = pStmt.executeQuery();<br />
...</code></p>
<p>Thats it! The query will return all records from geoaddress table that are within 69 mile radius (1 unit) from lat/long of 20/55!</p>
<p>Reference: http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/qnatech.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/qnatech.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/qnatech.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/qnatech.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/qnatech.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/qnatech.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/qnatech.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/qnatech.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/qnatech.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/qnatech.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/qnatech.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/qnatech.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/qnatech.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/qnatech.wordpress.com/205/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=qnatech.wordpress.com&amp;blog=4345516&amp;post=205&amp;subd=qnatech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://qnatech.wordpress.com/2011/06/08/how-to-do-a-proximity-search-using-haversine-formula/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c2c5a6b33a6c910ba95351d8afb0a2a2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">qnaguru</media:title>
		</media:content>
	</item>
	</channel>
</rss>
