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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.