https://github.com/datamade/django-geomultiplechoice

🗺 A Django widget to select multiple geographic areas

https://github.com/datamade/django-geomultiplechoice

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • â—‹
    CITATION.cff file
  • ✓
    codemeta.json file
    Found codemeta.json file
  • ✓
    .zenodo.json file
    Found .zenodo.json file
  • â—‹
    DOI references
  • â—‹
    Academic publication links
  • â—‹
    Committers with academic emails
  • â—‹
    Institutional organization owner
  • â—‹
    JOSS paper metadata
  • â—‹
    Scientific vocabulary similarity
    Low similarity (12.8%) to scientific vocabulary

Keywords from Contributors

archival projection profiles interactive sequences generic observability autograding hacking shellcodes
Last synced: 11 months ago · JSON representation

Repository

🗺 A Django widget to select multiple geographic areas

Basic Info
  • Host: GitHub
  • Owner: datamade
  • License: mit
  • Language: Python
  • Default Branch: master
  • Size: 3.25 MB
Statistics
  • Stars: 6
  • Watchers: 3
  • Forks: 1
  • Open Issues: 4
  • Releases: 0
Created over 6 years ago · Last pushed about 3 years ago
Metadata Files
Readme License

README.md

🗺 GeoMultipleChoice

A Django widget to select multiple geographic areas.

GeoMultipleChoice demo

Originally created by @jeancochrane. Packaged up by @beamalsky.

Quick Start

This package is available for installation via PyPI. Simply run:

bash pip install django-geomultiplechoice

Add it to INSTALL_APPS in your projects settings.py file:

python INSTALLED_APPS = [ ... 'django_geomultiplechoice', ... ]

You should now be ready to start widget setup following the documentation below.

Widget options

The example project in this repo contains the following sample form implementation:

```python class ExampleGeoMultipleChoiceForm(forms.ModelForm): class Meta: model = SelectedArea fields = 'all'

def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)

    settings_overrides = {
        'DEFAULT_ZOOM': 12,
        'DEFAULT_CENTER': (41.88, -87.7),
        'RESET_VIEW' : True, # Defaults to True
        # Sets the bounds of RESET VIEW; y min, x min, y max, x max
        # See https://github.com/makinacorpus/django-leaflet/issues/192
        'SPATIAL_EXTENT': (-87.3, 41.5, -88, 42.15),
        'MAP_ID': 'my-example-map', # Defaults to 'map'
        'MAP_HEIGHT': '400px',
        'MAP_WIDTH': '100%',
        'MAP_LAYER_STYLE': {
          'color': '#7a7a7a',
          'weight': 3,
          'opacity': 0.5,
          'fillColor': '#999999',
          'fillOpacity': 0.3,
        },
        'MAP_LAYER_SELECTED_STYLE': {
          'color': '#7a7a7a',
          'weight': 3,
          'opacity': 0.5,
          'fillColor': 'black',
          'fillOpacity': 0.7
        }
    }

    self.fields['areas'].widget = GeoMultipleChoiceWidget(
        choices=[
            (choice.id, choice) for choice
            in Area.objects.all()
        ],
        settings_overrides=settings_overrides
    )

```

settings_overrides accepts all arguments used by django-leaflet in its LEAFLET_CONFIG, in addition to the following:

  • DEFAULT_ZOOM and DEFAULT_CENTER are required.
  • MAP_ID sets the html id for your widget map. Useful if you have multiple maps on the page.
  • MAP_HEIGHT and MAP_WIDTH allow you to size the widget in your form. Must be used together.
  • This example uses the default values for MAP_LAYER_STYLE and MAP_LAYER_STYLING.

SelectedArea is a model defined in example/models.py, and can be adjusted for your needs.

Importing Census data

This repo includes an example application using geographical data for 2018 Census block groups in Chicago. Look at data/Makefile and management/commands/import_data.py to see the ETL pipeline for that data.

If you'd like to use the same pipeline in your project but for a different area:

  1. Copy the data directory into your project
  2. Update STATES in scripts/states.py. If the area is in a new state, create a new entry in STATES for that state; otherwise, update the existing state.
  3. Update all in data/Makefile to match the form $(DATA_DIR)/final/cb_2018_{state id}_bg_500k.shp for each state you're importing shapefiles for.
  4. To delete and regenerate the shapefiles, run:

bash cd data && make clean && make

Or if your app is containerized:

bash docker-compose run --rm app make clean -f example/data/Makefile docker-compose run --rm app make -f example/data/Makefile

  1. Run python manage.py import_data to import the new geographical data. Or if your app is containerized, run docker-compose run --rm app python manage.py import_data

Changing the data structure

Though the example implementation of this widget uses Census block groups, we've intentionally left the door open to varied geographic data. By default the widget expects each area to have the attributes in example.models.Area:

python class Area(models.Model): id = models.CharField(max_length=12, primary_key=True) geom = geo_models.MultiPolygonField(srid=4269)

If that structure doesn't work for you, it can be changed through creating a new widget that inherits from django_geomultiplechoice.widgets.GeoMultipleChoiceWidget and modifying get_features().

Local development

This app requires Docker and Docker Compose for local development.

To install and get started, run the following commands in your shell:

```

Clone the repo

git clone git@github.com:datamade/django-geomultiplechoice.git

Move into the folder

cd django-geomultiplechoice ```

Then build and run the app with Docker:

bash docker-compose up --build

You'll also need to import the Census data into your database, for which we've provided a sample import_data.py. Open a new window in your terminal and run:

bash docker-compose run --rm app python manage.py import_data

Visit http://localhost:8000/ and you should see the example form running!

GeoMultipleChoiceWidget example

Cleaning up

To remove data files, run:

bash docker-compose run --rm app make clean -f example/data/Makefile

To regenerate the Census shapefiles, run:

bash docker-compose run --rm app make -f example/data/Makefile

To tear down the app and its volumes, run:

bash docker-compose down --volumes

Owner

  • Name: datamade
  • Login: datamade
  • Kind: organization
  • Email: info@datamade.us
  • Location: Chicago, IL

We build open source technology using open data to empower journalists, researchers, governments and advocacy organizations.

GitHub Events

Total
  • Watch event: 1
Last Year
  • Watch event: 1

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 42
  • Total Committers: 2
  • Avg Commits per committer: 21.0
  • Development Distribution Score (DDS): 0.024
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
beamalsky b****y@g****m 41
dependabot[bot] 4****] 1

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 7
  • Total pull requests: 11
  • Average time to close issues: 5 days
  • Average time to close pull requests: about 1 month
  • Total issue authors: 2
  • Total pull request authors: 2
  • Average comments per issue: 0.57
  • Average comments per pull request: 0.91
  • Merged pull requests: 7
  • Bot issues: 0
  • Bot pull requests: 5
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • beamalsky (5)
  • fgregg (2)
Pull Request Authors
  • beamalsky (6)
  • dependabot[bot] (5)
Top Labels
Issue Labels
Pull Request Labels
dependencies (5)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 28 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 2
  • Total maintainers: 2
pypi.org: django-geomultiplechoice

A Django widget to select multiple geographic areas

  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 28 Last month
Rankings
Dependent packages count: 10.0%
Stargazers count: 21.5%
Dependent repos count: 21.7%
Forks count: 22.6%
Average: 30.5%
Downloads: 76.5%
Last synced: 11 months ago

Dependencies

requirements.txt pypi
  • django ==3.0.3
  • django-leaflet ==0.26.0
  • psycopg2 ==2.8.4
  • six ==1.12.0
.github/workflows/publish-to-pypi.yml actions
  • actions/checkout master composite
  • actions/setup-python v1 composite
.github/workflows/publish-to-test-pypi.yml actions
  • actions/checkout master composite
  • actions/setup-python v1 composite
Dockerfile docker
  • python 3.7 build
docker-compose.yml docker
  • django-geomultiplechoice latest
  • mdillon/postgis latest
setup.py pypi