Compare commits
9 Commits
population
...
contours
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01eef5ee9e | ||
|
|
46c66476b5 | ||
|
|
e03aac4d8f | ||
|
|
d885c16db2 | ||
|
|
abfda1c75e | ||
|
|
8f478ef22c | ||
|
|
c7bb50be5a | ||
|
|
ef17e2fe4c | ||
|
|
f3b8546063 |
@@ -12,7 +12,7 @@ name must be created.
|
||||
### Version numbers
|
||||
|
||||
The version of both the SQL extension and the Python package shall
|
||||
follow the[Semantic Versioning 2.0](http://semver.org/) guidelines:
|
||||
follow the [Semantic Versioning 2.0](http://semver.org/) guidelines:
|
||||
|
||||
* When backwards incompatibility is introduced the major number is incremented
|
||||
* When functionally is added (in a backwards-compatible manner) the minor number
|
||||
|
||||
@@ -7,8 +7,6 @@ CartoDB Spatial Analysis extension for PostgreSQL.
|
||||
* *pg* contains the PostgreSQL extension source code
|
||||
* *python* Python module
|
||||
|
||||
FIXME: should it be `./extension` and `./lib/python' ?
|
||||
|
||||
## Requirements
|
||||
|
||||
* pip
|
||||
|
||||
@@ -28,3 +28,6 @@ REGRESS_OPTS = --inputdir='$(TEST_DIR)' --outputdir='$(TEST_DIR)'
|
||||
PG_CONFIG = pg_config
|
||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||
include $(PGXS)
|
||||
|
||||
# This seems to be needed at least for PG 9.3.11
|
||||
all: $(DATA)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION crankshaft" to load this file. \quit
|
||||
-- Internal function.
|
||||
-- Set the seeds of the RNGs (Random Number Generators)
|
||||
-- used internally.
|
||||
@@ -133,4 +136,13 @@ BEGIN
|
||||
RETURN ST_Collect(points);
|
||||
END;
|
||||
$$
|
||||
LANGUAGE plpgsql VOLATILE
|
||||
LANGUAGE plpgsql VOLATILE;
|
||||
-- Make sure by default there are no permissions for publicuser
|
||||
-- NOTE: this happens at extension creation time, as part of an implicit transaction.
|
||||
-- REVOKE ALL PRIVILEGES ON SCHEMA cdb_crankshaft FROM PUBLIC, publicuser CASCADE;
|
||||
|
||||
-- Grant permissions on the schema to publicuser (but just the schema)
|
||||
GRANT USAGE ON SCHEMA cdb_crankshaft TO publicuser;
|
||||
|
||||
-- Revoke execute permissions on all functions in the schema by default
|
||||
-- REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_crankshaft FROM PUBLIC, publicuser;
|
||||
|
||||
3
pg/sql/0.0.1/00_header.sql
Normal file
3
pg/sql/0.0.1/00_header.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION crankshaft" to load this file. \quit
|
||||
@@ -51,4 +51,4 @@ BEGIN
|
||||
RETURN ST_Collect(points);
|
||||
END;
|
||||
$$
|
||||
LANGUAGE plpgsql VOLATILE
|
||||
LANGUAGE plpgsql VOLATILE;
|
||||
|
||||
12
pg/sql/0.0.1/07_contours.sql
Normal file
12
pg/sql/0.0.1/07_contours.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION
|
||||
cdb_contours_count (
|
||||
query TEXT,
|
||||
levels NUMERIC[]
|
||||
)
|
||||
RETURNS TABLE (the_geom geometry , level Numeric)
|
||||
AS $$
|
||||
from crankshaft.contours import create_countours_count
|
||||
return create_countours_count(query,levels)
|
||||
$$ LANGUAGE plpythonu;
|
||||
9
pg/sql/0.0.1/90_permissions.sql
Normal file
9
pg/sql/0.0.1/90_permissions.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
-- Make sure by default there are no permissions for publicuser
|
||||
-- NOTE: this happens at extension creation time, as part of an implicit transaction.
|
||||
-- REVOKE ALL PRIVILEGES ON SCHEMA cdb_crankshaft FROM PUBLIC, publicuser CASCADE;
|
||||
|
||||
-- Grant permissions on the schema to publicuser (but just the schema)
|
||||
GRANT USAGE ON SCHEMA cdb_crankshaft TO publicuser;
|
||||
|
||||
-- Revoke execute permissions on all functions in the schema by default
|
||||
-- REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_crankshaft FROM PUBLIC, publicuser;
|
||||
18
pg/test/0.0.1/sql/90_permissions.sql
Normal file
18
pg/test/0.0.1/sql/90_permissions.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
SELECT cdb_crankshaft._cdb_random_seeds(1234);
|
||||
|
||||
-- Use regular user role
|
||||
SET ROLE test_regular_user;
|
||||
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_crankshaft;
|
||||
|
||||
-- Exercise public functions
|
||||
SELECT ppoints.code, m.quads
|
||||
FROM ppoints
|
||||
JOIN cdb_moran_local('ppoints', 'value') m
|
||||
ON ppoints.cartodb_id = m.ids
|
||||
ORDER BY ppoints.code;
|
||||
SELECT round(cdb_overlap_sum(
|
||||
'0106000020E61000000100000001030000000100000004000000FFFFFFFFFF3604C09A0B9ECEC42E444000000000C060FBBF30C7FD70E01D44400000000040AD02C06481F1C8CD034440FFFFFFFFFF3604C09A0B9ECEC42E4440'::geometry,
|
||||
'values', 'value'
|
||||
), 2);
|
||||
@@ -1,2 +1,3 @@
|
||||
import random_seeds
|
||||
import clustering
|
||||
import contours
|
||||
|
||||
1
python/crankshaft/crankshaft/contours/__init__.py
Normal file
1
python/crankshaft/crankshaft/contours/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from contours import *
|
||||
47
python/crankshaft/crankshaft/contours/contours.py
Normal file
47
python/crankshaft/crankshaft/contours/contours.py
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import plpy
|
||||
|
||||
def contour_to_polygon(contour):
|
||||
plpy.notice('appending contour ')
|
||||
c = np.append(contour, [contour[0]], axis=0)
|
||||
points =','.join( [ " ".join(str(a) for a in b) for b in c])
|
||||
|
||||
return "POLYGON(({points}))::geometry".format(points=points)
|
||||
|
||||
def create_countours_count(query,levels,mesh_size=20):
|
||||
qresult = plpy.execute( "select ST_X(the_geom)::Numeric as x, ST_Y(the_geom)::Numeric as y from ({query}) a ".format(query=query))
|
||||
x =[]
|
||||
y =[]
|
||||
for a in qresult:
|
||||
if a['x'] and a['y']:
|
||||
x.append(float(a['x']))
|
||||
y.append(float(a['y']))
|
||||
|
||||
plpy.notice(np.shape(x))
|
||||
plpy.notice(np.shape(y))
|
||||
|
||||
if None in x:
|
||||
plpy.notice("NULL IN LIST X ")
|
||||
if None in y:
|
||||
plpy.notice("NULL IN LIST Y ")
|
||||
|
||||
x_min,x_max = np.min(x), np.max(x)
|
||||
y_min,y_max = np.min(y), np.max(y)
|
||||
plpy.notice(x_min)
|
||||
plpy.notice(x_max)
|
||||
plpy.notice(y_min)
|
||||
plpy.notice(y_max)
|
||||
plpy.notice(mesh_size)
|
||||
|
||||
x_grid = np.linspace(x_min,x_max, mesh_size)
|
||||
y_grid = np.linspace(y_min,y_max, mesh_size)
|
||||
range = [[x_min,x_max],[y_min,y_max]]
|
||||
a, xedges, yedges= np.histogram2d(x,y,bins=(mesh_size,mesh_size), range=range)
|
||||
a = np.swapaxes(a,0,1)
|
||||
plpy.notice("here about to create the contours")
|
||||
|
||||
CS = plt.contour(xedges[1:],yedges[1:] ,a,4,linewidths=0.5, colors='b')
|
||||
plpy.notice(levels)
|
||||
return[(contour_to_polygon(CS.Cntr.trace((level))[0]), float(level)) for level in levels]
|
||||
@@ -10,7 +10,7 @@ from setuptools import setup, find_packages
|
||||
setup(
|
||||
name='crankshaft',
|
||||
|
||||
version='0.0.01',
|
||||
version='0.0.1',
|
||||
|
||||
description='CartoDB Spatial Analysis Python Library',
|
||||
|
||||
@@ -40,9 +40,9 @@ setup(
|
||||
|
||||
# The choice of component versions is dictated by what's
|
||||
# provisioned in the production servers.
|
||||
install_requires=['pysal==1.11.0','numpy==1.6.1','scipy==0.17.0'],
|
||||
install_requires=['pysal==1.11.0','numpy==1.10.1','scipy==0.17.0', 'matplotlib==1.4.3'],
|
||||
|
||||
requires=['pysal', 'numpy'],
|
||||
requires=['pysal', 'numpy', 'matplotlib'],
|
||||
|
||||
test_suite='test'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user