Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/backend/SpatialInfo.java @ 3815:ecab7e7804a9 pre2.6-2012-01-04
merged flys-backend/pre2.6-2012-01-04
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:57 +0200 |
parents | 22eea1c9e907 |
children | 61cb16549eb1 |
comparison
equal
deleted
inserted
replaced
3814:8083f6384023 | 3815:ecab7e7804a9 |
---|---|
1 package de.intevation.flys.backend; | |
2 | |
3 import java.util.List; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.hibernate.Query; | |
8 import org.hibernate.Session; | |
9 | |
10 import com.vividsolutions.jts.geom.LineString; | |
11 | |
12 import de.intevation.flys.backend.SessionFactoryProvider; | |
13 import de.intevation.flys.model.Building; | |
14 import de.intevation.flys.model.CrossSectionTrack; | |
15 import de.intevation.flys.model.Fixpoint; | |
16 import de.intevation.flys.model.Line; | |
17 import de.intevation.flys.model.River; | |
18 import de.intevation.flys.model.RiverAxis; | |
19 | |
20 | |
21 public class SpatialInfo { | |
22 | |
23 private static Logger logger = Logger.getLogger(SpatialInfo.class); | |
24 | |
25 protected static String RIVERNAME = System.getProperty( | |
26 "flys.backend.spatial.river", "Saar"); | |
27 | |
28 protected Session session; | |
29 | |
30 | |
31 public static void main(String[] args) { | |
32 logger.info("Start SpatialInfo application."); | |
33 | |
34 SpatialInfo spatial = null; | |
35 | |
36 try { | |
37 spatial = new SpatialInfo(); | |
38 | |
39 River river = spatial.getRiver(RIVERNAME); | |
40 if (river == null) { | |
41 logger.warn("Could not find river '" + RIVERNAME + "'!"); | |
42 return; | |
43 } | |
44 | |
45 logger.info("Spatial information of River '" + RIVERNAME + "'"); | |
46 spatial.doRiverAxisInfo(river); | |
47 spatial.doCrossSectionTracksInfo(river); | |
48 spatial.doLinesInfo(river); | |
49 spatial.doBuildingsInfo(river); | |
50 spatial.doFixpointsInfo(river); | |
51 } | |
52 finally { | |
53 if (spatial != null) { | |
54 spatial.close(); | |
55 } | |
56 } | |
57 | |
58 logger.info("Finish SpatialInfo application."); | |
59 } | |
60 | |
61 | |
62 public SpatialInfo() { | |
63 session = SessionFactoryProvider | |
64 .createSessionFactory() | |
65 .openSession(); | |
66 } | |
67 | |
68 | |
69 public void close() { | |
70 session.close(); | |
71 } | |
72 | |
73 | |
74 protected River getRiver(String rivername) { | |
75 Query query = session.createQuery( | |
76 "from River where name =:name"); | |
77 query.setParameter("name", rivername); | |
78 | |
79 List<River> list = query.list(); | |
80 | |
81 if (list == null || list.size() == 0) { | |
82 logger.warn("No river '" + rivername + "' found!"); | |
83 return null; | |
84 } | |
85 | |
86 return list.get(0); | |
87 } | |
88 | |
89 | |
90 protected void doRiverAxisInfo(River river) { | |
91 RiverAxis axis = RiverAxis.getRiverAxis(river.getName()); | |
92 if (axis != null) { | |
93 LineString ls = axis.getGeom(); | |
94 logger.info("River axis is " + ls.getLength() + " long."); | |
95 logger.info("River boundary: " + ls.getBoundary()); | |
96 } | |
97 else { | |
98 logger.warn("River has no RiverAxis."); | |
99 } | |
100 } | |
101 | |
102 | |
103 protected void doCrossSectionTracksInfo(River river) { | |
104 Query query = session.createQuery( | |
105 "from CrossSectionTrack where river =:river"); | |
106 query.setParameter("river", river); | |
107 | |
108 List<CrossSectionTrack> list = query.list(); | |
109 | |
110 if (list == null || list.size() == 0) { | |
111 logger.warn("No CrossSectionTracks for '" + river.getName() + "' found!"); | |
112 return; | |
113 } | |
114 else { | |
115 logger.info("River contains " + list.size() + " CrossSectionTracks."); | |
116 } | |
117 } | |
118 | |
119 | |
120 protected void doLinesInfo(River river) { | |
121 Query query = session.createQuery( | |
122 "from Line where river =:river"); | |
123 query.setParameter("river", river); | |
124 | |
125 List<Line> list = query.list(); | |
126 | |
127 if (list == null || list.size() == 0) { | |
128 logger.warn("No Lines for '" + river.getName() + "' found!"); | |
129 return; | |
130 } | |
131 else { | |
132 logger.info("River contains " + list.size() + " Lines."); | |
133 } | |
134 } | |
135 | |
136 | |
137 protected void doBuildingsInfo(River river) { | |
138 Query query = session.createQuery( | |
139 "from Building where river =:river"); | |
140 query.setParameter("river", river); | |
141 | |
142 List<Building> list = query.list(); | |
143 | |
144 if (list == null || list.size() == 0) { | |
145 logger.warn("No Buildings for '" + river.getName() + "' found!"); | |
146 return; | |
147 } | |
148 else { | |
149 logger.info("River contains " + list.size() + " Buildings."); | |
150 } | |
151 } | |
152 | |
153 | |
154 protected void doFixpointsInfo(River river) { | |
155 Query query = session.createQuery( | |
156 "from Fixpoint where river =:river"); | |
157 query.setParameter("river", river); | |
158 | |
159 List<Fixpoint> list = query.list(); | |
160 | |
161 if (list == null || list.size() == 0) { | |
162 logger.warn("No Fixpoints for '" + river.getName() + "' found!"); | |
163 return; | |
164 } | |
165 else { | |
166 logger.info("River contains " + list.size() + " Fixpoints."); | |
167 } | |
168 } | |
169 } | |
170 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |