Parcel Values in Bernalillo County

6 Jan

In the last post, you learned how to use the ESRI REST API to access data. I am going to show one more example. this example will grab 2500 parcel records and return the total property value for all the parcels.

The example is almost identical to the previous post. You will create an array to hold the values of each parcel. Then we will use a reduce function to sum them. The full code is below.

Results of REST query

Results of REST query

<html>
<head>
<title>PUBLIC ART</title>
</head>
<body>
<div id=”title”>Loading…</div>
<div id=”total”></div>
<div id=”tax”></div>
<script>
var query;
var holdtotal=[0];

var params = “where=1=1&outfields=TOTVALUE&f=json”;
var url = “http://coagisweb.cabq.gov/arcgis/rest/services/public/BernCoParcels/MapServer/0/query&#8221;;
http=new XMLHttpRequest();
http.open(“POST”, url, true);
http.setRequestHeader(“Content-type”, “application/x-www-form-urlencoded”);
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
theGeom= JSON.parse(http.responseText);
var key, count = 0;
for(key in theGeom.features) {
if(theGeom.features.hasOwnProperty(key)) {
count++;
}}
document.getElementById(“title”).innerHTML=”<h3>I grabbed “+count+” parcels in Bernalillo County”;

for(i=0;i<count;i++){

holdtotal.push(theGeom.features[i].attributes.TOTVALUE);
}

var grandtotal=holdtotal.reduce(function(t,n){return t+n},0);

document.getElementById(“total”).innerHTML=”The total value of the parcels is $”+grandtotal.toLocaleString();

}}

http.send(params);
</script>
</body>
</html>

 

The above code should be straight forward with the exception of the variable grandtotal. The reduce function allows you to iterate through an array and add the previous value to the next returning a single value. the variable t is the total starting at 0 and n is the next value. when it is added, the value of t increases and adds itself to the next item. Then you just write the value to HTML.

With this technique you can create forms that would allow users to query data that you already publish in GIS. You can change your where clause to only grab residential properties, properties owned by a specific person or by lot size. Try some variations like where=acreage>600.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: