<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Regia on Medium]]></title>
        <description><![CDATA[Stories by Regia on Medium]]></description>
        <link>https://medium.com/@regiacorp?source=rss-54b534cd92e4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*e7OI_p-_iQoTotByNxjpZA.png</url>
            <title>Stories by Regia on Medium</title>
            <link>https://medium.com/@regiacorp?source=rss-54b534cd92e4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 03:25:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@regiacorp/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I Made a Fully Functional Geocoder in 2 Days for Utah]]></title>
            <link>https://medium.com/@regiacorp/how-i-made-a-fully-functional-geocoder-in-2-days-for-utah-e9b95a2f5677?source=rss-54b534cd92e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9b95a2f5677</guid>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[geocoding]]></category>
            <category><![CDATA[geospatial]]></category>
            <category><![CDATA[regia]]></category>
            <category><![CDATA[search-engines]]></category>
            <dc:creator><![CDATA[Regia]]></dc:creator>
            <pubDate>Thu, 25 Jan 2018 03:26:36 GMT</pubDate>
            <atom:updated>2018-01-25T20:58:03.879Z</atom:updated>
            <content:encoded><![CDATA[<p>This story begins with a really interesting challenge. Turns out real estate agents don’t try all that hard to accurately post location when they list a house on the MLS. The latitude and longitude for all Utah listings somehow end up in roughly 18 mainland states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L8UJCeQ3t7E5L9D8_ROVvA.png" /><figcaption>This is all MLS real estate in Park City, UT… oh boy.</figcaption></figure><p><em>Bummer</em>.</p><p>The larger problem is, I don’t want limitations when I forward/reverse geocode from a 3rd party like Mapbox or Google. While they are very considerate with how many free api calls I am entitled to, I believe long term I will need an unlimited number for my project. On top of this, it seems both corporations do not allow you to legally store your results.</p><p>So let the challenge begin.</p><p>The first issue: <strong>where is all the data I need?</strong> <a href="https://openaddresses.io/">https://openaddresses.io/</a> seemed like the best candidate at first. After downloading their data however, it turns out they are missing a considerable amount of addresses (especially for Utah). After quite a bit of research I realized I can’t look for the whole country in one fell swoop.</p><p><strong>The golden egg</strong>: Individual State governments are required to keep tabs on parcels. Who owns what property. <a href="https://gis.utah.gov/data/cadastre/parcels/">Even better, they record the address, city and zipcode for every parcel</a>!</p><blockquote>Never ascribe to cleverness that which can be explained by oversight.</blockquote><p>I hit the jackpot. I just needed to download and edit all of the parcels in Utah.</p><p>Sidequest:<strong> What database is best for address lookups?</strong> I am still a young full stack developer, so my knowledge of databases is limited. Usually I looked for a well rounded DB, but in this case a search-engine based DB sounded like the right solution (solve the address as someone is typing and give similar results along with the ideal candidate).</p><p><a href="https://db-engines.com/en/ranking/search+engine">There is a great database ranking website</a> to find out which db is best for your needs. Since elasticsearch won first place for search-engines, it wasn’t a tough decision. Took me an hour or so to figure out all the common commands and how to setup the db. In fact, <a href="https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-elasticsearch-on-ubuntu-16-04/">digitalocean has a great tutorial on how to setup elasticsearch.</a> Be weary that it is a little outdated, so be prepared to make the proper corrections.</p><p>Great, I have good data and a great DB, so whats next? <strong>How do I scrape and prepare the data? </strong>This was obviously the toughest part. I need to make sure the accuracy is high and not filled with holes. More times than I care to admit, the parcel data was missing the city/town, and sometimes a parcel’s geometry was a MultiPolygon instead of a regular Polygon.</p><p>But I am getting ahead of myself. The first thing I did as explained previously was <a href="http://parcels.utah.gov/">download all of the parcel data</a>. Shapefiles are not easy to work with in Javascript, so I converted all the data to JSON with ogr2ogr. I made a nifty bash script that took all of the zip files and made one big output folder of geoJSON:</p><pre>#!/bin/bash</pre><pre>echo &quot;unzipping all files&quot;</pre><pre>unzip \*.zip</pre><pre>echo &quot;ready for conversion...&quot;</pre><pre>mkdir out</pre><pre>for f in *; do</pre><pre>if [[ -d $f ]]; then</pre><pre>echo &quot;adding geojson to $f&quot;</pre><pre>ogr2ogr -f GeoJSON &quot;out/$f.json&quot; -t_srs EPSG:4326 &quot;$f/$f.shp&quot;</pre><pre>fi</pre><pre>done</pre><p>Now that my data was ready to be scraped, I made another script that pulled all the parcels that contained addresses and saved the address along with the longitude and latitude.</p><p><strong>Problem: </strong>Most parcel data was missing the city from which it resides. Turns out this is for a good reason.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wf1z0nv2zkunfs18x52Qog.png" /><figcaption>Some houses will reside outside any legal boundary, while technically still part of that municipality or township</figcaption></figure><p>If you look <a href="https://www.arcgis.com/home/webmap/viewer.html?webmap=e2e0430f97114c3aa958262fa5e3e6ed">here</a> you can see all the boundaries for Utah Municipalities and Metro Townships Boundaries. If a parcel lands outside these zones, their city won’t be recorded. On top of that there are unincorporated communities that are not logged by the government.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*D7loL_Oeq6lOeWqsjrjUgg.png" /><figcaption>Courtesy of google. Flowell shares a zipcode with it’s nearest neighbor Fillmore.</figcaption></figure><p>So to handle these edge cases that made up roughly 35-40% of all parcel data, <a href="https://gis.utah.gov/data/boundaries/citycountystate/">I pulled in the data mentioned above</a>. Once again, I converted said data into geoJSON and kept them ready for when I was unsure which city an address resides. The easiest way to find the addresses’ city? Use the zipcode associated with it! The <a href="http://federalgovernmentzipcodes.us/">federal government has a free database</a> of city, zipcode, lat, long, etc. What a nice program. They even had Flowell, Utah!</p><p><strong>So how do I find which city an address belongs to?</strong> First, I checked the zipcode of that address, and find all possible cities that have that zipcode in the federal governments database. Next, I used a <a href="https://www.npmjs.com/package/closest-feature">basic spatial searching algorithm</a> that checked which geojson feature (city boundaries) is closest. It’s entirely possible this isn’t 100% accurate; sometimes the algorithm will ignore unincorporated communities like Flowell for instance. But its accurate enough for now!</p><p><strong>Lastly</strong>, to ensure the most accurate LAT and LON of an address, I would find the center point of the parcel. After fixing a few more small edge cases (I mentioned MultiPolygon/Polygon — it won’t find the center of a parcel if it has MultiPolygon geometry) the data was ready for elasticsearch.</p><p>30 minutes to write the script and 445.18 seconds for elasticsearch to pull in the data. Now the DB was ready for requests!</p><pre>const elasticsearch = require(&#39;elasticsearch&#39;);<br>const client = new elasticsearch.Client({<br>  host: &#39;10.0.0.31:9200&#39;,<br>  log: &#39;trace&#39;<br>});</pre><pre>client.search({<br>  index: &#39;2018&#39;,<br>  type: &#39;geocodes&#39;,<br>  body: {<br>    query: {<br>      match: {<br>        addr: &#39;12318 S SHAHAKA RD&#39;<br>      }<br>    }<br>  }<br>}).then((res) =&gt; {<br>  console.log(&quot;res&quot;, res.hits.hits);<br>}).catch((err) =&gt; {<br>  console.log(&quot;error&quot;, err);<br>});</pre><p>The response:</p><pre>[ { _index: &#39;2018&#39;,</pre><pre>_type: &#39;geocodes&#39;,</pre><pre>_id: &#39;27303300150000&#39;,</pre><pre>_score: 27.29438,</pre><pre>_source:</pre><pre>{ lon: -111.99647360203369,</pre><pre>lat: 40.52742300149186,</pre><pre>addr: &#39;12318 S SHAHAKA RD Riverton UT 84096&#39; } },<br></pre><pre>...<br></pre><pre>{ _index: &#39;2018&#39;,</pre><pre>_type: &#39;geocodes&#39;,</pre><pre>_id: &#39;27303300180000&#39;,</pre><pre>_score: 14.4564,</pre><pre>_source:</pre><pre>{ lon: -111.99697896886951,</pre><pre>lat: 40.527037981880994,</pre><pre>addr: &#39;12348 S SHAHAKA RD Riverton UT 84096&#39; } } ]</pre><p>There you have it! This was a really fun project! Let me know if I missed any details you may be interested in.</p><p>CTO.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9b95a2f5677" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>