first pass on overpass api, still getting an error with columns

This commit is contained in:
John Krauss
2017-01-03 15:39:01 +00:00
parent d7552031f6
commit ff50c5e2bf
8 changed files with 88 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
comment = 'CartoDB Observatory backend extension'
default_version = '1.1.6'
requires = 'postgis, postgres_fdw'
requires = 'postgis, postgres_fdw, plpythonu'
superuser = true
schema = cdb_observatory

View File

@@ -0,0 +1,7 @@
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetOverpass(query text)
RETURNS table (lat Numeric, lon Numeric, "type" TEXT, id Numeric, tags TEXT) as $$
from observatory.osm import get_overpass
return get_overpass(query)
$$ LANGUAGE plpythonu;

View File

@@ -1,6 +1,7 @@
-- Install dependencies
CREATE EXTENSION postgis;
CREATE EXTENSION postgres_fdw;
CREATE EXTENSION plpythonu;
-- Install the extension
CREATE EXTENSION observatory VERSION 'dev';

4
src/python/Makefile Normal file
View File

@@ -0,0 +1,4 @@
# Install the package locally for development
install:
pip install --upgrade ./crankshaft

View File

@@ -0,0 +1,24 @@
from overpass import API
import json
def get_overpass(query):
'''
Return results of a raw overpass query.
'''
'''
(node
[amenity]
(around:400,
40.704301, -73.936658);
way
[amenity]
(around:400,
40.704301, -73.936658))
'''
api = API()
response = api.Get(query, responseformat='json')
return [(el['lat'], el['lon'], el['type'], el['id'], json.dumps(el['tags']), ) for el in response['elements'] if 'lat' in el]

View File

@@ -0,0 +1 @@
overpass==0.5.6

View File

@@ -0,0 +1,50 @@
"""
CartoDB Spatial Analysis Python Library
See:
https://github.com/CartoDB/crankshaft
"""
from setuptools import setup, find_packages
setup(
name='observatory',
version='0.0.1',
description='CARTO Observatory Python Library',
url='https://github.com/CartoDB/observatory-extension',
author='Research and Data - CARTO',
author_email='john@carto.com',
license='MIT',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Mapping comunity',
'Topic :: Maps :: Mapping Tools',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2.7',
],
keywords='maps mapping tools spatial data',
packages=find_packages(exclude=['contrib', 'docs', 'tests']),
extras_require={
'dev': ['unittest'],
'test': ['unittest', 'nose', 'mock'],
},
# The choice of component versions is dictated by what's
# provisioned in the production servers.
# IMPORTANT NOTE: please don't change this line. Instead issue a ticket to systems for evaluation.
install_requires=[],
#install_requires=['overpass==0.5.6'],
requires=[],
#requires=['overpass'],
#test_suite='test'
)