All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.model.json_serialization.EncodedPolylineJSONDeserializer Maven / Gradle / Ivy

package org.opentripplanner.model.json_serialization;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.opentripplanner.common.geometry.GeometryUtils;
import org.opentripplanner.util.PolylineEncoder;
import org.opentripplanner.util.model.EncodedPolylineBean;

import java.io.IOException;
import java.util.List;

/**
 * Decode an encoded polyline.
 */
public class EncodedPolylineJSONDeserializer extends JsonDeserializer {
    @Override public Geometry deserialize(JsonParser jsonParser,
            DeserializationContext deserializationContext)
            throws IOException, JsonProcessingException {
        EncodedPolylineBean bean = new EncodedPolylineBean(jsonParser.getValueAsString(), null, 0);
        List coords = PolylineEncoder.decode(bean);
        return GeometryUtils.getGeometryFactory().createLineString(coords.toArray(new Coordinate[coords.size()]));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy