Skip to content

Commit

Permalink
Merge pull request #31 from UDST/dev
Browse files Browse the repository at this point in the history
Finalize v0.1.7
  • Loading branch information
smmaurer authored Aug 8, 2023
2 parents e57d5e5 + 47cfec0 commit 73d28fa
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 71 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
language: python

python:
- '3.5'
- '3.6'
- '3.7'
- '3.8'
- '3.9'
- '3.10'

install:
- pip install .
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v0.1.7
======

2023/8/7

* adds support for Shapely 2.0

v0.1.6
======

Expand Down
59 changes: 42 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,67 @@
## If you have found an error:
Thanks for using OSMnet!

- check the error message and [documentation](https://udst.github.io/osmnet/index.html)
- search the previously opened and closed issues to see if the problem has already been reported
- if the problem is with a dependency of OSMnet, please open an issue on the dependency's repo
- if the problem is with OSMnet and you think you may have a fix, please submit a PR, otherwise please open an issue in the [issue tracker](https:/UDST/osmnet/issues) following the issue template
This is an open source project that's part of the Urban Data Science Toolkit. Development and maintenance is a collaboration between UrbanSim Inc, U.C. Berkeley's Urban Analytics Lab, and other contributors.

## Making a feature proposal or contributing code:
## If you have a problem:

- Take a look at the [open issues](https:/UDST/osmnet/issues) and [closed issues](https:/UDST/osmnet/issues?q=is%3Aissue+is%3Aclosed) to see if there's already a related discussion

- Open a new issue describing the problem -- if possible, include any error messages, a full reproducible example of the code that generated the error, the operating system and version of Python you're using, and versions of any libraries that may be relevant

## Feature proposals:

- Take a look at the [open issues](https:/UDST/osmnet/issues) and [closed issues](https:/UDST/osmnet/issues?q=is%3Aissue+is%3Aclosed) to see if there's already a related discussion

- Post your proposal as a new issue, so we can discuss it (some proposals may not be a good fit for the project)

## Contributing code:

- Create a new branch of `UDST/osmnet/dev`, or fork the repository to your own account

- Make your changes, following the existing styles for code and inline documentation

- Add [tests](https:/UDST/osmnet/tree/dev/osmnet/tests) if possible
- We use the test suite: Pytest

- Run tests and address any issues that may be flagged. If flags are raised that are not due to the PR note that in a new comment in the PR
- Run Pytest test suite: `py.test`
- OSMnet currently supports Python 3.5, 3.6, 3.7, 3.8. Tests will be run in these environments when the PR is created but any flags raised in these environments should also be addressed
- Run pycodestyle Python style guide checker: `pycodestyle --max-line-length=100 osmnet`

- Open a pull request to the `UDST/osmnet` `dev` branch, including a writeup of your changes -- take a look at some of the closed PR's for examples

- Current maintainers will review the code, suggest changes, and hopefully merge it and schedule it for an upcoming release

- post your requested feature on the [issue tracker](https:/UDST/osmnet/issues) and mark it with a `New feature` label so it can be reviewed
- fork the repo, make your change (your code should attempt to conform to OSMnet's existing coding, commenting, and docstring styles), add new or update [unit tests](https:/UDST/osmnet/tree/master/osmnet/tests), and submit a PR
- respond to the code review
## Updating the documentation:

- See instructions in `docs/README.md`


## Preparing a release:

- Make a new branch for release prep

- Update the version number and changelog
- Update the version number and changelog:
- `CHANGELOG.md`
- `setup.py`
- `osmnet/__init__.py`
- `docs/source/index.rst`
- `docs/source/conf.py`

- Make sure all the tests are passing, and check if updates are needed to `README.md` or to the documentation

- Open a pull request to the master branch to finalize it

- After merging, tag the release on GitHub and follow the distribution procedures below
- Open a pull request to the `dev` branch to finalize it and wait for a PR review and approval

- After the PR has been approved, it can be merged to `dev`. Then a release PR can be created from `dev` to merge into `master`. Once merged, tag the release on GitHub and follow the distribution procedures below:

## Distributing a release on PyPI (for pip installation):

- Register an account at https://pypi.org, ask one of the current maintainers to add you to the project, and `pip install twine`

- Check out the copy of the code you'd like to release

- Run `python setup.py sdist bdist_wheel --universal`
- Run `python setup.py sdist bdist_wheel` (WITHOUT the `--universal` flag, since OSMnet no longer supports Python 2)

- This should create a `dist` directory containing two package files -- delete any old ones before the next step
- This should create a `dist` directory containing a gzip package file -- delete any old ones before the next step

- Run `twine upload dist/*` -- this will prompt you for your pypi.org credentials

Expand All @@ -49,8 +70,12 @@

## Distributing a release on Conda Forge (for conda installation):

- The [conda-forge/osmnet-feedstock](https:/conda-forge/osmnet-feedstock) repository controls the Conda Forge release
- The [conda-forge/osmnet-feedstock](https:/conda-forge/osmnet-feedstock) repository controls the Conda Forge release, including which GitHub users have maintainer status for the repo

- Conda Forge bots usually detect new releases on PyPI and set in motion the appropriate feedstock updates, which a current maintainer will need to approve and merge

- Maintainers can add on additional changes before merging the PR, for example to update the requirements or edit the list of maintainers

- You can also fork the feedstock and open a PR manually. It seems like this must be done from a personal account (not a group account like UDST) so that the bots can be granted permission for automated cleanup

- Check https://anaconda.org/conda-forge/osmnet for the new version (may take a few minutes for it to appear)
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007

Copyright (C) 2020 UrbanSim Inc.
Copyright (C) 2022 UrbanSim Inc.

Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ Overview

OSMnet offers tools to download street network data from OpenStreetMap
and extract a graph network comprised of nodes and edges to be used in
`Pandana`_ street network accessibility calculations.
`Pandana`_ street network accessibility calculations and or `UrbanAccess`_
to connect GTFS transit networks to road networks.

Let us know what you are working on or if you think you have a great use case
by tweeting us at ``@urbansim`` or post on the UrbanSim `forum`_.
by tweeting us at ``@urbansim``.

Library Status
--------------
Expand Down Expand Up @@ -84,7 +85,6 @@ Related UDST libraries
.. _OSMnet repo: https:/udst/osmnet
.. _here: https://udst.github.io/osmnet/index.html
.. _UrbanAccess: https:/UDST/urbanaccess
.. _forum: http://discussion.urbansim.com/

.. |Build Status| image:: https://travis-ci.org/UDST/osmnet.svg?branch=master
:target: https://travis-ci.org/UDST/osmnet
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ build: false

environment:
matrix:
- PYTHON: 3.6
- PYTHON: 3.8

init:
- "ECHO %PYTHON%"
Expand Down
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
source_suffix = '.rst'
master_doc = 'index'
project = u'OSMnet'
copyright = u'2020, UrbanSim Inc.'
copyright = u'2023, UrbanSim Inc.'
author = u'UrbanSim Inc.'
version = u'0.1.6'
release = u'0.1.6'
version = u'0.1.7'
release = u'0.1.7'
language = None

nitpicky = True
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ OSMnet

Tools for the extraction of `OpenStreetMap`_ (OSM) street network data. Intended to be used in tandem with `Pandana`_ and `UrbanAccess`_ libraries to extract street network nodes and edges.

v0.1.6, released July 13, 2020.
v0.1.7, released August 7, 2023.

Contents
--------
Expand Down
4 changes: 1 addition & 3 deletions docs/source/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Introduction
OSMnet provides tools for the extraction of `OpenStreetMap`_ (OSM) street network data. OSMnet is intended to be used in tandem with `Pandana`_ and `UrbanAccess`_ libraries to extract street network nodes and edges.

Let us know what you are working on or if you think you have a great use case
by tweeting us at ``@urbansim`` or post on the UrbanSim `forum`_.
by tweeting us at ``@urbansim``.

Reporting bugs
~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -39,5 +39,3 @@ Related UDST libraries
.. _Pandana: https:/UDST/pandana

.. _UrbanAccess: https:/UDST/urbanaccess

.. _forum: http://discussion.urbansim.com/
2 changes: 1 addition & 1 deletion osmnet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .load import *

__version__ = "0.1.6"
__version__ = "0.1.7"

version = __version__
33 changes: 16 additions & 17 deletions osmnet/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def osm_net_download(lat_min=None, lng_min=None, lat_max=None, lng_max=None,
polygon = Polygon([(lng_max, lat_min), (lng_min, lat_min),
(lng_min, lat_max), (lng_max, lat_max)])
geometry_proj, crs_proj = project_geometry(polygon,
crs={'init': 'epsg:4326'})
crs="EPSG:4326")

# subdivide the bbox area poly if it exceeds the max area size
# (in meters), then project back to WGS84
Expand All @@ -144,11 +144,11 @@ def osm_net_download(lat_min=None, lng_min=None, lat_max=None, lng_max=None,
geometry, crs = project_geometry(geometry_proj_consolidated_subdivided,
crs=crs_proj, to_latlong=True)
log('Requesting network data within bounding box from Overpass API '
'in {:,} request(s)'.format(len(geometry)))
'in {:,} request(s)'.format(len(geometry.geoms)))
start_time = time.time()

# loop through each polygon in the geometry
for poly in geometry:
for poly in geometry.geoms:
# represent bbox as lng_max, lat_min, lng_min, lat_max and round
# lat-longs to 8 decimal places to create
# consistent URL strings
Expand All @@ -168,7 +168,7 @@ def osm_net_download(lat_min=None, lng_min=None, lat_max=None, lng_max=None,

log('Downloaded OSM network data within bounding box from Overpass '
'API in {:,} request(s) and'
' {:,.2f} seconds'.format(len(geometry), time.time()-start_time))
' {:,.2f} seconds'.format(len(geometry.geoms), time.time()-start_time))

# stitch together individual json results
for json in response_jsons_list:
Expand Down Expand Up @@ -234,7 +234,7 @@ def overpass_request(data, pause_duration=None, timeout=180,

# get the response size and the domain, log result
size_kb = len(response.content) / 1000.
domain = re.findall(r'//(?s)(.*?)/', url)[0]
domain = re.findall(r'(?s)//(.*?)/', url)[0]
log('Downloaded {:,.1f}KB from {} in {:,.2f} seconds'
.format(size_kb, domain, time.time()-start_time))

Expand Down Expand Up @@ -428,10 +428,11 @@ def project_geometry(geometry, crs, to_latlong=False):
Parameters
----------
geometry : shapely Polygon or MultiPolygon
geometry : shapely.geometry.Polygon or shapely.geometry.MultiPolygon
the geometry to project
crs : int
crs : string or pyproj.CRS
the starting coordinate reference system of the passed-in geometry
such as "EPSG:4326"
to_latlong : bool, optional
if True, project from crs to WGS84, if False, project
from crs to local UTM zone
Expand All @@ -441,11 +442,7 @@ def project_geometry(geometry, crs, to_latlong=False):
geometry_proj, crs : tuple (projected Shapely geometry, crs of the
projected geometry)
"""
gdf = gpd.GeoDataFrame()
gdf.crs = crs
gdf.name = 'geometry to project'
gdf['geometry'] = None
gdf.loc[0, 'geometry'] = geometry
gdf = gpd.GeoDataFrame(geometry=[geometry], crs=crs)
gdf_proj = project_gdf(gdf, to_latlong=to_latlong)
geometry_proj = gdf_proj['geometry'].iloc[0]
return geometry_proj, gdf_proj.crs
Expand All @@ -465,7 +462,7 @@ def project_gdf(gdf, to_crs=None, to_latlong=False):
----------
gdf : geopandas.GeoDataFrame
the GeoDataFrame to be projected
to_crs : dict or string or pyproj.CRS
to_crs : string or pyproj.CRS
if None, project to UTM zone in which gdf's centroid lies, otherwise
project to this CRS
to_latlong : bool
Expand All @@ -477,7 +474,8 @@ def project_gdf(gdf, to_crs=None, to_latlong=False):
the projected GeoDataFrame
"""
if gdf.crs is None or len(gdf) < 1:
raise ValueError("GeoDataFrame must have a valid CRS and cannot be empty")
raise ValueError(
"GeoDataFrame must have a valid CRS and cannot be empty")

# if to_latlong is True, project the gdf to latlong
if to_latlong:
Expand All @@ -490,15 +488,16 @@ def project_gdf(gdf, to_crs=None, to_latlong=False):
# otherwise, automatically project the gdf to UTM
else:
if gdf.crs.is_projected:
raise ValueError("Geometry must be unprojected to calculate UTM zone")
raise ValueError(
"Geometry must be unprojected to calculate UTM zone")

# calculate longitude of centroid of union of all geometries in gdf
avg_lng = gdf["geometry"].unary_union.centroid.x

# calculate UTM zone from avg longitude to define CRS to project to
utm_zone = int(math.floor((avg_lng + 180) / 6.0) + 1)
utm_crs = ('+proj=utm +zone={} +ellps=WGS84 +datum=WGS84 +units=m +no_defs'
.format(utm_zone))
utm_crs = ('+proj=utm +zone={} +ellps=WGS84 '
'+datum=WGS84 +units=m +no_defs'.format(utm_zone))

# project the GeoDataFrame to the UTM CRS
gdf_proj = gdf.to_crs(utm_crs)
Expand Down
Loading

0 comments on commit 73d28fa

Please sign in to comment.