Instantly share code, notes, and snippets.

Ryan Cooper maptastik

View GitHub Profile
View curl_to_ogr2ogr.bash
curl https://url-to-data.com/data.geojson | ogr2ogr -f "ESRI Shapefile" data.shp /vsistdin/
View curl_osgeo4w_cert_workaround.md

Problem

When trying to use cURL from the OSGEO4W shell, it throws the following error:

curl: (60) SSL certificate problem: unable to get local issuer certificate More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not establish a secure connection to it. To learn more about this situation and how to fix it, please visit the web page mentioned above.

View README.md

This is an example of exporting an environment so it can be used to create a new environment. It will also show how to specify a channel that should be included in the build process

First, you'll need to activate the environment you want to use.

activate old-environment

Then export then environment to environment.yml

View agol_map.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Map of single-part geometry data pulled directly from AGOL</title>
</head>
<body>
<!-- Load require.js. Delete this if your page already loads require.js -->
View bad_geojson_pts.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View README.md
View fcUniqueVals.py
""" Generate a list of unique values for a field in a feature class
Parameters:
fc (str): Input feature class
field (str): Field to find unique values for
Returns:
list: unique values in a field
"""
View randomFCSample.py
import arcpy
import numpy as np
def randomFCSample(fc, fd='sample_fd', sample_field='OBJECTID', sample_pct=10):
"""Return a randomish sample of a feature class as a feature layer
Parameters:
fc (str): Input feature class to sample
fd (str): Name of output feature layer
sample_field (int): Numeric field to sample values from
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)