本文整理汇总了Java中org.postgis.PGgeometry类的典型用法代码示例。如果您正苦于以下问题:Java PGgeometry类的具体用法?Java PGgeometry怎么用?Java PGgeometry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PGgeometry类属于org.postgis包,在下文中一共展示了PGgeometry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNullableResult
import org.postgis.PGgeometry; //导入依赖的package包/类
public T getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
PGgeometry pGgeometry = (PGgeometry) cs.getObject(columnIndex);
if (pGgeometry == null) {
return null;
}
return (T) pGgeometry.getGeometry();
}
示例2: conv2DBGeometry
import org.postgis.PGgeometry; //导入依赖的package包/类
/**
* Converts a GeOxygene <code>GM_Object</code> to a native geometry object.
*
* @param geom
* GeOxygene GM_Object to convert
* @param connection
* the current database connection
* @return native database geometry object corresponding to geom.
*/
public Object conv2DBGeometry(IGeometry geom, Connection connection) {
try {
if (geom == null) {
return null;
}
String srid = "";
if (geom.getCRS() != -1) {
srid = "SRID=" + geom.getCRS() + ";";
}
// logger.info("conv2DBGeometry " + srid + geom.toString());
PGgeometry pgGeom = new PGgeometry(srid + geom.toString());
return pgGeom;
} catch (SQLException e) {
GeOxygeneGeometryUserType.logger.warn("## WARNING ## GeOxygene to Postgis returns NULL "); //$NON-NLS-1$
e.printStackTrace();
return null;
}
}
示例3: reverseMap
import org.postgis.PGgeometry; //导入依赖的package包/类
@Override
public Map<String, Object> reverseMap(List<LatLng> latLngs, Action action) {
Point[] points = new Point[latLngs.size() + 1]; //+1 to close the ring
List<LatLng> path = latLngs;
for (int i = 0; i < path.size(); i++) {
LatLng latLng = path.get(i);
points[i] = new Point(latLng.getLng(), latLng.getLat());
}
//close the ring
points[points.length - 1] = points[0];
Polygon polygon = new Polygon(new LinearRing[]{new LinearRing(points)});
polygon.setSrid(Mappers.WGS84_SRID);
Map<String, Object> params = new HashMap<>(1);
params.put(colName, new PGgeometry(polygon));
return params;
}
示例4: getOriginDestinationRouteNamesWithinDistance
import org.postgis.PGgeometry; //导入依赖的package包/类
@Override
public Set<String> getOriginDestinationRouteNamesWithinDistance(LatLng origin, LatLng destination, int distanceInMeters) {
final Set<String> results = new HashSet<>();
jdbcTemplate.query("SELECT DISTINCT orig.route route_orig, dest.route route_dest " +
" FROM subroute AS orig " +
" JOIN subroute AS dest ON st_intersects(orig.geom, dest.geom) " +
" WHERE st_dwithin(orig.geom, st_transform(?, 32161), ?) " +
" AND st_dwithin(dest.geom, st_transform(?, 32161), ?) ",
rs -> {
while (rs.next()) {
results.add(rs.getString("route_orig"));
results.add(rs.getString("route_dest"));
}
return null;
},
new PGgeometry(Mappers.toPoint(origin)),
distanceInMeters,
new PGgeometry(Mappers.toPoint(destination)),
distanceInMeters);
return results;
}
示例5: isWithinOriginOrDestination
import org.postgis.PGgeometry; //导入依赖的package包/类
@Override
public Map<String, Object> isWithinOriginOrDestination(List<LatLng> line, SubrouteKey subroute) {
String sql = "WITH trail AS ( " +
" SELECT ST_Transform(?, 32161) AS geom " +
") " +
"SELECT " +
" ST_DWithin(trail.geom, ST_PointN(subroute.geom, 1), 100) withinOrig, " +
" ST_DWithin(trail.geom, ST_EndPoint(subroute.geom), 100) withinDest, " +
" subroute.direction curr_direction, " +
" next_subroute.direction AS next_direction " +
" FROM trail, subroute AS subroute " +
" JOIN subroute AS next_subroute ON subroute.route = next_subroute.route " +
" AND subroute.direction <> next_subroute.direction " +
" JOIN route AS route ON subroute.route = route.id " +
" WHERE route.gpsenabled = TRUE " +
" AND subroute.route = ? " +
" AND subroute.direction = ? ";
PGgeometry pgGeometry = Mappers.toPGGeometry(line, Mappers.WGS84_SRID);
List<Map<String, Object>> results = jdbcTemplate.queryForList(sql, pgGeometry, subroute.getRoute(), subroute.getDirection());
return results.isEmpty() ? null : results.get(0);
}
示例6: readGeometry
import org.postgis.PGgeometry; //导入依赖的package包/类
@Override
public String readGeometry(Wrapper aRs, int aColumnIndex, Connection aConnection) throws SQLException {
Object read = aRs instanceof ResultSet ? ((ResultSet) aRs).getObject(aColumnIndex) : ((CallableStatement) aRs).getObject(aColumnIndex);
boolean wasNull = aRs instanceof ResultSet ? ((ResultSet) aRs).wasNull() : ((CallableStatement) aRs).wasNull();
if (wasNull) {
return null;
} else {
if (read instanceof PGgeometry) {
PGgeometry pgg = (PGgeometry) read;
read = pgg.getGeometry();
}else if(read.getClass().getName().equals(PGgeometry.class.getName())){// Crazy netbeans designer!
return read.toString();
}
if (read instanceof org.postgis.Geometry) {
org.postgis.Geometry g = (org.postgis.Geometry) read;
StringBuffer sb = new StringBuffer();
g.outerWKT(sb);
return sb.toString();
} else {
return null;
}
}
}
示例7: convertToDatabaseColumn
import org.postgis.PGgeometry; //导入依赖的package包/类
@Override
public Object convertToDatabaseColumn( final T attribute )
{
if ( null == attribute )
{
final PGobject pgObject = new PGobject();
pgObject.setType( "geometry" );
return pgObject;
}
final String wkt = Wkt.newEncoder( Dialect.POSTGIS_EWKT_1 ).encode( attribute );
try
{
return new PGgeometry( wkt );
}
catch ( final SQLException se )
{
throw new IllegalStateException( "Failed converting geometry", se );
}
}
示例8: getMultiPoint
import org.postgis.PGgeometry; //导入依赖的package包/类
@Override
public GeometryObject getMultiPoint(Object geomObj) throws SQLException {
GeometryObject multiPoint = null;
if (geomObj instanceof PGgeometry) {
Geometry geometry = ((PGgeometry)geomObj).getGeometry();
if (geometry.getType() == Geometry.MULTIPOINT) {
multiPoint = getMultiPoint((MultiPoint)geometry);
}
else if (geometry.getType() == Geometry.POINT) {
Point pointObj = (Point)geometry;
double[][] coordiantes = new double[1][];
coordiantes[0] = getPointCoordinates(pointObj);
multiPoint = GeometryObject.createMultiPoint(coordiantes, pointObj.getDimension(), pointObj.getSrid());
}
}
return multiPoint;
}
示例9: getMultiCurve
import org.postgis.PGgeometry; //导入依赖的package包/类
@Override
public GeometryObject getMultiCurve(Object geomObj) throws SQLException {
GeometryObject multiCurve = null;
if (geomObj instanceof PGgeometry) {
Geometry geometry = ((PGgeometry)geomObj).getGeometry();
if (geometry.getType() == Geometry.MULTILINESTRING) {
multiCurve = getMultiCurve((MultiLineString)geometry);
}
else if (geometry.getType() == Geometry.LINESTRING) {
LineString lineStringObj = (LineString)geometry;
double[][] coordiantes = new double[1][];
coordiantes[0] = getCurveCoordinates(lineStringObj);
multiCurve = GeometryObject.createMultiPoint(coordiantes, lineStringObj.getDimension(), lineStringObj.getSrid());
}
}
return multiCurve;
}
示例10: getMultiPolygon
import org.postgis.PGgeometry; //导入依赖的package包/类
@Override
public GeometryObject getMultiPolygon(Object geomObj) throws SQLException {
GeometryObject multiPolygon = null;
if (geomObj instanceof PGgeometry) {
Geometry geometry = ((PGgeometry)geomObj).getGeometry();
if (geometry.getType() == Geometry.MULTIPOLYGON) {
multiPolygon = getMultiPolygon((MultiPolygon)geometry);
}
else if (geometry.getType() == Geometry.POLYGON) {
Polygon polygonObj = (Polygon)geometry;
double[][] coordinates = getPolygonCoordinates(polygonObj);
int[] exteriorRings = new int[]{ 0 };
multiPolygon = GeometryObject.createMultiPolygon(coordinates, exteriorRings, polygonObj.getDimension(), polygonObj.getSrid());
}
}
return multiPolygon;
}
示例11: getGeometry
import org.postgis.PGgeometry; //导入依赖的package包/类
@Override
public GeometryObject getGeometry(Object geomObj) throws SQLException {
if (geomObj instanceof PGgeometry) {
Geometry geometry = ((PGgeometry)geomObj).getGeometry();
switch (geometry.getType()) {
case Geometry.POINT:
return getPoint((Point)geometry);
case Geometry.MULTIPOINT:
return getMultiPoint((MultiPoint)geometry);
case Geometry.LINESTRING:
return getCurve((LineString)geometry);
case Geometry.MULTILINESTRING:
return getMultiCurve((MultiLineString)geometry);
case Geometry.POLYGON:
return getPolygon((Polygon)geometry);
case Geometry.MULTIPOLYGON:
return getMultiPolygon((MultiPolygon)geometry);
default:
throw new SQLException("Cannot convert PostGIS geometry type '" + geometry.getType() + "' to internal representation: Unsupported type.");
}
}
return null;
}
示例12: convertObjectValueToDataValue
import org.postgis.PGgeometry; //导入依赖的package包/类
@Override
public Object convertObjectValueToDataValue( final Object objectValue, final Session session )
{
if( null == objectValue )
{
return null;
}
final Geometry geometry = (Geometry) objectValue;
final String wkt = Wkt.newEncoder( Dialect.POSTGIS_EWKT_1 ).encode( geometry );
try
{
return new PGgeometry( wkt );
}
catch ( final SQLException se )
{
throw new IllegalStateException( "Failed converting geometry", se );
}
}
示例13: convertDataValueToObjectValue
import org.postgis.PGgeometry; //导入依赖的package包/类
@Override
public Geometry convertDataValueToObjectValue( final Object dataValue, final Session session )
{
if( null == dataValue )
{
return null;
}
if ( dataValue instanceof PGgeometry )
{
final org.postgis.Geometry geometry = ( (PGgeometry) dataValue ).getGeometry();
return Wkt.newDecoder( Wkt.Dialect.POSTGIS_EWKT_1 ).decode( geometry.toString() );
}
else if ( dataValue instanceof String )
{
/*
In some circumstances the data will come back in WKB format (i.e. When using the Driver directly)
and sometimes it will be returned in WKT format (i.e. In GlassFish when using the DataSource) and
it is unclear what is causing the variance so support both scenarios.
*/
final String wk = (String) dataValue;
final char ch = wk.charAt( 0 );
if( '0' == ch )
{
//Guess that it is in WKB format
return Wkb.newDecoder( Wkb.Dialect.POSTGIS_EWKB_1 ).decode( ByteBuffer.from( wk ) );
}
else
{
//Assume a WKT format
return Wkt.newDecoder( Wkt.Dialect.POSTGIS_EWKT_1 ).decode( wk );
}
}
else
{
throw new IllegalStateException( "Unable to convert data value:" + dataValue );
}
}
示例14: getPointOrCurveGeometry
import org.postgis.PGgeometry; //导入依赖的package包/类
public PGgeometry getPointOrCurveGeometry(AbstractGeometry abstractGeometry)
throws SQLException {
switch (abstractGeometry.getGMLClass()) {
case POINT:
return getPoint((Point) abstractGeometry);
case MULTI_POINT:
return getMultiPoint((MultiPoint) abstractGeometry);
case LINE_STRING:
case CURVE:
case COMPOSITE_CURVE:
case ORIENTABLE_CURVE:
return getCurve((AbstractCurve) abstractGeometry);
case MULTI_CURVE:
return getMultiCurve((MultiCurve) abstractGeometry);
case GEOMETRIC_COMPLEX:
GeometricComplex complex = (GeometricComplex)abstractGeometry;
if (containsPointPrimitives(complex, true))
return getPointGeometry((GeometricComplex)abstractGeometry);
else if (containsCurvePrimitives(complex, true))
return getCurveGeometry((GeometricComplex)abstractGeometry);
else
return null;
default:
return null;
}
}
示例15: insert
import org.postgis.PGgeometry; //导入依赖的package包/类
public void insert(String attributeName, PGgeometry geometry, long cityObjectId) throws SQLException {
if (attributeName == null || attributeName.length() == 0)
return;
psGenericAttribute.setString(1, attributeName);
psGenericAttribute.setInt(2, 6);
psGenericAttribute.setNull(3, Types.VARCHAR);
psGenericAttribute.setNull(4, 0);
psGenericAttribute.setNull(5, 0);
psGenericAttribute.setNull(6, Types.VARCHAR);
psGenericAttribute.setNull(7, Types.DATE);
psGenericAttribute.setObject(8, geometry);
psGenericAttribute.setLong(9, cityObjectId);
psGenericAttribute.addBatch();
if (++batchCounter == Internal.POSTGRESQL_MAX_BATCH_SIZE)
dbImporterManager.executeBatch(DBImporterEnum.CITYOBJECT_GENERICATTRIB);
}