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

Support osm communes only #14

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
COMMUNES_PATH=/path/to/communes-shp.zip
ARRONDISSEMENTS_PATH=/path/to/arrondissements-municipaux-shp.zip
DATASOURCES_TYPE=admin-express
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ La préparation des sources inclut la récupération des données auprès des se
yarn prepare-sources
```

Il est possible de travailler avec exclusivement des sources OSM ou Admin Express pour la France, les DOM avec OSM pour les COM.
Pour travailler en OSM pur, il faut faire

```bash
DATASOURCES_TYPE=osm yarn prepare-sources
```

ou ajouter DATASOURCES_TYPE=osm dans le fichier `.env` copié depuis le fichier modèle `.env.sample`

### Génération des données + généralisation

```
Expand Down
58 changes: 40 additions & 18 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,45 @@ const {communes, epci, departements, regions, communesIndexes, epciIndexes} = re

const SOURCES_PATH = join(__dirname, 'sources')
const DIST_PATH = join(__dirname, 'dist')
const FILES_ADMIN_EXPRESS = [
'COMMUNE.cpg',
'COMMUNE.shp',
'COMMUNE.dbf',
'COMMUNE.prj',
'COMMUNE.shx',
'ARRONDISSEMENT_MUNICIPAL.cpg',
'ARRONDISSEMENT_MUNICIPAL.shp',
'ARRONDISSEMENT_MUNICIPAL.dbf',
'ARRONDISSEMENT_MUNICIPAL.prj',
'ARRONDISSEMENT_MUNICIPAL.shx'
]
const FILES_OSM_COMMUNES_METRO = [
'osm-communes.cpg',
'osm-communes.shp',
'osm-communes.dbf',
'osm-communes.prj',
'osm-communes.shx',
'osm-arrondissements-municipaux.cpg',
'osm-arrondissements-municipaux.shp',
'osm-arrondissements-municipaux.dbf',
'osm-arrondissements-municipaux.prj',
'osm-arrondissements-municipaux.shx'
]
const DEFAULT_SHP_FILES = [
'osm-communes-com.cpg',
'osm-communes-com.shp',
'osm-communes-com.dbf',
'osm-communes-com.prj',
'osm-communes-com.shx'
]
const DATASOURCES_TYPE = process.env.DATASOURCES_TYPE || 'admin-express'

let COMBINED_SHAPEFILE_LIST;
if (DATASOURCES_TYPE == 'admin-express') {
COMBINED_SHAPEFILE_LIST = [...FILES_ADMIN_EXPRESS, ...DEFAULT_SHP_FILES]
} else {
COMBINED_SHAPEFILE_LIST = [...FILES_OSM_COMMUNES_METRO, ...DEFAULT_SHP_FILES]
}

async function getSimplifiedGeometries(featuresFiles, interval) {
const readFeatures = await extractFeaturesFromShapefiles(featuresFiles, interval)
Expand Down Expand Up @@ -210,24 +249,7 @@ async function readSourcesFiles(fileNames) {
}

async function main() {
const featuresFiles = await readSourcesFiles([
'COMMUNE.cpg',
'COMMUNE.shp',
'COMMUNE.dbf',
'COMMUNE.prj',
'COMMUNE.shx',
'ARRONDISSEMENT_MUNICIPAL.cpg',
'ARRONDISSEMENT_MUNICIPAL.shp',
'ARRONDISSEMENT_MUNICIPAL.dbf',
'ARRONDISSEMENT_MUNICIPAL.prj',
'ARRONDISSEMENT_MUNICIPAL.shx',
'osm-communes-com.cpg',
'osm-communes-com.shp',
'osm-communes-com.dbf',
'osm-communes-com.prj',
'osm-communes-com.shx'
])

const featuresFiles = await readSourcesFiles(COMBINED_SHAPEFILE_LIST)
await buildContours(featuresFiles, 1000)
await buildContours(featuresFiles, 100)
await buildContours(featuresFiles, 50)
Expand Down
30 changes: 21 additions & 9 deletions prepare-sources.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
require('dotenv').config()
const path = require('path')
const fs = require('fs')
const {pathExists, mkdirp} = require('fs-extra')
Expand All @@ -11,9 +12,13 @@ const SOURCES_PATH = path.join(__dirname, 'sources')
const ADMIN_EXPRESS_BASE_URL = 'http://files.opendatarchives.fr/professionnels.ign.fr/adminexpress/'
const ADMIN_EXPRESS_FILE = 'ADMIN-EXPRESS-COG_3-0__SHP__FRA_WM_2021-05-19.7z'

const OSM_COMMUNES_COM_BASE_URL = 'https://osm13.openstreetmap.fr/~cquest/openfla/export/'
const OSM_COMMUNES_BASE_URL = 'https://osm13.openstreetmap.fr/~cquest/openfla/export/'
const OSM_COMMUNES_FILE = 'communes-20220101-shp.zip'
const OSM_ARRONDISSEMENTS_FILE = 'arrondissements-municipaux-20220101-shp.zip'
const OSM_COMMUNES_COM_FILE = 'communes-com-20220101-shp.zip'

const DATASOURCES_TYPE = process.env.DATASOURCES_TYPE || 'admin-express'

function getSourceFilePath(fileName) {
return path.join(SOURCES_PATH, fileName)
}
Expand Down Expand Up @@ -50,16 +55,16 @@ async function decompressAdminExpressFiles() {
})
}

async function decompressOsmCommunesComFiles() {
async function decompressOsmFiles(osm_file, file_pattern) {
await decompress(
getSourceFilePath(OSM_COMMUNES_COM_FILE),
getSourceFilePath(osm_file),
SOURCES_PATH,
{
filter(file) {
return file.path.startsWith('communes-com')
return file.path.startsWith(file_pattern)
},
map(file) {
file.path = 'osm-communes-com' + path.extname(file.path)
file.path = 'osm-' + file_pattern + path.extname(file.path)
return file
}
}
Expand All @@ -68,10 +73,17 @@ async function decompressOsmCommunesComFiles() {

async function main() {
await mkdirp(SOURCES_PATH)
await downloadSourceFile(ADMIN_EXPRESS_BASE_URL + ADMIN_EXPRESS_FILE, ADMIN_EXPRESS_FILE)
await decompressAdminExpressFiles()
await downloadSourceFile(OSM_COMMUNES_COM_BASE_URL + OSM_COMMUNES_COM_FILE, OSM_COMMUNES_COM_FILE)
await decompressOsmCommunesComFiles()
if (DATASOURCES_TYPE == 'admin-express') {
await downloadSourceFile(ADMIN_EXPRESS_BASE_URL + ADMIN_EXPRESS_FILE, ADMIN_EXPRESS_FILE)
await decompressAdminExpressFiles()
} else {
await downloadSourceFile(OSM_COMMUNES_BASE_URL + OSM_COMMUNES_FILE, OSM_COMMUNES_FILE)
await decompressOsmFiles(OSM_COMMUNES_FILE, 'communes')
await downloadSourceFile(OSM_COMMUNES_BASE_URL + OSM_ARRONDISSEMENTS_FILE, OSM_ARRONDISSEMENTS_FILE)
await decompressOsmFiles(OSM_ARRONDISSEMENTS_FILE, 'arrondissements-municipaux')
}
await downloadSourceFile(OSM_COMMUNES_BASE_URL + OSM_COMMUNES_COM_FILE, OSM_COMMUNES_COM_FILE)
await decompressOsmFiles(OSM_COMMUNES_COM_FILE, 'communes-com')
}

main().catch(error => {
Expand Down