use of com.vividsolutions.jts.io.ParseException in project ili2db by claeis.
the class GpkgColumnConverter method toIomPolyline.
@Override
public IomObject toIomPolyline(Object geomobj, String sqlAttrName, boolean is3D) throws SQLException, ConverterException {
byte[] bv = (byte[]) geomobj;
Gpkg2iox conv = new Gpkg2iox();
try {
return conv.read(bv);
} catch (ParseException e) {
throw new ConverterException(e);
}
}
use of com.vividsolutions.jts.io.ParseException in project hale by halestudio.
the class MsSqlGeometries method convertToInstanceGeometry.
/**
* @see eu.esdihumboldt.hale.io.jdbc.GeometryAdvisor#convertToInstanceGeometry(java.lang.Object,
* eu.esdihumboldt.hale.common.schema.model.TypeDefinition,
* java.lang.Object, java.util.function.Supplier)
*/
@Override
public GeometryProperty<?> convertToInstanceGeometry(Object geom, TypeDefinition columnType, SQLServerConnection connection, Supplier<CRSDefinition> crsProvider) throws Exception {
Statement stmt = null;
ResultSet rs = null;
try {
// We need Column Data type
String columnDataType = columnType.getName().getLocalPart();
String geomAsHex = BaseEncoding.base16().lowerCase().encode((byte[]) geom);
String sqlGeom = //
"SELECT top 1 GeomConvert.geom.STSrid srid, GeomConvert.geom.STAsText() as geomAsText, GeomConvert.geom.STGeometryType() as geomType " + //
"FROM " + "(SELECT cast(cast(temp.wkb as varbinary(max)) as " + columnDataType + //
") as geom " + //
"FROM " + "( select " + "0x" + geomAsHex + //
" as wkb) as temp" + //
") " + //
"as GeomConvert";
stmt = connection.createStatement();
rs = stmt.executeQuery(sqlGeom);
Geometry jtsGeom = null;
int srId = 0;
if (rs.next()) {
srId = rs.getInt(1);
String geomAsText = rs.getString(2);
String geomType = rs.getString(3);
// WKTReader does not support CircularString, CurvePolygon,
// CompoundCurve
WKTReader wktReader = getSpecificWktReader(geomType);
try {
// conversion to JTS via WKT
jtsGeom = wktReader.read(geomAsText);
} catch (ParseException e) {
log.error("Could not load geometry from database", e);
}
}
CRSDefinition crsDef = null;
String authName = SRSUtil.getAuthorityName(srId, connection);
if (authName != null && authName.equals("EPSG")) {
// For geography/geometry data type, SQL server assumes lon/lat
// axis order, if we read using SQL function
String epsgCode = authName + ":" + SRSUtil.getSRS(srId, connection);
if (columnDataType.equals("geography"))
crsDef = new CodeDefinition(epsgCode, true);
else
crsDef = new CodeDefinition(epsgCode, null);
} else {
String wkt = SRSUtil.getSRSText(srId, connection);
if (wkt != null) {
crsDef = new WKTDefinition(wkt, null);
}
}
if (crsDef == null) {
log.warn("Could not find spatial reference system id " + srId + " in MS sql server");
crsDef = crsProvider.get();
if (crsDef == null) {
log.warn("Could not retrieve default spatial reference for " + srId + " in MS sql server");
}
// saving in cache
if (crsDef != null) {
String srsName = CRS.toSRS(crsDef.getCRS());
if (srsName != null) {
final int index = srsName.lastIndexOf(':');
String authorityName = null;
String authorizedId = null;
if (index > 0) {
authorityName = srsName.substring(0, index);
authorizedId = srsName.substring(index + 1).trim();
}
// we don't need wkt.
SRSUtil.addSRSinCache(srId, authorityName, authorizedId, null);
}
}
}
return new DefaultGeometryProperty<Geometry>(crsDef, jtsGeom);
} finally {
if (rs != null)
try {
rs.close();
} catch (Exception e) {
//
}
if (stmt != null)
try {
stmt.close();
} catch (Exception e) {
//
}
}
}
use of com.vividsolutions.jts.io.ParseException in project incubator-rya by apache.
the class GeoMesaGeoIndexer method storeStatements.
@Override
public void storeStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
// create a feature collection
final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
for (final RyaStatement ryaStatement : ryaStatements) {
final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
// if the predicate list is empty, accept all predicates.
// Otherwise, make sure the predicate is on the "valid" list
final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
if (isValidPredicate && (statement.getObject() instanceof Literal)) {
try {
final SimpleFeature feature = createFeature(featureType, statement);
featureCollection.add(feature);
} catch (final ParseException e) {
logger.warn("Error getting geo from statement: " + statement.toString(), e);
}
}
}
// write this feature collection to the store
if (!featureCollection.isEmpty()) {
featureStore.addFeatures(featureCollection);
}
}
use of com.vividsolutions.jts.io.ParseException in project incubator-rya by apache.
the class GeoMesaGeoIndexer method createFeature.
private static SimpleFeature createFeature(final SimpleFeatureType featureType, final Statement statement) throws ParseException {
final String subject = StatementSerializer.writeSubject(statement);
final String predicate = StatementSerializer.writePredicate(statement);
final String object = StatementSerializer.writeObject(statement);
final String context = StatementSerializer.writeContext(statement);
// create the feature
final Object[] noValues = {};
// create the hash
final String statementId = Md5Hash.md5Base64(StatementSerializer.writeStatement(statement));
final SimpleFeature newFeature = SimpleFeatureBuilder.build(featureType, noValues, statementId);
// write the statement data to the fields
final Geometry geom = GeoParseUtils.getGeometry(statement, new GmlParser());
if (geom == null || geom.isEmpty() || !geom.isValid()) {
throw new ParseException("Could not create geometry for statement " + statement);
}
newFeature.setDefaultGeometry(geom);
newFeature.setAttribute(SUBJECT_ATTRIBUTE, subject);
newFeature.setAttribute(PREDICATE_ATTRIBUTE, predicate);
newFeature.setAttribute(OBJECT_ATTRIBUTE, object);
newFeature.setAttribute(CONTEXT_ATTRIBUTE, context);
// preserve the ID that we created for this feature
// (set the hint to FALSE to have GeoTools generate IDs)
newFeature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE);
return newFeature;
}
use of com.vividsolutions.jts.io.ParseException in project incubator-rya by apache.
the class GeoWaveGeoIndexer method storeStatements.
@Override
public void storeStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
// create a feature collection
final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
for (final RyaStatement ryaStatement : ryaStatements) {
final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
// if the predicate list is empty, accept all predicates.
// Otherwise, make sure the predicate is on the "valid" list
final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
if (isValidPredicate && (statement.getObject() instanceof Literal)) {
try {
final SimpleFeature feature = createFeature(featureType, statement);
featureCollection.add(feature);
} catch (final ParseException e) {
logger.warn("Error getting geo from statement: " + statement.toString(), e);
}
}
}
// write this feature collection to the store
if (!featureCollection.isEmpty()) {
featureStore.addFeatures(featureCollection);
}
}
Aggregations