Skip to content

Commit

Permalink
Merge branch 'ChakshuGautam:master' into add/village_boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
kumarguddu609 authored Feb 3, 2024
2 parents e1f9c6d + 6b272c4 commit 95e9c2d
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ node_modules
.idea
.DS_store
server/.DS_Store
/server/geojson-data/indian_village_boundaries
/server/geojson-data/*json
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ See code example in the [server](./server/app.js) folder.

Run `./setup.sh`. This script will install bun and download required files to setup server
```sh
cd server
./setup.sh
```

Start Server
```sh
cd server
bun app.js
```

Expand Down
5 changes: 4 additions & 1 deletion server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ WORKDIR /usr/src/app

COPY . .

RUN apt-get update && apt-get install -y \
curl
CMD /bin/bash
COPY ./package*.json ./bun.lockb ./
RUN bun install
RUN ./setup.sh

ENV NODE_ENV production

Expand Down
1 change: 1 addition & 0 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const swaggerApp = express();
swagger(swaggerApp);

const GeoLocationLevel = {
VILLAGE: 'VILLAGE',
SUBDISTRICT: 'SUBDISTRICT',
DISTRICT: 'DISTRICT',
STATE: 'STATE'
Expand Down
1 change: 0 additions & 1 deletion server/pickled_output.json

This file was deleted.

60 changes: 44 additions & 16 deletions server/scripts/parse.geojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,64 @@ console.log('Parsing INDIA_STATE');
const INDIA_STATE = JSON.parse(fs.readFileSync(`${geoJsonFilesPath}/INDIA_STATE.geojson`, 'utf8'));
featuresLength = INDIA_STATE.features.length;
for (let i = 0; i < featuresLength; i++) {
const locationProperty = INDIA_STATE.features[i].properties;
INDIA_STATE.features[i].properties = {
stname: locationProperty.STNAME,
stcode11: locationProperty.STCODE11,
levelLocationName: locationProperty.STNAME,
...locationProperty
}
const locationProperty = INDIA_STATE.features[i].properties;
INDIA_STATE.features[i].properties = {
stname: locationProperty.STNAME,
levelLocationName: locationProperty.STNAME,
...locationProperty
}
}
fs.writeFileSync(`${geoJsonFilesPath}/INDIA_STATE.geojson`, JSON.stringify(INDIA_STATE));

console.log('Parsing INDIA_DISTRICT');
const INDIA_DISTRICT = JSON.parse(fs.readFileSync(`${geoJsonFilesPath}/INDIA_DISTRICT.geojson`, 'utf8'));
featuresLength = INDIA_DISTRICT.features.length;
for (let i = 0; i < featuresLength; i++) {
const locationProperty = INDIA_DISTRICT.features[i].properties;
INDIA_DISTRICT.features[i].properties = {
levelLocationName: locationProperty.dtname,
...locationProperty
}
const locationProperty = INDIA_DISTRICT.features[i].properties;
INDIA_DISTRICT.features[i].properties = {
levelLocationName: locationProperty.dtname,
...locationProperty
}
}
fs.writeFileSync(`${geoJsonFilesPath}/INDIA_DISTRICT.geojson`, JSON.stringify(INDIA_DISTRICT));

console.log('Parsing INDIA_SUBDISTRICT');
const INDIA_SUBDISTRICT = JSON.parse(fs.readFileSync(`${geoJsonFilesPath}/INDIA_SUBDISTRICT.geojson`, 'utf8'));
featuresLength = INDIA_SUBDISTRICT.features.length;
for (let i = 0; i < featuresLength; i++) {
const locationProperty = INDIA_SUBDISTRICT.features[i].properties;
INDIA_SUBDISTRICT.features[i].properties = {
levelLocationName: locationProperty.sdtname,
const locationProperty = INDIA_SUBDISTRICT.features[i].properties;
INDIA_SUBDISTRICT.features[i].properties = {
levelLocationName: locationProperty.sdtname,
...locationProperty
}
}
fs.writeFileSync(`${geoJsonFilesPath}/INDIA_SUBDISTRICT.geojson`, JSON.stringify(INDIA_SUBDISTRICT));


console.log('Parsing indian_village_boundaries geoJSONs')
var states = fs.readdirSync(`${geoJsonFilesPath}/indian_village_boundaries/`);

for (const state of states) {
console.log(`Parsing geoJSON(s) for state ${state}`)
var stateFiles = fs.readdirSync(`${geoJsonFilesPath}/indian_village_boundaries/${state}`)
for (const file of stateFiles) {
if (!file.endsWith(`.geojson`)) continue;
console.log(`Parsing ${file}`);
const villagesGeoJson = JSON.parse(fs.readFileSync(`${geoJsonFilesPath}/indian_village_boundaries/${state}/${file}`));
const geoJsonLength = villagesGeoJson.features.length;
for (let i = 0; i < geoJsonLength; i++) {
const locationProperty = villagesGeoJson.features[i].properties;
villagesGeoJson.features[i].properties = {
dtName: locationProperty.DISTRICT,
stName: locationProperty.STATE,
sdtName: locationProperty.SUB_DIST,
levelLocationName: locationProperty.NAME,
...locationProperty
}
}
fs.writeFileSync(`${geoJsonFilesPath}/indian_village_boundaries/${state}/${file}`, JSON.stringify(villagesGeoJson));
}
}
fs.writeFileSync(`${geoJsonFilesPath}/INDIA_SUBDISTRICT.geojson`, JSON.stringify(INDIA_SUBDISTRICT));

const masterLocationNamesJson = require(`${geoJsonFilesPath}/MASTER_LOCATION_NAMES.json`)
fs.writeFileSync(`${geoJsonFilesPath}/PARSED_MASTER_LOCATION_NAMES.json`, JSON.stringify(masterLocationNamesJson));
31 changes: 25 additions & 6 deletions setup.sh → server/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,38 @@ fi
bun install

# Changing PWD to download geojson data using curl
mkdir server/geojson-data &> /dev/null
cd server/geojson-data
mkdir ./geojson-data &> /dev/null
cd geojson-data

curl -Lo INDIA_DISTRICT.geojson "https://github.com/datta07/INDIAN-SHAPEFILES/raw/master/INDIA/INDIA_DISTRICTS.geojson"
curl -Lo INDIA_SUBDISTRICT.geojson "https://github.com/datta07/INDIAN-SHAPEFILES/raw/master/INDIA/INDIAN_SUB_DISTRICTS.geojson"
curl -Lo INDIA_STATE.geojson "https://github.com/datta07/INDIAN-SHAPEFILES/raw/master/INDIA/INDIA_STATES.geojson"

# Changing PWD back to project root
cd - &> /dev/null
# This JSON contains state > districts > subDistricts > villages for all states
curl -Lo MASTER_LOCATION_NAMES.json "https://github.com/pranshumaheshwari/indian-cities-and-villages/raw/master/data.json"

# village boundary
git clone https://github.com/datameet/indian_village_boundaries.git
# indian_village_boundaries repo cleanup
cd indian_village_boundaries
rm -rf .git docs website CONTRIBUTING.md LICENSE README.md
# Renaming states dir
mv ./br ./bihar
mv ./ga ./goa
mv ./gj ./gujarat
mv ./ka ./karnataka
mv ./kl ./kerala
mv ./mh ./maharashtra
mv ./or ./odisha
mv ./rj ./rajasthan
mv ./sk ./sikkim

# Changing PWD back to /server/
cd ../..

# Updating geoJSON files through script to make them usable in server
cd server/scripts
cd scripts
bun parse.geojson.js

# Changing PWD back to project root
# Changing PWD back to /server/
cd - &> /dev/null

0 comments on commit 95e9c2d

Please sign in to comment.