comparison artifacts/src/main/java/org/dive4elements/river/utils/GeometryUtils.java @ 8202:e4606eae8ea5

sed src/**/*.java 's/logger/log/g'
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 05 Sep 2014 12:58:17 +0200
parents 4b49b226abc1
children e9d912c97fa8
comparison
equal deleted inserted replaced
8201:4b8c5a08de04 8202:e4606eae8ea5
47 import org.opengis.referencing.operation.MathTransform; 47 import org.opengis.referencing.operation.MathTransform;
48 import org.opengis.referencing.operation.TransformException; 48 import org.opengis.referencing.operation.TransformException;
49 49
50 public class GeometryUtils { 50 public class GeometryUtils {
51 51
52 private static final Logger logger = Logger.getLogger(GeometryUtils.class); 52 private static final Logger log = Logger.getLogger(GeometryUtils.class);
53 53
54 public static final String PREFIX_EPSG = "EPSG:"; 54 public static final String PREFIX_EPSG = "EPSG:";
55 55
56 public static final String DEFAULT_EPSG = "EPSG:31467"; 56 public static final String DEFAULT_EPSG = "EPSG:31467";
57 57
79 79
80 return max; 80 return max;
81 } 81 }
82 } 82 }
83 catch(HibernateException iae) { 83 catch(HibernateException iae) {
84 logger.warn("Exception, no valid river axis found for " + rivername); 84 log.warn("Exception, no valid river axis found for " + rivername);
85 return null; 85 return null;
86 } 86 }
87 logger.warn("No valid river axis found for " + rivername); 87 log.warn("No valid river axis found for " + rivername);
88 88
89 return null; 89 return null;
90 } 90 }
91 91
92 public static String getRiverBounds(String rivername) { 92 public static String getRiverBounds(String rivername) {
224 */ 224 */
225 public static CoordinateReferenceSystem getCoordinateReferenceSystem( 225 public static CoordinateReferenceSystem getCoordinateReferenceSystem(
226 String epsg 226 String epsg
227 ) { 227 ) {
228 if (epsg == null) { 228 if (epsg == null) {
229 logger.warn("cannot create CoordinateReferenceSystem with null"); 229 log.warn("cannot create CoordinateReferenceSystem with null");
230 return null; 230 return null;
231 } 231 }
232 232
233 if (!epsg.startsWith(PREFIX_EPSG)) { 233 if (!epsg.startsWith(PREFIX_EPSG)) {
234 epsg = PREFIX_EPSG + epsg; 234 epsg = PREFIX_EPSG + epsg;
236 236
237 try { 237 try {
238 return CRS.decode(epsg); 238 return CRS.decode(epsg);
239 } 239 }
240 catch (FactoryException fe) { 240 catch (FactoryException fe) {
241 logger.error( 241 log.error(
242 "unable to get CoordinateReferenceSystem for: " + epsg, 242 "unable to get CoordinateReferenceSystem for: " + epsg,
243 fe); 243 fe);
244 } 244 }
245 245
246 return null; 246 return null;
256 Envelope orig, 256 Envelope orig,
257 String targetSrs, 257 String targetSrs,
258 String origSrs 258 String origSrs
259 ) { 259 ) {
260 if (targetSrs == null || orig == null || origSrs == null) { 260 if (targetSrs == null || orig == null || origSrs == null) {
261 logger.warn("unable to transform envelope: empty parameters"); 261 log.warn("unable to transform envelope: empty parameters");
262 return orig; 262 return orig;
263 } 263 }
264 264
265 logger.debug("Transform envlope to '" + targetSrs + "'"); 265 log.debug("Transform envlope to '" + targetSrs + "'");
266 try { 266 try {
267 CoordinateReferenceSystem sourceCRS = 267 CoordinateReferenceSystem sourceCRS =
268 getCoordinateReferenceSystem(origSrs); 268 getCoordinateReferenceSystem(origSrs);
269 269
270 CoordinateReferenceSystem targetCRS = 270 CoordinateReferenceSystem targetCRS =
274 ReferencedEnvelope tmpEnv = 274 ReferencedEnvelope tmpEnv =
275 new ReferencedEnvelope(orig, CRS.decode(origSrs)); 275 new ReferencedEnvelope(orig, CRS.decode(origSrs));
276 276
277 Envelope target = tmpEnv.transform(targetCRS, false); 277 Envelope target = tmpEnv.transform(targetCRS, false);
278 278
279 if (logger.isDebugEnabled()) { 279 if (log.isDebugEnabled()) {
280 logger.debug(" orig envelope : " + orig); 280 log.debug(" orig envelope : " + orig);
281 logger.debug(" transformed envelope: " + target); 281 log.debug(" transformed envelope: " + target);
282 } 282 }
283 283
284 return target; 284 return target;
285 } 285 }
286 } 286 }
287 catch (NoSuchAuthorityCodeException nsae) { 287 catch (NoSuchAuthorityCodeException nsae) {
288 logger.error("Cannot get CoordinateReferenceSystem!", nsae); 288 log.error("Cannot get CoordinateReferenceSystem!", nsae);
289 } 289 }
290 catch (FactoryException fe) { 290 catch (FactoryException fe) {
291 logger.error("Cannot get CoordinateReferenceSystem!", fe); 291 log.error("Cannot get CoordinateReferenceSystem!", fe);
292 } 292 }
293 catch (TransformException te) { 293 catch (TransformException te) {
294 logger.error("Cannot transform envelope from source " 294 log.error("Cannot transform envelope from source "
295 + origSrs + " to target srs " + targetSrs); 295 + origSrs + " to target srs " + targetSrs);
296 } 296 }
297 297
298 return null; 298 return null;
299 } 299 }
308 308
309 public static boolean writeShapefile(File shape, 309 public static boolean writeShapefile(File shape,
310 SimpleFeatureType featureType, FeatureCollection<?, ?> collection, 310 SimpleFeatureType featureType, FeatureCollection<?, ?> collection,
311 CoordinateReferenceSystem crs) { 311 CoordinateReferenceSystem crs) {
312 if (collection.isEmpty()) { 312 if (collection.isEmpty()) {
313 logger.warn("Shapefile is not written - no features given!"); 313 log.warn("Shapefile is not written - no features given!");
314 return false; 314 return false;
315 } 315 }
316 316
317 Transaction transaction = null; 317 Transaction transaction = null;
318 318
358 transaction.commit(); 358 transaction.commit();
359 359
360 return true; 360 return true;
361 } 361 }
362 catch (MalformedURLException mue) { 362 catch (MalformedURLException mue) {
363 logger.error("Unable to prepare shapefile: " + mue.getMessage()); 363 log.error("Unable to prepare shapefile: " + mue.getMessage());
364 } 364 }
365 catch (IOException ioe) { 365 catch (IOException ioe) {
366 logger.error("Unable to write shapefile: " + ioe.getMessage()); 366 log.error("Unable to write shapefile: " + ioe.getMessage());
367 } 367 }
368 catch (NoSuchAuthorityCodeException nsae) { 368 catch (NoSuchAuthorityCodeException nsae) {
369 logger.error("Cannot get CoordinateReferenceSystem for '" 369 log.error("Cannot get CoordinateReferenceSystem for '"
370 + DEFAULT_EPSG + "'"); 370 + DEFAULT_EPSG + "'");
371 } 371 }
372 catch (FactoryException fe) { 372 catch (FactoryException fe) {
373 logger.error("Cannot get CoordinateReferenceSystem for '" 373 log.error("Cannot get CoordinateReferenceSystem for '"
374 + DEFAULT_EPSG + "'"); 374 + DEFAULT_EPSG + "'");
375 } 375 }
376 catch (TransformException te) { 376 catch (TransformException te) {
377 logger.error("Was not able to transform geometry!", te); 377 log.error("Was not able to transform geometry!", te);
378 } 378 }
379 finally { 379 finally {
380 if (transaction != null) { 380 if (transaction != null) {
381 try { 381 try {
382 transaction.close(); 382 transaction.close();

http://dive4elements.wald.intevation.org