private void addWaterlevels(final Session session, final GafProfile profile, final GafPart part) { if (m_waterlevelEvent == null) return; final GafKind kind = part.getKind(); if (!GafKind.W.equals(kind)) return; final GafPoint[] points = part.getPoints(); for (final GafPoint point : points) { final WaterlevelFixation fixation = new WaterlevelFixation(); fixation.setEvent(m_waterlevelEvent); fixation.setDescription(StringUtils.EMPTY); fixation.setCreationDate(m_waterlevelEvent.getCreationDate()); fixation.setEditingDate(m_waterlevelEvent.getEditingDate()); fixation.setEditingUser(m_waterlevelEvent.getEditingUser()); fixation.setMeasurementDate(m_waterlevelEvent.getMeasurementDate()); fixation.setLocation(point.getPoint()); fixation.setStation(profile.getStation()); fixation.setWaterlevel(point.getHeight()); m_waterlevelEvent.getWaterlevelFixations().add(fixation); session.save(fixation); } }
private CrossSectionPart commitPart( final Session session, final String dbType, final CrossSection crossSection, final GafPart part, final PDBNameGenerator nameGenerator) throws Exception { final CrossSectionPart csPart = new CrossSectionPart(); final GafKind partKind = part.getKind(); final String name = nameGenerator.createUniqueName(partKind.toString()); csPart.setName(name); if (part.getKind() == GafKind.W) { final String gafFileName = m_profiles.getGafFilename(); csPart.setDescription( String.format(Messages.getString("Gaf2Db.5"), gafFileName)); // $NON-NLS-1$ } else csPart.setDescription(StringUtils.EMPTY); final CrossSectionPartType partType = findPartType(partKind); csPart.setCrossSectionPartType(partType); final Geometry line = part.getLine(dbType); csPart.setLine(line); csPart.setCrossSection(crossSection); session.save(csPart); return csPart; }
private void commitProfile(final Session session, final String dbType, final GafProfile profile) throws Exception { final CrossSection crossSection = commitCrossSection(session, dbType, profile); /* Get PP part */ final GafPart[] parts = profile.getParts(); final GafPart ppPart = profile.findPart(GafKind.P); /* add parts */ for (final GafPart gafPart : parts) { final PDBNameGenerator partNameGenerator = new PDBNameGenerator(); final CrossSectionPart csPart = commitPart(session, dbType, crossSection, gafPart, partNameGenerator); if (csPart == null) continue; final GafPoint[] points = gafPart.getPoints(); for (int j = 0; j < points.length; j++) { final PDBNameGenerator pointNameGenerator = new PDBNameGenerator(); final GafPoint gafPoint = points[j]; commitPoint(gafPart, session, csPart, gafPoint, j, pointNameGenerator, ppPart); } addWaterlevels(session, profile, gafPart); } }
private BigDecimal calculateWidthFromDistance( final GafPart gafPart, final com.vividsolutions.jts.geom.Point location) { final GafPoint startPoint = gafPart.getPoints()[0]; final com.vividsolutions.jts.geom.Point startLocation = startPoint.getPoint(); if (location == null || startLocation == null) return null; final double distance = location.distance(startLocation); return new BigDecimal(distance).setScale(3, BigDecimal.ROUND_HALF_UP); }
/** * Calculates the width of a point if it is not set in the gaf file.<br> * For PP points, it is just the distance to the first point.<br> * For non-pp points, it is the station of the point projected to the pp-line. */ private BigDecimal getOrCalculatePoint( final GafPart gafPart, final GafPoint gafPoint, final GafPart projectionPart) { final BigDecimal width = gafPoint.getWidth(); if (width != null) return width; final com.vividsolutions.jts.geom.Point location = gafPoint.getPoint(); if (GafKind.P.equals(gafPart.getKind()) || projectionPart == null) { return calculateWidthFromDistance(gafPart, location); } else { final Geometry line = projectionPart.getLine(m_dbType); if (!(line instanceof LineString) || line.getNumPoints() < 2) return calculateWidthFromDistance(gafPart, location); final LineString ls = (LineString) line; final LocationIndexedLine lineRef = new LocationIndexedLine(line); final LinearLocation loc = lineRef.project(location.getCoordinate()); final Coordinate closestPt = loc.getCoordinate(line); final double distance = ls.getCoordinateN(0).distance(closestPt); return new BigDecimal(distance).setScale(3, BigDecimal.ROUND_HALF_UP); } }