Skip to content

Instantly share code, notes, and snippets.

@jongiddy
Created June 23, 2017 08:27
Show Gist options
  • Save jongiddy/67c7ace4e7394e1e5f3bea978ddf74ec to your computer and use it in GitHub Desktop.
Save jongiddy/67c7ace4e7394e1e5f3bea978ddf74ec to your computer and use it in GitHub Desktop.
Code to turn a Barefoot road database into a file
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.json.JSONException
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Collections;
import java.sql.Connection;
import java.sql.DriverManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.bmwcarit.barefoot.road.BaseRoad;
import com.bmwcarit.barefoot.road.BfmapReader;
import com.bmwcarit.barefoot.road.BfmapWriter;
import com.bmwcarit.barefoot.road.PostGISReader;
import com.bmwcarit.barefoot.road.RoadReader;
import com.bmwcarit.barefoot.road.RoadWriter;
import com.bmwcarit.barefoot.util.SourceException;
import com.bmwcarit.barefoot.util.Tuple;
import com.bmwcarit.barefoot.roadmap.Loader;
object MakeMapfile {
def main(args: Array[String]): Unit = {
val properties:Properties = new Properties();
properties.load(new FileInputStream("/vagrant/db.properties"))
val writer = new BfmapWriter("/vagrant/map.bfmap")
val host = properties.getProperty("database.host")
val port:Int = properties.getProperty("database.port", "0").toInt
val database = properties.getProperty("database.name")
val table = properties.getProperty("database.table")
val user = properties.getProperty("database.user")
val password = properties.getProperty("database.password")
val path = properties.getProperty("database.road-types")
if (host == null || port == 0 || database == null || table == null || user == null
|| password == null || path == null) {
throw new SourceException("could not read database properties");
}
var config:Map[java.lang.Short, Tuple[java.lang.Double, Integer]] = null;
try {
config = Loader.read(path);
} catch{
case _ : Throwable =>
throw new SourceException("could not read road types from file " + path);
}
val gisReader:PostGISReader = new PostGISReader(host, port, database, table, user, password, config)
writer.open()
try{
gisReader.open()
try {
var baseroadBuffer:BaseRoad = gisReader.next()
while (baseroadBuffer != null){
writer.write(baseroadBuffer)
baseroadBuffer = gisReader.next()
}
} finally {
gisReader.close()
}
} finally {
writer.close()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment