Package: 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.ContentInstallationBasicsLoading dataGenerating geojsonPlottingExamplesInstallationThe package can be installed bypip install convert2geojsonThe latest development version of the package can be installed from
GitHub by runningpip install git+https://github.com/computational-antiquity/convert2geojson.gitThis 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 youripyleaflet
installtionoripywidgets
installtion.Basic usageImport the package withfromconvert2geojsonimportConvert2GeoJsonLoading dataThe 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.columnsto show everything, and the column titles for
longitudal and latitudal data (standard parameter names arelat='latitude'andlon='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 asNaNare droped from the
supplied dataframe.The original dataframe can however still be accessed asdata.rawDF.Generate geoJsonTo generate the geoJSON simple rundata.convert()This generates a geoJSON formated dictionary which is available atdata.geojson()To save the geoJSON to a file, rundata.save()You can provide parameters for the name and path, standards arename='data.geojson'andpath='.'.PlottingFor plotting the package is leveraging theipyleaflet
packagewhich is also
available as a JupyterLab extension.For a first overview usedata.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 formatcustomBasemap={'url':'https://{s}.URL_to_mapdata/{z}/{x}/{y}.png','max_zoom':'max available zoom level','attribution':'Attribution','name':'Name for layer control'}ScreenshotScreenshot of generated mapGrouped PlottingFor densely distributed geographical data, to styling options are
available.By choosingstyle='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.ScreenshotScreenshot of generated cluster mapCategorical plotting as pie chart distributionBy choosingstyle='pie'and providing a category found in the
dataframe columns, by settinggroupBy='Category', the package
generates a standalone map showing the clustered markers as pie charts
separated into sub-groups by the chosen category.ScreenshotScreenshot of generated pie charts mapExamplesHave a look at theLoading datasetsor theAdvanced Plottingnotebooks in the/examplefolder