Instantly share code, notes, and snippets.

Ryan Cooper maptastik

View GitHub Profile
View curl_to_ogr2ogr.bash
curl | ogr2ogr -f "ESRI Shapefile" data.shp /vsistdin/


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:

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.


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">
<meta charset="UTF-8">
<title>Map of single-part geometry data pulled directly from AGOL</title>
<!-- 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.
""" Generate a list of unique values for a field in a feature class
fc (str): Input feature class
field (str): Field to find unique values for
list: unique values in a field
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
fc (str): Input feature class to sample
fd (str): Name of output feature layer
sample_field (int): Numeric field to sample values from

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
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)