ingo@1230: package de.intevation.flys.backend; ingo@1230: ingo@1230: import java.util.List; ingo@1230: ingo@1230: import org.apache.log4j.Logger; ingo@1230: ingo@1230: import org.hibernate.Query; ingo@1230: import org.hibernate.Session; ingo@1230: ingo@1230: import com.vividsolutions.jts.geom.LineString; ingo@1230: ingo@1230: import de.intevation.flys.backend.SessionFactoryProvider; ingo@1230: import de.intevation.flys.model.Building; ingo@1230: import de.intevation.flys.model.CrossSectionTrack; ingo@1230: import de.intevation.flys.model.Fixpoint; ingo@1230: import de.intevation.flys.model.Line; ingo@1230: import de.intevation.flys.model.River; ingo@1230: import de.intevation.flys.model.RiverAxis; ingo@1230: ingo@1230: ingo@1230: public class SpatialInfo { ingo@1230: ingo@1230: private static Logger logger = Logger.getLogger(SpatialInfo.class); ingo@1230: ingo@1230: protected static String RIVERNAME = System.getProperty( ingo@1230: "flys.backend.spatial.river", "Saar"); ingo@1230: ingo@1230: protected Session session; ingo@1230: ingo@1230: ingo@1230: public static void main(String[] args) { ingo@1230: logger.info("Start SpatialInfo application."); ingo@1230: ingo@1230: SpatialInfo spatial = null; ingo@1230: ingo@1230: try { ingo@1230: spatial = new SpatialInfo(); ingo@1230: ingo@1230: River river = spatial.getRiver(RIVERNAME); ingo@1230: if (river == null) { ingo@1230: logger.warn("Could not find river '" + RIVERNAME + "'!"); ingo@1230: return; ingo@1230: } ingo@1230: ingo@1230: logger.info("Spatial information of River '" + RIVERNAME + "'"); ingo@1230: spatial.doRiverAxisInfo(river); ingo@1230: spatial.doCrossSectionTracksInfo(river); ingo@1230: spatial.doLinesInfo(river); ingo@1230: spatial.doBuildingsInfo(river); ingo@1230: spatial.doFixpointsInfo(river); ingo@1230: } ingo@1230: finally { ingo@1230: if (spatial != null) { ingo@1230: spatial.close(); ingo@1230: } ingo@1230: } ingo@1230: ingo@1230: logger.info("Finish SpatialInfo application."); ingo@1230: } ingo@1230: ingo@1230: ingo@1230: public SpatialInfo() { ingo@1230: session = SessionFactoryProvider ingo@1230: .createSessionFactory() ingo@1230: .openSession(); ingo@1230: } ingo@1230: ingo@1230: ingo@1230: public void close() { ingo@1230: session.close(); ingo@1230: } ingo@1230: ingo@1230: ingo@1230: protected River getRiver(String rivername) { ingo@1230: Query query = session.createQuery( ingo@1230: "from River where name =:name"); ingo@1230: query.setParameter("name", rivername); ingo@1230: ingo@1230: List list = query.list(); ingo@1230: ingo@1230: if (list == null || list.size() == 0) { ingo@1230: logger.warn("No river '" + rivername + "' found!"); ingo@1230: return null; ingo@1230: } ingo@1230: ingo@1230: return list.get(0); ingo@1230: } ingo@1230: ingo@1230: ingo@1230: protected void doRiverAxisInfo(River river) { ingo@1231: RiverAxis axis = RiverAxis.getRiverAxis(river.getName()); ingo@1230: if (axis != null) { ingo@1230: LineString ls = axis.getGeom(); ingo@1230: logger.info("River axis is " + ls.getLength() + " long."); ingo@1231: logger.info("River boundary: " + ls.getBoundary()); ingo@1230: } ingo@1230: else { ingo@1230: logger.warn("River has no RiverAxis."); ingo@1230: } ingo@1230: } ingo@1230: ingo@1230: ingo@1230: protected void doCrossSectionTracksInfo(River river) { ingo@1230: Query query = session.createQuery( ingo@1230: "from CrossSectionTrack where river =:river"); ingo@1230: query.setParameter("river", river); ingo@1230: ingo@1230: List list = query.list(); ingo@1230: ingo@1230: if (list == null || list.size() == 0) { ingo@1230: logger.warn("No CrossSectionTracks for '" + river.getName() + "' found!"); ingo@1230: return; ingo@1230: } ingo@1230: else { ingo@1230: logger.info("River contains " + list.size() + " CrossSectionTracks."); ingo@1230: } ingo@1230: } ingo@1230: ingo@1230: ingo@1230: protected void doLinesInfo(River river) { ingo@1230: Query query = session.createQuery( ingo@1230: "from Line where river =:river"); ingo@1230: query.setParameter("river", river); ingo@1230: ingo@1230: List list = query.list(); ingo@1230: ingo@1230: if (list == null || list.size() == 0) { ingo@1230: logger.warn("No Lines for '" + river.getName() + "' found!"); ingo@1230: return; ingo@1230: } ingo@1230: else { ingo@1230: logger.info("River contains " + list.size() + " Lines."); ingo@1230: } ingo@1230: } ingo@1230: ingo@1230: ingo@1230: protected void doBuildingsInfo(River river) { ingo@1230: Query query = session.createQuery( ingo@1230: "from Building where river =:river"); ingo@1230: query.setParameter("river", river); ingo@1230: ingo@1230: List list = query.list(); ingo@1230: ingo@1230: if (list == null || list.size() == 0) { ingo@1230: logger.warn("No Buildings for '" + river.getName() + "' found!"); ingo@1230: return; ingo@1230: } ingo@1230: else { ingo@1230: logger.info("River contains " + list.size() + " Buildings."); ingo@1230: } ingo@1230: } ingo@1230: ingo@1230: ingo@1230: protected void doFixpointsInfo(River river) { ingo@1230: Query query = session.createQuery( ingo@1230: "from Fixpoint where river =:river"); ingo@1230: query.setParameter("river", river); ingo@1230: ingo@1230: List list = query.list(); ingo@1230: ingo@1230: if (list == null || list.size() == 0) { ingo@1230: logger.warn("No Fixpoints for '" + river.getName() + "' found!"); ingo@1230: return; ingo@1230: } ingo@1230: else { ingo@1230: logger.info("River contains " + list.size() + " Fixpoints."); ingo@1230: } ingo@1230: } ingo@1230: } ingo@1230: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :