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

org.wikibrain.spatial.cookbook.AdjacentPolygonExample Maven / Gradle / Ivy

package org.wikibrain.spatial.cookbook;

import com.google.common.collect.Sets;
import com.vividsolutions.jts.geom.Geometry;
import org.wikibrain.conf.Configurator;
import org.wikibrain.core.cmd.Env;
import org.wikibrain.core.cmd.EnvBuilder;
import org.wikibrain.core.dao.LocalPageDao;
import org.wikibrain.core.lang.Language;
import org.wikibrain.core.lang.LanguageSet;
import org.wikibrain.core.model.LocalPage;
import org.wikibrain.core.model.NameSpace;
import org.wikibrain.core.model.Title;
import org.wikibrain.spatial.cookbook.tflevaluate.DistanceMetrics;
import org.wikibrain.spatial.dao.SpatialDataDao;
import org.wikibrain.spatial.dao.SpatialNeighborDao;
import org.wikibrain.wikidata.WikidataDao;

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

/**
 * Created by toby on 5/24/14.
 */
public class AdjacentPolygonExample {

    public static void main(String[] args){


        try {

            Env env = new EnvBuilder().build();
            Configurator c = env.getConfigurator();
            SpatialNeighborDao snDao = c.get(SpatialNeighborDao.class);
            WikidataDao wdDao = c.get(WikidataDao.class);
            LocalPageDao lpDao = c.get(LocalPageDao.class);
            SpatialDataDao sdDao = c.get(SpatialDataDao.class);
            DistanceMetrics distanceMetrics = new DistanceMetrics();

            LanguageSet loadedLangs = lpDao.getLoadedLanguages();

            // set up the parameters for the call to getContainedItemIds
            String originName = "China";
            String layerName = "country";
            Set subLayers = Sets.newHashSet();
            subLayers.add("wikidata");




            LocalPage lp = lpDao.getByTitle(new Title(originName, Language.getByLangCode("simple")), NameSpace.ARTICLE);
            Integer id = wdDao.getItemId(lp);
            Geometry rootPoint = sdDao.getGeometry(id, layerName, "earth");
            Map resMap = snDao.getNeighbors(rootPoint, layerName, "earth", new HashSet());


            for(Integer i : resMap.keySet()){
                System.out.println(i.toString() + "  " + wdDao.getUniversalPage(i).getBestEnglishTitle(lpDao, true).getCanonicalTitle() + "  " + distanceMetrics.getDistance(resMap.get(i), rootPoint) + " km");
            }


            System.out.println(resMap.keySet().size() + " adjacent polygons found");



        } catch(Exception e){
            e.printStackTrace();
        }



    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy