resolve issues in build and with code, now returning geometries and data as expected from obs_getoverpass

This commit is contained in:
John Krauss 2017-01-03 16:37:16 +00:00
parent ff50c5e2bf
commit 000a440417
5 changed files with 69 additions and 7 deletions

View File

@ -1,6 +1,7 @@
include ./Makefile.global
EXT_DIR = src/pg
PYP_DIR = src/python
.PHONY: install
.PHONY: run_tests
@ -12,14 +13,17 @@ EXT_DIR = src/pg
# It requires sudo.
install: ## Generate and install development version of the extension; requires sudo.
$(MAKE) -C $(EXT_DIR) install
$(MAKE) -C $(PYP_DIR) install
# Run the tests for the installed development extension.
test: ## Run the tests for the development version of the extension
$(MAKE) -C $(EXT_DIR) test
$(MAKE) -C $(PYP_DIR) test
# Generate a new release into release
release: ## Generate a new release of the extension. Only for release manager
$(MAKE) -C $(EXT_DIR) release
$(MAKE) -C $(PYP_DIR) release
# Install the current release.
# It requires sudo.
@ -27,6 +31,7 @@ release: ## Generate a new release of the extension. Only for release manager
# sudo make deploy RELEASE_VERSION=1.0.0
deploy: ## Deploy a released extension. Only for release manager. Requires sudo.
$(MAKE) -C $(EXT_DIR) deploy
$(MAKE) -C $(PYP_DIR) deploy
# Cleanup development extension script files
clean-dev: ## clean up development extension script files

View File

@ -684,11 +684,13 @@ BEGIN
Array_Cat(Array_Agg(geom_tablename),
Array_Agg(denom_tablename) FILTER (WHERE denom_tablename IS NOT NULL)))
)) tablename) bar) tablenames,
String_Agg(numer_tablename || '.' || numer_geomref_colname || ' = ' ||
geom_tablename || '.' || geom_geomref_colname ||
Coalesce(' AND ' || numer_tablename || '.' || numer_geomref_colname || ' = ' ||
denom_tablename || '.' || denom_geomref_colname, ''),
' AND ') AS obs_wheres,
String_Agg('ST_Intersects(' || geom_tablename || '.' || geom_colname
|| ', _geoms.geom)', ' AND ')
AS user_wheres

View File

@ -1,7 +1,44 @@
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetOverpass(query text)
RETURNS table (lat Numeric, lon Numeric, "type" TEXT, id Numeric, tags TEXT) as $$
CREATE OR REPLACE FUNCTION cdb_observatory._OBS_GetOverpass(
query text
) RETURNS TABLE (
geom TEXT,
"type" TEXT,
id TEXT,
properties TEXT
) AS $$
from observatory.osm import get_overpass
return get_overpass(query)
import plpy
import json
result = get_overpass(query)
return [{
'geom': json.dumps(feature['geometry']),
'type': feature['type'],
'id': str(feature['id']),
'properties': json.dumps(feature['properties'])
} for feature in result]
$$ LANGUAGE plpythonu;
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetOverpass(
query text
) RETURNS TABLE (
geom Geometry(Geometry, 4326),
"type" TEXT,
id TEXT,
properties JSON
) AS $$
BEGIN
RETURN QUERY
EXECUTE $string$
SELECT ST_GeomFromGeojson(geom) geom,
"type",
id,
properties::JSON
FROM cdb_observatory._OBS_GetOverPass($1)
$string$ USING query
RETURN;
END;
$$ LANGUAGE plpgsql;

View File

@ -1,4 +1,9 @@
include ../../Makefile.global
# Install the package locally for development
install:
pip install --upgrade ./crankshaft
pip install --upgrade ./observatory
test:
#TODO noop

View File

@ -18,7 +18,20 @@ way
40.704301, -73.936658))
'''
api = API()
response = api.Get(query, responseformat='json')
'''
(node [amenity] (around:400, 40.704301, -73.936658); way [amenity] (around:400, 40.704301, -73.936658))
'''
return [(el['lat'], el['lon'], el['type'], el['id'], json.dumps(el['tags']), ) for el in response['elements'] if 'lat' in el]
api = API()
response = api.Get(query)
return response['features']
#return [(el['lat'], el['lon'], el['type'], el['id'], json.dumps(el['tags']) )
# for el in response['elements'] if 'lat' in el][0]
def get_overpass_poi(within_geom, geom, filters=None, name=None):
'''
Simplified access to overpass API
'''
pass