use of com.vividsolutions.jts.geom.LinearRing in project hibernate-orm by hibernate.
the class EnvelopeAdapter method toPolygon.
/**
* Converts the specified {@code Envelope} to a {@code Polygon} having the specified srid.
*
* @param env The envelope to convert
* @param srid The srid for the polygon
*
* @return The Polygon
*/
public static Polygon toPolygon(Envelope env, int srid) {
final Coordinate[] coords = new Coordinate[5];
coords[0] = new Coordinate(env.getMinX(), env.getMinY());
coords[1] = new Coordinate(env.getMinX(), env.getMaxY());
coords[2] = new Coordinate(env.getMaxX(), env.getMaxY());
coords[3] = new Coordinate(env.getMaxX(), env.getMinY());
coords[4] = new Coordinate(env.getMinX(), env.getMinY());
final LinearRing shell = geomFactory.createLinearRing(coords);
final Polygon pg = geomFactory.createPolygon(shell, null);
pg.setSRID(srid);
return pg;
}
use of com.vividsolutions.jts.geom.LinearRing in project osm4j-geometry by topobyte.
the class ChainOfWays method toLinearRing.
public LinearRing toLinearRing(OsmEntityProvider resolver) throws EntityNotFoundException {
int len = getLength();
if (len < 4) {
return new LinearRing(null, factory);
}
CoordinateSequence points = toCoordinateSequence(resolver);
LinearRing shell = new LinearRing(points, factory);
return shell;
}
use of com.vividsolutions.jts.geom.LinearRing in project osm4j-geometry by topobyte.
the class RegionBuilder method build.
/**
* Build a MultiPolygon from a Set of Ways.
*
* @param ways
* the ways to use for geometry construction.
* @return the constructed MultiPolygon.
* @throws EntityNotFoundException
* when a required entity cannot be obtained.
*/
public RegionBuilderResult build(MultiSet<OsmWay> ways, OsmEntityProvider resolver, Set<OsmNode> nodes) throws EntityNotFoundException {
RegionBuilderResult result = new RegionBuilderResult();
logger.debug("Have " + ways.keySet().size() + " ways");
// Only keep ways with 2 or more nodes. Also don't keep ways with just 2
// times the same node.
List<OsmWay> invalidWays = new ArrayList<>();
for (OsmWay way : ways.keySet()) {
int numNodes = way.getNumberOfNodes();
if (numNodes == 0 || numNodes == 1) {
invalidWays.add(way);
} else if (numNodes == 2 && OsmModelUtil.isClosed(way)) {
invalidWays.add(way);
}
}
ways.removeAllOccurences(invalidWays);
logger.debug("Removed " + invalidWays.size() + " invalid ways");
CountingMultiValMap<Long, OsmWay> wayTailMap = RelationUtil.buildWayTailMap(ways);
List<ChainOfWays> chains = RelationUtil.buildRings(ways, wayTailMap);
List<ChainOfNodes> rings = new ArrayList<>();
List<ChainOfNodes> nonRings = new ArrayList<>();
RelationUtil.convertToSegmentChainsAndResolveNodeIntersections(chains, rings, nonRings);
try {
RelationUtil.checkRings(chains, resolver, missingEntitiesStrategy);
} catch (EntityNotFoundException e) {
switch(missingEntitiesStrategy) {
case BUILD_PARTIAL:
// exception with BUILD_PARTIAL
break;
case BUILD_EMPTY:
return new RegionBuilderResult();
default:
case THROW_EXCEPTION:
throw (e);
}
}
// This could be used to close non-closed chains
// RelationUtil.closeUnclosedRingWithStraightLine(rings);
List<LinearRing> linearRings = new ArrayList<>();
convert(rings, nonRings, resolver, result.getCoordinates(), result.getLineStrings(), linearRings);
Set<LinearRing> validRings = new HashSet<>();
for (LinearRing r : linearRings) {
Set<LinearRing> repaired = SelfIntersectionUtil.repair(r);
for (LinearRing ring : repaired) {
validRings.add(ring);
}
}
MultiPolygon mp = PolygonHelper.multipolygonFromRings(validRings, false);
result.setMultiPolygon(mp);
if (includePuntal) {
GeometryUtil.buildNodes(nodeBuilder, nodes, result.getCoordinates());
}
return result;
}
use of com.vividsolutions.jts.geom.LinearRing in project tests by datanucleus.
the class JtsGeometryMappingTest method testLinearRingMapping.
public void testLinearRingMapping() throws SQLException, ParseException {
if (!runTestsForDatastore()) {
return;
}
LinearRing linearRing = (LinearRing) wktReader.read("LINEARRING(0 0,10 0,10 10,0 10,0 0)");
SampleLinearRing sampleLinearRing;
SampleLinearRing sampleLinearRing_read;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
sampleLinearRing = new SampleLinearRing(2101, "LinearRing", linearRing);
pm.makePersistent(sampleLinearRing);
id = JDOHelper.getObjectId(sampleLinearRing);
sampleLinearRing = (SampleLinearRing) pm.detachCopy(sampleLinearRing);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
sampleLinearRing_read = (SampleLinearRing) pm.getObjectById(id, true);
assertEquals(sampleLinearRing, sampleLinearRing_read);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of com.vividsolutions.jts.geom.LinearRing in project tests by datanucleus.
the class JtsGeometry3dMappingTest method testGeometryCollection3DMapping.
public void testGeometryCollection3DMapping() throws SQLException, ParseException {
if (!runTestsForDatastore()) {
return;
}
SampleGeometryCollection3D sampleGeometryCollection;
SampleGeometryCollection3D sampleGeometryCollection_read;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
Point point = geomFactory.createPoint(new Coordinate(10.0, 10.0, 100.0));
LineString linestring = geomFactory.createLineString(new Coordinate[] { new Coordinate(0.0, 50.0, 100.0), new Coordinate(100.0, 50.0, 100.0) });
LinearRing extRing = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(25.0, 25.0, 100), new Coordinate(75.0, 25.0, 100.0), new Coordinate(75.0, 75.0, 100.0), new Coordinate(25.0, 75.0, 100.0), new Coordinate(25.0, 25.0, 100) });
Polygon polygon = geomFactory.createPolygon(extRing, null);
GeometryCollection collection = geomFactory.createGeometryCollection(new Geometry[] { point, linestring, polygon });
sampleGeometryCollection = new SampleGeometryCollection3D(7101, "Collection of 3-dimensional geometries", collection);
pm.makePersistent(sampleGeometryCollection);
id = JDOHelper.getObjectId(sampleGeometryCollection);
sampleGeometryCollection = (SampleGeometryCollection3D) pm.detachCopy(sampleGeometryCollection);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
sampleGeometryCollection_read = (SampleGeometryCollection3D) pm.getObjectById(id, true);
assertEquals(sampleGeometryCollection, sampleGeometryCollection_read);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
Aggregations