diff --git a/travis.yml b/.travis.yml similarity index 97% rename from travis.yml rename to .travis.yml index 1e43c1e..fbcf75f 100644 --- a/travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ before_install: install: - export CPLUS_INCLUDE_PATH=/usr/include/gdal - export C_INCLUDE_PATH=/usr/include/gdal - - pip install git+https://github.com/OpenDataAnalytics/gaia.git@basegaia#egg=gaia + - pip install git+https://github.com/OpenDataAnalytics/gaia.git#egg=gaia - pip install -r requirements.txt - pip install -r requirements-dev.txt - pip install -e . diff --git a/docs/conf.py b/docs/conf.py index ce1156e..ea7a4cd 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -30,7 +30,7 @@ def __getattr__(cls, name): MOCK_MODULES = ['pysal', 'scipy', 'gdal', 'gdalconst', 'osgeo', 'ogr', 'osr', 'osgeo.gdal_array', 'numpy', 'pandas', 'geopandas', 'psycopg2', 'scikit-image', 'skimage', 'skimage.graph', 'numpy.ma', - 'matplotlib', 'matplotlib.pyplot'] + 'matplotlib', 'matplotlib.pyplot', 'scipy.stats', 'gdalnumeric'] sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES) # -- General configuration ------------------------------------------------ diff --git a/docs/examples/gaia_processes.html b/docs/examples/gaia_processes.html index d204568..c589ed1 100644 --- a/docs/examples/gaia_processes.html +++ b/docs/examples/gaia_processes.html @@ -11766,7 +11766,7 @@

Gaia Density Computations Exampleimport folium import numpy as np from folium.plugins import ImageOverlay -from gaia_densitycomputations.processes import SimpleGridDensityProcess +from gaia_densitycomputations.processes import SimpleGridDensityProcess, KernelDensityProcess from gaia.geo.geo_inputs import VectorFileIO @@ -11774,6 +11774,15 @@

Gaia Density Computations Example + + @@ -11820,16 +11826,31 @@

Gaia Density Computations Example
-
In [3]:
+
In [7]:
sdp.compute()
+print sdp.output.uri
 
+
+
+ + +
+
+
/Users/mbertrand/dev/kitware/gaia/tests/data/output/c5fff097-ad3b-48e8-89c7-e641d6240e63/c5fff097-ad3b-48e8-89c7-e641d6240e63.tif
+
+
+
+ +
+
+
@@ -11843,7 +11864,7 @@

Gaia Density Computations Example
-
In [5]:
+
In [4]:
+ +
+
+
In [5]:
+
+
+
# Calculate kernel density with default bandwidth estimator ('scott')
+inputio = VectorFileIO(uri='/Users/mbertrand/dev/kitware/gaia-densitycomputations-plugin/tests/data/iraq_hospitals.geojson')
+kdp = KernelDensityProcess(inputs=[inputio], width=200)
+kdp.compute()
+print kdp.output.uri
+
+
+
+
+ +
+
+ + +
+
+
/Users/mbertrand/dev/kitware/gaia/tests/data/output/4b84bd47-12c2-4e96-9340-7b7cfb1a2ecc/4b84bd47-12c2-4e96-9340-7b7cfb1a2ecc.tif
+
+
@@ -11882,16 +11946,126 @@

Gaia Density Computations Example
-
In [ ]:
+
In [6]:
-
 
+
# Display kernel density on map
+from folium.plugins import MarkerCluster
+
+world_map = folium.Map([34.00,43.00],
+                  zoom_start=6,
+                  tiles='cartodbpositron')
+
+hospitals = folium.features.GeoJson(inputio.read().to_json(), name='Hospitals')
+temparray = np.array(kdp.output.read().GetRasterBand(1).ReadAsArray())
+overlay = ImageOverlay(temparray, [[27.0466603,38.9358608],[40.3888093,50.8226656]], 
+                       colormap=lambda x: (1, 0, 0, x),
+                       mercator_project=True, control=True)
+overlay.layer_name = 'Kernel Density'
+
+world_map.add_children(overlay)
+world_map.add_children(hospitals)
+
+folium.LayerControl().add_to(world_map)
+world_map
 
+
+
+ + +
Out[6]:
+ +
+
+
+ +
+ +
+
+ +
+
+
+
In [8]:
+
+
+
# Calculate kernel density with a custom bandwidth value
+inputio = VectorFileIO(uri='/Users/mbertrand/dev/kitware/gaia-densitycomputations-plugin/tests/data/iraq_hospitals.geojson')
+kdp = KernelDensityProcess(inputs=[inputio], width=200, bandwidth=0.8)
+kdp.compute()
+print kdp.output.uri
+
+ +
+
+
+ +
+
+ + +
+
+
/Users/mbertrand/dev/kitware/gaia/tests/data/output/09c8a41b-71c7-4805-9f18-e084c6774933/09c8a41b-71c7-4805-9f18-e084c6774933.tif
+
+
+
+ +
+
+ +
+
+
+
In [9]:
+
+
+
# Display kernel density on map
+from folium.plugins import MarkerCluster
+
+world_map = folium.Map([34.00,43.00],
+                  zoom_start=6,
+                  tiles='cartodbpositron')
+
+hospitals = folium.features.GeoJson(inputio.read().to_json(), name='Hospitals')
+temparray = np.array(kdp.output.read().GetRasterBand(1).ReadAsArray())
+overlay = ImageOverlay(temparray, [[27.0466603,38.9358608],[40.3888093,50.8226656]], 
+                       colormap=lambda x: (1, 0, 0, x),
+                       mercator_project=True, control=True)
+overlay.layer_name = 'Kernel Density'
+
+world_map.add_children(overlay)
+world_map.add_children(hospitals)
+
+folium.LayerControl().add_to(world_map)
+world_map
+
+ +
+
+
+ +
+
+ + +
Out[9]:
+ +
+
+
+ +
+ +
+
+

diff --git a/docs/examples/gaia_processes.ipynb b/docs/examples/gaia_processes.ipynb index 317116c..1246742 100644 --- a/docs/examples/gaia_processes.ipynb +++ b/docs/examples/gaia_processes.ipynb @@ -25,10 +25,17 @@ "import folium\n", "import numpy as np\n", "from folium.plugins import ImageOverlay\n", - "from gaia_densitycomputations.processes import SimpleGridDensityProcess\n", + "from gaia_densitycomputations.processes import SimpleGridDensityProcess, KernelDensityProcess\n", "from gaia.geo.geo_inputs import VectorFileIO" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Simple Grid Density Process" + ] + }, { "cell_type": "markdown", "metadata": { @@ -49,14 +56,11 @@ "# Point dataset to calculate density of\n", "ports = VectorFileIO(uri='../../tests/data/ports_and_harbours.geojson')\n", "\n", - "# Grid resolution to use for density calculation\n", - "resolution = {\n", - " \"nCol\": 200,\n", - " \"nRow\": 100\n", - "}\n", + "# Grid width to use for density calculation\n", + "width=200\n", "\n", "# Create an instance of the Simple Density Process\n", - "sdp = SimpleGridDensityProcess(inputs = [ports], resolution=resolution)" + "sdp = SimpleGridDensityProcess(inputs = [ports], width=width)" ] }, { @@ -70,13 +74,22 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 7, "metadata": { "collapsed": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "/Users/mbertrand/dev/kitware/gaia/tests/data/output/c5fff097-ad3b-48e8-89c7-e641d6240e63/c5fff097-ad3b-48e8-89c7-e641d6240e63.tif\n" + ] + } + ], "source": [ - "sdp.compute()" + "sdp.compute()\n", + "print sdp.output.uri" ] }, { @@ -88,7 +101,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": { "collapsed": false }, @@ -96,13 +109,13 @@ { "data": { "text/html": [ - "
" + "
" ], "text/plain": [ - "" + "" ] }, - "execution_count": 5, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -113,7 +126,10 @@ " tiles='cartodbpositron')\n", "\n", "temparray = np.array(sdp.output.read().GetRasterBand(1).ReadAsArray())\n", - "overlay = ImageOverlay(temparray, [[-90.0,-180.0],[90.0,180.0]], mercator_project=True, control=True)\n", + "overlay = ImageOverlay(temparray, \n", + " [[-90.0,-180.0],[90.0,180.0]], \n", + " colormap=lambda x: (1, 0, 0, x),\n", + " mercator_project=True, control=True)\n", "overlay.layer_name = 'Port Density'\n", "\n", "world_map.add_children(overlay)\n", @@ -123,13 +139,145 @@ ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { "collapsed": true }, - "outputs": [], - "source": [] + "source": [ + "## Kernel Density Process" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "/Users/mbertrand/dev/kitware/gaia/tests/data/output/4b84bd47-12c2-4e96-9340-7b7cfb1a2ecc/4b84bd47-12c2-4e96-9340-7b7cfb1a2ecc.tif\n" + ] + } + ], + "source": [ + "# Calculate kernel density with default bandwidth estimator ('scott')\n", + "inputio = VectorFileIO(uri='/Users/mbertrand/dev/kitware/gaia-densitycomputations-plugin/tests/data/iraq_hospitals.geojson')\n", + "kdp = KernelDensityProcess(inputs=[inputio], width=200)\n", + "kdp.compute()\n", + "print kdp.output.uri" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Display kernel density on map\n", + "from folium.plugins import MarkerCluster\n", + "\n", + "world_map = folium.Map([34.00,43.00],\n", + " zoom_start=6,\n", + " tiles='cartodbpositron')\n", + "\n", + "hospitals = folium.features.GeoJson(inputio.read().to_json(), name='Hospitals')\n", + "temparray = np.array(kdp.output.read().GetRasterBand(1).ReadAsArray())\n", + "overlay = ImageOverlay(temparray, [[27.0466603,38.9358608],[40.3888093,50.8226656]], \n", + " colormap=lambda x: (1, 0, 0, x),\n", + " mercator_project=True, control=True)\n", + "overlay.layer_name = 'Kernel Density'\n", + "\n", + "world_map.add_children(overlay)\n", + "world_map.add_children(hospitals)\n", + "\n", + "folium.LayerControl().add_to(world_map)\n", + "world_map" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "/Users/mbertrand/dev/kitware/gaia/tests/data/output/09c8a41b-71c7-4805-9f18-e084c6774933/09c8a41b-71c7-4805-9f18-e084c6774933.tif\n" + ] + } + ], + "source": [ + "# Calculate kernel density with a custom bandwidth value\n", + "inputio = VectorFileIO(uri='/Users/mbertrand/dev/kitware/gaia-densitycomputations-plugin/tests/data/iraq_hospitals.geojson')\n", + "kdp = KernelDensityProcess(inputs=[inputio], width=200, bandwidth=0.8)\n", + "kdp.compute()\n", + "print kdp.output.uri" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Display kernel density on map\n", + "from folium.plugins import MarkerCluster\n", + "\n", + "world_map = folium.Map([34.00,43.00],\n", + " zoom_start=6,\n", + " tiles='cartodbpositron')\n", + "\n", + "hospitals = folium.features.GeoJson(inputio.read().to_json(), name='Hospitals')\n", + "temparray = np.array(kdp.output.read().GetRasterBand(1).ReadAsArray())\n", + "overlay = ImageOverlay(temparray, [[27.0466603,38.9358608],[40.3888093,50.8226656]], \n", + " colormap=lambda x: (1, 0, 0, x),\n", + " mercator_project=True, control=True)\n", + "overlay.layer_name = 'Kernel Density'\n", + "\n", + "world_map.add_children(overlay)\n", + "world_map.add_children(hospitals)\n", + "\n", + "folium.LayerControl().add_to(world_map)\n", + "world_map" + ] } ], "metadata": { diff --git a/docs/index.rst b/docs/index.rst index 85edd57..8bb8622 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -2,11 +2,37 @@ Gaia Density Computations Plugin ================================ This is a plugin for Gaia (https://github.com/OpenDataAnalytics/gaia) that -calculates the point density of a dataset given a raster grid of a specified size (in columns and rows). -The current implementation performs a simple calculation of adding the number of points within each grid cell. +calculates the point density of a dataset given a raster grid of a specified size (in columns and rows), +using one of the following processes: + * `SimpleDensityProcess `__ + + * Calculate point density by adding the number of points within each grid cell. + + * Required input: a vector dataset containing points + + * Optional arguments: + + * width: Width of output image in pixels (default=1024) + + * `Example `__ + + * `KernelDensityProcess `__ + + * Calculates point density using a Gaussian kernel density function. + + * Required input: a vector dataset containing points + + * Optional arguments: + + * width: Width of output image in pixels (default=1024) + + * weight: Column of vector dataset, with integer values. Points will be multiplied by this value. + + * bandwidth: The method used to calculate the kernel density estimator bandwidth. Valid values are 'scott' (default), 'silverman', or a numerical value. + + * `Example `__ -An example of how to use this plugin can be found `here `__. Installation ----------------- diff --git a/gaia_densitycomputations/processes.py b/gaia_densitycomputations/processes.py index df77b96..be73d4f 100644 --- a/gaia_densitycomputations/processes.py +++ b/gaia_densitycomputations/processes.py @@ -16,7 +16,6 @@ # See the License for the specific language governing permissions and # limitations under the License. ############################################################################## -from gaia import types import gaia.formats as formats import gdal @@ -24,17 +23,12 @@ import osr import ogr import numpy as np -import itertools -import geopandas import sys - -from gaia.inputs import GaiaIO +from scipy.stats import gaussian_kde +from gaia import types +from gaia.core import GaiaException from gaia.gaia_process import GaiaProcess -from gaia_densitycomputations import config -from gaia.geo.geo_inputs import RasterFileIO -from skimage.graph import route_through_array -import matplotlib.pyplot as plt -from math import sqrt, ceil +from gaia.geo.geo_inputs import RasterFileIO, VectorFileIO class SimpleGridDensityProcess(GaiaProcess): @@ -52,24 +46,24 @@ class SimpleGridDensityProcess(GaiaProcess): ] #: Required arguments, data types as dict - required_args = [ + optional_args = [ { - 'name': 'resolution', - 'title': 'Output image size', - 'description': 'Output image size (cols,rows), ex: "200,100"', - 'type': str + 'name': 'width', + 'title': 'Output image width', + 'description': 'Output image width in pixels', + 'type': int } ] default_output = formats.RASTER + width = 1024 - def __init__(self, resolution, **kwargs): + def __init__(self, **kwargs): """ Create an instance of the DensityComputationsProcess class :param resolution: grid cell resolution of the output :param kwargs: Optional keyword arguments """ - self.resolution = [int(n) for n in resolution.split(',')] super(SimpleGridDensityProcess, self).__init__(**kwargs) if not self.output: @@ -81,9 +75,11 @@ def calculate_density(self): within each grid cell. """ - shpDriver = ogr.GetDriverByName('GeoJSON') - strjson = self.inputs[0].read().to_json() - dataSource = shpDriver.Open(strjson, 0) + vec_driver = ogr.GetDriverByName('GeoJSON') + input = self.inputs[0] + strjson = input.read(format=formats.JSON) + crs = input.get_epsg() + dataSource = vec_driver.Open(strjson, 0) # Open the source file, and exit if doesn't exist if dataSource is None: @@ -91,36 +87,24 @@ def calculate_density(self): sys.exit(1) if os.path.exists(self.output.uri): - shpDriver.DeleteDataSource(self.output.uri) + vec_driver.DeleteDataSource(self.output.uri) else: self.output.create_output_dir(self.output.uri) # Get the layer layer = dataSource.GetLayer() - # Get the layer extent - extent = layer.GetExtent() - - # Open the layer - # Set the bounding box - xmin = extent[0] - ymin = extent[2] - xmax = extent[1] - ymax = extent[3] - - # Number of columns and rows - nbrColumns = self.resolution[0] - nbrRows = self.resolution[1] + gb = GridBounds(layer, width=self.width, crs=crs) # Caculate the cell size in x and y direction - csx = (xmax - xmin) / nbrColumns - csy = (ymax - ymin) / nbrRows + csx = (gb.xmax - gb.xmin) / self.width + csy = (gb.ymax - gb.ymin) / gb.height rows = [] - i = ymax - while i > ymin: - j = xmin + i = gb.ymax + while i > gb.ymin: + j = gb.xmin cols = [] - while j < xmax: + while j < gb.xmax: # Set a spatial filter layer.SetSpatialFilterRect(j, (i-csy), (j+csx), i) # And count the features @@ -133,8 +117,8 @@ def calculate_density(self): ncols = array.shape[1] nrows = array.shape[0] - originX = extent[0] - originY = extent[3] + originX = gb.xmin + originY = gb.ymin # Convert the results to geoTiff raster driver = gdal.GetDriverByName('GTiff') @@ -147,10 +131,7 @@ def calculate_density(self): outband = outRaster.GetRasterBand(1) # Add colors to the raster image outband.SetRasterColorInterpretation(gdal.GCI_PaletteIndex) - ct = gdal.ColorTable() - ct.CreateColorRamp(0, (0, 0, 255), 14, (0, 255, 0)) - ct.CreateColorRamp(15, (0, 255, 0), 30, (127, 127, 0)) - ct.CreateColorRamp(30, (127, 127, 0), 50, (255, 0, 0)) + ct = create_color_table(array.max()) outband.SetColorTable(ct) outband.SetNoDataValue(0) outband.FlushCache() @@ -170,6 +151,221 @@ def compute(self): """ self.calculate_density() + +class KernelDensityProcess(GaiaProcess): + + #: Tuple of required inputs; name, type , max # of each; None = no max + required_inputs = [ + {'description': 'Point dataset', + 'type': types.VECTOR, + 'max': 1 + } + ] + + optional_args = [ + { + 'description': + 'Weight attribute (attribute should have integer values)', + 'name': 'weight', + 'title': 'Weight', + 'type': str + }, + { + 'description': + 'Bandwidth estimator (scott, silverman, or a numeric value)', + 'name': 'bandwidth', + 'title': 'Bandwidth Estimator', + 'type': str + }, + { + 'description': + 'Width of output in pixels', + 'name': 'resolution', + 'title': 'Resolutionr', + 'type': int + } + ] + + bandwidth = 'scott' + width = 1024 + + default_output = formats.RASTER + + def __init__(self, **kwargs): + """ + Create an instance of the KernelDensityProcess class + """ + super(KernelDensityProcess, self).__init__(**kwargs) + + try: + self.bandwidth = float(self.bandwidth) + except ValueError: + if self.bandwidth not in ('scott', 'silverman'): + raise GaiaException('Invalid bandwidth') + + if not self.output: + self.output = RasterFileIO(name='result', uri=self.get_outpath()) + + def compute(self): + vec_driver = ogr.GetDriverByName('GeoJSON') + input = self.inputs[0] + strjson = input.read(format=formats.JSON) + crs = input.get_epsg() + data_source = vec_driver.Open(strjson, 0) + layer = data_source.GetLayer() + + # Buffer result to avoid edge effects + points = [] + for i in range(layer.GetFeatureCount()): + feature = layer.GetNextFeature() + geom = feature.GetGeometryRef() + weight = (1 if not hasattr(self, 'weight') else + feature.GetField(self.weight)) + for j in range(weight): + points.append((geom.GetX(), geom.GetY(), weight)) + + xtrain = np.vstack([[c[1] for c in points], + [c[0] for c in points]]).T + + # Set up the data grid for the contour plot + gb = GridBounds(layer, self.width, crs) + + xgrid, ygrid = construct_grids(gb.xres, gb.yres, + self.width, gb.height, + gb.xmin, gb.ymin) + x, y = np.meshgrid(xgrid, ygrid) + xy = np.vstack([y.ravel(), x.ravel()]).T + + kde = gaussian_kde(xtrain.T, bw_method=self.bandwidth) + density = kde(xy.T) + density = density.reshape(x.shape) + density = (density/(density.max()/255.0)).astype(np.int32) + + self.output.create_output_dir(self.output.uri) + driver = gdal.GetDriverByName('GTiff') + outDs = driver.Create(self.output.uri, density.shape[1], + density.shape[0], 1, gdal.GDT_UInt16) + outband = outDs.GetRasterBand(1) + # write the data + outband.WriteArray(density[::-1], 0, 0) + ct = create_color_table(int(density.max())) + outband.SetColorTable(ct) + outband.SetNoDataValue(0) + # # flush data to disk, set the NoData value and calculate stats + outband.FlushCache() + + gt = [gb.xmin, gb.xres, 0, gb.ymax, 0, -gb.yres] + outDs.SetGeoTransform(gt) + outDs.SetProjection(gb.projection.ExportToWkt()) + outDs.FlushCache() + del outDs + + +class GridBounds(object): + """ + Helper class to determine bounds and pixel height of a raster image, + based on the extent of a vector layer, specified pixel width, and + projection CRS. + """ + + xmin = -180.0 + xmax = 180.0 + ymin = -90.0 + ymax = 90.0 + xres = 1024 + yres = 1024 + projection = None + + def __init__(self, layer, width=1024, crs=4326): + """ + Initialize the object based on input parameters + :param layer: Vector layer + :param width: Desired width of output raster in pixels + :param crs: EPSG code of the layer + """ + self.projection = osr.SpatialReference() + self.projection.ImportFromEPSG(int(crs)) + unit = self.projection.GetAttrValue('Unit') + maxextent = [-180.0, 180.0, -90.0, 90.0] + + if unit != 'degree': + wg84source = osr.SpatialReference() + wg84source.ImportFromEPSG(4326) + + epsg = self.projection.GetAttrValue("AUTHORITY", 1) + if epsg in ('900913', '3857', '102100', '102113', '54004', '41001'): + maxextent = [-20037508.34, 20037508.34, + -20037508.34, 20037508.34] + else: + transform = osr.CoordinateTransformation(wg84source, + self.projection) + ul = ogr.CreateGeometryFromWkt("POINT (-180.0 90.0)") + lr = ogr.CreateGeometryFromWkt("POINT (180.0 -90.0)") + for point in (ul, lr): + point.Transform(transform) + maxextent = [ul.GetX(), lr.GetX(), ul.GetY(), lr.GetY()] + + extent = layer.GetExtent() + x_buffer = (extent[1]-extent[0])/2 + y_buffer = (extent[3]-extent[2])/2 + + # Set the bounding box + self.xmin = max(extent[0]-x_buffer, maxextent[0]) + self.ymin = max(extent[2]-y_buffer, maxextent[2]) + self.xmax = min(extent[1]+x_buffer, maxextent[1]) + self.ymax = min(extent[3]+y_buffer, maxextent[3]) + + self.xres = (self.xmax-self.xmin)/float(width) + self.height = int(round((self.ymax-self.ymin)/self.xres)) + self.yres = (self.ymax-self.ymin)/float(self.height) + + +def create_color_table(max, min=0, intervals=None): + """ + Create and return a color table. + :param max_value: Maximum value of raster grid + :param min_value: Optional minimum value (default=0) + :param intervals: Optional list of ColorRamp values as lists + :return: gdal.ColorTable + """ + ct = gdal.ColorTable() + if not intervals: + intvl = int(max/4) + ct.CreateColorRamp(min, (0, 0, 255), intvl-1, (0, 255, 0)) + ct.CreateColorRamp(intvl, (0, 255, 0), intvl*2-1, (127, 127, 0)) + ct.CreateColorRamp(intvl*2, (127, 127, 0), max, (255, 0, 0)) + else: + for i in intervals: + ct.CreateColorRamp(i[0], i[1], i[2], i[3]) + return ct + + +def construct_grids(xres, yres, columns, rows, minx, miny): + """ + Create a grid of coordinates + :param xres: Resolution of longitude columns + :param yres: Resolution of latitude rows + :param columns: Number of columns + :param rows: Number of rows + :param minx: Minimum X coordinate + :param miny: Minimum Y coordinate + :return: Grids of X and Y coordinate values + """ + # x,y coordinates for corner cells + xmin = minx + xres + xmax = xmin + (columns * xres) + ymin = miny + yres + ymax = ymin + (rows * yres) + + # x coordinates of the grid cells + xgrid = np.arange(xmin, xmax, xres) + # y coordinates of the grid cells + ygrid = np.arange(ymin, ymax, yres) + + return xgrid, ygrid + + PLUGIN_CLASS_EXPORTS = [ SimpleGridDensityProcess, + KernelDensityProcess ] diff --git a/requirements.txt b/requirements.txt index fe2b2e9..e9154af 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ -matplotlib==1.5.1 -scikit-image==0.12.3 +scipy==0.18.1 \ No newline at end of file diff --git a/tests/cases/test_parser.py b/tests/cases/test_parser.py index a41c171..c8c27e3 100644 --- a/tests/cases/test_parser.py +++ b/tests/cases/test_parser.py @@ -21,12 +21,7 @@ import gdal import unittest import numpy as np - -import pysal - -from gaia import formats from gaia.parser import deserialize -from gaia.core import config testfile_path = os.path.join(os.path.dirname( os.path.realpath(__file__)), '../data') @@ -60,3 +55,29 @@ def test_process_densitycomputations(self): finally: if process: process.purge() + + def test_process_kerneldensity(self): + """Test Density Computations Process""" + with open(os.path.join(testfile_path, + 'kerneldensity.json')) as inf: + body_text = inf.read().replace('{basepath}', testfile_path) + process = json.loads(body_text, object_hook=deserialize) + try: + process.compute() + expected_layer = process.output.read() + # Get layer stats + expected_results = \ + expected_layer.GetRasterBand(1).GetStatistics(0, 1) + + actual_layer = gdal.Open(os.path.join( + testfile_path, + 'kerneldensity_process_results.tif'), gdal.GA_Update) + actual_results = actual_layer.GetRasterBand(1).GetStatistics(0, 1) + + expected_results_rounded = np.around(expected_results, decimals=2) + actual_results_rounded = np.around(actual_results, decimals=2) + self.assertEquals(np.all(expected_results_rounded), + np.all(actual_results_rounded)) + finally: + if process: + process.purge() diff --git a/tests/cases/test_processors.py b/tests/cases/test_processors.py index 807b972..00bbb67 100644 --- a/tests/cases/test_processors.py +++ b/tests/cases/test_processors.py @@ -16,15 +16,14 @@ # See the License for the specific language governing permissions and # limitations under the License. ############################################################################### -import json + import os import unittest -import pysal import gdal import numpy as np -from gaia import formats -from gaia.geo.geo_inputs import RasterFileIO, VectorFileIO -from gaia_densitycomputations.processes import SimpleGridDensityProcess +from gaia.geo.geo_inputs import VectorFileIO +from gaia_densitycomputations.processes import SimpleGridDensityProcess, \ + KernelDensityProcess testfile_path = os.path.join(os.path.dirname( os.path.realpath(__file__)), '../data') @@ -64,3 +63,32 @@ def test_process_densitycomputations(self): finally: if process: process.purge() + + def test_process_kerneldensity(self): + """ + Test KernelDensityProcess for raster inputs + """ + + uri = os.path.join(testfile_path, 'iraq_hospitals.geojson') + points = VectorFileIO(uri) + process = KernelDensityProcess(inputs=[points]) + try: + process.compute() + expected_layer = process.output.read() + # Get layer stats + expected_results = \ + expected_layer.GetRasterBand(1).GetStatistics(0, 1) + + actual_layer = gdal.Open(os.path.join( + testfile_path, + 'kerneldensity_process_results.tif'), + gdal.GA_Update) + actual_results = actual_layer.GetRasterBand(1).GetStatistics(0, 1) + + expected_results_rounded = np.around(expected_results, decimals=2) + actual_results_rounded = np.around(actual_results, decimals=2) + self.assertEquals(np.all(expected_results_rounded), + np.all(actual_results_rounded)) + finally: + if process: + process.purge() diff --git a/tests/data/densitycomputations.json b/tests/data/densitycomputations.json index 6cc1aa2..5c30c1d 100644 --- a/tests/data/densitycomputations.json +++ b/tests/data/densitycomputations.json @@ -6,5 +6,5 @@ "uri": "tests/data/ports_and_harbours.geojson" } ], - "resolution": "200,100" + "width": 200 } diff --git a/tests/data/densitycomputations_process_results.tif b/tests/data/densitycomputations_process_results.tif index 20f02f4..883349a 100644 Binary files a/tests/data/densitycomputations_process_results.tif and b/tests/data/densitycomputations_process_results.tif differ diff --git a/tests/data/iraq_hospitals.geojson b/tests/data/iraq_hospitals.geojson new file mode 100644 index 0000000..e78a66b --- /dev/null +++ b/tests/data/iraq_hospitals.geojson @@ -0,0 +1 @@ +{"type":"FeatureCollection","totalFeatures":86,"features":[{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7748","geometry":{"type":"Point","coordinates":[44.3781274,33.3451792]},"geometry_name":"the_geom","properties":{"fid":28,"osm_id":"94298797","timestamp":"2012-07-20T11:15:39Z","name":"جامعة بغداد -- كلية الطب آل","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7747","geometry":{"type":"Point","coordinates":[43.1142917,36.3579936]},"geometry_name":"the_geom","properties":{"fid":32,"osm_id":"100530934","timestamp":"2008-05-16T10:49:22Z","name":"المستشفى الجمهوري","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7746","geometry":{"type":"Point","coordinates":[43.1683962,36.3834541]},"geometry_name":"the_geom","properties":{"fid":39,"osm_id":"256791649","timestamp":"2008-04-26T21:15:25Z","name":"مستشفى الخنساء","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7745","geometry":{"type":"Point","coordinates":[44.3815083,32.0206296]},"geometry_name":"the_geom","properties":{"fid":58,"osm_id":"502313229","timestamp":"2009-09-19T19:43:15Z","name":"","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7744","geometry":{"type":"Point","coordinates":[47.7835659,30.5336591]},"geometry_name":"the_geom","properties":{"fid":82,"osm_id":"608621375","timestamp":"2015-05-02T07:51:46Z","name":"مستشفى الفيحاء العام","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7743","geometry":{"type":"Point","coordinates":[47.8058282,30.4923797]},"geometry_name":"the_geom","properties":{"fid":83,"osm_id":"608621377","timestamp":"2010-01-07T21:23:11Z","name":"","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7742","geometry":{"type":"Point","coordinates":[45.3394547,35.5775699]},"geometry_name":"the_geom","properties":{"fid":103,"osm_id":"837190806","timestamp":"2010-07-29T07:58:56Z","name":"Rapareen Hospital","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7741","geometry":{"type":"Point","coordinates":[43.0040201,36.8492443]},"geometry_name":"the_geom","properties":{"fid":109,"osm_id":"876891225","timestamp":"2010-10-07T06:24:43Z","name":"Azadi Hospital","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7740","geometry":{"type":"Point","coordinates":[47.8509644,30.5071881]},"geometry_name":"the_geom","properties":{"fid":149,"osm_id":"985237288","timestamp":"2010-11-11T22:29:05Z","name":"المشفى التعليمي","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-773f","geometry":{"type":"Point","coordinates":[44.3253978,33.3764162]},"geometry_name":"the_geom","properties":{"fid":165,"osm_id":"997416381","timestamp":"2010-11-21T05:22:05Z","name":"","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-773e","geometry":{"type":"Point","coordinates":[44.3243249,33.377993]},"geometry_name":"the_geom","properties":{"fid":166,"osm_id":"997416382","timestamp":"2010-11-21T05:22:06Z","name":"","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-773d","geometry":{"type":"Point","coordinates":[41.9172609,34.464534]},"geometry_name":"the_geom","properties":{"fid":184,"osm_id":"1037834419","timestamp":"2010-12-13T22:47:53Z","name":"rawar","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-773c","geometry":{"type":"Point","coordinates":[41.9253465,34.4852965]},"geometry_name":"the_geom","properties":{"fid":187,"osm_id":"1037840450","timestamp":"2010-12-14T02:38:25Z","name":"dentist Dr.khalid","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-773b","geometry":{"type":"Point","coordinates":[41.907562,34.4883431]},"geometry_name":"the_geom","properties":{"fid":188,"osm_id":"1037841348","timestamp":"2010-12-13T22:51:24Z","name":"alqadsya","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-773a","geometry":{"type":"Point","coordinates":[44.3562015,33.2550027]},"geometry_name":"the_geom","properties":{"fid":189,"osm_id":"1037908152","timestamp":"2010-12-13T23:42:52Z","name":"dental clinic dr.nadir","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7739","geometry":{"type":"Point","coordinates":[41.984913,34.3718815]},"geometry_name":"the_geom","properties":{"fid":191,"osm_id":"1037964461","timestamp":"2010-12-14T02:20:10Z","name":"anah","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7738","geometry":{"type":"Point","coordinates":[44.0397526,36.1916917]},"geometry_name":"the_geom","properties":{"fid":192,"osm_id":"1045223122","timestamp":"2012-07-19T10:01:30Z","name":"Rizgary","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7737","geometry":{"type":"Point","coordinates":[44.0207785,36.1994]},"geometry_name":"the_geom","properties":{"fid":193,"osm_id":"1045228779","timestamp":"2014-09-16T14:33:51Z","name":"Hawler","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7736","geometry":{"type":"Point","coordinates":[44.3602695,33.3171287]},"geometry_name":"the_geom","properties":{"fid":215,"osm_id":"1167754844","timestamp":"2011-02-23T08:12:29Z","name":"Iraqi Red Crescent Hospital","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7735","geometry":{"type":"Point","coordinates":[44.0172282,36.1982019]},"geometry_name":"the_geom","properties":{"fid":221,"osm_id":"1199433528","timestamp":"2011-03-12T23:03:59Z","name":"Emergency","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7734","geometry":{"type":"Point","coordinates":[44.432297,33.3189412]},"geometry_name":"the_geom","properties":{"fid":226,"osm_id":"1233005627","timestamp":"2011-04-04T21:49:12Z","name":"Al-Wasiti Hospital for Corrective Surgery","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7733","geometry":{"type":"Point","coordinates":[44.4329622,33.3194791]},"geometry_name":"the_geom","properties":{"fid":228,"osm_id":"1233035915","timestamp":"2011-04-04T21:49:11Z","name":"Al-Elwya Hospital For Gyn/Obs","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7732","geometry":{"type":"Point","coordinates":[44.4292213,33.3170749]},"geometry_name":"the_geom","properties":{"fid":241,"osm_id":"1241932179","timestamp":"2014-06-28T21:39:42Z","name":"Nuclear Medicine Hospital","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7731","geometry":{"type":"Point","coordinates":[44.428127,33.3182942]},"geometry_name":"the_geom","properties":{"fid":246,"osm_id":"1241932190","timestamp":"2011-04-12T12:14:13Z","name":"Ibn Al-Nafees Cardiology Hospital","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7730","geometry":{"type":"Point","coordinates":[44.4285336,33.3164293]},"geometry_name":"the_geom","properties":{"fid":247,"osm_id":"1241932192","timestamp":"2011-04-12T12:14:13Z","name":"Al-Sheekh Zayed Hospital","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-772f","geometry":{"type":"Point","coordinates":[44.4281061,32.4877799]},"geometry_name":"the_geom","properties":{"fid":314,"osm_id":"1455362332","timestamp":"2011-10-04T21:02:23Z","name":"صيدلية دار الحياة","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-772e","geometry":{"type":"Point","coordinates":[44.4097834,32.4694609]},"geometry_name":"the_geom","properties":{"fid":367,"osm_id":"1821569533","timestamp":"2012-07-11T15:46:02Z","name":"مستشفى الإمام الصادق التع","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-772d","geometry":{"type":"Point","coordinates":[44.4104137,32.4696962]},"geometry_name":"the_geom","properties":{"fid":368,"osm_id":"1821569724","timestamp":"2012-07-11T15:46:53Z","name":"مستشفى الفيحاء الأهلي","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-772c","geometry":{"type":"Point","coordinates":[44.4214656,32.4697296]},"geometry_name":"the_geom","properties":{"fid":373,"osm_id":"1838398273","timestamp":"2012-07-26T05:55:54Z","name":"","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-772b","geometry":{"type":"Point","coordinates":[44.3231739,33.2351689]},"geometry_name":"the_geom","properties":{"fid":396,"osm_id":"1966367994","timestamp":"2013-11-10T18:06:55Z","name":"Un Building","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-772a","geometry":{"type":"Point","coordinates":[42.9644218,36.8706787]},"geometry_name":"the_geom","properties":{"fid":416,"osm_id":"2033097498","timestamp":"2012-11-25T21:38:20Z","name":"","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7729","geometry":{"type":"Point","coordinates":[42.9560104,36.8693741]},"geometry_name":"the_geom","properties":{"fid":417,"osm_id":"2033097504","timestamp":"2012-11-25T21:38:20Z","name":"","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7728","geometry":{"type":"Point","coordinates":[43.9688724,36.1606675]},"geometry_name":"the_geom","properties":{"fid":468,"osm_id":"2100576314","timestamp":"2013-01-07T21:44:32Z","name":"Erbil Emergency Hospital","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7727","geometry":{"type":"Point","coordinates":[44.3435245,33.377348]},"geometry_name":"the_geom","properties":{"fid":490,"osm_id":"2202187518","timestamp":"2013-03-14T19:47:59Z","name":"Al Kazimiyah Pediatric","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7726","geometry":{"type":"Point","coordinates":[44.3412454,33.3747162]},"geometry_name":"the_geom","properties":{"fid":491,"osm_id":"2202187519","timestamp":"2013-03-14T19:47:59Z","name":"Al Kazimiyah","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7725","geometry":{"type":"Point","coordinates":[44.3796559,33.3627109]},"geometry_name":"the_geom","properties":{"fid":492,"osm_id":"2202187574","timestamp":"2013-03-14T19:48:01Z","name":"","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7724","geometry":{"type":"Point","coordinates":[45.9099282,32.4809]},"geometry_name":"the_geom","properties":{"fid":494,"osm_id":"2262959131","timestamp":"2013-04-11T16:53:32Z","name":"المركز الصحي الوافدين","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7723","geometry":{"type":"Point","coordinates":[46.0781043,32.4555228]},"geometry_name":"the_geom","properties":{"fid":501,"osm_id":"2263244322","timestamp":"2013-04-11T20:21:22Z","name":"المركز الصحي عبد الله بن ر","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7722","geometry":{"type":"Point","coordinates":[43.6495399,37.053272]},"geometry_name":"the_geom","properties":{"fid":546,"osm_id":"2375736733","timestamp":"2013-10-03T23:47:33Z","name":"NEXWEŞ XANE","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7721","geometry":{"type":"Point","coordinates":[45.3273526,34.6233469]},"geometry_name":"the_geom","properties":{"fid":559,"osm_id":"2389819224","timestamp":"2013-07-19T16:16:15Z","name":"Kalar Public Hospital","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7720","geometry":{"type":"Point","coordinates":[45.3105159,34.6323429]},"geometry_name":"the_geom","properties":{"fid":599,"osm_id":"2469054640","timestamp":"2013-09-23T17:54:08Z","name":"نەخۆشخانەی شێرەی نەقیب","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-771f","geometry":{"type":"Point","coordinates":[44.554191,32.362527]},"geometry_name":"the_geom","properties":{"fid":637,"osm_id":"2479346329","timestamp":"2013-10-01T18:58:53Z","name":"مستوصف البصيرة","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-771e","geometry":{"type":"Point","coordinates":[43.983834,32.634116]},"geometry_name":"the_geom","properties":{"fid":651,"osm_id":"2480072096","timestamp":"2013-10-02T13:34:19Z","name":"المستشفى البيطري","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-771d","geometry":{"type":"Point","coordinates":[44.5115,33.224142]},"geometry_name":"the_geom","properties":{"fid":733,"osm_id":"2482526804","timestamp":"2013-10-04T16:16:20Z","name":"مستشفى التويثة","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-771c","geometry":{"type":"Point","coordinates":[44.409175,33.193542]},"geometry_name":"the_geom","properties":{"fid":765,"osm_id":"2483921998","timestamp":"2013-10-05T17:35:40Z","name":"مستوصف فاضل حسن","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-771b","geometry":{"type":"Point","coordinates":[44.461938,33.282012]},"geometry_name":"the_geom","properties":{"fid":766,"osm_id":"2483942501","timestamp":"2013-10-05T17:41:52Z","name":"مستشفى الرشيد","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-771a","geometry":{"type":"Point","coordinates":[43.081054,33.46044]},"geometry_name":"the_geom","properties":{"fid":849,"osm_id":"2485147264","timestamp":"2013-10-06T15:44:11Z","name":"مستوصف القرية العصرية","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7719","geometry":{"type":"Point","coordinates":[43.4698571,33.4673838]},"geometry_name":"the_geom","properties":{"fid":876,"osm_id":"2485156331","timestamp":"2015-07-10T09:24:24Z","name":"مركز الصحي علي الفارس","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7718","geometry":{"type":"Point","coordinates":[44.80662,32.40599]},"geometry_name":"the_geom","properties":{"fid":920,"osm_id":"2485228060","timestamp":"2013-10-06T16:26:35Z","name":"مستوصف أبو هرطمان","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7717","geometry":{"type":"Point","coordinates":[44.629664,32.030246]},"geometry_name":"the_geom","properties":{"fid":1090,"osm_id":"2485433819","timestamp":"2013-10-06T18:41:04Z","name":"مستوصف الطحينية","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7716","geometry":{"type":"Point","coordinates":[44.583708,32.011855]},"geometry_name":"the_geom","properties":{"fid":1150,"osm_id":"2485457661","timestamp":"2013-10-06T18:59:36Z","name":"مستوصف الحجازية","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7715","geometry":{"type":"Point","coordinates":[44.623489,32.085525]},"geometry_name":"the_geom","properties":{"fid":1151,"osm_id":"2485457666","timestamp":"2013-10-06T18:59:37Z","name":"مستوصف الصليجية الجمهوري","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7714","geometry":{"type":"Point","coordinates":[44.581917,31.95226]},"geometry_name":"the_geom","properties":{"fid":1152,"osm_id":"2485461729","timestamp":"2013-10-06T19:01:19Z","name":"مستشفى الشامية","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7713","geometry":{"type":"Point","coordinates":[44.4520872,33.0446912]},"geometry_name":"the_geom","properties":{"fid":1217,"osm_id":"2486242587","timestamp":"2013-10-07T11:03:33Z","name":"عيادة عبد الله","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7712","geometry":{"type":"Point","coordinates":[44.4521394,33.0440198]},"geometry_name":"the_geom","properties":{"fid":1218,"osm_id":"2486242794","timestamp":"2013-10-07T11:03:37Z","name":"عياده عبد الله","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7711","geometry":{"type":"Point","coordinates":[43.724029,33.354226]},"geometry_name":"the_geom","properties":{"fid":1245,"osm_id":"2486321852","timestamp":"2013-10-07T11:58:34Z","name":"مستشفى الفلوجة","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7710","geometry":{"type":"Point","coordinates":[44.612811,33.716646]},"geometry_name":"the_geom","properties":{"fid":1281,"osm_id":"2486359355","timestamp":"2013-10-07T12:40:26Z","name":"مستشفى الأمراض الصدرية","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-770f","geometry":{"type":"Point","coordinates":[44.680566,31.630252]},"geometry_name":"the_geom","properties":{"fid":1350,"osm_id":"2487770798","timestamp":"2013-10-08T09:31:13Z","name":"مستوصف الهرد","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-770e","geometry":{"type":"Point","coordinates":[44.37203,32.019643]},"geometry_name":"the_geom","properties":{"fid":1351,"osm_id":"2487775263","timestamp":"2013-10-08T09:35:55Z","name":"مستشفى قادسية صدام","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-770d","geometry":{"type":"Point","coordinates":[47.018726,31.858091]},"geometry_name":"the_geom","properties":{"fid":1364,"osm_id":"2487813613","timestamp":"2013-10-08T10:05:38Z","name":"مستشفى الجذام","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-770c","geometry":{"type":"Point","coordinates":[46.789559,30.930143]},"geometry_name":"the_geom","properties":{"fid":1409,"osm_id":"2487948212","timestamp":"2013-10-08T11:51:11Z","name":"عيادة حاج فلويحي","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-770b","geometry":{"type":"Point","coordinates":[45.401477,32.466164]},"geometry_name":"the_geom","properties":{"fid":1442,"osm_id":"2488025482","timestamp":"2013-10-08T12:44:42Z","name":"مستوصف العوينة","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-770a","geometry":{"type":"Point","coordinates":[43.1895016,36.3215663]},"geometry_name":"the_geom","properties":{"fid":1478,"osm_id":"2488247027","timestamp":"2013-10-08T15:29:02Z","name":"مستشفى صدام العام","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7709","geometry":{"type":"Point","coordinates":[43.112612,36.359156]},"geometry_name":"the_geom","properties":{"fid":1479,"osm_id":"2488247028","timestamp":"2013-10-08T15:29:02Z","name":"مستشفى الموصل العام","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7708","geometry":{"type":"Point","coordinates":[43.1892838,36.3212077]},"geometry_name":"the_geom","properties":{"fid":1480,"osm_id":"2488247029","timestamp":"2013-10-08T15:29:02Z","name":"مستشفى الموصل","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7707","geometry":{"type":"Point","coordinates":[43.166785,36.3873243]},"geometry_name":"the_geom","properties":{"fid":1481,"osm_id":"2488247030","timestamp":"2014-10-13T15:35:20Z","name":"مستشفى الولادة","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7706","geometry":{"type":"Point","coordinates":[43.113233,36.488222]},"geometry_name":"the_geom","properties":{"fid":1482,"osm_id":"2488247031","timestamp":"2013-10-08T15:29:02Z","name":"مستوصف الصحة الحيوانية","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7705","geometry":{"type":"Point","coordinates":[43.989223,34.635789]},"geometry_name":"the_geom","properties":{"fid":1505,"osm_id":"2488441737","timestamp":"2013-10-08T17:55:28Z","name":"عيادة العمار","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7704","geometry":{"type":"Point","coordinates":[44.936919,33.900216]},"geometry_name":"the_geom","properties":{"fid":1526,"osm_id":"2488507067","timestamp":"2013-10-08T18:28:55Z","name":"المركز الصحي في الحميدية","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7703","geometry":{"type":"Point","coordinates":[45.0627309,34.0903856]},"geometry_name":"the_geom","properties":{"fid":1573,"osm_id":"2489330417","timestamp":"2013-10-09T11:59:55Z","name":"مستوصف مجمع حمرين","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7702","geometry":{"type":"Point","coordinates":[45.0626686,34.0901663]},"geometry_name":"the_geom","properties":{"fid":1577,"osm_id":"2489330493","timestamp":"2013-10-09T12:00:03Z","name":"مستوصف جمع حمرين","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7701","geometry":{"type":"Point","coordinates":[43.0014827,36.8538275]},"geometry_name":"the_geom","properties":{"fid":1667,"osm_id":"2549370821","timestamp":"2013-11-24T19:16:50Z","name":"Vajeen Private Hospital","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-7700","geometry":{"type":"Point","coordinates":[44.3723374,33.3697086]},"geometry_name":"the_geom","properties":{"fid":1748,"osm_id":"2619332724","timestamp":"2014-08-23T08:23:18Z","name":"Dijla Hospital مستشفى دجلة","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-76ff","geometry":{"type":"Point","coordinates":[44.0357082,36.1932782]},"geometry_name":"the_geom","properties":{"fid":1791,"osm_id":"2818047479","timestamp":"2014-04-26T14:15:00Z","name":"","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-76fe","geometry":{"type":"Point","coordinates":[44.4295576,33.3132313]},"geometry_name":"the_geom","properties":{"fid":1923,"osm_id":"2938103075","timestamp":"2014-06-28T21:41:21Z","name":"Ibn Al Haitham Teaching Eye Hospital","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-76fd","geometry":{"type":"Point","coordinates":[44.4304459,33.3127593]},"geometry_name":"the_geom","properties":{"fid":1924,"osm_id":"2938108044","timestamp":"2014-06-28T21:43:04Z","name":"Dr Ammar Clinic-Paradise Center","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-76fc","geometry":{"type":"Point","coordinates":[47.6516962,30.4742806]},"geometry_name":"the_geom","properties":{"fid":1974,"osm_id":"2950594031","timestamp":"2014-07-06T10:53:27Z","name":"المركز الأولي الصحي في الش","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-76fb","geometry":{"type":"Point","coordinates":[46.2251847,32.4003119]},"geometry_name":"the_geom","properties":{"fid":2142,"osm_id":"3077175166","timestamp":"2014-09-14T18:06:27Z","name":"المركز الصحي عمار بن ياسر","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-76fa","geometry":{"type":"Point","coordinates":[46.1163624,32.124684]},"geometry_name":"the_geom","properties":{"fid":2150,"osm_id":"3086007866","timestamp":"2014-09-19T12:10:09Z","name":"المركز الصحي البشائر","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-76f9","geometry":{"type":"Point","coordinates":[45.9173355,31.9855037]},"geometry_name":"the_geom","properties":{"fid":2151,"osm_id":"3086011806","timestamp":"2014-09-19T12:13:16Z","name":"المركز الصحي الرسالة","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-76f8","geometry":{"type":"Point","coordinates":[45.9475332,32.370189]},"geometry_name":"the_geom","properties":{"fid":2152,"osm_id":"3086015904","timestamp":"2014-09-19T12:18:03Z","name":"المركز الصحي الطويسات","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-76f7","geometry":{"type":"Point","coordinates":[45.604258,32.5220083]},"geometry_name":"the_geom","properties":{"fid":2153,"osm_id":"3086030274","timestamp":"2014-09-19T12:28:26Z","name":"المركز الصحي الاحرار","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-76f6","geometry":{"type":"Point","coordinates":[44.5589689,36.6370025]},"geometry_name":"the_geom","properties":{"fid":2365,"osm_id":"3351632338","timestamp":"2015-04-25T14:47:15Z","name":"gynocology and obestetric hospital","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-76f5","geometry":{"type":"Point","coordinates":[44.0443627,36.1946023]},"geometry_name":"the_geom","properties":{"fid":2395,"osm_id":"3368090884","timestamp":"2015-02-23T13:29:56Z","name":"Zheen International Hospital","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-76f4","geometry":{"type":"Point","coordinates":[47.7822413,30.552106]},"geometry_name":"the_geom","properties":{"fid":2465,"osm_id":"3492822406","timestamp":"2015-05-02T08:04:08Z","name":"مستشفى الموانئ العام","type":"hospital"}},{"type":"Feature","id":"iraq_hospitals.fid-76c404c7_15254deab67_-76f3","geometry":{"type":"Point","coordinates":[47.7072786,30.3821975]},"geometry_name":"the_geom","properties":{"fid":2473,"osm_id":"3495004297","timestamp":"2015-05-03T12:49:43Z","name":"مستشفى الزبير العام","type":"hospital"}}],"crs":{"type":"EPSG","properties":{"code":"4326"}}} \ No newline at end of file diff --git a/tests/data/kerneldensity.json b/tests/data/kerneldensity.json new file mode 100644 index 0000000..b60fb34 --- /dev/null +++ b/tests/data/kerneldensity.json @@ -0,0 +1,10 @@ +{ + "_type": "gaia_densitycomputations.processes.KernelDensityProcess", + "inputs": [ + { + "_type": "gaia.geo.geo_inputs.VectorFileIO", + "uri": "tests/data/iraq_hospitals.geojson" + } + ], + "width": 200 +} diff --git a/tests/data/kerneldensity_process_results.tif b/tests/data/kerneldensity_process_results.tif new file mode 100644 index 0000000..9e81e44 Binary files /dev/null and b/tests/data/kerneldensity_process_results.tif differ