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 site
print(site.USER_SITE)
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
Linux, Python 3.5: /home/ojdo/.local/lib/python3.5/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 these two functions.
However, there is utility function find_closest_edge
, which looks deceptively simple but took some time to get this "clean". It performs an operation similar to ArcGIS's Near for the special case of matching point features to their nearest line passing by. It heavily relies on several functions implemented in my other toolbox shapelytools
.
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. So use something like GeoPandas' to_crs
function to convert your geographic (lat, lon) data to a projected (x, y) coordinate system before using anything from this package.
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.
Provides functions like get_entity
to read data from coopr.pyomo models to pandas DataFrames. (Un)fortunately, 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, but its functions might remain useful in other contexts.
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. This is the predecessor to my pandashp
toolbox, which itself now is partially unneeded because of GeoPandas.