From c024ad5740e922f042d8d6f82beb8a9221b06080 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sun, 13 Mar 2011 23:22:56 +0000 Subject: [PATCH] Introduce GPX support git-svn-id: https://svn.argeo.org/slc/trunk@4294 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- runtime/org.argeo.slc.support.gis/.classpath | 1 + .../build.properties | 11 +- .../main/java/org/argeo/slc/gpx/TrackDao.java | 7 + .../java/org/argeo/slc/gpx/TrackPoint.java | 63 ++++ .../java/org/argeo/slc/gpx/TrackSegment.java | 83 +++++ .../java/org/argeo/slc/gpx/TrackSpeed.java | 118 +++++++ .../slc/gpx/hibernate/HibernateTrackDao.java | 291 ++++++++++++++++++ .../slc/gpx/hibernate/TrackPoint.hbm.xml | 19 ++ .../slc/gpx/hibernate/TrackSegment.hbm.xml | 33 ++ .../slc/gpx/hibernate/TrackSpeed.hbm.xml | 25 ++ .../hibernate/HibernateTrackDaoTestCase.java | 61 ++++ .../src/test/resources/log4j.properties | 5 +- .../slc/gpx/hibernate/applicationContext.xml | 51 +++ 13 files changed, 765 insertions(+), 3 deletions(-) create mode 100644 runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackDao.java create mode 100644 runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackPoint.java create mode 100644 runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackSegment.java create mode 100644 runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackSpeed.java create mode 100644 runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/hibernate/HibernateTrackDao.java create mode 100644 runtime/org.argeo.slc.support.gis/src/main/resources/org/argeo/slc/gpx/hibernate/TrackPoint.hbm.xml create mode 100644 runtime/org.argeo.slc.support.gis/src/main/resources/org/argeo/slc/gpx/hibernate/TrackSegment.hbm.xml create mode 100644 runtime/org.argeo.slc.support.gis/src/main/resources/org/argeo/slc/gpx/hibernate/TrackSpeed.hbm.xml create mode 100644 runtime/org.argeo.slc.support.gis/src/test/java/org/argeo/slc/gpx/hibernate/HibernateTrackDaoTestCase.java create mode 100644 runtime/org.argeo.slc.support.gis/src/test/resources/org/argeo/slc/gpx/hibernate/applicationContext.xml diff --git a/runtime/org.argeo.slc.support.gis/.classpath b/runtime/org.argeo.slc.support.gis/.classpath index f0a46691b..409fbda17 100644 --- a/runtime/org.argeo.slc.support.gis/.classpath +++ b/runtime/org.argeo.slc.support.gis/.classpath @@ -2,6 +2,7 @@ + diff --git a/runtime/org.argeo.slc.support.gis/build.properties b/runtime/org.argeo.slc.support.gis/build.properties index f667d5dd5..7c9aa40a5 100644 --- a/runtime/org.argeo.slc.support.gis/build.properties +++ b/runtime/org.argeo.slc.support.gis/build.properties @@ -15,4 +15,13 @@ additional.bundles = com.springsource.slf4j.api,\ com.springsource.javax.media.jai.codec,\ com.springsource.javax.media.jai.core,\ org.argeo.dep.osgi.jai.imageio,\ - org.springframework.context + org.springframework.context,\ + org.argeo.slc.unit,\ + com.springsource.junit,\ + com.springsource.org.dom4j,\ + org.springframework.jdbc,\ + com.springsource.org.postgresql.jdbc3,\ + com.springsource.javax.transaction,\ + org.argeo.dep.osgi.postgis.jdbc,\ + com.springsource.org.apache.commons.collections,\ + com.springsource.javassist diff --git a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackDao.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackDao.java new file mode 100644 index 000000000..5a20baf1e --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackDao.java @@ -0,0 +1,7 @@ +package org.argeo.slc.gpx; + +import java.io.InputStream; + +public interface TrackDao { + public Object importTrackPoints(String sensor, InputStream in); +} diff --git a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackPoint.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackPoint.java new file mode 100644 index 000000000..76e290cb1 --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackPoint.java @@ -0,0 +1,63 @@ +package org.argeo.slc.gpx; + +import java.util.Date; + +import com.vividsolutions.jts.geom.Point; + +public class TrackPoint { + private Integer tid; + private String segmentUuid; + private String sensor; + private Date utcTimestamp; + private Point location; + private Double elevation; + + public Integer getTid() { + return tid; + } + + public void setTid(Integer tid) { + this.tid = tid; + } + + public String getSegmentUuid() { + return segmentUuid; + } + + public void setSegmentUuid(String segmentUuid) { + this.segmentUuid = segmentUuid; + } + + public String getSensor() { + return sensor; + } + + public void setSensor(String sensor) { + this.sensor = sensor; + } + + public Date getUtcTimestamp() { + return utcTimestamp; + } + + public void setUtcTimestamp(Date ts) { + this.utcTimestamp = ts; + } + + public Point getLocation() { + return location; + } + + public void setLocation(Point location) { + this.location = location; + } + + public Double getElevation() { + return elevation; + } + + public void setElevation(Double elevation) { + this.elevation = elevation; + } + +} diff --git a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackSegment.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackSegment.java new file mode 100644 index 000000000..2ae0a4ba9 --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackSegment.java @@ -0,0 +1,83 @@ +package org.argeo.slc.gpx; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import com.vividsolutions.jts.geom.LineString; + +public class TrackSegment { + private Integer tid; + private String uuid; + private String sensor; + private Date startUtc; + private Date endUtc; + private LineString segment; + private List trackPoints = new ArrayList(); + private List trackSpeeds = new ArrayList(); + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getSensor() { + return sensor; + } + + public void setSensor(String sensor) { + this.sensor = sensor; + } + + public List getTrackPoints() { + return trackPoints; + } + + public void setTrackPoints(List trackPoints) { + this.trackPoints = trackPoints; + } + + public Date getStartUtc() { + return startUtc; + } + + public void setStartUtc(Date start) { + this.startUtc = start; + } + + public Date getEndUtc() { + return endUtc; + } + + public void setEndUtc(Date end) { + this.endUtc = end; + } + + public LineString getSegment() { + return segment; + } + + public void setSegment(LineString segment) { + this.segment = segment; + } + + public Integer getTid() { + return tid; + } + + public void setTid(Integer tid) { + this.tid = tid; + } + + public List getTrackSpeeds() { + return trackSpeeds; + } + + public void setTrackSpeeds(List trackSpeeds) { + this.trackSpeeds = trackSpeeds; + } + +} diff --git a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackSpeed.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackSpeed.java new file mode 100644 index 000000000..7e6bfd036 --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/TrackSpeed.java @@ -0,0 +1,118 @@ +package org.argeo.slc.gpx; + +import java.util.Date; + +import com.vividsolutions.jts.geom.LineString; +import com.vividsolutions.jts.geom.Point; + +public class TrackSpeed { + private Integer tid; + private String segmentUuid; + private String sensor; + private Date utcTimestamp; + private Point location; + private LineString line; + private Double length; + private Long duration; + // length(line)/(duration in h) + private Double speed; + // can be null + private Double acceleration; + + public TrackSpeed() { + } + + public TrackSpeed(TrackPoint ref, LineString line, Long duration) { + segmentUuid = ref.getSegmentUuid(); + sensor = ref.getSensor(); + utcTimestamp = ref.getUtcTimestamp(); + location = ref.getLocation(); + this.line = line; + this.duration = duration; + + this.length = Math.abs(line.getLength()); + // in km/h + this.speed = (this.length * 60 * 60) / this.duration; + } + + public Integer getTid() { + return tid; + } + + public void setTid(Integer tid) { + this.tid = tid; + } + + public String getSegmentUuid() { + return segmentUuid; + } + + public void setSegmentUuid(String segmentUuid) { + this.segmentUuid = segmentUuid; + } + + public String getSensor() { + return sensor; + } + + public void setSensor(String sensor) { + this.sensor = sensor; + } + + public Date getUtcTimestamp() { + return utcTimestamp; + } + + public void setUtcTimestamp(Date ts) { + this.utcTimestamp = ts; + } + + public Point getLocation() { + return location; + } + + public void setLocation(Point location) { + this.location = location; + } + + public LineString getLine() { + return line; + } + + public void setLine(LineString line) { + this.line = line; + } + + public Long getDuration() { + return duration; + } + + public void setDuration(Long duration) { + this.duration = duration; + } + + public Double getSpeed() { + return speed; + } + + public void setSpeed(Double speed) { + this.speed = speed; + } + + public Double getLength() { + return length; + } + + public void setLength(Double length) { + this.length = length; + } + + public Double getAcceleration() { + return acceleration; + } + + public void setAcceleration(Double acceleration) { + this.acceleration = acceleration; + } + +} diff --git a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/hibernate/HibernateTrackDao.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/hibernate/HibernateTrackDao.java new file mode 100644 index 000000000..6f7593bc6 --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpx/hibernate/HibernateTrackDao.java @@ -0,0 +1,291 @@ +package org.argeo.slc.gpx.hibernate; + +import java.io.InputStream; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.ArgeoException; +import org.argeo.slc.gpx.TrackDao; +import org.argeo.slc.gpx.TrackPoint; +import org.argeo.slc.gpx.TrackSegment; +import org.argeo.slc.gpx.TrackSpeed; +import org.geotools.geometry.DirectPosition2D; +import org.geotools.referencing.CRS; +import org.opengis.geometry.DirectPosition; +import org.opengis.referencing.crs.CoordinateReferenceSystem; +import org.opengis.referencing.operation.MathTransform; +import org.springframework.orm.hibernate3.support.HibernateDaoSupport; +import org.xml.sax.Attributes; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.GeometryFactory; +import com.vividsolutions.jts.geom.LineString; +import com.vividsolutions.jts.geom.Point; +import com.vividsolutions.jts.geom.PrecisionModel; + +public class HibernateTrackDao extends HibernateDaoSupport implements TrackDao { + private final static Log log = LogFactory.getLog(HibernateTrackDao.class); + private final static DateFormat ISO8601 = new SimpleDateFormat( + "yyyy-MM-dd'T'HH:mm:ss"); + + private Long batchSize = 100l; + private Integer targetSrid = 4326; + private Float maxSpeed = 250f; + + public Object importTrackPoints(String sensor, InputStream in) { + long begin = System.currentTimeMillis(); + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setValidating(false); + SAXParser sp = spf.newSAXParser(); + InputSource input = new InputSource(in); + TrackGpxHandler handler = new TrackGpxHandler(sensor, targetSrid); + sp.parse(input, handler); + return null; + } catch (Exception e) { + throw new ArgeoException("Cannot parse GPX stream", e); + } finally { + long duration = System.currentTimeMillis() - begin; + if (log.isDebugEnabled()) + log.debug("Imported from sensor '" + sensor + "' in " + + (duration) + " ms"); + } + } + + protected void processTrackSegment(TrackSegment trackSegment, + GeometryFactory geometryFactory) { + TrackSpeed currentTrackSpeed = null; + List coords = new ArrayList(); + trackPoints: for (int i = 0; i < trackSegment.getTrackPoints().size(); i++) { + TrackPoint trackPoint = trackSegment.getTrackPoints().get(i); + coords.add(new Coordinate(trackPoint.getLocation().getX(), + trackPoint.getLocation().getY())); + + if (i == 0) + trackSegment.setStartUtc(trackPoint.getUtcTimestamp()); + + if (i == trackSegment.getTrackPoints().size() - 1) + trackSegment.setEndUtc(trackPoint.getUtcTimestamp()); + else { + // SPEED + TrackPoint next = trackSegment.getTrackPoints().get(i + 1); + + Coordinate[] crds = { trackPoint.getLocation().getCoordinate(), + next.getLocation().getCoordinate() }; + LineString line = geometryFactory.createLineString(crds); + Long duration = next.getUtcTimestamp().getTime() + - trackPoint.getUtcTimestamp().getTime(); + if (duration < 0) { + log.warn("Duration " + duration + " is negative between " + + trackPoint.getLocation() + " and " + + next.getLocation() + + ", skipping speed computation"); + currentTrackSpeed = null; + continue trackPoints; + } + TrackSpeed trackSpeed = new TrackSpeed(trackPoint, line, + duration); + if (trackSpeed.getSpeed() > maxSpeed) { + log.warn("Speed " + trackSpeed.getSpeed() + " is above " + + maxSpeed + " between " + trackPoint.getLocation() + + " and " + next.getLocation() + + ", skipping speed computation"); + currentTrackSpeed = null; + continue trackPoints; + } + + if (currentTrackSpeed != null) { + // in m/s² + Double speed1 = trackSpeed.getLength() + / (trackSpeed.getDuration() / 1000); + Double speed2 = currentTrackSpeed.getLength() + / (currentTrackSpeed.getDuration() / 1000); + Double acceleration = (speed1 - speed2) + / (currentTrackSpeed.getDuration() / 1000); + trackSpeed.setAcceleration(acceleration); + } + trackSegment.getTrackSpeeds().add(trackSpeed); + currentTrackSpeed = trackSpeed; + } + + } + LineString segment = geometryFactory.createLineString(coords + .toArray(new Coordinate[coords.size()])); + trackSegment.setSegment(segment); + + } + + public void setBatchSize(Long batchSize) { + this.batchSize = batchSize; + } + + public void setTargetSrid(Integer targetSrid) { + this.targetSrid = targetSrid; + } + + public void setMaxSpeed(Float maxSpeed) { + this.maxSpeed = maxSpeed; + } + + class TrackGpxHandler extends DefaultHandler { + private final CoordinateReferenceSystem wgs84; + private final GeometryFactory targetGF; + + private final MathTransform reprojection; + + public static final String TAG_TRKSEG = "trkseg"; + public static final String TAG_TRKPT = "trkpt"; + public static final String TAG_TIME = "time"; + public static final String TAG_ELE = "ele"; + public static final String ATTR_LAT = "lat"; + public static final String ATTR_LON = "lon"; + + private String sensor; + + private StringBuffer accumulator = new StringBuffer(); + + private Long segmentCount = 0l; + private Long pointCount = 0l; + private Long currentSegmentPointCount = 0l; + private String currentSegmentUuid = null; + private TrackPoint currentTrackPoint = null; + + private TrackSegment currentTrackSegment = null; + + private List trackPoints = new ArrayList(); + + public TrackGpxHandler(String sensor, Integer srid) { + this.sensor = sensor; + PrecisionModel precisionModel = new PrecisionModel(); + targetGF = new GeometryFactory(precisionModel, srid); + if (srid != 4326) { + try { + wgs84 = CRS.decode("EPSG:4326"); + reprojection = CRS.findMathTransform(wgs84, + CRS.decode("EPSG:" + srid)); + } catch (Exception e) { + throw new ArgeoException("Cannot find reprojection", e); + } + } else { + reprojection = null; + wgs84 = null; + } + } + + public void characters(char[] buffer, int start, int length) { + accumulator.append(buffer, start, length); + } + + @Override + public void startElement(String uri, String localName, String qName, + Attributes attributes) throws SAXException { + // log.debug("Element: localName=" + localName + ", uri=" + uri + // + ", qName=" + qName); + + accumulator.setLength(0); // Ready to accumulate new text + if (qName.equals(TAG_TRKSEG)) { + currentSegmentUuid = UUID.randomUUID().toString(); + currentTrackSegment = new TrackSegment(); + currentTrackSegment.setSensor(sensor); + currentTrackSegment.setUuid(currentSegmentUuid); + } else if (qName.equals(TAG_TRKPT)) { + currentTrackPoint = new TrackPoint(); + currentTrackPoint.setSensor(sensor); + currentTrackPoint.setSegmentUuid(currentSegmentUuid); + String latStr = attributes.getValue(ATTR_LAT); + String lonStr = attributes.getValue(ATTR_LON); + Coordinate coordinate = new Coordinate( + Double.parseDouble(lonStr), Double.parseDouble(latStr)); + Point location = reproject(coordinate); + currentTrackPoint.setLocation(location); + } + } + + @Override + public void endElement(String uri, String localName, String qName) + throws SAXException { + // if (log.isDebugEnabled()) + // log.debug("TAG " + qName); + if (qName.equals(TAG_TRKSEG)) { + // if (log.isDebugEnabled()) + // log.debug("Processed segment " + currentSegmentUuid + ": " + // + currentSegmentPointCount + " points"); + + if (currentTrackSegment.getTrackPoints().size() > 1) { + processTrackSegment(currentTrackSegment, targetGF); + + // persist + getHibernateTemplate().save(currentTrackSegment); + segmentCount++; + if (segmentCount % batchSize == 0) { + getHibernateTemplate().flush(); + getHibernateTemplate().clear(); + } + } else if (currentTrackSegment.getTrackPoints().size() == 1) { + TrackPoint trackPoint = currentTrackSegment + .getTrackPoints().get(0); + getHibernateTemplate().save(trackPoint); + } + currentSegmentPointCount = 0l; + currentSegmentUuid = null; + } else if (qName.equals(TAG_TRKPT)) { + trackPoints.add(currentTrackPoint); + pointCount++; + currentSegmentPointCount++; + + currentTrackSegment.getTrackPoints().add(currentTrackPoint); + + // getHibernateTemplate().save(currentTrackPoint); + + currentTrackPoint = null; + } else if (qName.equals(TAG_ELE)) { + Double elevation = Double.parseDouble(accumulator.toString() + .trim()); + currentTrackPoint.setElevation(elevation); + } else if (qName.equals(TAG_TIME) && currentTrackPoint != null) { + String timeStr = accumulator.toString().trim(); + try { + Date time = ISO8601.parse(timeStr); + currentTrackPoint.setUtcTimestamp(time); + } catch (ParseException e) { + throw new ArgeoException("Cannot parse date " + timeStr); + } + } + + } + + protected Point reproject(Coordinate coordinate) { + if (reprojection != null) { + try { + // invert order + DirectPosition2D pos = new DirectPosition2D(wgs84, + coordinate.y, coordinate.x); + DirectPosition targetPos = reprojection + .transform(pos, null); + Coordinate targetCoordinate = new Coordinate( + targetPos.getOrdinate(0), targetPos.getOrdinate(1)); + return targetGF.createPoint(targetCoordinate); + } catch (Exception e) { + throw new ArgeoException("Cannot reproject " + coordinate, + e); + } + } else { + return targetGF.createPoint(coordinate); + } + } + } + +} diff --git a/runtime/org.argeo.slc.support.gis/src/main/resources/org/argeo/slc/gpx/hibernate/TrackPoint.hbm.xml b/runtime/org.argeo.slc.support.gis/src/main/resources/org/argeo/slc/gpx/hibernate/TrackPoint.hbm.xml new file mode 100644 index 000000000..993812350 --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/resources/org/argeo/slc/gpx/hibernate/TrackPoint.hbm.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/runtime/org.argeo.slc.support.gis/src/main/resources/org/argeo/slc/gpx/hibernate/TrackSegment.hbm.xml b/runtime/org.argeo.slc.support.gis/src/main/resources/org/argeo/slc/gpx/hibernate/TrackSegment.hbm.xml new file mode 100644 index 000000000..898c86465 --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/resources/org/argeo/slc/gpx/hibernate/TrackSegment.hbm.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/runtime/org.argeo.slc.support.gis/src/main/resources/org/argeo/slc/gpx/hibernate/TrackSpeed.hbm.xml b/runtime/org.argeo.slc.support.gis/src/main/resources/org/argeo/slc/gpx/hibernate/TrackSpeed.hbm.xml new file mode 100644 index 000000000..c3d3d6446 --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/resources/org/argeo/slc/gpx/hibernate/TrackSpeed.hbm.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/runtime/org.argeo.slc.support.gis/src/test/java/org/argeo/slc/gpx/hibernate/HibernateTrackDaoTestCase.java b/runtime/org.argeo.slc.support.gis/src/test/java/org/argeo/slc/gpx/hibernate/HibernateTrackDaoTestCase.java new file mode 100644 index 000000000..ee22ec59d --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/test/java/org/argeo/slc/gpx/hibernate/HibernateTrackDaoTestCase.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.argeo.slc.gpx.hibernate; + +import java.io.File; +import java.io.FileInputStream; + +import org.apache.commons.io.IOUtils; +import org.argeo.slc.gpx.TrackDao; +import org.argeo.slc.hibernate.unit.HibernateTestCase; +import org.hibernatespatial.HBSpatialExtension; +import org.hibernatespatial.cfg.HSConfiguration; + +public class HibernateTrackDaoTestCase extends HibernateTestCase { + static { + HSConfiguration config = new HSConfiguration(); + config.setDefaultDialect("org.hibernatespatial.postgis.PostgisDialect"); + + HBSpatialExtension.setConfiguration(config); + } + + public void testImport() throws Exception { + String sensor = "mbaudier"; + File dir = new File("/home/mbaudier/ArgeoOffice/perso/gps/trips/2010"); + + TrackDao trackDao = getBean(TrackDao.class); + long begin = System.currentTimeMillis(); + for (File file : dir.listFiles()) { + if (!file.getName().endsWith(".gpx")) + continue; + FileInputStream in = null; + try { + in = new FileInputStream(file); + trackDao.importTrackPoints(sensor, in); + } catch (Exception e) { + log.warn("Could not import " + file + ": " + e.getMessage()); + throw e; + } finally { + IOUtils.closeQuietly(in); + } + } + double duration = System.currentTimeMillis() - begin; + if (log.isDebugEnabled()) + log.debug("Imported files from " + dir + " in " + + (duration / 1000 / 60) + " min"); + } +} diff --git a/runtime/org.argeo.slc.support.gis/src/test/resources/log4j.properties b/runtime/org.argeo.slc.support.gis/src/test/resources/log4j.properties index 0133bab88..7f7069c47 100644 --- a/runtime/org.argeo.slc.support.gis/src/test/resources/log4j.properties +++ b/runtime/org.argeo.slc.support.gis/src/test/resources/log4j.properties @@ -5,8 +5,9 @@ log4j.rootLogger=WARN, console # Slc log4j.logger.org.argeo=DEBUG -# Castor -log4j.logger.org.exolab.castor=WARN +# Hibernate +log4j.logger.org.hibernate=WARN +log4j.logger.org.hibernatespatial=WARN # Spring log4j.logger.org.springframework=WARN diff --git a/runtime/org.argeo.slc.support.gis/src/test/resources/org/argeo/slc/gpx/hibernate/applicationContext.xml b/runtime/org.argeo.slc.support.gis/src/test/resources/org/argeo/slc/gpx/hibernate/applicationContext.xml new file mode 100644 index 000000000..93218660b --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/test/resources/org/argeo/slc/gpx/hibernate/applicationContext.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + org/argeo/slc/gpx/hibernate/TrackPoint.hbm.xml + org/argeo/slc/gpx/hibernate/TrackSegment.hbm.xml + org/argeo/slc/gpx/hibernate/TrackSpeed.hbm.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.39.2