Skip to content

Instantly share code, notes, and snippets.

@Lenninlasd
Last active November 14, 2017 15:42
Show Gist options
  • Save Lenninlasd/0bb654bdfc0d9d98c49ddd7f58b9d3c6 to your computer and use it in GitHub Desktop.
Save Lenninlasd/0bb654bdfc0d9d98c49ddd7f58b9d3c6 to your computer and use it in GitHub Desktop.
Heatmap
===================== Test Data ====================
## Assign different coordinates with jq
cat earthquakes.geojson| jq '.. | select( has("features") )? | .features | .[] | .geometry.coordinates |= [.[0],.[1]] '
## Remove third coordinate:
sed -i -e 's/, [0-9]*\.[0-9]* ]/ ]/g' earthquakes.geojson
Remove unwanted attributes, and third dimension:
jq '.features | .[] | del(.properties.felt) | del(.properties.mag) | del(.properties.time) | del(.properties.tsunami) | .geometry.coordinates |= [.[0],.[1]]' earthquakes.json >> jda.json
==================== Solr Data ========================
## Get CSV from solr data.
jq -r '.[] | .sm_field_location|=.[0] | .sm_field_location|=split(",") | .lat=.sm_field_location[0] | .lon=.sm_field_location[1] | .lon|=tonumber | .lat|=tonumber | select(.lat > 0) | select(.lon >0 ) | [.entity_id, .lat, .lon] | @csv' data-min.json >> jda.csv
## Generate a new vector with a random number between 0.00 and 1.00:
LINES=`cat jda.csv | wc -l`
259633
(echo rand && jot -r $(expr $LINES - 1) 0.00 1.00) >> jda_rand.csv
## TODO: Right now values are generated in 0.01 incremements.
## Use join in order to concatenate the csv and the .txt files into a new csv
heatmap-data: paste -d"," jda.csv jda_rand.csv >> jda_merged.csv
## Convert CSV to GeoJSON
## Add manually the header (id, lat, lon, random) and create the following .vrt file.
<OGRVRTDataSource>
<OGRVRTLayer name="jda_merged">
<SrcDataSource>jda_merged.csv</SrcDataSource>
<GeometryType>wkbPoint</GeometryType>
<LayerSRS>WGS84</LayerSRS>
<GeometryField encoding="PointFromColumns" x="lon" y="lat"/>
<Field name="id" src="id" type="String" />
<Field name="random" src="rand" type="Real" />
</OGRVRTLayer>
</OGRVRTDataSource>
ogr2ogr -f GeoJSON jda.geojson jda.vrt
## Split the jda.geojson data in 10 random chunks:
chmod +x chunks.sh
source chunks.sh
limits=(0.01 0.02 0.04 0.08 0.16 0.32 0.64 1)
index=0
for i in "${limits[@]}";
do;
index=$(($index+1))
eval "jq -r '.features = [ .features | .[] | select(.properties.random <= $i) ] | { type, crs, features }' jda.geojson >> jda_rand_$index.geojson"
echo $index
done;
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Display the source blob
Display the rendered blob
Raw
View raw

(Sorry about that, but we can’t show files that are this big right now.)

Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment