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

org.aksw.jena_sparql_api.geo.LinkGeomizer Maven / Gradle / Ivy

There is a newer version: 3.17.0-1
Show newest version
package org.aksw.jena_sparql_api.geo;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.aksw.jena_sparql_api.lookup.LookupService;

import org.apache.jena.graph.Node;
import org.apache.jena.graph.Triple;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.PrecisionModel;
import com.vividsolutions.jts.operation.distance.DistanceOp;

//class

public class LinkGeomizer {
    public static Map geomize(Iterable triples, LookupService lookupServiceSubjects, LookupService lookupServiceObjects) {
        Map result = new HashMap();

        Set subjects = new HashSet();
        Set objects = new HashSet();

        for(Triple triple : triples) {
            subjects.add(triple.getSubject());
            objects.add(triple.getObject());
        }

        Map mapSubjects = lookupServiceSubjects.fetchMap(subjects);
        Map mapObjects = lookupServiceObjects.fetchMap(objects);

        System.out.println("mapSubjects: " + mapSubjects);
        System.out.println("mapObjects: " + mapObjects);

        GeometryFactory gf = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326);

        for(Triple triple : triples) {
            Geometry gs = mapSubjects.get(triple.getSubject());
            Geometry go = mapObjects.get(triple.getObject());

            if(gs == null || go == null) {
                continue;
            }

            Coordinate[] coordinates = DistanceOp.nearestPoints(gs, go);

//            Point ps = GeometryFactory.createPointFromInternalCoord(points[0], gs);
//            Point po = GeometryFactory.createPointFromInternalCoord(points[1], go);

            LineString lineString = gf.createLineString(coordinates);
            result.put(triple, lineString);
        }

        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy