Geocoding unit locations
At RealVectors, we believe that knowledge is power only when it is shared. So here is an attempt to share some of what we are building into our products.
Imagine the possibilities if we can geocode every unit of an apartment or a portfolio - i.e. we have each unit's or features' geographical co-ordinates in 2-dimensional space.
Now imagine if we can have a computer do this in a matter of seconds as opposed to an army of our associates and maintenance personnel physically having to walk each unit. Such manual effort will always suffer from data inconsistency and errors.
In our prior posts we shared some examples of using computer vision to augment data for analytics in a consistent manner. We build upon that here and present a similar technique to geocode each unit by having a computer algorithm scan a property's siteplan.
Below is an original siteplan that is used as the starting point.
import numpy as np import cv2 # load the image image = cv2.imread("siteplan.png") lower = np.array([30, 80, 140]) upper = np.array([110, 170, 225]) shapeMask = cv2.inRange(image, lower, upper) #cv2.imshow("Mask", shapeMask)
The above code scans the siteplan to create a mask that is then used to separate out the units from the rest of the image. The resulting image after the mask is applied is further enhanced to find the bounding contours.
(cnts, _) = cv2.findContours(shapeMask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) # loop over the contours for c in cnts: # draw the contour and show it x,y,w,h = cv2.boundingRect(c) print x, y, w, h if w >= 5 and h >= 5: cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),2) try: M = cv2.moments(c) cX = int(M["m10"] / M["m00"]) cY = int(M["m01"] / M["m00"]) cv2.putText(image, str(cX) + ", " + str(cY), (cX - 20, cY - 20), cv2.FONT_HERSHEY_SIMPLEX, 0.25, (255, 0, 0), 1) except: print "math error" #cv2.imshow("Image", image) cv2.imshow("Image", image)
In the image below the green lines show the contours around each unit; the blue numbers show the co-ordinates of the center of each unit relative to the top left of the image. The centers can then be translated into geographic co-ordinates once we know the latitude and longitude of the NE and SW corners of the siteplan image.