Everything should be made as simple as possible, but not simpler. (Albert Einstein)

Tuesday, February 23, 2016

Notes on GIS / GEOINT, Tracking Your Location via Your Cat


An interesting blog post by Joseph J. Kerski, Esri Education Manager and a staff in the Coursera GEOINT course

https://spatialreserves.wordpress.com/2014/08/17/compromising-privacy-while-posting-pictures/ 
 
I know where your cat lives. http://iknowwhereyourcatlives.com/ 
 
BTW. The cat was just an excuse, in fact we want to know where the owners live. ;)) 

It's amazing that in 1949 far before Internet era, George Orwell wrote a novel "1984" about total surveillance by authority, 
In the society that Orwell describes, every citizen is under constant surveillance by the authorities, mainly by telescreens (with the exception of the Proles). The people are constantly reminded of this by the slogan "Big Brother is watching you"
https://www.schneier.com/blog/archives/2015/02/samsung_televis.html 
https://en.wikipedia.org/wiki/Big_Brother_%28Nineteen_Eighty-Four%29
http://www.theguardian.com/world/2013/sep/23/orwell-nsa-surveillance-alan-rusbridger
http://www.worldcrunch.com/world-affairs/how-2015-mass-surveillance-compares-to-orwell-s-1984-big-br...

-----------------------------


GIS specialization: https://www.coursera.org/specializations/gis 
  
QGIS, http://www.qgis.org/en/site/ 
ArcGIS, (online, desktop) http://www.arcgis.com/ 
Esri, https://www.esri.com/ 
Geonet, https://geonet.esri.com/ 
Comparison: https://www.gislounge.com/qgis-versus-arcgis/  
Stack Exchange, https://gis.stackexchange.com/
Reddit, http://reddit.com/r/gis
Public Lab, http://publiclab.org/
Digital Geography, http://digital-geography.com/ 
@@@
 
"Social Engineering: The Art of Psychological Warfare, Human Hacking, Persuasion, and Deception" by Vince Reynolds
Some books: 

1. ArcGIS by Example, Packt Publishing.
2. ArcGIS Blueprints, Packt Publishing.
3. ArcGIS for Desktop Cookbook, Packt Publishing.
4. ArcGIS Web Development, Manning Publications.
5. ArcPy and ArcGIS - Geospatial Analysis with Python, Packt Publishing.
6. Developing Mobile Web ArcGIS Applications, Packt Publishing.
7. Learning Geospatial Analysis with Python, Second Edition, Packt Publishing.
8. Learning R for Geospatial Analysis, Packt Publishing.
9. Microsoft Mapping - Geospatial Development in Windows 10 with Bing Maps and C#, Second Edition, Apress.
10. HTML5 Geolocation, O'Reilly.
11. Programming ArcGIS 10.1 with Python Cookbook, Packt Publishing.
12. Python Geospatial Analysis Cookbook, Packt Publishing.
13. Web Mapping Illustrated, O'Reilly.  

14. Learning ArcGIS Pro, Packt Publishing. 

Suggested by Erin Snider, 
"One Second After" Best realistic emergency management discussions on a theoretical scenario of an EMP hitting the US.
"Deep Survival" Psychology behind why people die and why people live in disasters, accidents, wilderness

Also "Everyday Survival", "Surviving Survival".  

-----------------------------------------------------------

Reverse Geocoding with Python and Google API

Having a pair of latitude & longitude coordinates, we want to get street address. In this case I utilize Google API. Scripting code in Python.
  
First, get an API key, https://developers.google.com/maps/documentation/geocoding/get-api-key
 
Standard plan is free, with following limitation: #2,500 free requests per day and  #10 requests per second.
  
Now, here is my code: 



#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@title: reverse-geocoding.py via Google API
@author: soesilo wijono
'''
from __future__ import print_function
import requests
import json
def getplace(lat, lon):
    '''
    @param lat: latitude, float
    @param lon: longitude, float
    @return: string of street address
    '''
    url = "https://maps.googleapis.com/maps/api/geocode/json"
    params = {'latlng' : '%s,%s' % (lat, lon),
              'result_type' : 'street_address',
              'key' : 'YOUR_API_KEY'
              }
    v = requests.get(url, params=params)
    j = v.json()

    country = country_iso = None
    if j['status'] == 'OK':
        place_id = j['results'][0]['place_id']
        street_addr = j['results'][0]['formatted_address']
        print(street_addr)
        components = j['results'][0]['address_components']
        for c in components:
            if "street_number" in c['types']:
                print("street number:", c['long_name'])
            if "route" in c['types']:
                print("route:", c['long_name'])
            if "neighborhood" in c['types']:
                print("neighborhood:", c['long_name'])
            if "sublocality" in c['types']:
                print("sublocality:", c['long_name'])
            if "administrative_area_level_2" in c['types']:
                print("administrative area level 2:", c['long_name'])
            if "administrative_area_level_1" in c['types']:
                print("administrative area level 1:", c['long_name'], c['short_name'])
            if "country" in c['types']:
                print("country:", c['long_name'], c['short_name'])
            if "postal_code" in c['types']:
                print("postal code:", c['long_name'])
    else:
        print("%s,%s,%s" % (0, "ERROR", j['status']))
            
    return street_addr
    
if __name__ == '__main__':
    getplace(40.714224, -73.961452)

Replace "YOUR_API_KEY" with your Google Developer API key. Then run the code either in console or in Python IDE.    
As an example, let's do reverse geocoding latitude=40.714224 and longitude=-73.961452.
Upon running the above code, the output is, 

'''
277 Bedford Ave, Brooklyn, NY 11211, USA

street number: 277
route: Bedford Avenue
neighborhood: Williamsburg
sublocality: Brooklyn
administrative area level 2: Kings County
administrative area level 1: New York NY
country: United States US
postal code: 11211
'''
 
(Remember though, lat/long can be fake.) 

Import the above script from another script for batch/automation processing.
As an example, say that we have a database contains 1 million lat/long coordinates of "smart & sweet girls" around the world ;)  

The database is in a CSV file called "lat-long-of-smart-beautiful-girls.csv", with 2 columns "Lat" and "Long". 
Then, run following script,
 

from reverse_geocoding import getplace 
import pandas as pd 

latlong = pd.read_csv('lat-long-of-smart-beautiful-girls.csv') 
addresses = [] 
for idx,row in latlong.iterrows(): 
    addr = getplace(row.Lat, row.Long) 
    addresses.append(addr) 

result = pd.DataFrame({'addr' : addresses}) 
result.to_csv('addresses-of-smart-beautiful-girls.csv', index=False) 
 
Now we have another database "addresses-of-smart-beautiful-girls.csv" as the result, contains 1 million addresses. We can use it, e.g. to print labels, to send boxes of "fine Belgian chocolate" to the smart girls ;))

---------------------------------------------------
To Automate Getting World Border with Python

First, get a Python script we shall import, from here, https://github.com/che0/countries/blob/master/countries.py
 
Download ArcGIS world borders shape file dataset from here, http://thematicmapping.org/downloads/world_borders.php

Put them in the same folder with this Python script below. The shape files can be extracted to a subfolder, e.g. "map" as in the following example.
Here is an example usage in Python, 

full_path = r'D:\coursera\gis\map\TM_WORLD_BORDERS-0.3.shp' 
cc = countries.CountryChecker(full_path) 

# test france
cntry = cc.getCountry(countries.Point(49.7821, 3.5708))
print( cntry.iso, cntry.shape.GetField('NAME') )

The above code snippet is testing a location in France. Output is,
FR France 

This snippet is useful to automate (batch processing) reverse country geocoding of huge amount of lat/long coordinates, especially to be used in real time applications.

-------------------------------------

Week 3: CGD (Crowdsourced Geospatial Data), Camouflage and Deception (WW2)  

http://www.tomnod.com/campaign/spratly_mooc_2016/map/citxuy1n

(A) Is there a strong argument that the utility of closed source information will decrease relative to open source information in GEOINT?
(B) Is being skeptical of CGD different than being skeptical of other data?
 
From a perspective: possible deception
 
Prologue: Great movie to come, The War Magician, "a fact-based World War II thriller that is being written by Book Of Eli scribe Gary Whitta from David Fisher’s fact-based book". 
A must see film before you die! ;)) 
 
In World War II, British Military Intelligence had "ghost army". Jasper Maskelyne is magician. He created large-scale ruses, deception, and camouflage during WW2.
 
David Copperfield made airplane "disappear". Long time ago, Jasper Maskelyne "moved" Alexandria harbour.  
 
[quote] 
The harbor at Alexandria was critical to the Allies; it housed the royal fleet and served as the avenue to deploy reinforcements. Naturally, the Axis powers wanted to destroy it. Jasper Maskelyne was supposedly charged with the task of not letting that happen.
 
To set up his trick, Maskelyne first needed to move the entire harbour. About a mile away from Alexandria was another body of water called Lake Mariout.
... 

[/quote] 
 
He created deceptive illusion to "move" the harbour. It worked, Nazi bombers destroyed the "fake harbour" instead of real one, for 8 consecutive nights!
 
Many other stories, e.g. he created fake tanks, trucks, soldiers etc.
[quote] 
Jasper Maskelyne's finest hour came in 1942, when he was told to convince Field Marshal Erwin Rommel that the Eighth Army was in the South of the Egyptian desert and that an attack would come up from there and not from the North. He was asked to conceal 150,000 men with 1,000 guns and tanks. Somehow he cleverly did this without the Germans knowing anything about it.
[/quote] 
 
Does the same illusion happen in Spratly island? To deceive satellite imagery? In the 21st century? Probably not, or yes?
 
The deceptive illusions probably work for CGD, but won't work for 21st century's closed source information. Closed sources is still very important for its reliability. 
 

 
(A) Is there a strong argument that the utility of closed source information will decrease relative to open source information in GEOINT?
IMHO, no.
 
(B) Is being skeptical of CGD different than being skeptical of other data?
--Scientific skepticism (partly yes) or pseudoskepticism (no)?
--It's relative, what kind of "other data"? CGD involves remote sensing which is very difficult to be verified. You must penetrate & land on the Spratly island to do audit investigation. While, for example financial data (other) can be verified easier.
  
Dr. Todd Bacastow:
I also recommend "Sleights of Mind: What the Neuroscience of Magic Reveals about Our Everyday Deceptions." See http://www.amazon.com/Sleights-Mind-Neuroscience-Everyday-Deceptions/dp/0312611676. So, will open source be used for tipping and close source be used for confirmation? 

The authors' website: http://illusionoftheyear.com/ 


^_^