Skip to content

Commit

Permalink
java 1.8 to 1.7 because of cs.helsinki ukko cluster is old aff
Browse files Browse the repository at this point in the history
  • Loading branch information
rovaniemi committed Jun 19, 2017
1 parent 1e7aa46 commit 16c2761
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 53 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ gradle-app.setting
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache
.gradletasknamecache

# Profiler
*.hprof
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ In output file you will have nodes and edges (highways in real world) with weigh
7. Now you have `graph.json` in the same directory where the .jar file is.
8. If you use this data in your own service read [openstreetmap licence.](https://opendatacommons.org/licenses/odbl/1.0/)

### Possible errors

1. Parsing take much time or crash.
- You need more memory for the program. Change java run command to `java -jar -Xmx4096m <jar-file-name>.jar`. That will increase java heap max size to 4gb. You will need 4gb ram for that.

### Prerequisites

Expand Down
16 changes: 11 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
apply plugin: 'java'
jar {
manifest {
attributes 'Main-Class': 'osmparser.Osmparser'
}
}

apply plugin: 'maven'
apply plugin: 'jacoco'

Expand All @@ -7,8 +13,8 @@ version = '0.1'

description = "Java program that parses OSM XML files into a json graph representation.Java program that parses OSM XML files into a json graph representation."

sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
mavenCentral()
Expand All @@ -17,9 +23,9 @@ repositories {

task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'com.karlin.osm-graph-parser.Osmparser'
attributes 'Implementation-Title': 'osm-graph-parser',
'Implementation-Version': '0.1',
'Main-Class': 'osmparser.Osmparser'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
Expand Down
Empty file removed map/.gitkeep
Empty file.
6 changes: 5 additions & 1 deletion src/main/java/osmparser/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public void addEdge(long from, long to){

public Map<Long, Node> getGraph() {
Map<Long,Node> map = new HashMap<>();
graph.keySet().stream().filter(e -> this.graph.get(e).haveEdges()).forEach(e -> map.put(e, this.graph.get(e)));
for (Long l:graph.keySet()) {
if(this.graph.get(l).haveEdges()){
map.put(l, this.graph.get(l));
}
}
return map;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/osmparser/JsonMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void getNodeJson(Map<Long,Node> graph, String filename) throws IOExceptio
Writer writer = new FileWriter(filename + ".json");
List<Node> list = convertIds(graph);
Collections.sort(list);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Gson gson = new GsonBuilder().create();
gson.toJson(list, writer);
}
}
14 changes: 7 additions & 7 deletions src/main/java/osmparser/XmlReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

public class XmlReader {

public long howManyDocuments(){
try{
return Files.list(Paths.get("map/")).filter(n -> n.toString().contains("map-") && n.toString().contains(".osm")).count();
} catch (IOException e) {
e.printStackTrace();
File[] files = new File("map/").listFiles();
int counter = 0;
for (int i = 0; i < files.length; i++) {
if(files[i].getName().startsWith("map-") && files[i].getName().endsWith(".osm")){
counter++;
}
}
return 0;
return counter;
}

public Document getDocument(String documentName, int i){
Expand Down
14 changes: 0 additions & 14 deletions src/test/java/omsparser/JsonMakerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,6 @@ public void setUp() {
public void tearDown() {
}

@Test
public void methodCreateJsonFile(){
JsonMaker maker = new JsonMaker();
Map<Long, Node> j = new HashMap<>();
long count = 0;
try{
maker.getNodeJson(j,"test");
count = Files.list(Paths.get("")).filter(n -> n.toString().contains("test.json")).count();
} catch (IOException e) {
e.printStackTrace();
}
Assert.assertEquals(1, count);
}

@Test
public void convertIdsWorks(){
JsonMaker maker = new JsonMaker();
Expand Down
24 changes: 0 additions & 24 deletions src/test/java/omsparser/OsmparserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,4 @@ public void setUp() {
public void tearDown() {
}

@Test
public void masterTest() throws IOException {
Osmparser osmparser = new Osmparser();
osmparser.main(new String[]{""});
Assert.assertEquals(1, Files.list(Paths.get("")).filter(n -> n.toString().contains("graph.json")).count());
}

@Test
public void masterTestWithFile() throws IOException {
Charset utf8 = StandardCharsets.UTF_8;
List<String> lines = Arrays.asList("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<osm version=\"0.6\" generator=\"CGImap 0.6.0 (1590 thorn-02.openstreetmap.org)\" copyright=\"OpenStreetMap and contributors\" attribution=\"http://www.openstreetmap.org/copyright\" license=\"http://opendatacommons.org/licenses/odbl/1-0/\">\n" +
" <bounds minlat=\"53.9427100\" minlon=\"4.4592000\" maxlat=\"53.9436000\" maxlon=\"4.4617000\"/>\n" +
"</osm>\n");
try {
Files.write(Paths.get("map/map-01.osm"), lines, utf8);
} catch (IOException e) {
e.printStackTrace();
}
Osmparser osmparser = new Osmparser();
osmparser.main(new String[]{""});
Assert.assertEquals(1, Files.list(Paths.get("")).filter(n -> n.toString().contains("graph.json")).count());
}

}

0 comments on commit 16c2761

Please sign in to comment.