本文整理了Java中com.vividsolutions.jts.geom.Polygon.<init>()
方法的一些代码示例,展示了Polygon.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Polygon.<init>()
方法的具体详情如下:
包路径:com.vividsolutions.jts.geom.Polygon
类名称:Polygon
方法名:<init>
[英]Constructs a Polygon
with the given exterior boundary.
[中]用给定的外部边界构造一个Polygon
。
代码示例来源:origin: com.vividsolutions/jts
/**
* Constructs a <code>Polygon</code> with the given exterior boundary and
* interior boundaries.
*
* @param shell
* the outer boundary of the new <code>Polygon</code>, or
* <code>null</code> or an empty <code>LinearRing</code> if
* the empty geometry is to be created.
* @param holes
* the inner boundaries of the new <code>Polygon</code>, or
* <code>null</code> or empty <code>LinearRing</code> s if
* the empty geometry is to be created.
* @throws IllegalArgumentException if a ring is invalid
*/
public Polygon createPolygon(LinearRing shell, LinearRing[] holes) {
return new Polygon(shell, holes, this);
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
Polygon concaveHull = new Polygon(lr, null, this.geomFactory);
return concaveHull;
代码示例来源:origin: com.vividsolutions/jts-core
/**
* Constructs a <code>Polygon</code> with the given exterior boundary and
* interior boundaries.
*
* @param shell
* the outer boundary of the new <code>Polygon</code>, or
* <code>null</code> or an empty <code>LinearRing</code> if
* the empty geometry is to be created.
* @param holes
* the inner boundaries of the new <code>Polygon</code>, or
* <code>null</code> or empty <code>LinearRing</code> s if
* the empty geometry is to be created.
* @throws IllegalArgumentException if a ring is invalid
*/
public Polygon createPolygon(LinearRing shell, LinearRing[] holes) {
return new Polygon(shell, holes, this);
}
代码示例来源:origin: osmlab/atlas
@Override
public com.vividsolutions.jts.geom.Polygon convert(final Polygon object)
{
return new com.vividsolutions.jts.geom.Polygon(LINEAR_RING_CONVERTER.convert(object),
new LinearRing[0], FACTORY);
}
}
代码示例来源:origin: org.geotools/gt-coverage
/**
* Returns the polygon surrounding the specified rectangle.
* Code lifted from ArcGridDataSource (temporary).
*/
public static Polygon getPolygon(final Rectangle2D rect, final int srid) {
final PrecisionModel pm = new PrecisionModel();
final GeometryFactory gf = new GeometryFactory(pm, srid);
final Coordinate[] coord = new Coordinate[] {
new Coordinate(rect.getMinX(), rect.getMinY()),
new Coordinate(rect.getMaxX(), rect.getMinY()),
new Coordinate(rect.getMaxX(), rect.getMaxY()),
new Coordinate(rect.getMinX(), rect.getMaxY()),
new Coordinate(rect.getMinX(), rect.getMinY())
};
final LinearRing ring = gf.createLinearRing(coord);
return new Polygon(ring, null, gf);
}
代码示例来源:origin: org.geotools/gt2-coverage
/**
* Returns the polygon surrounding the specified rectangle.
* Code lifted from ArcGridDataSource (temporary).
*/
private static Polygon getPolygon(final Rectangle2D rect) {
final PrecisionModel pm = new PrecisionModel();
final GeometryFactory gf = new GeometryFactory(pm, 0);
final Coordinate[] coord = new Coordinate[] {
new Coordinate(rect.getMinX(), rect.getMinY()),
new Coordinate(rect.getMaxX(), rect.getMinY()),
new Coordinate(rect.getMaxX(), rect.getMaxY()),
new Coordinate(rect.getMinX(), rect.getMaxY()),
new Coordinate(rect.getMinX(), rect.getMinY())
};
final LinearRing ring = gf.createLinearRing(coord);
return new Polygon(ring, null, gf);
}
代码示例来源:origin: org.orbisgis/h2gis
/**
* Create a new polygon without hole.
*
* @param polygon
* @return
*/
public static Polygon removeHolesPolygon(Polygon polygon) {
return new Polygon((LinearRing) polygon.getExteriorRing(), null, polygon.getFactory());
}
}
代码示例来源:origin: org.orbisgis/h2gis-functions
/**
* Create a new polygon without hole.
*
* @param polygon
* @return
*/
public static Polygon removeHolesPolygon(Polygon polygon) {
return new Polygon((LinearRing) polygon.getExteriorRing(), null, polygon.getFactory());
}
}
代码示例来源:origin: org.geotools/gt-coverage
/**
* Convert the crop envelope into a polygon and the use the
* world-to-grid transform to get a ROI for the source coverage.
*/
public static Polygon getPolygon(final GeneralEnvelope env, final GeometryFactory gf) throws IllegalStateException, MismatchedDimensionException {
final Rectangle2D rect = env.toRectangle2D();
final Coordinate[] coord = new Coordinate[]{
new Coordinate(rect.getMinX(), rect.getMinY()),
new Coordinate(rect.getMinX(), rect.getMaxY()),
new Coordinate(rect.getMaxX(), rect.getMaxY()),
new Coordinate(rect.getMaxX(), rect.getMinY()),
new Coordinate(rect.getMinX(), rect.getMinY())};
final LinearRing ring = gf.createLinearRing(coord);
final Polygon modelSpaceROI = new Polygon(ring, null, gf);
// check that we have the same thing here
assert modelSpaceROI.getEnvelopeInternal().equals(new ReferencedEnvelope(rect, env.getCoordinateReferenceSystem()));
return modelSpaceROI;
}
代码示例来源:origin: osmlab/atlas
public static Polygon toPolygon(final Coordinate[] coordinates)
{
if (coordinates.length < MININMUM_NUMBER_OF_POLYGON_POINTS && coordinates.length != 0)
{
// An invalid polygon. one example A->B->A
return null;
}
final CoordinateArraySequence sequence = new CoordinateArraySequence(coordinates);
final LinearRing shell = new LinearRing(sequence, GEOMETRY_FACTORY);
return new Polygon(shell, new LinearRing[] {}, GEOMETRY_FACTORY);
}
代码示例来源:origin: org.orbisgis/orbisgis-core
/**
* Create a new polygon without hole.
*
* @param polygon
* @return
*/
public static Polygon removeHolePolygon(Polygon polygon) {
return new Polygon((LinearRing) polygon.getExteriorRing(), null, polygon.getFactory());
}
代码示例来源:origin: shizuchengxuyuan/net.sz.java
public com.vividsolutions.jts.geom.Polygon makeJTSPolygonFrom(KPolygon polygon) {
com.vividsolutions.jts.geom.Polygon jtsPolygon;
Coordinate[] coordinateArray = new Coordinate[polygon.getPoints().size() + 1];
for (int i = 0; i < polygon.getPoints().size(); i++) {
Vector3 p = polygon.getPoints().get(i);
coordinateArray[i] = new Coordinate(p.x, p.z, p.y);
}
// link the first and last points
coordinateArray[polygon.getPoints().size()] = new Coordinate(coordinateArray[0].x, coordinateArray[0].y, coordinateArray[0].z);
LinearRing linearRing = geometryFactory.createLinearRing(coordinateArray);
jtsPolygon = new com.vividsolutions.jts.geom.Polygon(linearRing, null, geometryFactory);
return jtsPolygon;
}
代码示例来源:origin: sitewhere/sitewhere
/**
* Create a polgon for a list of locations.
*
* @param locations
* @return
*/
public static <T extends ILocation> Polygon createPolygonForLocations(List<T> locations) {
Coordinate[] coords = new Coordinate[locations.size() + 1];
for (int x = 0; x < locations.size(); x++) {
ILocation loc = locations.get(x);
coords[x] = new Coordinate(loc.getLongitude(), loc.getLatitude());
}
ILocation loc = locations.get(0);
coords[locations.size()] = new Coordinate(loc.getLongitude(), loc.getLatitude());
GeometryFactory fact = new GeometryFactory();
LinearRing linear = new GeometryFactory().createLinearRing(coords);
return new Polygon(linear, null, fact);
}
}
代码示例来源:origin: com.sitewhere/sitewhere-core
/**
* Create a polgon for a list of locations.
*
* @param locations
* @return
*/
public static <T extends ILocation> Polygon createPolygonForLocations(List<T> locations) {
Coordinate[] coords = new Coordinate[locations.size() + 1];
for (int x = 0; x < locations.size(); x++) {
ILocation loc = locations.get(x);
coords[x] = new Coordinate(loc.getLongitude(), loc.getLatitude());
}
ILocation loc = locations.get(0);
coords[locations.size()] = new Coordinate(loc.getLongitude(), loc.getLatitude());
GeometryFactory fact = new GeometryFactory();
LinearRing linear = new GeometryFactory().createLinearRing(coords);
return new Polygon(linear, null, fact);
}
}
代码示例来源:origin: jzyong/game-server
/**
* KPolygon 转 Polygon
*
* @param kpolygon
* @return
*/
public Polygon makePolygonFrom(KPolygon kpolygon) {
Polygon polygon;
Coordinate[] coordinateArray = new Coordinate[kpolygon.getPoints().size() + 1];
for (int i = 0; i < kpolygon.getPoints().size(); i++) {
Vector3 p = kpolygon.getPoints().get(i);
coordinateArray[i] = new Coordinate(p.x, p.z, p.y);
}
// link the first and last points
coordinateArray[kpolygon.getPoints().size()] = new Coordinate(coordinateArray[0].x, coordinateArray[0].y, coordinateArray[0].z);
LinearRing linearRing = geometryFactory.createLinearRing(coordinateArray);
polygon = new Polygon(linearRing, null, geometryFactory);
return polygon;
}
代码示例来源:origin: DataSystemsLab/GeoSpark
public Polygon call(T spatialObject)
{
Double x1, x2, y1, y2;
LinearRing linear;
Coordinate[] coordinates = new Coordinate[5];
GeometryFactory fact = new GeometryFactory();
final Envelope envelope = spatialObject.getEnvelopeInternal();
x1 = envelope.getMinX();
x2 = envelope.getMaxX();
y1 = envelope.getMinY();
y2 = envelope.getMaxY();
coordinates[0] = new Coordinate(x1, y1);
coordinates[1] = new Coordinate(x1, y2);
coordinates[2] = new Coordinate(x2, y2);
coordinates[3] = new Coordinate(x2, y1);
coordinates[4] = coordinates[0];
linear = fact.createLinearRing(coordinates);
Polygon polygonObject = new Polygon(linear, null, fact);
return polygonObject;
}
});
代码示例来源:origin: DataSystemsLab/GeoSpark
public Polygon call(Polygon v1, Polygon v2)
{
//Reduce precision in JTS to avoid TopologyException
PrecisionModel pModel = new PrecisionModel();
GeometryPrecisionReducer pReducer = new GeometryPrecisionReducer(pModel);
Geometry p1 = pReducer.reduce(v1);
Geometry p2 = pReducer.reduce(v2);
//Union two polygons
Geometry polygonGeom = p1.union(p2);
Coordinate[] coordinates = polygonGeom.getCoordinates();
ArrayList<Coordinate> coordinateList = new ArrayList<Coordinate>(Arrays.asList(coordinates));
Coordinate lastCoordinate = coordinateList.get(0);
coordinateList.add(lastCoordinate);
Coordinate[] coordinatesClosed = new Coordinate[coordinateList.size()];
coordinatesClosed = coordinateList.toArray(coordinatesClosed);
GeometryFactory fact = new GeometryFactory();
LinearRing linear = new GeometryFactory().createLinearRing(coordinatesClosed);
Polygon polygon = new Polygon(linear, null, fact);
//Return the two polygon union result
return polygon;
}
});
代码示例来源:origin: org.datasyslab/geospark
public Polygon call(T spatialObject)
{
Double x1, x2, y1, y2;
LinearRing linear;
Coordinate[] coordinates = new Coordinate[5];
GeometryFactory fact = new GeometryFactory();
final Envelope envelope = spatialObject.getEnvelopeInternal();
x1 = envelope.getMinX();
x2 = envelope.getMaxX();
y1 = envelope.getMinY();
y2 = envelope.getMaxY();
coordinates[0] = new Coordinate(x1, y1);
coordinates[1] = new Coordinate(x1, y2);
coordinates[2] = new Coordinate(x2, y2);
coordinates[3] = new Coordinate(x2, y1);
coordinates[4] = coordinates[0];
linear = fact.createLinearRing(coordinates);
Polygon polygonObject = new Polygon(linear, null, fact);
return polygonObject;
}
});
代码示例来源:origin: FutureCitiesCatapult/TomboloDigitalConnector
@Override
public void handle(OsmWay way) throws IOException
{
Geometry osmGeometry = null;
try {
osmGeometry = builder.build(way, dataSet);
if (osmGeometry instanceof LinearRing) {
osmGeometry = new Polygon((LinearRing) osmGeometry, null, GEOMETRY_FACTORY);
}
} catch (IllegalArgumentException e) {
log.warn("Could not build way (illegal argument): {}", e.getMessage());
} catch (EntityNotFoundException e) {
// Nothing to do, continue...
log.warn("Could not build way (entity not found): {}", e.getMessage());
}
ways.put(way.getId(), way);
handleEntity(way, osmGeometry);
}
代码示例来源:origin: bedatadriven/activityinfo
@Test
public void updateGeometry() throws SQLException {
userId = 3;
ResourceId formId = CuidAdapter.adminLevelFormClass(1);
ResourceId recordId = entity(1);
ResourceId fieldId = CuidAdapter.field(formId, CuidAdapter.GEOMETRY_FIELD);
Optional<FormStorage> storage = catalog.getForm(formId);
GeometryFactory factory = new GeometryFactory();
Polygon polygon = new Polygon(new LinearRing(new CoordinateArraySequence(
new Coordinate[]{
new Coordinate(100, 0),
new Coordinate(101, 0),
new Coordinate(101, 1),
new Coordinate(100, 1),
new Coordinate(100, 0)
}), factory), new LinearRing[0], factory);
storage.get().updateGeometry(recordId, fieldId, polygon);
query(formId, "_id", "ST_XMIN(boundary)", "ST_XMAX(boundary)");
}
内容来源于网络,如有侵权,请联系作者删除!