Skip to content

Instantly share code, notes, and snippets.

Ryan Cooper maptastik

Block or report user

Report or block maptastik

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
maptastik /
Last active Aug 2, 2019
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):

View tnm_edit.arcade
var y = (2 * Atan(Exp(Geometry($feature).y / 6378137)) - PI / 2) / (PI / 180)
var x = Geometry($feature).x / (PI / 180) / 6378137
return "" + y +"," + x + ",16"
maptastik / numeric_test_points.geojson
Last active Jul 9, 2019
Plotting data-driven proportional symbol markers with geopandas
View numeric_test_points.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View int_to_auto_increment.sql
-- See
-- Create a new sequence
CREATE sequence <column_id_seq>;
-- Alter the field you're converting to an auto-incrementing field be setting a default value based on a sequence
ALTER TABLE <table_name> alter <id_column> SET DEFAULT nextval(<'id_column_seq'>);
-- Set the current max value of the id column as the starting point for the sequence
SELECT setval(<'id_column_seq'>, <max_id_column_value> );
maptastik / LineIntersectionsGeopandas.ipynb
Created Apr 4, 2019
Using geopandas to find line intersection points within a dataset
View LineIntersectionsGeopandas.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
maptastik / MultipleGeometryGDF.ipynb
Created Apr 3, 2019
Creating and working with multiple geometry columns in a single GeoDataFrame
View MultipleGeometryGDF.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
maptastik / SphericalMercator2WGS84.arcade
Last active Mar 22, 2019
Arcade expressions for deriving WGS84 decimal degree coordinates
View SphericalMercator2WGS84.arcade
// Arcade expressions to convert point coordinates from Web Mercator to WGS84 Decimal Degrees
// Based on the LibreCalc expressions found at
// Latitude
(2 * Atan(Exp(Geometry($feature).y / 6378137)) - PI / 2) / (PI / 180)
// Longitude
Geometry($feature).x / (PI / 180) / 6378137
View intersectingPolygonAttributes.arcade
var polygon = FeatureSetByName($map, 'Polygon Layer Name', ['Field1', 'Field2', 'Field3'])
var polygonUnderFeatureInfo = Intersects(polyogn, $feature) //
return First(Intersects(parcels, $feature))
# max = max FACILITYID value in dataset. This can be calculated with a function
with arcpy.da.UpdateCursor('feature_class', ['FACILITYID'], "FACILITYID IS NULL") as cursor:
for row in cursor:
new_facilityid_number = max + 1
row[0] = str(new_facilityid_number)
max = new_facilityid_number

It is sort of tricky to run spatial queries against tables in a GeoPackage anywhere, but especially outside of QGIS. This is because we're reliant on Spatialite to carry out those queries and Spatialite is just not well supported. A real shame!

Luckily there are a few resources for helping you get up and going with installing Spatialite for working with GeoPackages in a SQL client like DB Browser.

There is a page in the DB Browser Wik on GitHub called " SpatiaLite on Windows" and it is dedicated to installing Spatialite for use with DB Browser. Note that there are special instructions for a Windows 10 issue.

Bryan McBride at Spatial Networks wrote up a nice piece on working with GeoPackages in DB Browser called "Working with Geospatial Data: An Introduction". It's got a nice walk-thru of how to use DB Browser with GeoPackage as well as some general installation instructions.

You can’t perform that action at this time.