Utah.govOnline ServicesAgency ListBusiness.Utah.gov

Home arrow GIS Resources arrow Scripts and Code arrow C# Code arrow C#, Voting Precinct Web Service Example
C#, Voting Precinct Web Service Example PDF Print E-mail

Written by Bert Granberg,

GIS-based web services allow web programmers to build website that incorporate GIS functionality to make maps, perform queries, and do spatial analysis without having to understand or acquire GIS software, GIS data, & GIS expertise. They are a great way to get more return out of your GIS investment.

The C# code below is a simple illustration of the use of a gis-based web service within a website to find a voting precinct in the SGID for a given location. It utilizes a web reference to a web service called WSUTSGID_FeatureAttributes created by AGRC that allows any SGID data layer to be queried given the following:

  • mapserv user name (free, but you must register as a user at mapserv.utah.gov )
  • SGID layer name (in this case SGID.U024.VotingPrecincts)
  • Field names from which you want results (in this case Precinct_ID & CNTY_NAME_)
  • UTM X & Y coordinates for location of interest


Note: While AGRC works closely with counties to obtain current voting precinct data, these data sets are not complete at the moment. For current voting precinct information, we recommend contacting county clerks directly.

Example Input:

Example Results:

// note: mapserv.attributes is a namespace name i specified when adding a web reference to:
// http://mapserv.utah.gov/WSUTSGID_FeatureAttributes/default.asmx

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        mapserv.attributes.WSUTSGID_FeatureAttributes ws = new mapserv.attributes.WSUTSGID_FeatureAttributes();
        mapserv.attributes.Attribute[ ] results = ws.GetFeatureAttributes("YOURMAPSERVUSERNAMEHERE",
                                                "SGID.U024.VotingPrecincts",
                                                 new string[ ] { "PrecinctID", "CNTY_NAME_" },
                                                 double.Parse(utmXTextBox.Text),
                                                 double.Parse(utmYTextBox.Text));


        Label headerLabel = new Label();
        headerLabel.Text = "FIELD: VALUE";
        PlaceHolder1.Controls.Add(headerLabel);
        PlaceHolder1.Controls.Add(new LiteralControl(@"<br />"));

        for (int i = 0; i < results.Length; i++)
        {
         
            Label newLabel = new Label();
            newLabel.Text = results[i].Field + ": " + results[i].Value;
            PlaceHolder1.Controls.Add(newLabel);
            PlaceHolder1.Controls.Add(new LiteralControl(@"<br />"));
        }
    }
}


Users' Comments  
 

No comment posted

Add your comment

07, Jul. 2008
Last Updated ( 07, Jul. 2008 )
 
< Prev   Next >

AGRC Contacts | UGIC Contacts

feed image feed image

Utah GIS Portal © 2008 AGRC

Optimized for