PyPi package 1.0.0

This commit is contained in:
Ilya Zverev 2017-06-07 22:15:08 +03:00
parent 1b77fc54ef
commit 302b59b9b8
9 changed files with 114 additions and 46 deletions

4
.gitignore vendored
View file

@ -5,5 +5,9 @@
*.json
*.gz
*.csv
*.pyc
private/
data/
__pycache__/
*.egg*
build/

9
CHANGELOG.md Normal file
View file

@ -0,0 +1,9 @@
# OSM Conflator Change Log
## master branch
## 1.0.0
_Released 2017-06-07_
The initial PyPi release with all the features.

View file

@ -1,38 +0,0 @@
# OSM Conflator
This is a script for merging points from some third-party source with OpenStreetMap data.
Please make sure the license allows that. After merging and uploading, the data can be updated.
See [the OSM wiki page](https://wiki.openstreetmap.org/wiki/OSM_Conflator) for detailed
description and instructions.
## Installation
Clone this repository, and from inside it run `pip install -r requirements.txt`.
## Profiles
Each source should have a profile. It is a python script with variables configuring
names, tags and processing. See heavily commented examples in the `profiles` directory.
## Usage
For a simplest case, run:
./conflate.py <profile.py>
You might want to add `-v` to get status messages, and other arguments to pass a dataset file
or write the resulting osmChange somewhere. Run `./conflate.py -h` to see a list of arguments.
## Uploading to OpenStreetMap
It is recommended to open the resulting file in the JOSM editor and manually check the changes.
Alternatively, you can use [bulk_upload.py](https://wiki.openstreetmap.org/wiki/Bulk_upload.py)
to upload a change file from the command line.
Please mind the [Import Guidelines](https://wiki.openstreetmap.org/wiki/Import/Guidelines), or your
work may be reverted.
## License
Written by Ilya Zverev for MAPS.ME. Published under the Apache 2.0 license.

54
README.rst Normal file
View file

@ -0,0 +1,54 @@
OSM Conflator
=============
This is a script for merging points from some third-party source with
OpenStreetMap data. Please make sure the license allows that. After
merging and uploading, the data can be updated.
See `the OSM wiki page`_ for detailed description and instructions.
Installation
------------
Clone this repository, and from inside it run
``pip install -r requirements.txt``.
Profiles
--------
Each source should have a profile. It is a python script with variables
configuring names, tags and processing. See heavily commented examples
in the ``profiles`` directory.
Usage
-----
For a simplest case, run:
::
./conflate.py <profile.py>
You might want to add ``-v`` to get status messages, and other arguments
to pass a dataset file or write the resulting osmChange somewhere. Run
``./conflate.py -h`` to see a list of arguments.
Uploading to OpenStreetMap
--------------------------
It is recommended to open the resulting file in the JOSM editor and
manually check the changes. Alternatively, you can use
`bulk\_upload.py`_ to upload a change file from the command line.
Please mind the `Import Guidelines`_, or your work may be reverted.
License
-------
Written by Ilya Zverev for MAPS.ME. Published under the Apache 2.0
license.
.. _the OSM wiki page: https://wiki.openstreetmap.org/wiki/OSM_Conflator
.. _bulk\_upload.py: https://wiki.openstreetmap.org/wiki/Bulk_upload.py
.. _Import Guidelines: https://wiki.openstreetmap.org/wiki/Import/Guidelines

1
conflate/__init__.py Normal file
View file

@ -0,0 +1 @@
from .conflate import SourcePoint, OSMPoint, OsmConflator, Profile, ProfileException, run, __version__

View file

@ -8,6 +8,7 @@ import requests
import os
import sys
from io import BytesIO
from .version import __version__
import json # for profiles
import re # for profiles
import zipfile # for profiles
@ -16,6 +17,7 @@ try:
except ImportError:
import xml.etree.ElementTree as etree
TITLE = 'OSM Conflator ' + __version__
OVERPASS_SERVER = 'http://overpass-api.de/api/'
BBOX_PADDING = 0.003 # in degrees, ~330 m default
MAX_DISTANCE = 100 # how far can object be to be considered a match, in meters
@ -633,7 +635,7 @@ class OsmConflator:
def backup_osm(self):
"""Writes OSM data as-is."""
osm = etree.Element('osm', version='0.6', generator='OSM Conflator')
osm = etree.Element('osm', version='0.6', generator=TITLE)
for osmel in self.osmdata.values():
el = osmel.to_xml()
if osmel.osm_type != 'node':
@ -643,13 +645,13 @@ class OsmConflator:
def to_osc(self, josm=False):
"""Returns a string with osmChange or JOSM XML."""
osc = etree.Element('osm' if josm else 'osmChange', version='0.6', generator='OSM Conflator')
osc = etree.Element('osm' if josm else 'osmChange', version='0.6', generator=TITLE)
if josm:
neg_id = -1
changeset = etree.SubElement(osc, 'changeset')
ch_tags = {
'source': self.source,
'created_by': 'OSM Conflator',
'created_by': TITLE,
'type': 'import'
}
for k, v in ch_tags.items():
@ -770,9 +772,9 @@ def transform_dataset(profile, dataset):
def run(profile=None):
parser = argparse.ArgumentParser(description='''
OSM Conflator.
{}.
Reads a profile with source data and conflates it with OpenStreetMap data.
Produces an JOSM XML file ready to be uploaded.''')
Produces an JOSM XML file ready to be uploaded.'''.format(TITLE))
if not profile:
parser.add_argument('profile', type=argparse.FileType('r'), help='Name of a profile (python or json) to use')
parser.add_argument('-i', '--source', type=argparse.FileType('rb'), help='Source file to pass to the profile dataset() function')
@ -789,8 +791,9 @@ def run(profile=None):
log_level = logging.INFO
else:
log_level = logging.WARNING
logging.basicConfig(level=log_level, format='%(asctime)s %(message)s', datefmt='%H:%M:%S')
logging.basicConfig(level=log_level, format='%(asctime)s %(name)s %(message)s', datefmt='%H:%M:%S')
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
if not profile:
logging.debug('Loading profile %s', options.profile)

1
conflate/version.py Normal file
View file

@ -0,0 +1 @@
__version__ = '1.0.0'

View file

@ -1,2 +0,0 @@
requests
kdtree

36
setup.py Normal file
View file

@ -0,0 +1,36 @@
from setuptools import setup
from os import path
here = path.abspath(path.dirname(__file__))
exec(open(path.join(here, 'conflate', 'version.py')).read())
setup(
name='osm_conflate',
version=__version__,
author='Ilya Zverev',
author_email='ilya@zverev.info',
packages=['conflate'],
install_requires=[
'kdtree',
'requests',
],
url='https://github.com/mapsme/osm_conflate',
license='Apache License 2.0',
description='Command-line script for merging points from a third-party source with OpenStreetMap data',
long_description=open(path.join(here, 'README.rst')).read(),
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Information Technology',
'Intended Audience :: Developers',
'Topic :: Software Development :: Libraries :: Python Modules',
'Natural Language :: English',
'Operating System :: OS Independent',
'Topic :: Utilities',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3 :: Only',
],
entry_points={
'console_scripts': ['conflate = conflate:run']
},
)