libadalina-core 1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- libadalina_core-1.0/.gitignore +1 -0
- libadalina_core-1.0/.gitlab-ci.yml +15 -0
- libadalina_core-1.0/.gitmodules +3 -0
- libadalina_core-1.0/LICENSE +21 -0
- libadalina_core-1.0/MANIFEST.in +3 -0
- libadalina_core-1.0/PKG-INFO +67 -0
- libadalina_core-1.0/README.md +39 -0
- libadalina_core-1.0/build.sh +6 -0
- libadalina_core-1.0/docs/Makefile +20 -0
- libadalina_core-1.0/docs/build/.gitignore +1 -0
- libadalina_core-1.0/docs/make.bat +35 -0
- libadalina_core-1.0/docs/source/conf.py +66 -0
- libadalina_core-1.0/docs/source/examples/hospitals_in_provinces.rst +25 -0
- libadalina_core-1.0/docs/source/examples/index.rst +11 -0
- libadalina_core-1.0/docs/source/examples/population_in_provinces.rst +26 -0
- libadalina_core-1.0/docs/source/examples/population_served_by_hospitals.rst +29 -0
- libadalina_core-1.0/docs/source/index.rst +54 -0
- libadalina_core-1.0/docs/source/modules/index.rst +13 -0
- libadalina_core-1.0/docs/source/modules/readers.rst +9 -0
- libadalina_core-1.0/docs/source/modules/sedona_configuration.rst +17 -0
- libadalina_core-1.0/docs/source/modules/sedona_utils.rst +20 -0
- libadalina_core-1.0/docs/source/modules/spatial_join.rst +9 -0
- libadalina_core-1.0/docs/source/modules/writers.rst +9 -0
- libadalina_core-1.0/libadalina_core/__init__.py +0 -0
- libadalina_core-1.0/libadalina_core/examples/example_hospitals_in_provinces.py +46 -0
- libadalina_core-1.0/libadalina_core/examples/example_population_in_provinces.py +42 -0
- libadalina_core-1.0/libadalina_core/examples/example_population_served_by_hospitals.py +59 -0
- libadalina_core-1.0/libadalina_core/readers/__init__.py +0 -0
- libadalina_core-1.0/libadalina_core/readers/readers.py +18 -0
- libadalina_core-1.0/libadalina_core/sedona_configuration/__init__.py +0 -0
- libadalina_core-1.0/libadalina_core/sedona_configuration/jdk_installer.py +22 -0
- libadalina_core-1.0/libadalina_core/sedona_configuration/sedona_configuration.py +104 -0
- libadalina_core-1.0/libadalina_core/sedona_utils/__init__.py +0 -0
- libadalina_core-1.0/libadalina_core/sedona_utils/coordinate_formats.py +22 -0
- libadalina_core-1.0/libadalina_core/sedona_utils/utils.py +27 -0
- libadalina_core-1.0/libadalina_core/spatial_join/__init__.py +0 -0
- libadalina_core-1.0/libadalina_core/spatial_join/query_builder.py +147 -0
- libadalina_core-1.0/libadalina_core/writers/__init__.py +0 -0
- libadalina_core-1.0/libadalina_core/writers/writers.py +22 -0
- libadalina_core-1.0/libadalina_core.egg-info/PKG-INFO +67 -0
- libadalina_core-1.0/libadalina_core.egg-info/SOURCES.txt +50 -0
- libadalina_core-1.0/libadalina_core.egg-info/dependency_links.txt +1 -0
- libadalina_core-1.0/libadalina_core.egg-info/entry_points.txt +2 -0
- libadalina_core-1.0/libadalina_core.egg-info/requires.txt +13 -0
- libadalina_core-1.0/libadalina_core.egg-info/top_level.txt +1 -0
- libadalina_core-1.0/pyproject.toml +50 -0
- libadalina_core-1.0/requirements.dev.txt +5 -0
- libadalina_core-1.0/requirements.txt +6 -0
- libadalina_core-1.0/setup.cfg +4 -0
- libadalina_core-1.0/tests/__init__.py +0 -0
- libadalina_core-1.0/tests/test_polygonize.py +1 -0
- libadalina_core-1.0/tests/test_readers.py +20 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.idea
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# The Docker image that will be used to build your app
|
|
2
|
+
image: python:3.10-alpine
|
|
3
|
+
create-pages:
|
|
4
|
+
pages:
|
|
5
|
+
# The folder that contains the files to be exposed at the Page URL
|
|
6
|
+
publish: public
|
|
7
|
+
rules:
|
|
8
|
+
# This ensures that only pushes to the default branch will trigger
|
|
9
|
+
# a pages deploy
|
|
10
|
+
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
|
|
11
|
+
# Functions that should be executed before the build script is run
|
|
12
|
+
before_script: []
|
|
13
|
+
script:
|
|
14
|
+
- pip install sphinx==7.4.6 pydata-sphinx-theme==0.16.0
|
|
15
|
+
- sphinx-build -b html docs/source public
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 University of Milan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: libadalina-core
|
|
3
|
+
Version: 1.0
|
|
4
|
+
Summary: A library for spatial joins of geographic data
|
|
5
|
+
Author-email: Marco Casazza <d.marcocasazza@gmail.com>, Alberto Ceselli <alberto.ceselli@unimi.it>, Marco Premoli <marco.premoli@unimi.it>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://gitlab.com/amelia_unimi/libadalina
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Requires-Python: ~=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: apache-sedona[spark]==1.7.1
|
|
16
|
+
Requires-Dist: pyspark==3.3.2
|
|
17
|
+
Requires-Dist: pandas==2.2.3
|
|
18
|
+
Requires-Dist: geopandas==1.0.1
|
|
19
|
+
Requires-Dist: shapely==2.1.1
|
|
20
|
+
Requires-Dist: install-jdk==1.1.0
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest==8.4.1; extra == "dev"
|
|
23
|
+
Requires-Dist: black; extra == "dev"
|
|
24
|
+
Requires-Dist: isort; extra == "dev"
|
|
25
|
+
Requires-Dist: sphinx; extra == "dev"
|
|
26
|
+
Requires-Dist: pydata-sphinx-theme; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# libadalina-core
|
|
30
|
+
|
|
31
|
+
A Python library for spatial data processing.
|
|
32
|
+
It makes it easier to work with geospatial data in Python by providing a high-level interface
|
|
33
|
+
to Apache Sedona, a powerful geospatial processing engine, and integrates nicely with other well-known libraries
|
|
34
|
+
such as *geopandas* and *pandas*.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
liabadalina-core can be installed using pip:
|
|
39
|
+
```
|
|
40
|
+
pip install libadalina-core
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
If `JAVA_HOME` environment variable is not set a suitable JDK will be downloaded in `$HOME/.jre` and used automatically.
|
|
44
|
+
Not all JRE are supported, so if you encounter issues, you can try the automatically installed version.
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
You can find the documentation and example at [libadalina-core documentation](https://libadalinacore-6b2a95.gitlab.io/).
|
|
49
|
+
|
|
50
|
+
## Features
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
* Reading and writing geospatial data from various formats
|
|
54
|
+
* Spatial joins between datasets
|
|
55
|
+
* Spatial aggregations
|
|
56
|
+
* Utilities for working with Apache Sedona
|
|
57
|
+
* Configuration helpers for setting up Apache Sedona
|
|
58
|
+
|
|
59
|
+
## Requirements
|
|
60
|
+
|
|
61
|
+
- Python 3.10
|
|
62
|
+
- Dependencies:
|
|
63
|
+
- apache-sedona[spark]
|
|
64
|
+
- pyspark
|
|
65
|
+
- pandas
|
|
66
|
+
- geopandas
|
|
67
|
+
- install-jdk
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# libadalina-core
|
|
2
|
+
|
|
3
|
+
A Python library for spatial data processing.
|
|
4
|
+
It makes it easier to work with geospatial data in Python by providing a high-level interface
|
|
5
|
+
to Apache Sedona, a powerful geospatial processing engine, and integrates nicely with other well-known libraries
|
|
6
|
+
such as *geopandas* and *pandas*.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
liabadalina-core can be installed using pip:
|
|
11
|
+
```
|
|
12
|
+
pip install libadalina-core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
If `JAVA_HOME` environment variable is not set a suitable JDK will be downloaded in `$HOME/.jre` and used automatically.
|
|
16
|
+
Not all JRE are supported, so if you encounter issues, you can try the automatically installed version.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
You can find the documentation and example at [libadalina-core documentation](https://libadalinacore-6b2a95.gitlab.io/).
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
* Reading and writing geospatial data from various formats
|
|
26
|
+
* Spatial joins between datasets
|
|
27
|
+
* Spatial aggregations
|
|
28
|
+
* Utilities for working with Apache Sedona
|
|
29
|
+
* Configuration helpers for setting up Apache Sedona
|
|
30
|
+
|
|
31
|
+
## Requirements
|
|
32
|
+
|
|
33
|
+
- Python 3.10
|
|
34
|
+
- Dependencies:
|
|
35
|
+
- apache-sedona[spark]
|
|
36
|
+
- pyspark
|
|
37
|
+
- pandas
|
|
38
|
+
- geopandas
|
|
39
|
+
- install-jdk
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Minimal makefile for Sphinx documentation
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
# You can set these variables from the command line, and also
|
|
5
|
+
# from the environment for the first two.
|
|
6
|
+
SPHINXOPTS ?=
|
|
7
|
+
SPHINXBUILD ?= sphinx-build
|
|
8
|
+
SOURCEDIR = source
|
|
9
|
+
BUILDDIR = build
|
|
10
|
+
|
|
11
|
+
# Put it first so that "make" without argument is like "make help".
|
|
12
|
+
help:
|
|
13
|
+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
14
|
+
|
|
15
|
+
.PHONY: help Makefile
|
|
16
|
+
|
|
17
|
+
# Catch-all target: route all unknown targets to Sphinx using the new
|
|
18
|
+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
|
19
|
+
%: Makefile
|
|
20
|
+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
@ECHO OFF
|
|
2
|
+
|
|
3
|
+
pushd %~dp0
|
|
4
|
+
|
|
5
|
+
REM Command file for Sphinx documentation
|
|
6
|
+
|
|
7
|
+
if "%SPHINXBUILD%" == "" (
|
|
8
|
+
set SPHINXBUILD=sphinx-build
|
|
9
|
+
)
|
|
10
|
+
set SOURCEDIR=source
|
|
11
|
+
set BUILDDIR=build
|
|
12
|
+
|
|
13
|
+
%SPHINXBUILD% >NUL 2>NUL
|
|
14
|
+
if errorlevel 9009 (
|
|
15
|
+
echo.
|
|
16
|
+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
|
17
|
+
echo.installed, then set the SPHINXBUILD environment variable to point
|
|
18
|
+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
|
19
|
+
echo.may add the Sphinx directory to PATH.
|
|
20
|
+
echo.
|
|
21
|
+
echo.If you don't have Sphinx installed, grab it from
|
|
22
|
+
echo.https://www.sphinx-doc.org/
|
|
23
|
+
exit /b 1
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
if "%1" == "" goto help
|
|
27
|
+
|
|
28
|
+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
|
29
|
+
goto end
|
|
30
|
+
|
|
31
|
+
:help
|
|
32
|
+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
|
33
|
+
|
|
34
|
+
:end
|
|
35
|
+
popd
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Configuration file for the Sphinx documentation builder.
|
|
2
|
+
#
|
|
3
|
+
# For the full list of built-in configuration values, see the documentation:
|
|
4
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
sys.path.insert(0, os.path.abspath('../..'))
|
|
9
|
+
|
|
10
|
+
# -- Project information -----------------------------------------------------
|
|
11
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
|
12
|
+
|
|
13
|
+
project = 'libadalina-core'
|
|
14
|
+
copyright = '2025, OptLab, University of Milan'
|
|
15
|
+
author = 'Marco Casazza, Alberto Ceselli, Marco Premoli'
|
|
16
|
+
release = '0.1.0'
|
|
17
|
+
|
|
18
|
+
# -- General configuration ---------------------------------------------------
|
|
19
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
|
20
|
+
|
|
21
|
+
extensions = [
|
|
22
|
+
'sphinx.ext.autodoc',
|
|
23
|
+
'sphinx.ext.autosummary',
|
|
24
|
+
'sphinx.ext.viewcode',
|
|
25
|
+
'sphinx.ext.napoleon',
|
|
26
|
+
'sphinx.ext.intersphinx',
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
# Napoleon settings
|
|
30
|
+
napoleon_google_docstring = True
|
|
31
|
+
napoleon_numpy_docstring = True
|
|
32
|
+
napoleon_include_init_with_doc = False
|
|
33
|
+
napoleon_include_private_with_doc = False
|
|
34
|
+
napoleon_include_special_with_doc = True
|
|
35
|
+
napoleon_use_admonition_for_examples = False
|
|
36
|
+
napoleon_use_admonition_for_notes = False
|
|
37
|
+
napoleon_use_admonition_for_references = False
|
|
38
|
+
napoleon_use_ivar = False
|
|
39
|
+
napoleon_use_param = True
|
|
40
|
+
napoleon_use_rtype = True
|
|
41
|
+
napoleon_preprocess_types = False
|
|
42
|
+
napoleon_type_aliases = None
|
|
43
|
+
napoleon_attr_annotations = True
|
|
44
|
+
|
|
45
|
+
# Intersphinx settings
|
|
46
|
+
intersphinx_mapping = {
|
|
47
|
+
'python': ('https://docs.python.org/3', None),
|
|
48
|
+
'pandas': ('https://pandas.pydata.org/pandas-docs/stable', None),
|
|
49
|
+
'geopandas': ('https://geopandas.org/en/stable/', None),
|
|
50
|
+
'pyspark': ('https://spark.apache.org/docs/latest/api/python/', None),
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
templates_path = ['_templates']
|
|
54
|
+
exclude_patterns = []
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# -- Options for HTML output -------------------------------------------------
|
|
59
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
|
60
|
+
|
|
61
|
+
html_theme = 'pydata_sphinx_theme'
|
|
62
|
+
html_static_path = ['_static']
|
|
63
|
+
|
|
64
|
+
latex_elements = {
|
|
65
|
+
'fncychap': r'\usepackage[Bjornstrup]{fncychap}',
|
|
66
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Hospitals in Provinces
|
|
2
|
+
=======================
|
|
3
|
+
|
|
4
|
+
This example demonstrates how to find hospitals in specific provinces in Italy and aggregate their data.
|
|
5
|
+
|
|
6
|
+
.. literalinclude:: ../../../libadalina_core/examples/example_hospitals_in_provinces.py
|
|
7
|
+
:language: python
|
|
8
|
+
:linenos:
|
|
9
|
+
:caption: Example: Finding hospitals in provinces and aggregating data
|
|
10
|
+
|
|
11
|
+
Example Explanation
|
|
12
|
+
-------------------
|
|
13
|
+
|
|
14
|
+
This example shows how to:
|
|
15
|
+
|
|
16
|
+
1. Load geospatial data from GeoPackage files using ``geopackage_to_dataframe``
|
|
17
|
+
2. Filter data to select specific provinces (Milan and Cremona)
|
|
18
|
+
3. Perform a spatial join between provinces and hospitals using ``spatial_join``
|
|
19
|
+
4. Aggregate data to count hospitals and calculate total and average beds using ``spatial_aggregation``
|
|
20
|
+
|
|
21
|
+
The example demonstrates the use of the following libadalina-core features:
|
|
22
|
+
|
|
23
|
+
* Reading geospatial data
|
|
24
|
+
* Spatial joins
|
|
25
|
+
* Spatial aggregations with different aggregation functions
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Examples
|
|
2
|
+
========
|
|
3
|
+
|
|
4
|
+
This section provides examples of how to use the libadalina-core library for various geospatial data processing tasks.
|
|
5
|
+
|
|
6
|
+
.. toctree::
|
|
7
|
+
:maxdepth: 1
|
|
8
|
+
|
|
9
|
+
hospitals_in_provinces
|
|
10
|
+
population_in_provinces
|
|
11
|
+
population_served_by_hospitals
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Population in Provinces
|
|
2
|
+
=======================
|
|
3
|
+
|
|
4
|
+
This example demonstrates how to calculate population statistics for provinces in Italy.
|
|
5
|
+
|
|
6
|
+
.. literalinclude:: ../../../libadalina_core/examples/example_population_in_provinces.py
|
|
7
|
+
:language: python
|
|
8
|
+
:linenos:
|
|
9
|
+
:caption: Example: Calculating population statistics for provinces
|
|
10
|
+
|
|
11
|
+
Example Explanation
|
|
12
|
+
-------------------
|
|
13
|
+
|
|
14
|
+
This example shows how to:
|
|
15
|
+
|
|
16
|
+
1. Load geospatial data from GeoPackage files using ``geopackage_to_dataframe``
|
|
17
|
+
2. Filter data to select specific provinces in Northern Italy
|
|
18
|
+
3. Perform a spatial join between provinces and population data using ``spatial_join``
|
|
19
|
+
4. Aggregate population data by province using ``spatial_aggregation``
|
|
20
|
+
|
|
21
|
+
The example demonstrates the use of the following libadalina-core features:
|
|
22
|
+
|
|
23
|
+
* Reading geospatial data
|
|
24
|
+
* Filtering data based on attributes
|
|
25
|
+
* Spatial joins
|
|
26
|
+
* Spatial aggregations with sum aggregation function
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Population Served by Hospitals
|
|
2
|
+
==============================
|
|
3
|
+
|
|
4
|
+
This example demonstrates how to calculate the population served by hospitals in different provinces of Italy.
|
|
5
|
+
|
|
6
|
+
.. literalinclude:: ../../../libadalina_core/examples/example_population_served_by_hospitals.py
|
|
7
|
+
:language: python
|
|
8
|
+
:linenos:
|
|
9
|
+
:caption: Example: Calculating population served by hospitals
|
|
10
|
+
|
|
11
|
+
Example Explanation
|
|
12
|
+
-------------------
|
|
13
|
+
|
|
14
|
+
This example shows how to:
|
|
15
|
+
|
|
16
|
+
1. Load geospatial data from GeoPackage files using ``geopackage_to_dataframe``
|
|
17
|
+
2. Filter data to select specific provinces in Northern Italy
|
|
18
|
+
3. Create buffer zones around hospitals using ``polygonize``
|
|
19
|
+
4. Perform a spatial join between hospital buffer zones and population data using ``spatial_join``
|
|
20
|
+
5. Aggregate population data by hospital using ``spatial_aggregation``
|
|
21
|
+
|
|
22
|
+
The example demonstrates the use of the following libadalina-core features:
|
|
23
|
+
|
|
24
|
+
* Reading geospatial data
|
|
25
|
+
* Filtering data based on attributes
|
|
26
|
+
* Creating buffer zones around geometries
|
|
27
|
+
* Spatial joins
|
|
28
|
+
* Spatial aggregations with proportional calculations
|
|
29
|
+
* Handling of complex spatial relationships
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
.. libadalina-core documentation master file, created by
|
|
2
|
+
sphinx-quickstart on Thu Oct 26 10:00:00 2023.
|
|
3
|
+
You can adapt this file completely to your liking, but it should at least
|
|
4
|
+
contain the root `toctree` directive.
|
|
5
|
+
|
|
6
|
+
=============================
|
|
7
|
+
libadalina-core documentation
|
|
8
|
+
=============================
|
|
9
|
+
|
|
10
|
+
Introduction
|
|
11
|
+
************
|
|
12
|
+
|
|
13
|
+
*libadalina-core* is a Python library for spatial data processing and analysis providing utilities for reading,
|
|
14
|
+
writing, and processing geospatial data,
|
|
15
|
+
with a focus on spatial joins and aggregations.
|
|
16
|
+
|
|
17
|
+
It makes it easier to work with geospatial data in Python by providing a high-level interface
|
|
18
|
+
to Apache Sedona, a powerful geospatial processing engine, and integrates nicely with other well-known libraries
|
|
19
|
+
such as *geopandas* and *pandas*.
|
|
20
|
+
|
|
21
|
+
*libadalina-core* is part of the `ADaLinA project <https://expertise.unimi.it/resource/project/PNRR%5FBAC24ACESE%5F01>`__
|
|
22
|
+
that aims to develop a set of tools for the analysis of large-scale spatial data
|
|
23
|
+
to be integrated into the `AMELIA <https://https://grins.it/progetto/piattaforma-amelia>`__ platform.
|
|
24
|
+
|
|
25
|
+
Features
|
|
26
|
+
--------
|
|
27
|
+
|
|
28
|
+
* Reading and writing geospatial data from various formats
|
|
29
|
+
* Spatial joins between datasets
|
|
30
|
+
* Spatial aggregations
|
|
31
|
+
* Utilities for working with Apache Sedona
|
|
32
|
+
* Configuration helpers for setting up Apache Sedona
|
|
33
|
+
|
|
34
|
+
Requirements
|
|
35
|
+
------------
|
|
36
|
+
|
|
37
|
+
*libadalina-core* requires Python 3.10 and depends on the following libraries:
|
|
38
|
+
|
|
39
|
+
* apache-sedona
|
|
40
|
+
* pyspark
|
|
41
|
+
* pandas
|
|
42
|
+
* geopandas
|
|
43
|
+
* install-jdk
|
|
44
|
+
|
|
45
|
+
*libadalina-core* has been tested with OpenJDK 17.
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
.. toctree::
|
|
50
|
+
:maxdepth: 2
|
|
51
|
+
:caption: Table of contents
|
|
52
|
+
|
|
53
|
+
modules/index
|
|
54
|
+
examples/index
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Sedona Configuration
|
|
2
|
+
====================
|
|
3
|
+
|
|
4
|
+
The sedona_configuration module provides functions for configuring and initializing Apache Sedona.
|
|
5
|
+
|
|
6
|
+
.. automodule:: libadalina_core.sedona_configuration.sedona_configuration
|
|
7
|
+
:members:
|
|
8
|
+
:undoc-members:
|
|
9
|
+
:show-inheritance:
|
|
10
|
+
|
|
11
|
+
JDK Installer
|
|
12
|
+
-------------
|
|
13
|
+
|
|
14
|
+
.. automodule:: libadalina_core.sedona_configuration.jdk_installer
|
|
15
|
+
:members:
|
|
16
|
+
:undoc-members:
|
|
17
|
+
:show-inheritance:
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Sedona Utilities
|
|
2
|
+
================
|
|
3
|
+
|
|
4
|
+
The sedona_utils module provides utility functions for working with Apache Sedona.
|
|
5
|
+
|
|
6
|
+
Utilities
|
|
7
|
+
---------
|
|
8
|
+
|
|
9
|
+
.. automodule:: libadalina_core.sedona_utils.utils
|
|
10
|
+
:members:
|
|
11
|
+
:undoc-members:
|
|
12
|
+
:show-inheritance:
|
|
13
|
+
|
|
14
|
+
Coordinate Formats
|
|
15
|
+
------------------
|
|
16
|
+
|
|
17
|
+
.. automodule:: libadalina_core.sedona_utils.coordinate_formats
|
|
18
|
+
:members:
|
|
19
|
+
:undoc-members:
|
|
20
|
+
:show-inheritance:
|
|
File without changes
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from libadalina_core.readers.readers import geopackage_to_dataframe
|
|
2
|
+
import pathlib
|
|
3
|
+
import pandas as pd
|
|
4
|
+
|
|
5
|
+
from libadalina_core.spatial_join.query_builder import spatial_join, JoinType, spatial_aggregation, AggregationType, \
|
|
6
|
+
AggregationFunction
|
|
7
|
+
|
|
8
|
+
if __name__ == "__main__":
|
|
9
|
+
"""Example of how to use libadalina to find hospitals in specific provinces in Italy and aggregate their data."""
|
|
10
|
+
|
|
11
|
+
# Set pandas display options
|
|
12
|
+
pd.set_option('display.max_columns', None)
|
|
13
|
+
pd.set_option('display.width', None)
|
|
14
|
+
pd.set_option('display.max_colwidth', 100)
|
|
15
|
+
|
|
16
|
+
hospitals = geopackage_to_dataframe(
|
|
17
|
+
str(pathlib.Path(__file__).parent.parent.parent / "tests" / "samples" / "healthcare" / "EU_healthcare.gpkg"),
|
|
18
|
+
"EU"
|
|
19
|
+
)[["hospital_name", "geometry", "city", "cap_beds"]]
|
|
20
|
+
|
|
21
|
+
regions = geopackage_to_dataframe(
|
|
22
|
+
str(pathlib.Path(__file__).parent.parent.parent / "tests" / "samples" / "regions" / "NUTS_RG_20M_2024_4326.gpkg"),
|
|
23
|
+
"NUTS_RG_20M_2024_4326.gpkg"
|
|
24
|
+
)[["LEVL_CODE", "NUTS_NAME", "CNTR_CODE", "geometry"]]
|
|
25
|
+
|
|
26
|
+
# select province of Milan and Cremona
|
|
27
|
+
filtered_regions = regions[
|
|
28
|
+
(regions['LEVL_CODE'] == 3) &
|
|
29
|
+
(regions['CNTR_CODE'] == "IT") &
|
|
30
|
+
(regions['NUTS_NAME'].str.contains('Milano|Cremona', case=False))
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
# join with hospitals table to get hospitals in these provinces
|
|
34
|
+
result = (spatial_join(filtered_regions, hospitals, join_type=JoinType.LEFT)
|
|
35
|
+
# join operator renames the geometries adding suffixes _left and _right to avoid conflicts
|
|
36
|
+
.withColumnRenamed('geometry_left', 'geometry'))
|
|
37
|
+
result.show(truncate=False)
|
|
38
|
+
|
|
39
|
+
# get the number of hospitals in each province along with the total and average number of beds
|
|
40
|
+
result = spatial_aggregation(result, aggregate_functions=[
|
|
41
|
+
AggregationFunction("hospital_name", AggregationType.COUNT, 'hospitals'),
|
|
42
|
+
AggregationFunction("cap_beds", AggregationType.SUM, 'total_beds'),
|
|
43
|
+
AggregationFunction("cap_beds", AggregationType.AVG, 'average_beds'),
|
|
44
|
+
])
|
|
45
|
+
result.show(truncate=False)
|
|
46
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from libadalina_core.readers.readers import geopackage_to_dataframe
|
|
2
|
+
import pathlib
|
|
3
|
+
import pandas as pd
|
|
4
|
+
|
|
5
|
+
from libadalina_core.spatial_join.query_builder import spatial_join, JoinType, spatial_aggregation, AggregationType, \
|
|
6
|
+
AggregationFunction
|
|
7
|
+
|
|
8
|
+
if __name__ == "__main__":
|
|
9
|
+
"""Example of how to use libadalina to find the total amount of the population living in specific provinces in Italy."""
|
|
10
|
+
|
|
11
|
+
# Set pandas display options
|
|
12
|
+
pd.set_option('display.max_columns', None)
|
|
13
|
+
pd.set_option('display.width', None)
|
|
14
|
+
pd.set_option('display.max_colwidth', 100)
|
|
15
|
+
|
|
16
|
+
population = geopackage_to_dataframe(
|
|
17
|
+
str(pathlib.Path(__file__).parent.parent.parent / "tests" / "samples" / "population-north-italy" / "nord-italia.gpkg"),
|
|
18
|
+
"census2021"
|
|
19
|
+
)[['T', 'geometry']]
|
|
20
|
+
|
|
21
|
+
regions = geopackage_to_dataframe(
|
|
22
|
+
str(pathlib.Path(__file__).parent.parent.parent / "tests" / "samples" / "regions" / "NUTS_RG_20M_2024_4326.gpkg"),
|
|
23
|
+
"NUTS_RG_20M_2024_4326.gpkg"
|
|
24
|
+
)[["LEVL_CODE", "NUTS_NAME", "CNTR_CODE", "geometry"]]
|
|
25
|
+
|
|
26
|
+
# select province of Milan and Cremona
|
|
27
|
+
filtered_regions = regions[
|
|
28
|
+
(regions['LEVL_CODE'] == 3) &
|
|
29
|
+
(regions['CNTR_CODE'] == "IT") &
|
|
30
|
+
(regions['NUTS_NAME'].str.contains('Milano|Cremona', case=False))
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
# join with population table to get the population of these provinces
|
|
34
|
+
result = spatial_aggregation(
|
|
35
|
+
spatial_join(filtered_regions, population, join_type=JoinType.LEFT)
|
|
36
|
+
# join operator renames the geometries adding suffixes _left and _right to avoid conflicts
|
|
37
|
+
.withColumnRenamed('geometry_left', 'geometry'),
|
|
38
|
+
aggregate_functions=[
|
|
39
|
+
AggregationFunction("T", AggregationType.SUM, 'population', proportional='geometry_right'),
|
|
40
|
+
])
|
|
41
|
+
result.show(truncate=False)
|
|
42
|
+
|