Search in sources :

Example 1 with LatLonException

use of net.geoprism.registry.io.LatLonException in project geoprism-registry by terraframe.

the class ExcelImporter method getGeometry.

@Override
public Geometry getGeometry(FeatureRow row) {
    if (this.config.isExternalImport() && this.config.getExternalSystem() instanceof RevealExternalSystem) {
        return ((RevealExcelContentHandler) this.excelHandler).getGeometry();
    } else {
        ShapefileFunction latitudeFunction = this.config.getFunction(GeoObjectImportConfiguration.LATITUDE);
        ShapefileFunction longitudeFunction = this.config.getFunction(GeoObjectImportConfiguration.LONGITUDE);
        if (latitudeFunction != null && longitudeFunction != null) {
            Object latitude = latitudeFunction.getValue(row);
            Object longitude = longitudeFunction.getValue(row);
            if (latitude != null && longitude != null) {
                Double lat = new Double(latitude.toString());
                Double lon = new Double(longitude.toString());
                if (Math.abs(lat) > 90 || Math.abs(lon) > 180) {
                    LatLonException ex = new LatLonException();
                    ex.setLat(lat.toString());
                    ex.setLon(lon.toString());
                    throw ex;
                }
                ImportConfiguration configuration = this.objectImporter.getConfiguration();
                if (configuration instanceof GeoObjectImportConfiguration) {
                    ServerGeoObjectType type = ((GeoObjectImportConfiguration) configuration).getType();
                    if (type.getGeometryType().equals(GeometryType.POINT) || type.getGeometryType().equals(GeometryType.MIXED)) {
                        return new Point(new CoordinateSequence2D(lon, lat), factory);
                    }
                }
                return new MultiPoint(new Point[] { new Point(new CoordinateSequence2D(lon, lat), factory) }, factory);
            }
        }
        return null;
    }
}
Also used : LatLonException(net.geoprism.registry.io.LatLonException) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) CoordinateSequence2D(org.jaitools.jts.CoordinateSequence2D) RevealExternalSystem(net.geoprism.registry.graph.RevealExternalSystem) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ShapefileFunction(net.geoprism.data.importer.ShapefileFunction) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Aggregations

MultiPoint (com.vividsolutions.jts.geom.MultiPoint)1 Point (com.vividsolutions.jts.geom.Point)1 ShapefileFunction (net.geoprism.data.importer.ShapefileFunction)1 RevealExternalSystem (net.geoprism.registry.graph.RevealExternalSystem)1 GeoObjectImportConfiguration (net.geoprism.registry.io.GeoObjectImportConfiguration)1 LatLonException (net.geoprism.registry.io.LatLonException)1 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)1 CoordinateSequence2D (org.jaitools.jts.CoordinateSequence2D)1