Skip to content

Commit

Permalink
sciencegenome
Browse files Browse the repository at this point in the history
finished writing the code and had no internet access and hence final and binary release.
  • Loading branch information
sciencegenome committed Feb 12, 2025
1 parent 73eff0b commit beab1bf
Show file tree
Hide file tree
Showing 13 changed files with 290 additions and 96 deletions.
100 changes: 72 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
# deutsch-geo-env-mapper
- rust geospatial mapper.
- just put the files in the folder and then just search. No time for reload multiple times. Uses dotenv for automatic file indexing.
- application of dotenv for geo spatial command line detusch code mapper.
- polars analysis can be found here [deutsch geospatial mappers](https://github.com/zupzup/rust-polars-example)
- You can download the geospatial mapping from here [german postcode code to location mapping](https://www.suche-postleitzahl.org/downloads).
- rust geospatial mapper using dotenv for deutsch code mapper.
- just put the files in the folder with the same naming convention.
- Geospatial mapping data can be downloaded from here [german postcode code to location mapping](https://www.suche-postleitzahl.org/downloads).
- Deutsch github repository[repository link](https://github.com/plzTeam).
- polars analysis can be found here [deutsch geospatial mappers](https://github.com/zupzup/rust-polars-example).
- to install this just clone the folder and build the cargo or use the pre-compiled binary.
- please see the last commit message and if it says compiled binary then it is completed or else still in development version.
- Their github repository[repository link](https://github.com/plzTeam).


```
cargo build
```
```
gauravsablok@genome deutsch-geo-env-mapper main ? ./target/debug/deutsch-geo-env-mapper -h
```
deutsch geo-mapper
Usage: deutsch-geo-env-mapper <COMMAND>
Commands:
plz search according to the plz
note search according to the note
einwohner search according to the einwohner
qkm search according to the qkm
latitude search according to the latitude
longitude search according to the longitude
osm search according to the osm
ags search according to the ags
ord search according to the ort
landkreis search according to the landkries
bundesland search according to the bundesland
help Print this message or the help of the given subcommand(s)
plz search according to the plz
note search according to the note
einwohner search according to the einwohner
qkm search according to the qkm
latitude search according to the latitude
longitude search according to the longitude
osm search according to the osm
ags search according to the ags
ord search according to the ort
landkreis search according to the landkries
bundesland search according to the bundesland
general-pattern general pattern search
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
```

- search according to the plz
```
gauravsablok@genome deutsch-geo-env-mapper main ?
./target/debug/deutsch-geo-env-mapper plz 99955
Expand All @@ -50,32 +50,76 @@
99955 2903166 16064038 Kutzleben Unstrut-Hainich-Kreis Thüringen
99955 2903167 16064045 Mittelsömmern Unstrut-Hainich-Kreis Thüringen
99955 2903171 16064064 Urleben Unstrut-Hainich-Kreis Thüringen
```
- search according to the note
```
21:51:03 gauravsablok@genome deutsch-geo-env-mapper main ?
./target/debug/deutsch-geo-env-mapper note 01067
01067 01067-Dresden 11957 6.866839 51.06019 13.71117
```
- search according to the longitude
```
21:51:22 gauravsablok@genome deutsch-geo-env-mapper main ?
./target/debug/deutsch-geo-env-mapper longitude 13.71117
01067 01067 Dresden 11957 6.866839 51.06019 13.71117
```
- search according to the latitude
```
21:51:33 gauravsablok@genome deutsch-geo-env-mapper main ?
./target/debug/deutsch-geo-env-mapper latitude 51.06019
01067 01067 Dresden 11957 6.866839 51.06019 13.71117
```
- search according to the einwohner
```
21:51:40 gauravsablok@genome deutsch-geo-env-mapper main ?
./target/debug/deutsch-geo-env-mapper einwohner 11957
01067 01067 Dresden 11957 6.866839 51.06019 13.71117
```
- search according to the osm
```
23:23:53 gauravsablok@genome deutsch-geo-env-mapper main ?
./target/debug/deutsch-geo-env-mapper osm 1104550 130 ↵
./target/debug/deutsch-geo-env-mapper osm 1104550
78267 1104550 08335001 Aach Landkreis-Konstanz Baden-Württemberg
The results are: "The searched results are as follows"
```
- search according to the ags
```
23:23:58 gauravsablok@genome deutsch-geo-env-mapper main ?
./target/debug/deutsch-geo-env-mapper ags 08335001
78267 1104550 08335001 -A-a-c-h- Landkreis-Konstanz Baden-Württemberg
The results are: "The searched results are as follows"
23:24:02 gauravsablok@genome deutsch-geo-env-mapper main ?
./target/debug/deutsch-geo-env-mapper plz 78267
78267 78267 Aach 2179 10.648148 47.84445 8.85725
78267 1104550 08335001 Aach Landkreis-Konstanz Baden-Württemberg
```
- search according to the ord
```
11:48:31 gauravsablok@genome deutsch-geo-env-mapper main ?
./target/debug/deutsch-geo-env-mapper ord Aach
78267 1104550 08335001 "Aach" "Landkreis Konstanz" "Baden-Württemberg"
54298 1255910 07235001 "Aach" "Landkreis Trier-Saarburg" "Rheinland-Pfalz"
The results are: "The searched results are as follows"
```
- search according to the landkreis. if your landkries has spaces in the name then use the general pattern search
```
13:21:00 gauravsablok@genome deutsch-geo-env-mapper main ? ./target/debug/deutsch-geo-env-mapper landkreis Neckar-Odenwald-Kreis
74740 403733 08225001 "Adelsheim" "Neckar-Odenwald-Kreis" "Baden-Württemberg"
74858 403747 08225002 "Aglasterhausen" "Neckar-Odenwald-Kreis" "Baden-Württemberg"
74842 403741 08225009 "Billigheim" "Neckar-Odenwald-Kreis" "Baden-Württemberg"
```
- search according to the bundesland. if your bundesland has spaces in the name then use the general pattern search

```
13:22:55 gauravsablok@genome deutsch-geo-env-mapper main ? ./target/debug/deutsch-geo-env-mapper bundesland Mecklenburg-Vorpommern
18211 391131 13072001 "Admannshagen-Bargeshagen" "Landkreis Rostock" "Mecklenburg-Vorpommern"
17375 1408072 13075001 "Ahlbeck" "Landkreis Vorpommern-Greifswald" "Mecklenburg-Vorpommern"
18320 374204 13073001 "Ahrenshagen-Daskow" "Landkreis Vorpommern-Rügen" "Mecklenburg-Vorpommern"
18347 374244 13073002 "Ahrenshoop" "Landkreis Vorpommern-Rügen" "Mecklenburg-Vorpommern"
```

- search according to the general pattern. This means that you have spaces in your name or anything.
```
13:08:41 gauravsablok@genome deutsch-geo-env-mapper main ?
./target/debug/deutsch-geo-env-mapper general-pattern Konstanz
"2784842 08335043 Konstanz 78462 Landkreis Konstanz Baden-Württemberg"
"2784842 08335043 Konstanz 78464 Landkreis Konstanz Baden-Württemberg"
"2784842 08335043 Konstanz 78465 Landkreis Konstanz Baden-Württemberg
```
Gaurav Sablok
Binary file added deutsch-geo-env-mapper
Binary file not shown.
Binary file added deutsch-geo-env-mapper.tar
Binary file not shown.
36 changes: 25 additions & 11 deletions src/ags.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::mapper::MapperOrt;
use crate::mapper::MapperPrint;
use dotenv::dotenv;
use std::error::Error;
use std::fs::File;
Expand All @@ -25,31 +26,44 @@ pub fn ags_mapper(ags: &str) -> Result<String, Box<dyn Error>> {
mapper_ort.push(MapperOrt {
osmid: ort_mapper[0].to_string(),
ags: ort_mapper[1].to_string(),
ord: ort_mapper[2].replace("", "-").to_string(),
ord: ort_mapper[2..3]
.into_iter()
.map(|x| x.to_string())
.collect::<Vec<_>>(),
plz: ort_mapper[3].to_string(),
landries: ort_mapper[4].replace(" ", "-").to_string(),
bundesland: ort_mapper[5].replace(" ", "-").to_string(),
})
landkries: ort_mapper[4..5]
.into_iter()
.map(|x| x.to_string())
.collect::<Vec<_>>(),
bundesland: ort_mapper[ort_mapper.len() - 1..ort_mapper.len()]
.into_iter()
.map(|x| x.to_string())
.collect::<Vec<_>>(),
});
}

let mut searched_plz2: Vec<MapperOrt> = Vec::new();
let mut searched_plz2: Vec<MapperPrint> = Vec::new();
for i in mapper_ort.iter() {
if i.ags == ags.to_string() {
searched_plz2.push(MapperOrt {
searched_plz2.push(MapperPrint {
plz: i.plz.clone(),
osmid: i.osmid.clone(),
ags: i.ags.clone(),
ord: i.ord.clone(),
landries: i.landries.clone(),
bundesland: i.bundesland.clone(),
ord: i.ord.clone().join("").to_string(),
landkries: i.landkries.clone().join("").to_string(),
bundesland: i.bundesland.clone().join("").to_string(),
});
}
}

println!(
"{}\t{}\t{}\t{}\t{}\t{}",
"plz", "osmid", "ags", "ord", "landkries", "bundesland"
);
for i in searched_plz2.iter() {
println!(
"{}\t{}\t{}\t{}\t{}\t{}",
i.plz, i.osmid, i.ags, i.ord, i.landries, i.bundesland
"{}\t{}\t{}\t{:?}\t{:?}\t{:?}",
i.plz, i.osmid, i.ags, i.ord, i.landkries, i.bundesland
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ pub enum Commands {
Landkreis { landkries: String },
/// search according to the bundesland
Bundesland { bundesland: String },
/// general pattern search
GeneralPattern { generalpattern: String },
}
34 changes: 22 additions & 12 deletions src/bundesland.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::mapper::MapperOrt;
use crate::mapper::MapperPrint;
use dotenv::dotenv;
use std::error::Error;
use std::fs::File;
Expand All @@ -25,31 +26,40 @@ pub fn bundesland_mapper(bundesland: &str) -> Result<String, Box<dyn Error>> {
mapper_ort.push(MapperOrt {
osmid: ort_mapper[0].to_string(),
ags: ort_mapper[1].to_string(),
ord: ort_mapper[2].replace(" ", "-").to_string(),
ord: ort_mapper[2..3]
.into_iter()
.map(|x| x.to_string())
.collect::<Vec<_>>(),
plz: ort_mapper[3].to_string(),
landries: ort_mapper[4].replace(" ", ".").to_string(),
bundesland: ort_mapper[6].replace(" ", "-").to_string(),
})
landkries: ort_mapper[4..5]
.into_iter()
.map(|x| x.to_string())
.collect::<Vec<_>>(),
bundesland: ort_mapper[ort_mapper.len() - 1..ort_mapper.len()]
.into_iter()
.map(|x| x.to_string())
.collect::<Vec<_>>(),
});
}

let mut searched_plz2: Vec<MapperOrt> = Vec::new();
let mut searched_plz2: Vec<MapperPrint> = Vec::new();
for i in mapper_ort.iter() {
if i.bundesland == bundesland.to_string().replace(" ", "-").to_string() {
searched_plz2.push(MapperOrt {
if i.bundesland.contains(&bundesland.to_string()) {
searched_plz2.push(MapperPrint {
plz: i.plz.clone(),
osmid: i.osmid.clone(),
ags: i.ags.clone(),
ord: i.ord.clone(),
landries: i.landries.clone(),
bundesland: i.bundesland.clone(),
ord: i.ord.clone().join("").to_string(),
landkries: i.landkries.clone().join("").to_string(),
bundesland: i.bundesland.clone().join("").to_string(),
});
}
}

for i in searched_plz2.iter() {
println!(
"{}\t{}\t{}\t{}\t{}\t{}",
i.plz, i.osmid, i.ags, i.ord, i.landries, i.bundesland
"{}\t{}\t{}\t{:?}\t{:?}\t{:?}",
i.plz, i.osmid, i.ags, i.ord, i.landkries, i.bundesland
);
}

Expand Down
55 changes: 55 additions & 0 deletions src/generalpattern.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use dotenv::dotenv;
use std::error::Error;
use std::fs::File;
use std::io::{BufRead, BufReader};

/*
Author Gaurav Sablok
SLB Potsdam
Date: 2025-2-12
*/

pub fn generalpattern_mapper(path: &str) -> Result<String, Box<dyn Error>> {
dotenv().ok();

let file1 = std::env::var("file1").expect("file not present");
let file2 = std::env::var("file2").expect("file not found");
let file1read = File::open(file1).expect("path not found");
let file2read = File::open(file2).expect("path not found");
let bufferfile1 = BufReader::new(file1read);
let bufferfile2 = BufReader::new(file2read);

let mut bufferfile1_part: Vec<Vec<String>> = Vec::new();
let mut bufferfile2_part: Vec<Vec<String>> = Vec::new();

for i in bufferfile1.lines() {
let line = i.expect("line not found");
if line.starts_with("plz") {
continue;
} else if !line.starts_with("plz") {
let mutableline: Vec<_> = line.split(",").map(|x| x.to_string()).collect::<Vec<_>>();
bufferfile1_part.push(mutableline);
}
}

for i in bufferfile2.lines() {
let line = i.expect("line not found");
let mutline = line.split(",").map(|x| x.to_string()).collect::<Vec<_>>();
bufferfile2_part.push(mutline);
}

for i in bufferfile1_part.iter() {
if i.contains(&path.to_string()) {
println!("{:?}", i.join(" ").to_string());
}
}

for j in bufferfile2_part.iter() {
if j.contains(&path.to_string()) {
println!("{:?}", j.join(" ").to_string());
}
}

Ok("The search results have been written".to_string())
}
34 changes: 22 additions & 12 deletions src/landkries.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::mapper::MapperOrt;
use crate::mapper::MapperPrint;
use dotenv::dotenv;
use std::error::Error;
use std::fs::File;
Expand All @@ -25,31 +26,40 @@ pub fn landkries_mapper(landkries: &str) -> Result<String, Box<dyn Error>> {
mapper_ort.push(MapperOrt {
osmid: ort_mapper[0].to_string(),
ags: ort_mapper[1].to_string(),
ord: ort_mapper[2].replace(" ", "-").to_string(),
ord: ort_mapper[2..3]
.iter()
.map(|x| x.to_string())
.collect::<Vec<_>>(),
plz: ort_mapper[3].to_string(),
landries: ort_mapper[4].replace(" ", "-").to_string(),
bundesland: ort_mapper[5].replace(" ", "-").to_string(),
})
landkries: ort_mapper[ort_mapper.len() - 2..ort_mapper.len() - 1]
.iter()
.map(|x| x.to_string())
.collect::<Vec<_>>(),
bundesland: ort_mapper[ort_mapper.len() - 1..ort_mapper.len()]
.iter()
.map(|x| x.to_string())
.collect::<Vec<_>>(),
});
}

let mut searched_plz2: Vec<MapperOrt> = Vec::new();
let mut searched_plz2: Vec<MapperPrint> = Vec::new();
for i in mapper_ort.iter() {
if i.landries == landkries.to_string() {
searched_plz2.push(MapperOrt {
if i.landkries.contains(&landkries.to_string()) {
searched_plz2.push(MapperPrint {
plz: i.plz.clone(),
osmid: i.osmid.clone(),
ags: i.ags.clone(),
ord: i.ord.clone(),
landries: i.landries.clone(),
bundesland: i.bundesland.clone(),
ord: i.ord.clone().join("").to_string(),
landkries: i.landkries.clone().join("").to_string(),
bundesland: i.bundesland.clone().join("").to_string(),
});
}
}

for i in searched_plz2.iter() {
println!(
"{}\t{}\t{}\t{}\t{}\t{}",
i.plz, i.osmid, i.ags, i.ord, i.landries, i.bundesland
"{}\t{}\t{}\t{:?}\t{:?}\t{:?}",
i.plz, i.osmid, i.ags, i.ord, i.landkries, i.bundesland
);
}

Expand Down
Loading

0 comments on commit beab1bf

Please sign in to comment.