Instantly share code, notes, and snippets.

View README.md

Add features from several GPX files in a directory to a GeoPackage

This is motivated by the fact that Runkeeper exports all your GPS data to individual GPX files. These GPX files contain 5 different tables:

  1. route_points
  2. routes
  3. track_points
  4. tracks
  5. waypoints
View shps_to_fgdb.py
import arcpy
def shp_to_fgdb(shps, out_fgdb):
if isinstance(shps, str):
shps = [shps]
for shp in shps:
out_fc_name = shp.split('\\')[-1].split('.')[0]
print('Working on {}...'.format(out_fc_name))
arcpy.FeatureClassToFeatureClass_conversion(shp, out_fgdb, out_fc_name)
View shps_in_dir.py
import os
def shps_in_dir(search_directory, full_path = True):
shp_list = []
for file in os.listdir(search_directory):
if file.endswith('.shp'):
shp_list.append(file)
if len(shp_list) > 0 and full_path:
shp_list = list(map(lambda x: os.path.join(search_directory,x), shp_list))
return shp_list
View allFieldsPopup.js
function allFieldsPopup(feature, layer) {
let featureProperties = feature.properties;
let popupHtml = '';
for(let property in featureProperties) {
popupHtml+=`<b>${property}:</b> ${featureProperties[property]}<br>`
}
layer.bindPopup(popupHtml)
}
View consolidatePolygons.js
function consolidatePolygons(polygonsJson) {
let consolidatedPolygonsArray = [];
let polygonsFeatures = polygonsJson.features;
for (let i = 0; i < polygonsFeatures.length; i++) {
let polygonFeature = polygonsFeatures[i];
let coordinates = polygonFeature.geometry.coordinates;
if (polygonFeature.geometry.type === "MultiPolygon") {
for (let j = 0; j < coordinates.length; j++) {
consolidatedPolygonsArray.push(coordinates[j]);
View createArrayOfPointCoordinates.js
function createArrayOfPointCoordinates(pointsJson) {
let pointsCoordinatesArray = [];
let pointsFeatures = pointsJson.features;
for (let i = 0; i < pointsFeatures.length; i++) {
let pointsFeature = pointsFeatures[i];
if (pointsFeature.geometry != null) {
let pointsFeaturesCoordinates = pointsFeature.geometry.coordinates;
pointsCoordinatesArray.push(pointsFeaturesCoordinates);
}
View countPointsInPolygons.js
function countPointsInPolygons(points, polygonJson) {
let countsArray = [];
let polygonFeaturesArray = polygonJson.features;
for (let i = 0; i < polygonFeaturesArray.length; i++) {
let iGeometry = turf.polygon(polygonFeaturesArray[i].geometry.coordinates);
let pointsWithinPolygon = turf.pointsWithinPolygon(points, iGeometry);
iGeometry.properties.count = pointsWithinPolygon.features.length;
countsArray.push(iGeometry);
}
return turf.featureCollection(countsArray);
View README.md

This function takes an input GeoJSON dataset and creates a generates a hex grid from the bounding box of that layer. Because of the way hex grids are created using turfjs, using the bounding box doesn't necessarily result in every area of the input GeoJSON being covered by a hex grid. As such you can also set buffer parameters, radius and bufferUnits, to expand the area for which the bounding box is created. You can define the size of the hexagons with the cellSide and hexUnits parameters.

View Lenox_Parks_Network_Test.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View in_state.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.