Java Code Examples for org.locationtech.jts.geom.Geometry#getSRID()

The following examples show how to use org.locationtech.jts.geom.Geometry#getSRID() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PostgisDb.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getSpatialindexGeometryWherePiece( String tableName, String alias, Geometry geometry ) throws Exception {
    GeometryColumn gCol = getGeometryColumnsForTable(tableName);
    if (alias == null) {
        alias = "";
    } else {
        alias = alias + ".";
    }
    int srid = geometry.getSRID();
    Envelope envelopeInternal = geometry.getEnvelopeInternal();
    Polygon bounds = DbsUtilities.createPolygonFromEnvelope(envelopeInternal);
    String sql = alias + gCol.geometryColumnName + " && ST_GeomFromText('" + bounds.toText() + "'," + srid
            + ") AND ST_Intersects(" + alias + gCol.geometryColumnName + ",ST_GeomFromText('" + geometry.toText() + "',"
            + srid + "))";
    return sql;
}
 
Example 2
Source File: JTS.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the Coordinate Reference System (CRS) from the given geometry.
 * This method expects the CRS to be stored in one the following ways:
 *
 * <ul>
 *   <li>Geometry {@linkplain Geometry#getUserData() user data} is an instance of {@code CoordinateReferenceSystem}.</li>
 *   <li>{@linkplain Geometry#getUserData() user data} is a (@link Map} with a value for the {@value #CRS_KEY} key.</li>
 *   <li>Geometry SRID is strictly positive, in which case it is interpreted as an EPSG code.</li>
 * </ul>
 *
 * If none of the above is valid, {@code null} is returned.
 *
 * @param  geometry the geometry from which to get the CRS, or {@code null}.
 * @return the coordinate reference system, or {@code null} if none.
 * @throws FactoryException if the CRS can not be created from the SRID code.
 */
public static CoordinateReferenceSystem getCoordinateReferenceSystem(final Geometry geometry) throws FactoryException {
    if (geometry != null) {
        final Object userData = geometry.getUserData();
        if (userData instanceof CoordinateReferenceSystem) {
            return (CoordinateReferenceSystem) userData;
        } else if (userData instanceof Map<?,?>) {
            final Map<?,?> map = (Map<?,?>) userData;
            final Object value = map.get(CRS_KEY);
            if (value instanceof CoordinateReferenceSystem) {
                return (CoordinateReferenceSystem) value;
            }
        }
        /*
         * Fallback on SRID with the assumption that they are EPSG codes.
         */
        final int srid = geometry.getSRID();
        if (srid > 0) {
            return CRS.forCode(Constants.EPSG + ':' + srid);
        }
    }
    return null;
}
 
Example 3
Source File: AbstractSamplingFeature.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
@Override
public void setGeometry(final Geometry geometry) throws InvalidSridException {
    if (geometry != null && geometry.getSRID() == 0) {
        throw new InvalidSridException(0);
    }
    this.geometry = geometry;
}
 
Example 4
Source File: JTSHelper.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
public static GeometryFactory getGeometryFactory(Geometry geometry) {
    if (geometry.getFactory().getSRID() > 0 || geometry.getSRID() == 0) {
        return geometry.getFactory();
    } else {
        return getGeometryFactoryForSRID(geometry.getSRID());
    }
}
 
Example 5
Source File: GeometryAdapter.java    From geofence with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public G unmarshal(String val) throws ParseException {
    WKTReader wktReader = new WKTReader();

    Geometry the_geom = wktReader.read(val);
    if (the_geom.getSRID() == 0)
        the_geom.setSRID(4326);

    try {
        return (G) the_geom;
    } catch (ClassCastException e) {
        throw new ParseException("WKT val is a " + the_geom.getClass().getName());
    }
}
 
Example 6
Source File: PolygonAdapter.java    From geofence with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Polygon unmarshal(String val) throws ParseException {
    WKTReader wktReader = new WKTReader();

    Geometry the_geom = wktReader.read(val);
    if (the_geom instanceof Polygon) {
        if (the_geom.getSRID() == 0)
            the_geom.setSRID(4326);

        return (Polygon) the_geom;
    }

    throw new ParseException("WKB val is not a Polygon.");
}
 
Example 7
Source File: XMultiPolygonAdapter.java    From geofence with GNU General Public License v2.0 5 votes vote down vote up
@Override
public MultiPolygon unmarshal(String val) throws ParseException {
    WKTReader wktReader = new WKTReader();

    Geometry the_geom = wktReader.read(val);
    if (the_geom.getSRID() == 0)
        the_geom.setSRID(4326);

    try {
        return (MultiPolygon) the_geom;
    } catch (ClassCastException e) {
        throw new ParseException("WKT val is a " + the_geom.getClass().getName());
    }
}
 
Example 8
Source File: ReferencedEnvelope.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
public ReferencedEnvelope(Geometry geometry) {
    this(geometry.getEnvelopeInternal(), geometry.getSRID());
}
 
Example 9
Source File: GmlEncoderv311.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
protected String getSrsName(Geometry geom) {
    return srsNamePrefix + geom.getSRID();
}
 
Example 10
Source File: PostgisGeometryParser.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Object toSqlObject( Geometry geometry ) throws Exception {
    org.postgis.Geometry pgGeometry = PGgeometry.geomFromString(geometry.toText());
    pgGeometry.srid = geometry.getSRID();
    return pgGeometry;
}