Created
November 23, 2017 13:52
-
-
Save mormegil-cz/520b4da7602e2c86c393947d6bad52c8 to your computer and use it in GitHub Desktop.
Skript pro přípravu importního souboru ulic z RÚIAN do mix’n’match katalogu.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://tools.wmflabs.org/mix-n-match/#/catalog/699 | |
void Main() | |
{ | |
var okresy = ImportCsv(@"UI_OKRES.CSV"); | |
var obce = ImportCsv(@"UI_OBEC.CSV"); | |
var ulice = ImportCsv(@"UI_ULICE.CSV"); | |
var namestiRegex = new Regex(@"\b[Nn]ám(\.|ěstí)"); | |
using (var writer = new StreamWriter("mixnmatch.tsv", false, Encoding.UTF8)) | |
{ | |
foreach (var u in ulice) | |
{ | |
// KOD;NAZEV;OBEC_KOD;PLATI_OD;PLATI_DO | |
string kod = u.Key; | |
string uliceNazev = u.Value[0]; | |
string obecKod = u.Value[1]; | |
string platiOd = u.Value[2].Replace(" 00:00:00", ""); | |
string platiDo = u.Value[3].Replace(" 00:00:00", ""); | |
bool isSquare = namestiRegex.IsMatch(uliceNazev); | |
string descType = isSquare ? "Náměstí" : "Ulice"; | |
string type = isSquare ? "square" : "street"; | |
var obec = obce[obecKod]; | |
// KOD;NAZEV;STATUS_KOD;POU_KOD;OKRES_KOD;CLENENI_SM_ROZSAH_KOD;CLENENI_SM_TYP_KOD;PLATI_OD;PLATI_DO;DATUM_VZNIKU | |
string obecNazev = obec[0]; | |
string okresKod = obec[3]; | |
var okres = okresy[okresKod]; | |
// KOD;NAZEV;VUSC_KOD;KRAJ_1960_KOD;NUTS_LAU;PLATI_OD;PLATI_DO;DATUM_VZNIKU | |
string okresNazev = okres[0]; | |
// Entry ID(your alphanumeric identifier; must be unique within the catalog) | |
// Entry name(will also be used for the search in mix'n'match later) | |
// Entry description | |
// Entry type(short string, e.g. "person" or "location"; recommended) | |
// Entry URL; if omitted, it will be constructed from the URL pattern and the entry ID. Either a URL pattern or a URL column are required! | |
if (platiDo.Length != 0) | |
{ | |
// writer.WriteLine("{0}\t{1}\tDřívější ulice v obci {2} (okres {3}) existující od {4} do {5}\tstreet", kod, uliceNazev, obecNazev, okresNazev, platiOd, platiDo); | |
} | |
else | |
{ | |
writer.WriteLine("{0}\t{1}\t{2} v obci {3} (okres {4})\t{5}", kod, uliceNazev, descType, obecNazev, okresNazev, type); | |
} | |
} | |
} | |
} | |
Dictionary<string, List<string>> ImportCsv(string fileName) | |
{ | |
var result = new Dictionary<string, List<string>>(); | |
using (var reader = new StreamReader(fileName, Encoding.GetEncoding(1250))) | |
{ | |
string line; | |
bool firstLine = true; | |
while ((line = reader.ReadLine()) != null) | |
{ | |
if (firstLine) | |
{ | |
firstLine = false; | |
continue; | |
} | |
if (line.Length == 0) continue; | |
var parts = line.Split(';'); | |
result.Add(parts[0], new List<string>(parts.Skip(1))); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment