Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Windows form showing the use of GeoIQ4Net to call analysis functions
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GeoIQ.Net;
using GeoIQ.Net.Data;
namespace GeoIQBootstrap
{
public partial class IntersectDemo : Form
{
private System.Timers.Timer _layerTimer = new System.Timers.Timer(500); //to check status of analysis
private AnalyticsResponse _response = null; //response object created by analysis
private Analytics _analytics = new Analytics("http://geocommons.com", "username", "password"); //wrapper class for GeoIQ analytic methods
public IntersectDemo()
{
InitializeComponent();
//initialize time and link label
_layerTimer.Enabled = false;
_layerTimer.Elapsed += new System.Timers.ElapsedEventHandler(_layerTimer_Elapsed);
this.lnkDownloadShape.Visible = false;
}
void _layerTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
string status = _analytics.GetState(_response.ID); //ID is that of new layer created by analysis
if (status.ToLower() == "\"complete\"") //this means analysis is complete
{
//use Invoke to access UI elements from timer thread
this.Invoke(new MethodInvoker(delegate
{
//set up link label to enable download of new data as KML
this.lnkDownloadShape.Text = "Analysis Complete: Download KML";
this.lnkDownloadShape.Links.Clear();
this.lnkDownloadShape.Links.Add(19, 18, "http://geocommons.com/overlays/" + _response.ID.ToString() + ".kml");
this.lnkDownloadShape.Visible = true;
this._layerTimer.Enabled = false;
}));
}
}
private void btnIntersect_Click(object sender, EventArgs e)
{
//call intersect method
//layer 87503 = GISPs, layer 149925 = zip codes
//prefer_1 tells GeoIQ to return records from layer 1 (GISPs in this case)
_response = _analytics.Intersect(87503, 149925, MergeOptions.prefer_1); //capture response object
//start timer to check status
this._layerTimer.Enabled = true;
}
private void lnkDownloadShape_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
//this actually downloads the data and may even fire off Google Earth
System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.