Skip to content

Instantly share code, notes, and snippets.

View randallwhitman's full-sized avatar

Randall Whitman randallwhitman

View GitHub Profile
diff --git a/README.md b/README.md
index e0381ae..ad8b512 100644
--- a/README.md
+++ b/README.md
@@ -71,7 +71,7 @@ Find a bug or want to request a new feature? Please let us know by submitting a
Esri welcomes contributions from anyone and everyone. Please see our [guidelines for contributing](https://github.com/esri/contributing)
## Licensing
-Copyright 2013-2019 Esri
+Copyright 2013-2020 Esri
create external table trips_by_origin_cell(leftlon double, botlat double, rightlon double, toplat double, totnum int, samedest int, pct double, destlhs double, destbot double, destrhs double, desttop double)
row format delimited fields terminated by '\t'
location '/user/rwhitman/out-trips-by-origin-cell';
create external table trip_origin_json (totnum int, samedest int, pct double, destlhs double, destbot double, destrhs double, desttop double, shape binary)
row format serde 'com.esri.hadoop.hive.serde.JsonSerde'
stored as inputformat 'com.esri.json.hadoop.UnenclosedJsonInputFormat'
outputformat 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
location '/user/rwhitman/trip-origin-json';
env HADOOP_CLASSPATH=../lib/esri-geometry-api.jar:../lib/spatial-sdk-hadoop.jar \
hadoop jar trip-discovery.jar com.esri.hadoop.examples.trip.TripCellDrv \
-libjars ../lib/esri-geometry-api.jar,../lib/spatial-sdk-hadoop.jar \
15 500 trips/japan-tokyo-gcs.json trips/vehicle-positions.csv out-trips-inferred
env HADOOP_CLASSPATH=../lib/esri-geometry-api.jar \
hadoop jar trip-discovery.jar com.esri.hadoop.examples.trip.TripCorrDrv \
-libjars ../lib/esri-geometry-api.jar \
1 'out-trips-inferred/part-r-*' out-trips-by-origin-cell
@randallwhitman
randallwhitman / TripCellMapper.java
Last active December 17, 2015 17:29
Trip Discovery - Mapper reads CSV data format
public class TripCellMap extends Mapper<LongWritable, Text, Text, CarSortWritable> {
// column indices for values in the vehicle CSV
static final int COL_CAR = 0; // vehicle ID
static final int COL_DAT = 1; // date in YYMMDD
static final int COL_TIM = 2; // time in HHMMSS
static final int COL_LON = 3; // longitude in DMS
static final int COL_LAT = 4; // latitude in DMS
static final int COL_DIR = 5; // compass orientation in degrees
static final int COL_SPD = 6; // speed in km/h
@randallwhitman
randallwhitman / TripCorrRed.reduce.java
Last active December 17, 2015 17:29
Trip Discovery - By Origin Cell, Count Trips to Common Destination Cell
public void reduce(Text key, Iterable<TripCorrWrit> values, Context ctx)
throws IOException, InterruptedException {
final int INIT_SIZE = 8000;
HashMap<String,Long> records = new HashMap<String,Long>(INIT_SIZE);
String sval, maxDest = null;
long totCount = 0, maxCount = 0;
for (TripCorrWrit entry : values) {
sval = entry.toString(); // bounds of destination cell - value of iterator, key of hashmap
@randallwhitman
randallwhitman / TripCellRed.reduce.java
Last active December 17, 2015 17:19
Trip Discovery - Infer Trips by Stoppage
public void reduce(Text key, Iterable<CarSortWritable> values, Context ctx)
throws IOException, InterruptedException {
String[] kys = key.toString().split(","); // carID & date
Text outKy = new Text(kys[0]);
// Expect at most tens of thousands of positions per car per day - expect up to thousands.
// (per year, up to 2-3 hundreds of thousands)
final int MAX_BUFFER_SIZE = 8000; // would fit a record every 11s all day
ArrayList<CarSortWritable> records = new ArrayList<CarSortWritable>(MAX_BUFFER_SIZE);
@randallwhitman
randallwhitman / TripCellRed.queryGrid.java
Last active December 17, 2015 17:19
Trip Discovery - Grid Cell Containing Location
private int queryGrid(double longitude, double latitude) {
int cellIndex; // xIdx + xCount * yIdx
if (longitude >= lonMin && longitude <= lonMax &&
latitude >= latMin && latitude <= latMax) { // avoid outliers
int xIdx = (int)((longitude-lonMin)/arcLon);
if (xIdx >= 0 && xIdx < xCount) {
int yIdx = (int)(yCount*(latitude-latMin)/latExtent); // approximate, to refine
yIdx = yIdx < yCount ? yIdx : yCount - 1;
cellIndex = xIdx + xCount * yIdx;
// Expect either correct, or one of either too high or too low, not both
@randallwhitman
randallwhitman / TripCellRed.setup.java
Last active December 17, 2015 17:19
Trip Discovery - Equal-Angle Grid
@Override
public void setup(Context context)
{
// first pull values from the configuration
Configuration config = context.getConfiguration();
int minutes = config.getInt("com.esri.trip.threshold", 15); //minutes stoppage delineating trips
threshold = minutes * 60; // minutes -> seconds
double gridSide = 1000.; // Nominal/average/target length of side of grid cell (meters)