Skip to main content

convert2geojson

Convert databases to geojson, useful for displaying datasets on maps.

A FeatureCollection is generated from those dataframe rows containing values for latitude and longitude.

Note: To limit the size of the GeoJSON file, lookup tables are generated automatically for fields with a limited number of values (<20) and saved as a top-level ‘properties’ key in the JSON file. This is not part of the GeoJSON standard and can lead to problems with linters, e.g. GeoJSONLint.

Content

  1. Installation

  2. Basics

  1. Examples

Installation

The package can be installed by

pip install convert2geojson

The latest development version of the package can be installed from GitHub by running

pip install git+https://github.com/computational-antiquity/convert2geojson.git

This installs the most recent version of the master branch.

If the plotting on maps in JupyterLab is not yielding results, there might be problems with your ipyleaflet installtion or ipywidgets installtion.

Basic usage

Import the package with

from convert2geojson import Convert2GeoJson

Loading data

The package is instantiated by providing a dataframe containing the geodata ,e.g. dataframe=df, a list of columns of the dataframe, which should be shown as information for every geo feature, e.g. properties=df.columns to show everything, and the column titles for longitudal and latitudal data (standard parameter names are lat='latitude' and lon='longitude').

data = Convert2GeoJson(
          df,
          df.columns,
          lat='latitude',
          lon='longitude'
       )

The geo data is expected to be gievn as float numbers. Rows with empty longitudal or latitudel data, or marked as NaN are droped from the supplied dataframe.

The original dataframe can however still be accessed as data.rawDF.

Generate geoJson

To generate the geoJSON simple run

data.convert()

This generates a geoJSON formated dictionary which is available at

data.geojson()

To save the geoJSON to a file, run

data.save()

You can provide parameters for the name and path, standards are name='data.geojson' and path='.'.

Plotting

For plotting the package is leveraging the ipyleaflet package which is also available as a JupyterLab extension.

For a first overview use

data.display()

This plots the geoJSON features as a layer on a basemap.

The basic plotting can be changed by parameters for the map layout (mapLayout=dict()), and the basemap data (basemap=dict()).

To use a custom basemap, you can provide a dictionary of the format

customBasemap = {
          'url': 'https://{s}.URL_to_mapdata/{z}/{x}/{y}.png',
          'max_zoom': 'max available zoom level',
          'attribution': 'Attribution',
          'name': 'Name for layer control'
          }

Screenshot

Screenshot of generated map

Screenshot of generated map

Grouped Plotting

For densely distributed geographical data, to styling options are available.

By choosing style='grouped' ipyleaflets MarkerCluster is used to show groups of markers depending on the zoom level. By clicking on a cluster, the map zooms to the level, which contains the selected markers in the cluster .

Additionally, since markers are now single entities, by clicking on any marker a popup shows the information of the dataframe belonging to the geographical point.

Screenshot

Screenshot of generated cluster map

Screenshot of generated cluster map

Categorical plotting as pie chart distribution

By choosing style='pie' and providing a category found in the dataframe columns, by setting groupBy='Category', the package generates a standalone map showing the clustered markers as pie charts separated into sub-groups by the chosen category.

Screenshot

Screenshot of generated pie chart map

Screenshot of generated pie charts map

Examples

Have a look at the Loading datasets or the Advanced Plotting notebooks in the /example folder

Metadata

Release files for convert2geojson 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for convert2geojson 0.0.2
File Size Uploaded
convert2geojson-0.0.2.tar.gz 21.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for convert2geojson 0.0.2
File Interpreter ABI Platform
convert2geojson-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 36.9 kB

Release files / convert2geojson-0.0.2.tar.gz

Download URL convert2geojson-0.0.2.tar.gz
Size 21.7 kB
Tags Source
SHA-256 checksum
How to use checksums
821228f527147ed816c58d26be0c40f85f5c951c13be5fd39be81c57461aa8f3
BLAKE2b-256 checksum
How to use checksums
055b0e12f512b3022e8328816769ca709fc9e118d256f4782e521207a3a16fa2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.0 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

Release files / convert2geojson-0.0.2-py3-none-any.whl

Download URL convert2geojson-0.0.2-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
985d7c5e2194b04c4e75284980bc7e993122c9fcd759360af6ccdd12bb2543e0
BLAKE2b-256 checksum
How to use checksums
8d78941687e80634f07350a5dbc532bf2165a775fa98da65e379d0e0546fdb21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.0 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page