This is a collection of small modules that I often/sometimes/not anymore use for my day-to-day scripting needs. I keep them in a separate directory that I keep always on the Python search path so that I can include them like installed site-packages.
I just clone this repo into the directory that is returned by the following Python snippet:
import os, site
from sys import version_info as ver
print(os.path.join(site.USER_BASE,
'Python{}{}'.format(ver.major, ver.minor),
'site-packages'))
Depending on your operating system and Python version, this evaluates to
Windows, Python 3.5: C:\Users\ojdo\AppData\Roaming\Python\Python35\site-packages
Linux, Python 2.7: /home/ojdo/.local/Python27/site-packages
Anyway, open a terminal in that directory (create it if necessary) and clone this repo into that directory:
git clone https://github.com/ojdo/python-tools.git .
You should now be able to import any of the following packages. Depending on what you need, you might alternatively just grab one of these files/functions.
Basically my private implementation of a GeoPandas GeoFrame. This module provides two functions, read_shp and write_shp. The first one reads an ESRI shapefile to a pandas DataFrame, saving the geometry information (Points, Lines, Polygons) in the column geometry. The second function does the reverse. These functions do not care about transformations, much different to GeoPandas. I plan to migrate to using Geopandas myself, so better don't use this.
Provides functions like get_entity to read data from coopr.pyomo models to pandas DataFrames. Unfortunately, pyomo changed its internals some time around the 3.5 release version, so these functions don't work with current pyomo versions. See URBS for an up-to-date version of these functions.
Archive for some misc functions needed for migrating URBS from GAMS to Python. Function read_xls for example implements automatic detection of Capital lettre column titles for onset detection. I don't use it any longer.
Many handy small functions dealing with collections of shapely objects, i.e. points, lines and polygons. I use them to script small geographic algorithms on my own. The module implements a naive nearest neighbor algorithm, pruning of short line segments, finding isolated endpoints among a list of possibly touching lines. Note: shapely is not aware of geographic coordinates! So while some of these functions might work with lat/lon coordinates in degrees, I use them mainly in projected coordinate systems with x/y coordinates in metres.
Convenience wrapper of pyshp, including automatic type detection (numeric, string) when reading/writing shapefiles. Might be not needed anymore, but was quite handy when written. I mainly use pandashp above nowadays because of the much more mighty DataFrame.
Wrapper module that provides function skeletonize, which reads in a pandashp DataFrame of road segments and returns a simplified version of it. The most expensive step is the skeletonization of a buffered version of this road network, decorated with some pre- and postprocessing steps.
pandashpabove- Skeletron and its dependencies