Package de.komoot.photon.importer.nominatim

Source Code of de.komoot.photon.importer.nominatim.DBUtils

package de.komoot.photon.importer.nominatim;

import com.vividsolutions.jts.geom.Geometry;
import org.elasticsearch.common.collect.Maps;
import org.openstreetmap.osmosis.hstore.PGHStore;
import org.postgis.jts.JtsGeometry;

import javax.annotation.Nullable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

/**
* utility functions to parse data from postgis
*
* @author christoph
*/
public class DBUtils {
  public static Map<String, String> getMap(ResultSet rs, String columnName) throws SQLException {
    Map<String, String> tags = Maps.newHashMap();

    PGHStore dbTags = (PGHStore) rs.getObject(columnName);
    if(dbTags != null) {
      for(Map.Entry<String, String> tagEntry : dbTags.entrySet()) {
        tags.put(tagEntry.getKey(), tagEntry.getValue());
      }
    }

    return tags;
  }

  @Nullable
  public static <T extends Geometry> T extractGeometry(ResultSet rs, String columnName) throws SQLException {
    JtsGeometry geom = (JtsGeometry) rs.getObject(columnName);
    if(geom == null) {
      //info("no geometry found in column " + columnName);
      return null;
    }
    return (T) geom.getGeometry();
  }
}
TOP

Related Classes of de.komoot.photon.importer.nominatim.DBUtils

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.