Skip to content

Commit

Permalink
include two more photos after contact with SGM
Browse files Browse the repository at this point in the history
  • Loading branch information
joergreichert committed Nov 23, 2023
1 parent 3ceef6d commit b168623
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -1,114 +1,110 @@
package de.oklab.leipzig.cdv.damals.generator

import de.oklab.leipzig.cdv.damals.generator.process.CSVParser
import de.oklab.leipzig.cdv.damals.generator.process.GeoJSONWriter.writeFile
import de.oklab.leipzig.cdv.damals.generator.process.Processor
import de.oklab.leipzig.cdv.damals.generator.process.ProcessorDefinitions.ID_PROCESSOR
import de.oklab.leipzig.cdv.damals.generator.process.ProcessorDefinitions.POINT_PROCESSOR
import de.oklab.leipzig.cdv.damals.generator.process.ProcessorDefinitions.PROP_PROCESSORS_CSV
import de.oklab.leipzig.cdv.damals.generator.process.ProcessorDefinitions.PROP_PROCESSORS_XLSX
import de.oklab.leipzig.cdv.damals.generator.process.ProcessorDefinitions.imagesWithoutMetadata
import de.oklab.leipzig.cdv.damals.generator.process.ProcessorDefinitions.metaDataWithoutImages
import de.oklab.leipzig.cdv.damals.generator.process.CSVParser
import de.oklab.leipzig.cdv.damals.generator.process.GeoJSONWriter.writeFile
import de.oklab.leipzig.cdv.damals.generator.process.ProcessorDefinitions
import de.oklab.leipzig.cdv.damals.generator.process.XLSXParser
import java.time.ZoneId
import java.time.ZonedDateTime
import org.geojson.Feature
import org.geojson.FeatureCollection
import org.geojson.LngLatAlt
import org.geojson.Point
import java.io.FileWriter
import java.io.File
import de.oklab.leipzig.cdv.damals.generator.process.Processor
import de.oklab.leipzig.cdv.damals.generator.process.ProcessorDefinitions.dateProc
import org.geojson.GeoJsonObject
import org.geojson.LngLatAlt
import java.util.*
import java.io.FileWriter
import java.time.ZoneId
import java.time.ZonedDateTime

object DamalsGeoJSONGeneratorMain {

@JvmStatic
fun main(args: Array<String>) {
generate()
}
@JvmStatic
fun main(args: Array<String>) {
generate()
}

fun generate() {
FeatureCollection().apply {
//generateFromCSV()
generateFromExcel()
writeFile("src/main/resources/photos.geojson")
}
}

private fun FeatureCollection.generateFromCSV() {
val input = System.getProperty("user.dir") + "/src/main/resources/StadtAL_CodingDaVinci.csv"
val keysAndValues = CSVParser.getKeysAndValues(input)
fillFeatureCollection(this, keysAndValues, PROP_PROCESSORS_CSV)
}

fun generate() {
FeatureCollection().apply {
//generateFromCSV()
generateFromExcel()
writeFile("src/main/resources/photos.geojson")
}
}
private fun FeatureCollection.generateFromExcel() {
//val input = System.getProperty("user.dir") + "/src/main/resources/Metadaten_SGM.xlsx"
//val keysAndValues = XLSXParser.getKeysAndValues(input)
//writeCSV(keysAndValues, System.getProperty("user.dir") + "/src/main/resources/Metadaten_SGM.csv")
val input = System.getProperty("user.dir") + "/src/main/resources/Metadaten_SGM.csv"
val keysAndValues = CSVParser.getKeysAndValues(input)
val filteredValues = keysAndValues.second.toMutableList()
filteredValues.addAll(imagesWithoutMetadata)
val filteredKeysAndValues = Pair(keysAndValues.first, filteredValues)
fillFeatureCollection(this, filteredKeysAndValues, PROP_PROCESSORS_XLSX)
}

private fun FeatureCollection.generateFromCSV() {
val input = System.getProperty("user.dir") + "/src/main/resources/StadtAL_CodingDaVinci.csv"
val keysAndValues = CSVParser.getKeysAndValues(input)
fillFeatureCollection(this, keysAndValues, PROP_PROCESSORS_CSV)
}
private fun writeCSV(keysAndValues: Pair<List<String>, List<List<String>>>, fileName: String) {
val header = keysAndValues.first
val values = keysAndValues.second
val sb = StringBuilder()
sb.append(header.joinToString(";")).append("\n")
values.forEach { value ->
sb.append(
value.map { it.replace("\"", "'") }
.joinToString(";") {
if (it.contains(";"))
"\"$it\""
else it
}
).append("\n")
}
FileWriter(File(fileName)).use {
it.write(sb.toString())
}
}

private fun FeatureCollection.generateFromExcel() {
//val input = System.getProperty("user.dir") + "/src/main/resources/Metadaten_SGM.xlsx"
//val keysAndValues = XLSXParser.getKeysAndValues(input)
//writeCSV(keysAndValues, System.getProperty("user.dir") + "/src/main/resources/Metadaten_SGM.csv")
val input = System.getProperty("user.dir") + "/src/main/resources/Metadaten_SGM.csv"
val keysAndValues = CSVParser.getKeysAndValues(input)
val filteredValues = keysAndValues.second.filter {
!metaDataWithoutImages.contains(it[0].lowercase(Locale.getDefault()))
}.toMutableList()
filteredValues.addAll(imagesWithoutMetadata)
val filteredKeysAndValues = Pair(keysAndValues.first, filteredValues)
fillFeatureCollection(this, filteredKeysAndValues, PROP_PROCESSORS_XLSX)
}
private fun fillFeatureCollection(
newFeatureCollection: FeatureCollection,
keysAndValues: Pair<List<String>, List<List<String>>>,
processors: List<Processor>
): FeatureCollection {
val keys = keysAndValues.first
val valuesList = keysAndValues.second
val dateProc = Processor("HERSTELLUNG_DATIERUNG_Datierung Anfang (autom.)")
for (values in valuesList) {
val newFeature = Feature().apply {
id = ID_PROCESSOR.apply(values, keys).toString()
processors.forEach { proc -> proc.apply(properties, values, keys) }
geometry = (POINT_PROCESSOR.apply(values, keys) as LngLatAlt?)?.let { Point(it) }
val datierungVon = dateProc.apply(values, keys)
this.properties["coordTimes"] = listOf(toMilliseconds(datierungVon))
}
if (newFeature.geometry != null && (newFeature.geometry as Point).coordinates !== null
&& newFeature.properties.containsKey("date")
) {
newFeatureCollection.add(newFeature)
}
}
return newFeatureCollection
}

private fun writeCSV(keysAndValues: Pair<List<String>, List<List<String>>>, fileName: String) {
val header = keysAndValues.first
val values = keysAndValues.second
val sb = StringBuilder()
sb.append(header.joinToString(";")).append("\n")
values.forEach {
value -> sb.append(
value.map { it.replace("\"", "'") }
.joinToString(";") {
if (it.contains(";"))
"\"$it\""
else it
}
).append("\n") }
FileWriter(File(fileName)).use {
it.write(sb.toString())
}
}

private fun fillFeatureCollection(
newFeatureCollection: FeatureCollection,
keysAndValues: Pair<List<String>, List<List<String>>>,
processors: List<Processor>
): FeatureCollection {
val keys = keysAndValues.first
val valuesList = keysAndValues.second
val dateProc = Processor("HERSTELLUNG_DATIERUNG_Datierung Anfang (autom.)")
for (values in valuesList) {
val newFeature = Feature().apply {
id = ID_PROCESSOR.apply(values, keys).toString()
processors.forEach { proc -> proc.apply(properties, values, keys) }
geometry = (POINT_PROCESSOR.apply(values, keys) as LngLatAlt?)?.let { Point(it) }
val datierungVon = dateProc.apply(values, keys)
this.properties["coordTimes"] = listOf(toMilliseconds(datierungVon))
}
if(newFeature.geometry != null && (newFeature.geometry as Point).coordinates !== null
&& newFeature.properties.containsKey("date")) {
newFeatureCollection.add(newFeature)
}
}
return newFeatureCollection
}

private fun toMilliseconds(datierungVon: Any?): Long {
if(datierungVon === null) return 0
return try {
val year = Integer.valueOf(datierungVon.toString())
ZonedDateTime.of(year, 1, 1, 0, 0, 0, 0,
ZoneId.of("UTC")).toInstant().toEpochMilli()
} catch(_: NumberFormatException) {
0
}
}
private fun toMilliseconds(datierungVon: Any?): Long {
if (datierungVon === null) return 0
return try {
val year = Integer.valueOf(datierungVon.toString())
ZonedDateTime.of(
year, 1, 1, 0, 0, 0, 0,
ZoneId.of("UTC")
).toInstant().toEpochMilli()
} catch (_: NumberFormatException) {
0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ object ProcessorDefinitions {
pictureNo -> "https://www.stadtmuseum.leipzig.de/media/wmZoom/${pictureNo.subSequence(0, 5)}/$pictureNo.jpg"
}
)

val metaDataWithoutImages = listOf(
// "bb045226", "bb045235", "bb045241", "bb045243", "bb045313",
// "bb045322", "bb045333", "bb045336", "bb045623", "bb045625",
// "bb045629", "bb045630", "bb045636", "bb045645", "bb045652",
// "bb046291", "bb046377", "bb046407", "bb046475", "bb046512",
// "bb046528", "bb046545", "bb046546", "bb046564", "bb046634",
// "bb046640", "bb046649", "bb046679", "bb046683", "bb047228"
"bb046545", "bb046554", "bb047228.jpg"
)

val predefined = listOf(
listOf("bb045248", "Augustplatz, Neues Theater", "1900", "1/14/Bb045248", "51.340517 12.381463"),
Expand All @@ -63,7 +53,7 @@ object ProcessorDefinitions {
listOf("bb046571", "Königliches Conservatorium der Musik", "1900", "c/c0/Bb046571", "51.332677 12.366812"),
listOf("bb046512_1", "Frankfurter Straße, Lortzings Haus mit Garten, vor 1897", "1897", "thumb/7/71/Bb046512_1.tif/lossy-page1-1024px-Bb046512_1.tif", "51.3430719 12.3639554"),
listOf("bb046628", "Großer Concertsaal im Neuen Gewandhaus", "1900", "1/1f/Bb046628", "51.331849 12.368349"),
//listOf("bb0466282", "Bismarck-Denkmal auf dem Augustusplatz", "1895", "f/f6/Bb0466282", "51.339907 12.381247"),
listOf("bb046282", "Bismarck-Denkmal auf dem Augustusplatz", "1895", "f/f6/Bb0466282", "51.339907 12.381247"),
listOf("bb046634_1", "König Albert-Park, Sächsisch-Thüringische Gewerbeausstellung, Eingang, 1897", "1900", "8/86/Bb046634", "51.330505 12.358851"),
listOf("bb047226", "Petersstraße während der Papiermesse", "1900", "5/50/BB047226", "51.338513 12.3746225")
)
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/leipzig/damals.geojson

Large diffs are not rendered by default.

0 comments on commit b168623

Please sign in to comment.