Skip to content

Instantly share code, notes, and snippets.

View maptastik's full-sized avatar

Ryan Cooper maptastik

View GitHub Profile
@maptastik
maptastik / fileList.py
Last active April 16, 2024 21:05
Create a Markdown formatted list of files in a directory
```
Create a Markdown formatted list of files in a directory
```
import os
dir = input("Directory to generate list: ")
list = os.listdir(dir)
file = open(dir + '\\' + 'list.txt', 'w')
for l in list:
@maptastik
maptastik / ogrIntoPostGIS.md
Last active March 15, 2024 14:27
Import data into PostGIS with ogr2ogr#

Generally I can use QGIS and its DBManager to import data into a PostGIS database. Sometimes that doesn't work perfectly. ogr2ogr can help though. Here are a few approaches to getting data into PostGIS with ogr2ogr.

This is probably the most basic approach:

 ogr2ogr -f "PostgreSQL" PG:"dbname=<db name> user=<username> password=<password> host=<host> port=<port #>" input.geojson -nln schema.table

Running this little command seems to work if you have need to specify the geometry type (Source):

@maptastik
maptastik / LineIntersectionsGeopandas.ipynb
Created April 4, 2019 03:34
Using geopandas to find line intersection points within a dataset
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@maptastik
maptastik / README.md
Last active October 1, 2023 12:44
Constructing the URL for files on Google Drive

First things first, you'll need to make sure your data are in a folder within your Google Drive rather than the root directory. Once you've added your data file to that folder, make sure that folder and the file are shareable.

These steps assume you're working through Google Drive in your browser:

  1. Navigate to the folder in your Google Drive.
  2. Examine the URL of the folder. It should look something like https://drive.google.com/drive/u/0/folders/<folder ID>. The folder ID should be a string of numbers and letter rather than the name you gave the folder.
  3. Generate the URL of your file. The URL consists of three (3) parts that you'll put together:
  4. https://googledrive.com/host/
  5. folder ID
  6. /your file
@maptastik
maptastik / clipToRasterExtent.py
Last active August 15, 2023 19:59
Clip a raster to the extent of another raster using arcpy and convert it to a TIFF
# Load arcpy
import arcpy
# Set workspace
arcpy.env.workspace = "<some filepath for your working environment>"
scratch = "<some scratch location for intermediate files>"
# Specify the data you'll be clipping and the area you want to clip that data by
myClip = "<location of raster to be clipped>"
clipArea = "<location of raster to clip by>"
@maptastik
maptastik / MultipleGeometryGDF.ipynb
Created April 3, 2019 02:25
Creating and working with multiple geometry columns in a single GeoDataFrame
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@maptastik
maptastik / README.md
Last active August 3, 2022 15:47
Loading ArcGIS Service & GeoJSON

Loading ArcGIS Service & GeoJSON

This block demos a few things:

  1. Loading basemaps of Scott County, KY created in ArcGIS and served from ArcGIS Server using Esri-Leaflet. The amount of dialog boxes one has to go through to style features in ArcGIS makes the styling process a bit clunky, but it's possible to create a nice basemap in ArcGIS. The layer switcher shows two. The first one is based on OpenMapSurfer's style. The second is based on Stamen's Toner.
  2. Loading external GeoJSON data with D3. I had never used this method before until I came across Ian Johnson's tutorial series "Working with spatial data for the web". In the past I've used leaflet-ajax. It has worked well for me, but I like the idea of having D3 at my disposal
@maptastik
maptastik / README.md
Created January 12, 2017 18:19
Export Data Driven Pages from ArcGIS in bulk as JPG and/or PDF

ddp_export.py

The purpose of this script is to bulk export data driven pages from ArcGIS. It generates output as JPG and/or PDF based on user input. This by inspired by an answer [the question about exporting data driven pages on GIS Stack Exchage] (http://gis.stackexchange.com/a/67520/27257).

To run this script:

  1. Open up cmd.exe (Command Prompt)
  2. Copy the location of where this script is located
  3. In the command prompt navigate to the directory containing this script: cd <path to directory>
  4. In the command prompt run the script: python ddp_export.py
  5. Follow the instructions.

On Ubuntu-flavored Linux distros, there appears to be a bug where when trying to access a URL, the browser gets hung up with a Resolving host... message for a long time. Sometimes the request will just stop and then maybe after a little while longer, the page will load. This seems to have been documented going back a couple major versions of Ubuntu and while there are several workarounds, the one that I found here worked for me:

$ sudo ls -la /etc/resolv.conf
> lrwxrwxrwx 1 root root 29 mar 7 20:20 /etc/resolv.conf -> ../run/resolvconf/stub-resolv.conf
$ sudo rm -f /etc/resolv.conf
$ sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
$ sudo ls -la /etc/resolv.conf
lrwxrwxrwx 1 root root 32 mar 8 07:30 /etc/resolv.conf -> /run/systemd/resolve/resolv.conf
import arcpy
# Assume a feature class called polygon_fc with two separate float/double fields, x and y
with arcpy.da.UpdateCursor('polygon_fc', ['SHAPE@', 'x', 'y']) as cursor:
for row in cursor:
geom_4326 = row[0].projectAs(arcpy.SpatialReference(4326))
row[1] = geom_4326.centroid.X
row[2] = geom_4326.centroid.Y
cursor.updateRow(row)