Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert map from CSV to GeoJSON #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: python
python:
- "3.6"
- "3.8"
script:
- python3 checkcsv.py map.csv
- python3 checkgeojson.py map.geojson
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Carte des anciens Rezomen
Carte des anciens Rézomen
=========================

Ce fichier CSV liste la position des anciens Rézomen. À partir de ces données, une [carte Google Maps est accessible ici](https://www.google.com/maps/d/viewer?mid=1R_ogcebnWSXzlkURnYW6t5LaXIA).
Ce fichier [GeoJSON](https://tools.ietf.org/html/rfc7946) liste la position des anciens Rézomen. À partir de ces données, une [carte est accessible ici](./map.geojson).

[![screenshot](sample.png)](https://www.google.com/maps/d/viewer?mid=1R_ogcebnWSXzlkURnYW6t5LaXIA)
[![screenshot](sample.png)](./map.geojson)

Ajoutez-vous via pull request ; merci de respecter l'ordre promo (descendant), nom de famille.
40 changes: 0 additions & 40 deletions checkcsv.py

This file was deleted.

44 changes: 44 additions & 0 deletions checkgeojson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3

import re
import sys
import json

REZOMAN_FIELDS = ['pseudo', 'name', 'promo', 'last_update']

def error(msg, rezoman = None):
error_msg = f"Error: {msg}"
if rezoman:
error_msg += f" for rezoman {rezoman['properties']['pseudo']}"
sys.stderr.write(error_msg + '\n')
sys.exit(1)


_promo = re.compile(r'^(19|20)[0-9][0-9]$')
_date = re.compile(r'^20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]$')
_coord = re.compile(r'^-?[0-9]{1,3}\.[0-9]{1,10}$')


if __name__ == '__main__':
with open(sys.argv[1]) as json_map:
rezomap = json.load(json_map)

for rezoman in rezomap['features']:
# Fields check
if not list(rezoman['properties'].keys()) == REZOMAN_FIELDS:
error('Invalid properties fields')

# Type checks
for field in REZOMAN_FIELDS:
if type(rezoman['properties'][field]) != str:
error(f"Field {field} must be a string", rezoman)

# Value checks
if not _promo.match(rezoman["properties"]["promo"]):
error('Invalid Promo', rezoman)
if not _date.match(rezoman["properties"]["last_update"]):
error('Invalid update date', rezoman)
if not _coord.match(str(rezoman["geometry"]["coordinates"][0])):
error('Invalid longitude', rezoman)
if not _coord.match(str(rezoman["geometry"]["coordinates"][1])):
error('Invalid latitude', rezoman)
29 changes: 0 additions & 29 deletions map.csv

This file was deleted.

Loading