Skip to content

Commit f033c52

Browse files
author
Derek Yeager
committed
Geolife Ingest handling of bad coordinates
1 parent 7d7525a commit f033c52

2 files changed

Lines changed: 36 additions & 13 deletions

File tree

extensions/adapters/vector/src/main/java/mil/nga/giat/geowave/adapter/vector/utils/GeometryUtils.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,9 @@ public static List<Polygon> constructGeometriesOverMapRegions(
212212

213213
/**
214214
* Make sure the coordinate falls in the range of provided coordinate
215-
* reference systems's coordinate system.
216-
* 'x' coordinate is wrapped around date line.
217-
* 'y' and 'z' coordinate are clipped. At some point, this function
218-
* will be adjusted to project 'y' appropriately.
215+
* reference systems's coordinate system. 'x' coordinate is wrapped around
216+
* date line. 'y' and 'z' coordinate are clipped. At some point, this
217+
* function will be adjusted to project 'y' appropriately.
219218
*
220219
* @param crs
221220
* @param coord
@@ -339,7 +338,7 @@ private static double clipRange(
339338
* the coordinate axis
340339
* @return
341340
*/
342-
private static double adjustCoordinateDimensionToRange(
341+
public static double adjustCoordinateDimensionToRange(
343342
final double val,
344343
final CoordinateReferenceSystem crs,
345344
final int axis ) {

extensions/formats/geolife/src/main/java/mil/nga/giat/geowave/format/geolife/GeoLifeIngestPlugin.java

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import mil.nga.giat.geowave.adapter.vector.FeatureDataAdapter;
1717
import mil.nga.giat.geowave.adapter.vector.ingest.AbstractSimpleFeatureIngestPlugin;
18-
import mil.nga.giat.geowave.core.geotime.GeometryUtils;
18+
import mil.nga.giat.geowave.adapter.vector.utils.GeometryUtils;
1919
import mil.nga.giat.geowave.core.geotime.IndexType;
2020
import mil.nga.giat.geowave.core.index.ByteArrayId;
2121
import mil.nga.giat.geowave.core.index.StringUtils;
@@ -34,10 +34,14 @@
3434
import org.apache.commons.io.IOUtils;
3535
import org.apache.log4j.Logger;
3636
import org.geotools.feature.simple.SimpleFeatureBuilder;
37+
import org.geotools.referencing.CRS;
3738
import org.opengis.feature.simple.SimpleFeature;
3839
import org.opengis.feature.simple.SimpleFeatureType;
40+
import org.opengis.referencing.FactoryException;
41+
import org.opengis.referencing.crs.CoordinateReferenceSystem;
3942

4043
import com.vividsolutions.jts.geom.Coordinate;
44+
import com.vividsolutions.jts.geom.GeometryFactory;
4145

4246
/*
4347
*/
@@ -58,6 +62,8 @@ public class GeoLifeIngestPlugin extends
5862

5963
private final Index[] supportedIndices;
6064

65+
private CoordinateReferenceSystem crs;
66+
6167
public GeoLifeIngestPlugin() {
6268
geolifePointType = GeoLifeUtils.createGeoLifePointDataType();
6369
pointKey = new ByteArrayId(
@@ -75,7 +81,14 @@ public GeoLifeIngestPlugin() {
7581
IndexType.SPATIAL_VECTOR.createDefaultIndex(),
7682
IndexType.SPATIAL_TEMPORAL_VECTOR.createDefaultIndex()
7783
};
78-
84+
try {
85+
crs = CRS.decode("EPSG:4326");
86+
}
87+
catch (FactoryException e) {
88+
LOGGER.error(
89+
"Unable to decode Coordinate Reference System authority code!",
90+
e);
91+
}
7992
}
8093

8194
@Override
@@ -183,6 +196,9 @@ protected CloseableIterator<GeoWaveData<SimpleFeature>> toGeoWaveDataInternal(
183196
Date startTimeStamp = null;
184197
Date endTimeStamp = null;
185198
String timestring = "";
199+
GeometryFactory geometryFactory = new GeometryFactory();
200+
double currLat;
201+
double currLng;
186202
try {
187203
while ((line = br.readLine()) != null) {
188204

@@ -191,13 +207,21 @@ protected CloseableIterator<GeoWaveData<SimpleFeature>> toGeoWaveDataInternal(
191207
continue;
192208
}
193209

194-
final Coordinate cord = new Coordinate(
210+
currLat = GeometryUtils.adjustCoordinateDimensionToRange(
211+
Double.parseDouble(vals[0]),
212+
crs,
213+
1);
214+
currLng = GeometryUtils.adjustCoordinateDimensionToRange(
195215
Double.parseDouble(vals[1]),
196-
Double.parseDouble(vals[0]));
216+
crs,
217+
0);
218+
final Coordinate cord = new Coordinate(
219+
currLng,
220+
currLat);
197221
pts.add(cord);
198222
geolifePointBuilder.set(
199223
"geometry",
200-
GeometryUtils.GEOMETRY_FACTORY.createPoint(cord));
224+
geometryFactory.createPoint(cord));
201225
geolifePointBuilder.set(
202226
"trackid",
203227
trackId);
@@ -218,10 +242,10 @@ protected CloseableIterator<GeoWaveData<SimpleFeature>> toGeoWaveDataInternal(
218242

219243
geolifePointBuilder.set(
220244
"Latitude",
221-
Double.parseDouble(vals[0]));
245+
currLat);
222246
geolifePointBuilder.set(
223247
"Longitude",
224-
Double.parseDouble(vals[1]));
248+
currLng);
225249

226250
Double elevation = Double.parseDouble(vals[3]);
227251
if (elevation == -777) {
@@ -238,7 +262,7 @@ protected CloseableIterator<GeoWaveData<SimpleFeature>> toGeoWaveDataInternal(
238262

239263
geolifeTrackBuilder.set(
240264
"geometry",
241-
GeometryUtils.GEOMETRY_FACTORY.createLineString(pts.toArray(new Coordinate[pts.size()])));
265+
geometryFactory.createLineString(pts.toArray(new Coordinate[pts.size()])));
242266

243267
geolifeTrackBuilder.set(
244268
"StartTimeStamp",

0 commit comments

Comments
 (0)