Skip to content

Commit

Permalink
Fix typing of values in properties field
Browse files Browse the repository at this point in the history
  • Loading branch information
arindam1993 committed Jun 20, 2024
1 parent c4f8749 commit cb8a98e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
25 changes: 18 additions & 7 deletions core/src/main/java/com/graphhopper/reader/osm/OSMReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import com.carrotsearch.hppc.IntLongMap;
import com.carrotsearch.hppc.LongArrayList;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.graphhopper.coll.GHIntLongHashMap;
import com.graphhopper.coll.GHLongHashSet;
import com.graphhopper.coll.GHLongLongHashMap;
Expand Down Expand Up @@ -48,6 +50,7 @@
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -368,23 +371,31 @@ protected void addEdge(int fromIndex, int toIndex, PointList pointList, ReaderWa

if (ldGeojsonWriter != null) {
try {
HashMap<String, String> props = new HashMap<String, String>();
props.put("id", Long.toString(way.getId()));
props.put("name", name);
props.put("grade", Integer.toString(grade));
JsonFactory factory = new JsonFactory();
StringWriter writer = new StringWriter();
JsonGenerator generator = factory.createGenerator(writer);
generator.writeStartObject();

generator.writeNumberField("id", way.getId());
generator.writeStringField("name", name);
generator.writeNumberField("grade", grade);

for(Map.Entry<String, Boolean> entry : tagParserManager.getBooleanEncodedValues(edgeFlags).entrySet()) {
props.put(entry.getKey(), Boolean.toString(entry.getValue()));
generator.writeBooleanField(entry.getKey(), entry.getValue());
}

for(Map.Entry<String, Integer> entry : tagParserManager.getIntEncodedValues(edgeFlags).entrySet()) {
props.put(entry.getKey(), Integer.toString(entry.getValue()));
generator.writeNumberField(entry.getKey(), entry.getValue());
}

for(Map.Entry<String, Double> entry : tagParserManager.getDecimalEncodedValues(edgeFlags).entrySet()) {
props.put(entry.getKey(), Double.toString(entry.getValue()));
generator.writeNumberField(entry.getKey(), entry.getValue());
}

generator.writeEndObject();
generator.close();

String props = writer.toString();
ldGeojsonWriter.write(pointList.toGeojsonString(props));
ldGeojsonWriter.write("\n");
} catch (IOException e) {
Expand Down
13 changes: 1 addition & 12 deletions web-api/src/main/java/com/graphhopper/util/PointList.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
*/
package com.graphhopper.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.graphhopper.util.shapes.GHPoint;
import com.graphhopper.util.shapes.GHPoint3D;
import org.locationtech.jts.geom.Coordinate;
Expand All @@ -27,7 +25,6 @@
import org.locationtech.jts.geom.impl.PackedCoordinateSequence;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.NoSuchElementException;

Expand Down Expand Up @@ -352,16 +349,8 @@ public String toString() {
return sb.toString();
}

public String toGeojsonString(HashMap<String, String> properties) {
public String toGeojsonString(String propJsonString) {
StringBuilder sb = new StringBuilder();
ObjectMapper objectMapper = new ObjectMapper();
String propJsonString = "{}";
try {
propJsonString = objectMapper.writeValueAsString(properties);
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sb.append("{\"type\": \"Feature\", \"properties\": "+propJsonString+",\"geometry\": {\"type\": \"LineString\", \"coordinates\": [");
for (int i = 0; i < size(); i++) {
if (i > 0)
Expand Down

0 comments on commit cb8a98e

Please sign in to comment.