org.locationtech.jts.geom.PrecisionModel Java Examples

The following examples show how to use org.locationtech.jts.geom.PrecisionModel. 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: ProfileValue.java    From arctic-sea with Apache License 2.0 6 votes vote down vote up
public Geometry getGeometry() {
    if (isSetGeometry()) {
        TreeMap<Time, Coordinate> map = new TreeMap<>();
        int srid = -1;
        for (ProfileLevel level : getValue()) {
            if (level.isSetPhenomenonTime() && level.isSetLocation()) {
                if (srid < 0) {
                    srid = level.getLocation().getSRID();
                }
                map.put(level.getPhenomenonTime(), level.getLocation().getCoordinate());
            }
        }
        if (!map.isEmpty()) {
            if (new HashSet<>(map.values()).size() == 1) {
                return getValue().iterator().next().getLocation();
            } else {
                return new GeometryFactory(new PrecisionModel(), srid)
                        .createLineString(map.values().toArray(new Coordinate[1]));
            }
        }
    }
    return null;
}
 
Example #2
Source File: OmObservationTest.java    From arctic-sea with Apache License 2.0 6 votes vote down vote up
@Test
public final void should_have_SpatialFilteringProfileParameter() throws OwsExceptionReport, DecodingException {
    OmObservation omObservation = new OmObservation();
    NamedValue<Geometry> namedValue = new NamedValue<>();
    namedValue.setName(new ReferenceType(OmConstants.PARAM_NAME_SAMPLING_GEOMETRY));
    GeometryFactory fac = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326);
    namedValue.setValue(new GeometryValue(fac.createPoint(new Coordinate(34.5, 76.4))));
    // test no parameter is set
    assertFalse(omObservation.isSetParameter());
    assertFalse(omObservation.isSetSpatialFilteringProfileParameter());
    omObservation.addParameter(namedValue);
    // test with set SpatialFilteringProfile parameter
    assertTrue(omObservation.isSetParameter());
    assertTrue(omObservation.isSetSpatialFilteringProfileParameter());
    assertThat(omObservation.getSpatialFilteringProfileParameter(), is(equalTo(namedValue)));
}
 
Example #3
Source File: FeatureUtilities.java    From geopaparazzi with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tries to split an invalid polygon in its {@link GeometryCollection}.
 * <p/>
 * <p>Based on JTSBuilder code.
 *
 * @param invalidPolygon the invalid polygon.
 * @return the geometries.
 */
@SuppressWarnings("rawtypes")
public static Geometry invalidPolygonSplit(Geometry invalidPolygon) {
    PrecisionModel pm = new PrecisionModel(10000000);
    GeometryFactory geomFact = invalidPolygon.getFactory();
    List lines = LinearComponentExtracter.getLines(invalidPolygon);
    List nodedLinework = new GeometryNoder(pm).node(lines);
    // union the noded linework to remove duplicates
    Geometry nodedDedupedLinework = geomFact.buildGeometry(nodedLinework).union();
    // polygonize the result
    Polygonizer polygonizer = new Polygonizer();
    polygonizer.add(nodedDedupedLinework);
    Collection polys = polygonizer.getPolygons();
    // convert to collection for return
    Polygon[] polyArray = GeometryFactory.toPolygonArray(polys);
    return geomFact.createGeometryCollection(polyArray);
}
 
Example #4
Source File: ODataFesParserTest.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setup() {
    this.parser = new ODataFesParser();
    this.geometryFactory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING_SINGLE), 4326);
    this.polygon = this.geometryFactory
            .createPolygon(new Coordinate[] {
                    new Coordinate(-15.46, 77.98), new Coordinate(-93.51, 38.27),
                    new Coordinate(47.10, -1.05), new Coordinate(58.71, 70.61), new Coordinate(-15.46, 77.98)
            });
    this.wktGeometry = new WKTWriter().write(polygon).replaceFirst(" ", "").replaceAll(", ", ",");
}
 
Example #5
Source File: WKTConversion.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Convert to org.locationtech.jts.geom geometry.
 *
 * @param wktString the wkt string
 * @param crsCode the crs code
 * @return the geometry
 */
public static Geometry convertToGeometry(String wktString, String crsCode) {
    int srid = 0;

    if (crsCode != null) {
        CoordinateReferenceSystem crs = CoordManager.getInstance().getCRS(crsCode);
        String sridString = CRS.toSRS(crs, true);
        srid = Integer.parseInt(sridString);
    }
    org.locationtech.jts.geom.GeometryFactory geometryFactory =
            new org.locationtech.jts.geom.GeometryFactory(new PrecisionModel(), srid);

    WKTReader parser = new WKTReader(geometryFactory);

    if (wktString.startsWith(WKT_PREFIX)) {
        wktString = wktString.substring(WKT_PREFIX.length());
    }

    Geometry shape = null;
    try {
        shape = parser.read(wktString);
    } catch (org.locationtech.jts.io.ParseException e) {
        ConsoleManager.getInstance().exception(WKTConversion.class, e);
    }

    return shape;
}
 
Example #6
Source File: GeometryUtility.java    From geofence with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Project geometry.
 *
 * @param originalGeom
 *            the original geom
 * @param srcCRSCode
 *            the src crs code
 * @param trgCRSCode
 *            the trg crs code
 * @return the geometry
 * @throws NoSuchAuthorityCodeException
 *             the no such authority code exception
 * @throws FactoryException
 *             the factory exception
 * @throws MismatchedDimensionException
 *             the mismatched dimension exception
 * @throws TransformException
 *             the transform exception
 */
public static Geometry projectGeometry(Geometry originalGeom, String srcCRSCode,
    String trgCRSCode) throws NoSuchAuthorityCodeException, FactoryException, MismatchedDimensionException,
    TransformException
{

    Geometry projectedGeometry = null;
    final MathTransform transform = CRS.findMathTransform(CRS.decode(srcCRSCode, true), CRS.decode(trgCRSCode, true), true);

    // converting geometries into a linear system
    try
    {
        projectedGeometry = JTS.transform(originalGeom, transform);
    }
    catch (Exception e)
    {
        GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(
                    PrecisionModel.FLOATING), 4326);
        WKTReader reader = new WKTReader(geometryFactory);

        try
        {
            Polygon worldCutPolygon = (Polygon) reader.read("POLYGON((-180 -89.9, -180 89.9, 180 89.9, 180 -89.9, -180 -89.9))");

            projectedGeometry = JTS.transform(originalGeom.intersection(worldCutPolygon),
                    transform);
        }
        catch (Exception ex)
        {
            throw new RuntimeException(ex);
        }
    }

    return projectedGeometry;
}
 
Example #7
Source File: GeometryCalculations.java    From geowave with Apache License 2.0 5 votes vote down vote up
public GeometryCalculations(final CoordinateReferenceSystem crs) {
  factory = new GeometryFactory(new PrecisionModel(), 4326);
  this.crs = crs;
  xMin = crs.getCoordinateSystem().getAxis(0).getMinimumValue();
  xMax = crs.getCoordinateSystem().getAxis(0).getMaximumValue();
  yMin = crs.getCoordinateSystem().getAxis(1).getMinimumValue();
  yMax = crs.getCoordinateSystem().getAxis(1).getMaximumValue();
}
 
Example #8
Source File: JTSHelper.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
public static GeometryFactory getGeometryFactoryForSRID(int srid) {
    return new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), srid);
}
 
Example #9
Source File: JTSHelper.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
public static SwitchCoordinateGeometryFactory getSwitchCoordinateGeometryFactoryForSRID(int srid) {
    return new SwitchCoordinateGeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), srid);
}
 
Example #10
Source File: JTSHelper.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
SwitchCoordinateGeometryFactory(PrecisionModel precisionModel, int srid) {
    super(precisionModel, srid);
}
 
Example #11
Source File: UnknownGeometry.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
@Override
public PrecisionModel getPrecisionModel() {
    return geom.getPrecisionModel();
}
 
Example #12
Source File: MvtReaderTest.java    From mapbox-vector-tile-java with Apache License 2.0 4 votes vote down vote up
private static GeometryFactory createGeometryFactory() {
    final PrecisionModel precisionModel = new PrecisionModel();
    final PackedCoordinateSequenceFactory coordinateSequenceFactory = 
            new PackedCoordinateSequenceFactory(PackedCoordinateSequenceFactory.DOUBLE, NUMBER_OF_DIMENSIONS);
    return new GeometryFactory(precisionModel, SRID, coordinateSequenceFactory);
}
 
Example #13
Source File: GeometryUtilities.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public static PrecisionModel basicPrecisionModel() {
    return (pm());
}
 
Example #14
Source File: DbsUtilities.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public static PrecisionModel basicPrecisionModel() {
    return (pm());
}