<?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>Walt Eis</title>
	<atom:link href="http://walteis.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://walteis.wordpress.com</link>
	<description>Lord King Squirrel rides again - more GIS and Mathematics</description>
	<lastBuildDate>Tue, 30 Apr 2013 15:51:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='walteis.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Walt Eis</title>
		<link>http://walteis.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://walteis.wordpress.com/osd.xml" title="Walt Eis" />
	<atom:link rel='hub' href='http://walteis.wordpress.com/?pushpress=hub'/>
		<item>
		<title>A long-lost specialty programming language</title>
		<link>http://walteis.wordpress.com/2013/04/29/a-long-lost-specialty-programming-language/</link>
		<comments>http://walteis.wordpress.com/2013/04/29/a-long-lost-specialty-programming-language/#comments</comments>
		<pubDate>Tue, 30 Apr 2013 02:01:00 +0000</pubDate>
		<dc:creator>walt</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://walteis.wordpress.com/?p=595</guid>
		<description><![CDATA[Back in the mid-1990s I worked for a legal services firm named RSI (or more correctly, Reproduction Services Incorporated).  I was the Applications Development Manager, responsible for managing development for both internal software and custom applications for clients. At the time RSI was one of the prime records collection for the law firms representing the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=595&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Back in the mid-1990s I worked for a legal services firm named RSI (or more correctly, Reproduction Services Incorporated).  I was the Applications Development Manager, responsible for managing development for both internal software and custom applications for clients.</p>
<p>At the time RSI was one of the prime records collection for the law firms representing the tobacco industry.  We collected mainly health records on plaintiffs in the many lawsuits against big tobacco that were all the rage.  Which meant managing thousands of pages of scanned documents.</p>
<p>We also worked with other clients on document management and several off-the-shelf software products.  These products included Summation, Trial Director, and Concordance.   As part of my job I also conducted training for clients in the use of these products (for a time I was a certified Summation instructor).</p>
<p>As I said, we did custom applications for clients.  Concordance included a scripting language (Concordance Programming Language, or CPL) that allowed for even greater flexibility from that product.  In going through some old drives I came across a CPL script that I had saved off for some reason.  Here&#8217;s a part of that script:</p>
<pre>main()
{
  int hConv; /* Handle to Conversation */
  int NULL;
  text hszService; /* Service Name Handle */
  text hszTopic; /* Topic Name Handle */
  text hszDocName;
  int db, i, Rec;
  /* Make sure the database is open. */
  if (db.documents &gt;= 0) 
  {
    /* Initialize the strings used to communicate with the DDE program. */
    hszService = "DOCDIR";
    hszTopic = "DDIMAGE";
    /* Try to connect, do a WinExec() if it isn't running. */
    /* It will run DOCDIR if it is in the path. */
    if ((hConv = ddeConnect(hszService,hszTopic)) == NULL) 
    {
      /* No connection, execute the display program, it may not be running. */
      /* Then try to connect to the server a second time. */
      spawn("d:\progra~1\Docdir\Docdir.exe", "");
      sleep(3000);
      hConv = ddeConnect(hszService, hszTopic);

    }
    /* Message("switch", 1); */
    switch(db.type[isfield(db, "REC")]) {
      case 'P':
      case 'T':
        hszDocName = "[SHOWIMAGE(" + db-&gt;DOCPREFIX + "-0001" + ")]"; 
        beep(450,5); 
        break;
      case 'N':
        hszDocName = "[SHOWIMAGE( " + rep("0",5-len(trim(str(db-&gt;REC)))) + str(db-&gt;REC) + "-0001" + ")]"; 
        break;
      default: beep(450,5);
        break;
    }

    i = ddeExec(hConv, hszDocName );
  }
  return(hConv);
}</pre>
<p>You can see the strong C influence as well as the use of an early Windows inter-process messaging protocol called <a href="http://en.wikipedia.org/wiki/Dynamic_Data_Exchange" target="_blank">Dynamic Data Exchange</a>.  The use of a C-style scripting language was a little unusual at the time (in my experience anyway).</p>
<p>In hindsight I wish I had saved more examples of CPL.  Note to self: make sure to keep examples of current projects.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/walteis.wordpress.com/595/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/walteis.wordpress.com/595/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=595&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://walteis.wordpress.com/2013/04/29/a-long-lost-specialty-programming-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e2a1c547f68f5e019f98a05239e15855?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lordkingsquirrel</media:title>
		</media:content>
	</item>
		<item>
		<title>Some Brief Notes on Histograms</title>
		<link>http://walteis.wordpress.com/2012/05/01/some-brief-notes-on-histograms/</link>
		<comments>http://walteis.wordpress.com/2012/05/01/some-brief-notes-on-histograms/#comments</comments>
		<pubDate>Tue, 01 May 2012 23:00:39 +0000</pubDate>
		<dc:creator>walt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[mathematics]]></category>

		<guid isPermaLink="false">http://walteis.wordpress.com/?p=550</guid>
		<description><![CDATA[To start, how about a simple definition: A histogram is a graphical representation of the distribution of data. A histogram can be thought of as a collection of buckets or bins, each with a min, a max, a width (max &#8211; min), and a depth (the number of values in each bin). Typically the number [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=550&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>To start, how about a simple definition: A <strong>histogram</strong> is a graphical representation of the distribution of data.</p>
<p>A histogram can be thought of as a collection of buckets or bins, each with a min, a max, a width (max &#8211; min), and a depth (the number of values in each bin).</p>
<p>Typically the number of bins is determined on a case-by-case basis by looking at the data.  When we create a histogram by hand (so to speak) that&#8217;s relatively easy to do.  But when writing software to create histograms, we need to estimate the optimal bin count.  There are several ways to do that, two which I use are:</p>
<p><span id="more-550"></span></p>
<p><img src='http://s0.wp.com/latex.php?latex=k+%3D+%5Cbigg%5B+%5Cfrac%7Bmax+x+-+min+x%7D%7Bh%7D+%5Cbigg%5D+&amp;bg=eeebf2&amp;fg=3c3d47&amp;s=0' alt='k = &#92;bigg[ &#92;frac{max x - min x}{h} &#92;bigg] ' title='k = &#92;bigg[ &#92;frac{max x - min x}{h} &#92;bigg] ' class='latex' />, where Scott&#8217;s method is used to calculate <em>h</em>, that is <img src='http://s0.wp.com/latex.php?latex=h+%3D+%5Cfrac%7B3.5%5Csigma%7D%7Bn%5E%5Cfrac%7B1%7D%7B3%7D%7D&amp;bg=eeebf2&amp;fg=3c3d47&amp;s=0' alt='h = &#92;frac{3.5&#92;sigma}{n^&#92;frac{1}{3}}' title='h = &#92;frac{3.5&#92;sigma}{n^&#92;frac{1}{3}}' class='latex' /></p>
<p>or</p>
<p><img src='http://s0.wp.com/latex.php?latex=k+%3D+%5CBig%5B+log_2+n+%2B+1+%5CBig+%5D&amp;bg=eeebf2&amp;fg=3c3d47&amp;s=0' alt='k = &#92;Big[ log_2 n + 1 &#92;Big ]' title='k = &#92;Big[ log_2 n + 1 &#92;Big ]' class='latex' />, also known as Sturge&#8217;s Formula</p>
<p>Sturge&#8217;s Formula is most useful for <img src='http://s0.wp.com/latex.php?latex=n+%3E+30+&amp;bg=eeebf2&amp;fg=3c3d47&amp;s=0' alt='n &gt; 30 ' title='n &gt; 30 ' class='latex' />, so in TraxView I use the first method.  Using a Math.NET Accumulator to simplify things, it looks something like this (warning: this is just a snippet, so there is stuff left out):</p>
<pre>Accumulator acc1 = new Accumulator();
double width;
_hist = new Histogram();

switch (_method)
{
case MethodConstant.EqualInterval:

    acc1.AddRange(Data.DataSet.Values.ToArray());

    // scott's choice method for bin width
    width = ((3.5 * acc1.Sigma) / (Math.Pow(acc1.Count, .333333333)));

    BinCount = (int)Math.Ceiling((Data.DataSet.Values.Max() - Data.DataSet.Values.Min()) / width);
    for (int i = 0; i &lt; BinCount; i++)
        _hist.Add(new Bucket(Math.Round(lb, 2), Math.Round(lb + width, 2)));
    break;
}
RecalcBinDepth();</pre>
<h3>How a histogram can be used</h3>
<p>A histogram, by definition, shows the distribution of data.  In TraxView, we use a histogram to see if the binning for our thematic shading makes sense.  Here&#8217;s an example, based on some very limited test data I have:</p>
<p><a href="http://walteis.files.wordpress.com/2012/05/histosample.png"><img class="alignnone size-medium wp-image-587 aligncenter" title="histosample" src="http://walteis.files.wordpress.com/2012/05/histosample.png?w=300&#038;h=169" alt="" width="300" height="169" /></a></p>
<p>And here&#8217;s another example, showing the difference that selecting different bin widths makes:</p>
<p><a href="http://walteis.files.wordpress.com/2012/05/histosample2.png"><img class="alignnone size-medium wp-image-588 aligncenter" title="histosample2" src="http://walteis.files.wordpress.com/2012/05/histosample2.png?w=300&#038;h=136" alt="" width="300" height="136" /></a></p>
<p>Questions or comments welcome.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/walteis.wordpress.com/550/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/walteis.wordpress.com/550/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=550&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://walteis.wordpress.com/2012/05/01/some-brief-notes-on-histograms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e2a1c547f68f5e019f98a05239e15855?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lordkingsquirrel</media:title>
		</media:content>

		<media:content url="http://walteis.files.wordpress.com/2012/05/histosample.png?w=300" medium="image">
			<media:title type="html">histosample</media:title>
		</media:content>

		<media:content url="http://walteis.files.wordpress.com/2012/05/histosample2.png?w=300" medium="image">
			<media:title type="html">histosample2</media:title>
		</media:content>
	</item>
		<item>
		<title>A Kolmogorov-Smirnov implementation</title>
		<link>http://walteis.wordpress.com/2012/04/26/a-kolmogorov-smirnov-implementation/</link>
		<comments>http://walteis.wordpress.com/2012/04/26/a-kolmogorov-smirnov-implementation/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 23:00:08 +0000</pubDate>
		<dc:creator>walt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[mathematics]]></category>

		<guid isPermaLink="false">http://walteis.wordpress.com/?p=493</guid>
		<description><![CDATA[The Kolmogorov-Smirnov (hereafter K-S) Statistic, allows for a fairly straight-forward test for both normality and uniformity.  Here I&#8217;ll concentrate on normality. I won&#8217;t go into any background information on the K-S statistic, for a very nice introduction head over to T.W. Kirkman&#8217;s Statistics to Use page. How it works The K-S test compares a sample with a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=493&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The Kolmogorov-Smirnov (hereafter K-S) Statistic, allows for a fairly straight-forward test for both normality and uniformity.  Here I&#8217;ll concentrate on normality.</p>
<p>I won&#8217;t go into any background information on the K-S statistic, for a very nice introduction head over to T.W. Kirkman&#8217;s <a href="http://www.physics.csbsju.edu/stats/" target="_blank">Statistics to Use</a> page.</p>
<h3>How it works</h3>
<p><span id="more-493"></span></p>
<p>The K-S test compares a sample with a theoretic or standard distribution.   If the difference is less than a critical value function for the number of samples the sample is normal.  So,</p>
<p>Let <img src='http://s0.wp.com/latex.php?latex=%5Chat%7BF%7D%28x%29&amp;bg=eeebf2&amp;fg=3c3d47&amp;s=0' alt='&#92;hat{F}(x)' title='&#92;hat{F}(x)' class='latex' /> be the cumulative distribution function (c.d.f.) of a standard, normal distribution,</p>
<p>Let the critical value function C<em>(n)</em> be defined as:</p>
<p><img src='http://s0.wp.com/latex.php?latex=C%28n%29+%3D+%5Cbegin%7Bcases%7D+n+%5Cle+20+%26%3A+%5Ctext%7Blookup+table%7D%2C%5C%5C+n+%3E+20+%26%3A+%5Cfrac%7B1.36%7D%7B%5Csqrt%7Bn%7D%7D.+%5Cend%7Bcases%7D&amp;bg=eeebf2&amp;fg=3c3d47&amp;s=0' alt='C(n) = &#92;begin{cases} n &#92;le 20 &amp;: &#92;text{lookup table},&#92;&#92; n &gt; 20 &amp;: &#92;frac{1.36}{&#92;sqrt{n}}. &#92;end{cases}' title='C(n) = &#92;begin{cases} n &#92;le 20 &amp;: &#92;text{lookup table},&#92;&#92; n &gt; 20 &amp;: &#92;frac{1.36}{&#92;sqrt{n}}. &#92;end{cases}' class='latex' />, and</p>
<p>Let <img src='http://s0.wp.com/latex.php?latex=S_%7Bn%7D%28x%29&amp;bg=eeebf2&amp;fg=3c3d47&amp;s=0' alt='S_{n}(x)' title='S_{n}(x)' class='latex' /> be the observed cumulative step function <img src='http://s0.wp.com/latex.php?latex=S_%7Bn%7D%28x%29+%3D+%5Cfrac%7Bk%7D%7Bn%7D&amp;bg=eeebf2&amp;fg=3c3d47&amp;s=0' alt='S_{n}(x) = &#92;frac{k}{n}' title='S_{n}(x) = &#92;frac{k}{n}' class='latex' />, where k is the number of observations &lt; x.</p>
<p>Then the K-S statistic <img src='http://s0.wp.com/latex.php?latex=d+%3D+sup%5BD%5E%2B%2CD%5E-%5D&amp;bg=eeebf2&amp;fg=3c3d47&amp;s=0' alt='d = sup[D^+,D^-]' title='d = sup[D^+,D^-]' class='latex' /> where the right-tail test</p>
<p><img src='http://s0.wp.com/latex.php?latex=D%5E%2B+%3D+sup%7C+%5Chat%7BF%7D%28x%29+-+S_n%28x%29%7C&amp;bg=eeebf2&amp;fg=3c3d47&amp;s=0' alt='D^+ = sup| &#92;hat{F}(x) - S_n(x)|' title='D^+ = sup| &#92;hat{F}(x) - S_n(x)|' class='latex' /> and the left-tail test</p>
<p><img src='http://s0.wp.com/latex.php?latex=D%5E-+%3D+sup%7C+S_n%28x%29+-+%5Chat%7BF%7D%28x-1%29%7C&amp;bg=eeebf2&amp;fg=3c3d47&amp;s=0' alt='D^- = sup| S_n(x) - &#92;hat{F}(x-1)|' title='D^- = sup| S_n(x) - &#92;hat{F}(x-1)|' class='latex' /></p>
<p>Finally, if <img src='http://s0.wp.com/latex.php?latex=d+%3C+C%28n%29&amp;bg=eeebf2&amp;fg=3c3d47&amp;s=0' alt='d &lt; C(n)' title='d &lt; C(n)' class='latex' />, then the sample is normal.</p>
<h3>The Code</h3>
<p>So here&#8217;s what I came up with.  No warranties are implied or expressed, etc.  You&#8217;ll note that the function makes use of the MathNet libraries.  You can get them at <a href="http://www.mathdotnet.com/">http://www.mathdotnet.com/</a></p>
<pre>public bool IsNormal
{
    get
    {
        // This method uses the Kolmogorov-Smirnov test to determine a normal distribution.
        // The level of significance (alpha) used is .05, and the critical values used are from Table 1 of: 
        // The Kolmogorov-Smirnov Test for Goodness of Fit
        // Frank J. Massey, Jr.
        // Journal of the American Statistical Association
        // Vol. 46, No. 253 (Mar., 1951) (pp. 68-78)

        if (DataSet.Count == 0)
            return false;

        List&lt;double&gt; vals = DataSet.Values.ToList();
        Accumulator acc = new Accumulator(vals.ToArray());
        double dmax = double.MinValue;
        double cv = 0;

        MathNet.Numerics.Distributions.NormalDistribution test = new MathNet.Numerics.Distributions.NormalDistribution(acc.Mean, acc.Sigma);

        // the 0 entry is to force the list to be a base 1 index table.
        List&lt;double&gt; cvTable = new List&lt;double&gt;() { 0, .975, .842, .708, .624, .565,
                                                .521, .486, .457, .432, .410,
                                                .391, .375, .361, .349, .338,
                                                .328, .318, .309, .301, .294};

        test.EstimateDistributionParameters(DataSet.Values.ToArray());
        vals.Sort();

        for (int i = 0; i &lt; vals.Count; i++)
        {
            double dr = Math.Abs(((i + 1) / (double)vals.Count) - test.CumulativeDistribution(vals[i]));
            double dl = Math.Abs(test.CumulativeDistribution(vals[i]) - (i / (double)vals.Count));
            dmax = Math.Max(dmax, Math.Max(dl, dr));
        }

        // get critical value and compare to d(N)
        if (vals.Count &lt;= 10)
            cv = cvTable[vals.Count];
        else if (vals.Count &gt; 10)
            cv = 1.36 / Math.Sqrt(vals.Count);

        return (dmax &lt; cv);
    }
}</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/walteis.wordpress.com/493/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/walteis.wordpress.com/493/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=493&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://walteis.wordpress.com/2012/04/26/a-kolmogorov-smirnov-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e2a1c547f68f5e019f98a05239e15855?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lordkingsquirrel</media:title>
		</media:content>
	</item>
		<item>
		<title>An IsNear() method using C#</title>
		<link>http://walteis.wordpress.com/2012/04/25/an-isnear-method-using-c/</link>
		<comments>http://walteis.wordpress.com/2012/04/25/an-isnear-method-using-c/#comments</comments>
		<pubDate>Wed, 25 Apr 2012 23:00:59 +0000</pubDate>
		<dc:creator>walt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[GIS]]></category>
		<category><![CDATA[Programing]]></category>

		<guid isPermaLink="false">http://walteis.wordpress.com/?p=467</guid>
		<description><![CDATA[Earlier I wrote about finding the NearestPoint() in C# &#8211; a handy little function.  I also have a companion function &#8211; IsNear().  As with the previous function, IsNear() makes use of Lambda functions and is fairly simple in its approach. How it works Given a set of PointF, and a test distance, the function returns True/False [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=467&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Earlier I wrote about finding the <em><a title="Determining the Nearest Point in C#" href="http://walteis.wordpress.com/2012/04/03/determining-the-nearest-point-in-c/">NearestPoint()</a></em><a title="Determining the Nearest Point in C#" href="http://walteis.wordpress.com/2012/04/03/determining-the-nearest-point-in-c/"></a> in C# &#8211; a handy little function.  I also have a companion function &#8211; <em>IsNear()</em>.  As with the previous function, <em>IsNear()</em> makes use of Lambda functions and is fairly simple in its approach.</p>
<h3>How it works</h3>
<p>Given a set of PointF, and a test distance, the function returns True/False for nearness, as well as the closest point and the index of that point.</p>
<p>Yes, I already have those last two things in my <em>NearestPoint() </em>function, but I liked that kitchen sink approach here (I guess).  Without further delay, here is the routine:</p>
<pre>public static bool IsNear(List&lt;PointF&gt; f1, PointF pt1, double checkDist, out PointF nearPoint, out int nearIndex)
{
    double calcDist = f1.Select(n =&gt; new { n, distance = Math.Sqrt(Math.Pow((n.X - pt1.X), 2) + System.Math.Pow((n.Y - pt1.Y), 2)) }).OrderBy(p =&gt; p.distance).First().distance;
    nearPoint = f1.Select(n =&gt; new { n, distance = Math.Sqrt(Math.Pow((n.X - pt1.X), 2) + System.Math.Pow((n.Y - pt1.Y), 2)) }).OrderBy(p =&gt; p.distance).First().n;
    nearIndex = f1.IndexOf(nearPoint); 

    if (calcDist &lt;= checkDist)
        return true;

    return false;
}</pre>
<p>Questions? Comments? Let me know.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/walteis.wordpress.com/467/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/walteis.wordpress.com/467/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=467&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://walteis.wordpress.com/2012/04/25/an-isnear-method-using-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e2a1c547f68f5e019f98a05239e15855?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lordkingsquirrel</media:title>
		</media:content>
	</item>
		<item>
		<title>Saving an edited layer in GeoObjects</title>
		<link>http://walteis.wordpress.com/2012/04/19/saving-an-edited-layer-in-geoobjects/</link>
		<comments>http://walteis.wordpress.com/2012/04/19/saving-an-edited-layer-in-geoobjects/#comments</comments>
		<pubDate>Thu, 19 Apr 2012 23:03:46 +0000</pubDate>
		<dc:creator>walt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://walteis.wordpress.com/?p=463</guid>
		<description><![CDATA[So we&#8217;ve extended the GeoObjects library, and seen how to edit an existing feature.  Next we&#8217;ll need to save those changes.  The GeoObjects SaveOverlayLayer() method does just what it says &#8211; it saves the Overlay Layer along with the two attributes that it carries &#8211; Id and Name.  Not so good if you are editing a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=463&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>So we&#8217;ve <a title="Extending The Blue Marble Geographics GeoObjects Library" href="http://walteis.wordpress.com/2012/03/28/extending-the-blue-marble-geographics-geoobjects-library/">extended</a> the GeoObjects library, and seen how to <a title="Editing Existing Features with GeoObjects" href="http://walteis.wordpress.com/2012/04/10/editing-existing-features-with-geoobjects/">edit an existing feature</a>.  Next we&#8217;ll need to save those changes.  The GeoObjects <em>SaveOverlayLayer()</em> method does just what it says &#8211; it saves the Overlay Layer along with the two attributes that it carries &#8211; Id and Name.  Not so good if you are editing a feature with more attributes.</p>
<p>The Extension library I wrote includes a new method -<em> SaveOverlayLayer2() .</em></p>
<h4>How it works</h4>
<p>GeoObjects saves the Overlay into a MapInfo TAB file. <em> SaveOverlayLayer2() </em>builds on that as the TAB format has a very simple format.  Our first step is to do a standard <em>SaveOverlayLayer </em>call.  This will give us the geographic data in a MapInfo .map file.</p>
<p>Next, we create a temp file to hold the .tab file.  This is a simple text file that looks somthing like this very simple example:</p>
<pre>!table
!version 300
!charset Neutral
Definition Table
 Type NATIVE Charset "Neutral"
 Fields 4
 ID Char (35) ;
 Column0 Char (35) ;
 Column1 Char (35) ;
 Column2 Char (35) ;</pre>
<p>The column definitions will come from our extended attributes and will be written using a .Net<em> StreamWriter</em> object. At the same time we&#8217;ll be building our .dat file, which is nothing more than a standard .dbf:</p>
<pre>dbfWriter annoAttrib = new dbfWriter();
annoAttrib.SetConnection(fileInfo.DirectoryName);

Dictionary&lt;string, string&gt;.KeyCollection featAttrs = attrDict[firstKey].Keys;
int firstKey = attrDict.Keys.First();

using (TextWriter streamWriter = new StreamWriter(s))
{
  streamWriter.WriteLine("!table");
  streamWriter.WriteLine("!version 300");
  streamWriter.WriteLine("!charset Neutral");
  streamWriter.WriteLine("");
  streamWriter.WriteLine("Definition Table");
  streamWriter.WriteLine("  Type NATIVE Charset \"Neutral\"");
  streamWriter.WriteLine("  Fields " + attrDict[firstKey].Keys.Count.ToString());

  foreach (string key in featAttrs)
  {
    annoAttrib.AddField(key, "VARCHAR", 35);
    streamWriter.WriteLine("    " + key + " Char (35) ;");
  }
}</pre>
<p>Once that is done, we&#8217;ll close the stream and write the .dat/dbf file.</p>
<pre>string shortFileName = "_attemp";
string baseFileName = Path.GetFileNameWithoutExtension(fileInfo.FullName);

annoAttrib.CreateDBF(shortFileName, true);

OverlayLayer overlay = (OverlayLayer)m.GetOverlayLayer(0);
int feat2Count = ((Features)overlay.Features).Count;

for (int i = 1; i &lt;= feat2Count; i++)
{
    Feature2 copyFeat = (Feature2)((Features)overlay.Features).get_Item(i);
    Dictionary&lt;string, string&gt; featAttrs = new Dictionary&lt;string, string&gt;();
    try
    {
        featAttrs = attrDict[copyFeat.Id];

        foreach (KeyValuePair&lt;string, string&gt; kvp2 in featAttrs)
        {
            annoAttrib.SetFieldValues(kvp2.Key, kvp2.Value);
        }
        annoAttrib.WriteRecord();
    }
    catch { }
}

annoAttrib.EndConnection();</pre>
<p>Once that is done, I rename the .dbf to a .dat, and we&#8217;re done with the MapInfo file.  If we want to create a Shapefile, we use GeoConvert on the saved MapInfo TAB.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/walteis.wordpress.com/463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/walteis.wordpress.com/463/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=463&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://walteis.wordpress.com/2012/04/19/saving-an-edited-layer-in-geoobjects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e2a1c547f68f5e019f98a05239e15855?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lordkingsquirrel</media:title>
		</media:content>
	</item>
		<item>
		<title>Editing Existing Features with GeoObjects</title>
		<link>http://walteis.wordpress.com/2012/04/10/editing-existing-features-with-geoobjects/</link>
		<comments>http://walteis.wordpress.com/2012/04/10/editing-existing-features-with-geoobjects/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 17:00:11 +0000</pubDate>
		<dc:creator>walt</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[GeoObjects]]></category>

		<guid isPermaLink="false">http://walteis.wordpress.com/?p=452</guid>
		<description><![CDATA[As I wrote earlier, the Blue Marble GeoObjects library is limited in its editing support.  One major limitation is that objects in the Overlay (or drawing) layer have no attributes that are returned via the GetAttribute() or GetAttributes() methods. What that means is that if you copy an existing feature to the Overlay layer, none [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=452&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>As I wrote <a title="Extending The Blue Marble Geographics GeoObjects Library" href="http://walteis.wordpress.com/2012/03/28/extending-the-blue-marble-geographics-geoobjects-library/">earlier</a>, the Blue Marble GeoObjects library is limited in its editing support.  One major limitation is that objects in the Overlay (or drawing) layer have no attributes that are returned via the <em>GetAttribute()</em> or <em>GetAttributes()</em> methods.</p>
<p>What that means is that if you copy an existing feature to the Overlay layer, none of the attributes are copied with it.  That makes updating the existing feature sort of challenging.  To overcome that limitation, we added a <em>CopyAttributes()</em>  method to our GeoObjects extension library.</p>
<p>It is a pretty simple addition, just get the existing features and add them to a Dictionary for that feature ID.  Do do this we need three things: the Dictionary, a <em>SetAttributes()</em> method, and the <em>CopyAttributes()</em> method.  Something like this:</p>
<pre>private static Dictionary&lt;int, Dictionary&lt;string, string&gt;&gt; attrDict = new Dictionary&lt;int, Dictionary&lt;string, string&gt;&gt;();
public static bool SetAttribute(this GeoObjectsMapLib.Feature2 f, string s, string s1)
{
    if (!attrDict.ContainsKey(f.Id))
        attrDict.Add(f.Id, new Dictionary&lt;string, string&gt;());

    if (attrDict[f.Id].ContainsKey(s))
        attrDict[f.Id][s] = s1;
    else
        attrDict[f.Id].Add(s, s1);

    return true;
}

public static void CopyAttributes(this Feature2 f2, Feature f)
{
    object attr = null;

    f.GetAttributes(ref attr);
    Object[] attributes = (Object[])attr;

    for (int j = 0; j &lt; attributes.Length; j++)
        f2.SetAttribute(attributes[j].ToString(), attributes[++j].ToString());
}</pre>
<p>In use it looks like this:</p>
<pre>Feature2 copyFeat;

foreach (Feature feat in (Features)someLayer.Features) 
{
    copyFeat = (Feature2)overlay.CopyFeature(feat);
    copyFeat.CopyAttributes(feat);
    copyFeat.Update(0);
}</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/walteis.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/walteis.wordpress.com/452/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=452&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://walteis.wordpress.com/2012/04/10/editing-existing-features-with-geoobjects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e2a1c547f68f5e019f98a05239e15855?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lordkingsquirrel</media:title>
		</media:content>
	</item>
		<item>
		<title>Determining the Nearest Point in C#</title>
		<link>http://walteis.wordpress.com/2012/04/03/determining-the-nearest-point-in-c/</link>
		<comments>http://walteis.wordpress.com/2012/04/03/determining-the-nearest-point-in-c/#comments</comments>
		<pubDate>Tue, 03 Apr 2012 21:30:50 +0000</pubDate>
		<dc:creator>walt</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://walteis.wordpress.com/?p=448</guid>
		<description><![CDATA[One feature of TraxView Mapping is the ability to create contour (or isopleth) maps from soil sample data.   Creating those contours is a bit of a challenge, which I&#8217;ll write more about at some point. In the meantime, here&#8217;s a short function I used to determine the nearest point from a collection to a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=448&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>One feature of TraxView Mapping is the ability to create contour (or isopleth) maps from soil sample data.   Creating those contours is a bit of a challenge, which I&#8217;ll write more about at some point.</p>
<p>In the meantime, here&#8217;s a short function I used to determine the nearest point from a collection to a test point.</p>
<pre>public static PointF NearestPoint(List&lt;PointF&gt; f1, PointF pt1, out int nearIndex)
{
    PointF nearPoint = f1.Select(n =&gt; new { n, distance = Math.Sqrt(Math.Pow((n.X - pt1.X), 2) + System.Math.Pow((n.Y - pt1.Y), 2)) }).OrderBy(p =&gt; p.distance).First().n;
    nearIndex = f1.IndexOf(nearPoint);

    return nearPoint;
}</pre>
<p>This function uses a Lambda function to create the delegate for the Select() method.  That delegate computes the distance from the test point to each point in the collection, orders the results, and returns the point with the smallest distance.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/walteis.wordpress.com/448/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/walteis.wordpress.com/448/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=448&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://walteis.wordpress.com/2012/04/03/determining-the-nearest-point-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e2a1c547f68f5e019f98a05239e15855?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lordkingsquirrel</media:title>
		</media:content>
	</item>
		<item>
		<title>Extending The Blue Marble Geographics GeoObjects Library</title>
		<link>http://walteis.wordpress.com/2012/03/28/extending-the-blue-marble-geographics-geoobjects-library/</link>
		<comments>http://walteis.wordpress.com/2012/03/28/extending-the-blue-marble-geographics-geoobjects-library/#comments</comments>
		<pubDate>Wed, 28 Mar 2012 21:27:20 +0000</pubDate>
		<dc:creator>walt</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[FODM]]></category>
		<category><![CDATA[GeoObjects]]></category>
		<category><![CDATA[SharpMap]]></category>

		<guid isPermaLink="false">http://walteis.wordpress.com/?p=431</guid>
		<description><![CDATA[TraxView Mapping uses the Blue Marble GeoObjects 4.1 library as its mapping engine. Overall, it works fine but there are several limitations that we needed to overcome during development, such as lack of robust editing capabilities and no easy interoperability with other libraries. Those limitations required us to develop several extension methods to GeoObjects to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=431&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>TraxView Mapping uses the Blue Marble GeoObjects 4.1 library as its mapping engine. Overall, it works fine but there are several limitations that we needed to overcome during development, such as lack of robust editing capabilities and no easy interoperability with other libraries. Those limitations required us to develop several extension methods to GeoObjects to add the functionality that we needed.</p>
<p>It&#8217;s probably likely that you have never heard of extensions. Here&#8217;s the Microsoft definition:</p>
<blockquote><p>Extension methods enable you to &#8220;add&#8221; methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type. For client code written in C# and Visual Basic, there is no apparent difference between calling an extension method and the methods that are actually defined in a type.</p></blockquote>
<p>Quick aside: So why not create derived classes using GeoObjects classes as bases? Long story short &#8211; it can&#8217;t be done. Seriously, no kidding, word to your mother, etc.</p>
<p>GeoObjects doesn&#8217;t include a method for saving features in WKT format. I found that the easiest way to translate features from GeoObjects format to use in other libraries (like the Field Operations Data Model libs) was to get the WKT for the GeoObjects feature. This method will extend the GeoMap object and uses a Feature2 Object (which is a Feature from the Overlay layer) like so: Map1.ToWKT(feat2). To do this I&#8217;ll be using SharpMap to do the heavy lifting.</p>
<p>A good rule of thumb when creating extensions is to isolate them in a separate namespace. In my case I created a GeoObjects Extensions namespace. Next we need to create the method definition:</p>
<pre>public static string ToWKT(this AxGeoObjectsMapLib.AxBMGeoMap m, Feature2 f)
 {

 }</pre>
<p>The first argument is the object being extended &#8211; in this case the Interop version of a GeoMap. The second argument is the feature to be converted (as stated above, a Feature2 object). Next I handle the different typs of GeoObjects Geometries. Here&#8217;s the code for a polygon:</p>
<pre>if (f.GeometryType == GeometryTypeConstants.gtPolygon)
{
  GeoObjectsMapLib.PolygonGeometry pg = (GeoObjectsMapLib.PolygonGeometry)f.Geometry;
  int pgSections = (pg.SectionCount == 0) ? 1 : pg.SectionCount;
  int low = (pg.SectionCount == 0) ? 0 : 1;

  SharpMap.Geometries.MultiPolygon shMulti = new SharpMap.Geometries.MultiPolygon();
  for (int i = low; i &lt; pgSections + 1; i++)
  {
     int vertexCount = pg.VertexCount(i);
     if (vertexCount &gt; 0)
     {
         OlePoint geopt;
         List&lt;SharpMap.Geometries.Point&gt; tempGeoPoints = new List&lt;SharpMap.Geometries.Point&gt;();
         for (int j = 1; j &lt; vertexCount + 1; j++)
         {
             geopt = new OlePointClass();
             geopt = (OlePoint)pg.GetVertex(j, i);
             m.ConvertCoordinate(CoordinateConversionConstants.ccDataspaceToGeodetic, geopt);
             tempGeoPoints.Add(new SharpMap.Geometries.Point(geopt.x, geopt.y));
         }
         geopt = new OlePointClass();
         geopt = (OlePoint)pg.GetVertex(1, i);
         m.ConvertCoordinate(CoordinateConversionConstants.ccDataspaceToGeodetic, geopt);
         tempGeoPoints.Add(new SharpMap.Geometries.Point(geopt.x, geopt.y));

         SharpMap.Geometries.Polygon shGeo = new SharpMap.Geometries.Polygon(new LinearRing(tempGeoPoints));
         shMulti.Polygons.Add(shGeo);
         }
     }
     if (shMulti.Polygons.Count == 1)
         rtnWKT = shMulti.Polygons[0].AsText();
     else
         rtnWKT = shMulti.ToString();
}</pre>
<p>Next time: Enhancing the Feature2 object to allow for true editing of existing features.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/walteis.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/walteis.wordpress.com/431/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=431&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://walteis.wordpress.com/2012/03/28/extending-the-blue-marble-geographics-geoobjects-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e2a1c547f68f5e019f98a05239e15855?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lordkingsquirrel</media:title>
		</media:content>
	</item>
		<item>
		<title>Updated Google Maps Project</title>
		<link>http://walteis.wordpress.com/2012/03/20/updated-google-maps-project/</link>
		<comments>http://walteis.wordpress.com/2012/03/20/updated-google-maps-project/#comments</comments>
		<pubDate>Tue, 20 Mar 2012 14:20:26 +0000</pubDate>
		<dc:creator>walt</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://walteis.wordpress.com/?p=341</guid>
		<description><![CDATA[Updated link under projects for the revised version of my Equus Beds Google Map Project. The new version uses v3 of the Google Maps JavaScript API and the MarkerManager library.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=341&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Updated link under <a href="http://walteis.wordpress.com/projects/" title="projects">projects </a>for the revised version of my Equus Beds Google Map Project.  The new version uses v3 of the Google Maps JavaScript API and the MarkerManager library.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/walteis.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/walteis.wordpress.com/341/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=341&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://walteis.wordpress.com/2012/03/20/updated-google-maps-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e2a1c547f68f5e019f98a05239e15855?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lordkingsquirrel</media:title>
		</media:content>
	</item>
		<item>
		<title>Equus Beds Project Updates</title>
		<link>http://walteis.wordpress.com/2012/03/15/equus-beds-project-updates/</link>
		<comments>http://walteis.wordpress.com/2012/03/15/equus-beds-project-updates/#comments</comments>
		<pubDate>Thu, 15 Mar 2012 19:01:54 +0000</pubDate>
		<dc:creator>walt</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Google Maps]]></category>

		<guid isPermaLink="false">http://walteis.wordpress.com/2012/03/15/equus-beds-project-updates/</guid>
		<description><![CDATA[After a long break from this blog I have decided to update my Equus Beds Google Maps API Project to v3 of the Google Maps JavaScript API.  Look for a link to the new version of the project within the next few days.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=336&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>After a long break from this blog I have decided to update my Equus Beds Google Maps API Project to v3 of the Google Maps JavaScript API.  Look for a link to the new version of the project within the next few days.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/walteis.wordpress.com/336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/walteis.wordpress.com/336/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=walteis.wordpress.com&#038;blog=4208134&#038;post=336&#038;subd=walteis&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://walteis.wordpress.com/2012/03/15/equus-beds-project-updates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e2a1c547f68f5e019f98a05239e15855?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lordkingsquirrel</media:title>
		</media:content>
	</item>
	</channel>
</rss>
