本文整理匯總了Java中com.vividsolutions.jts.geom.LinearRing類的典型用法代碼示例。如果您正苦於以下問題:Java LinearRing類的具體用法?Java LinearRing怎麽用?Java LinearRing使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LinearRing類屬於com.vividsolutions.jts.geom包,在下文中一共展示了LinearRing類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testParsePolygonNoHoles
import com.vividsolutions.jts.geom.LinearRing; //導入依賴的package包/類
public void testParsePolygonNoHoles() throws IOException {
XContentBuilder polygonGeoJson = XContentFactory.jsonBuilder()
.startObject()
.field("type", "Polygon")
.startArray("coordinates")
.startArray()
.startArray().value(100.0).value(1.0).endArray()
.startArray().value(101.0).value(1.0).endArray()
.startArray().value(101.0).value(0.0).endArray()
.startArray().value(100.0).value(0.0).endArray()
.startArray().value(100.0).value(1.0).endArray()
.endArray()
.endArray()
.endObject();
List<Coordinate> shellCoordinates = new ArrayList<>();
shellCoordinates.add(new Coordinate(100, 0));
shellCoordinates.add(new Coordinate(101, 0));
shellCoordinates.add(new Coordinate(101, 1));
shellCoordinates.add(new Coordinate(100, 1));
shellCoordinates.add(new Coordinate(100, 0));
LinearRing shell = GEOMETRY_FACTORY.createLinearRing(shellCoordinates.toArray(new Coordinate[shellCoordinates.size()]));
Polygon expected = GEOMETRY_FACTORY.createPolygon(shell, null);
assertGeometryEquals(jtsGeom(expected), polygonGeoJson);
}
示例2: osmPolygon2JTS
import com.vividsolutions.jts.geom.LinearRing; //導入依賴的package包/類
private Polygon osmPolygon2JTS(DataReaderContext readerCntx, LongArrayList osmNodeIds) {
// collect all coordinates in ArrayList
if (_coordinates == null || _coordinates.length < osmNodeIds.size())
_coordinates = new Coordinate[osmNodeIds.size()];
for (int i = 0; i < osmNodeIds.size(); i++)
{
long osmNodeId = osmNodeIds.get(i);
int internalID = readerCntx.getNodeMap().get(osmNodeId);
_coordinates[i] = new Coordinate(readerCntx.getNodeLongitude(internalID), readerCntx.getNodeLatitude(internalID));
}
Coordinate[] coords = Arrays.copyOf(_coordinates, osmNodeIds.size());
LinearRing ring = geometryFactory.createLinearRing(coords);
LinearRing holes[] = null;
// a JTS polygon consists of a ring and holes
return geometryFactory.createPolygon(ring, holes);
}
示例3: readPolygon
import com.vividsolutions.jts.geom.LinearRing; //導入依賴的package包/類
private static Polygon readPolygon(JSONArray value)
{
int n = value.length();
LinearRing shell = null;
LinearRing[] holes = new LinearRing[n-1];
for (int i = 0; i < n; i++)
{
JSONArray arrLineString = value.getJSONArray(i);
if (i == 0)
shell = factory.createLinearRing(readCoordinates(arrLineString));
else
holes[i-1] = factory.createLinearRing(readCoordinates(arrLineString));
}
if (holes == null || holes.length == 0)
return factory.createPolygon(shell);
else
return factory.createPolygon(shell, holes);
}
示例4: coordsToLinearRing
import com.vividsolutions.jts.geom.LinearRing; //導入依賴的package包/類
private static LinearRing coordsToLinearRing(final List<LngLatAlt> exteriorRing, final GISUtils.SRID srid) {
if (exteriorRing.isEmpty()) {
throw new IllegalArgumentException("Empty ring");
}
final Stream<Coordinate> stream = exteriorRing.stream()
.map(lngLatAlt -> new Coordinate(lngLatAlt.getLongitude(), lngLatAlt.getLatitude()));
final LngLatAlt first = exteriorRing.get(0);
final LngLatAlt last = exteriorRing.get(exteriorRing.size() - 1);
final Coordinate[] coords;
if (first.equals(last)) {
coords = stream.toArray(Coordinate[]::new);
} else {
// Complete partial ring
final Coordinate firstCoordinate = new Coordinate(first.getLongitude(), first.getLatitude());
coords = Stream.concat(stream, Stream.of(firstCoordinate)).toArray(Coordinate[]::new);
}
return GISUtils.getGeometryFactory(srid).createLinearRing(coords);
}
示例5: toPolygons
import com.vividsolutions.jts.geom.LinearRing; //導入依賴的package包/類
public static Geometry toPolygons(List<List<LatLon>> outer, List<List<LatLon>> inner)
{
Map<LinearRing, ArrayList<LinearRing>> shellsWithHoles = toShellsWithHoles(outer, inner);
Polygon[] polys = new Polygon[shellsWithHoles.size()];
int i = 0;
for(Map.Entry<LinearRing, ArrayList<LinearRing>> shellWithHoles : shellsWithHoles.entrySet())
{
LinearRing shell = shellWithHoles.getKey();
ArrayList<LinearRing> holesList = shellWithHoles.getValue();
LinearRing[] holes = null;
if(holesList != null)
{
holes = holesList.toArray(new LinearRing[holesList.size()]);
}
polys[i++] = factory.createPolygon(shell, holes);
}
if(polys.length == 1) return polys[0];
else return factory.createMultiPolygon(polys);
}
示例6: translateLinearRingType
import com.vividsolutions.jts.geom.LinearRing; //導入依賴的package包/類
private LinearRing translateLinearRingType(LinearRingType ring) throws GeometryException {
if (ring.getPosList() == null) {
throw new DeprecatedGeometrySpecificationException("Geen post list voor ring gespecificeerd");
}
CoordinateArraySequence sequence = gmlToPointConvertor.translateOrdinates(ring.getPosList());
int length = sequence.size();
Coordinate firstCoordinate = length == 0 ? null : sequence.getCoordinate(0);
if (length < NUMBER_OF_COORDINATES_NEEDED_FOR_RING) {
throw new InvalidGeometryException(GeometryValidationErrorType.TOO_FEW_POINTS, firstCoordinate);
}
if (!isClosed(sequence)) {
throw new InvalidGeometryException(GeometryValidationErrorType.RING_NOT_CLOSED, firstCoordinate);
}
return geometryFactory.createLinearRing(sequence);
}
示例7: getRing
import com.vividsolutions.jts.geom.LinearRing; //導入依賴的package包/類
/**
* Returns this ring as a {@link LinearRing}, or null if an Exception occurs while
* creating it (such as a topology problem). Details of problems are written to
* standard output.
*/
public LinearRing getRing() {
if (this.ring != null) {
return this.ring;
}
this.getCoordinates();
if (this.ringPts.length < 3) {
System.out.println(Arrays.toString(ringPts));
}
try {
this.ring = this.factory.createLinearRing(this.ringPts);
} catch (Exception ex) {
System.out.println(Arrays.toString(ringPts));
}
return this.ring;
}
示例8: createLinearRingFromJson
import com.vividsolutions.jts.geom.LinearRing; //導入依賴的package包/類
/**
* Create a GeoTools geometric linear-ring from coordinates in json.
*
* @param json the json array of coordinates
* @return the linear-ring
*/
public static LinearRing createLinearRingFromJson( JsonNode json )
{
// Native array of coordinates to pass to GeoFactory
Coordinate[] coords = new Coordinate[MapUtils.getNonEmptyNodes( json )];
// Read the json array of coordinates
for ( int i = 0; i < json.size(); i++ )
{
JsonNode node = json.get( i );
if ( MapUtils.nodeIsNonEmpty( node ) )
{
coords[i] = createCoordinateFromJson( node );
}
}
// Create the linear-ring from factory
return FACTORY.createLinearRing( coords );
}
示例9: homothetie
import com.vividsolutions.jts.geom.LinearRing; //導入依賴的package包/類
/**
* Calcule l'homothétie d'une géométrie.
* @param geom géométrie, geometry
* @param x0 position en X du centre de l'homothétie, X position of the center
* of the operation
* @param y0 position en Y du centre de l'homothétie, Y position of the center
* of the operation
* @param scaleX facteur d'échelle en X, X scale factor
* @param scaleY facteur d'échelle en Y, Y scale factor
* @return polygon résultant de l'homothétie, resulting polygon
*/
public static Polygon homothetie(Polygon geom, double x0, double y0,
double scaleX, double scaleY) {
// le contour externe
Coordinate[] coord = geom.getExteriorRing().getCoordinates();
Coordinate[] coord_ = new Coordinate[coord.length];
for (int i = 0; i < coord.length; i++) {
coord_[i] = new Coordinate(x0 + scaleX * (coord[i].x - x0), y0 + scaleY
* (coord[i].y - y0));
}
LinearRing lr = geom.getFactory().createLinearRing(coord_);
// les trous
LinearRing[] trous = new LinearRing[geom.getNumInteriorRing()];
for (int j = 0; j < geom.getNumInteriorRing(); j++) {
Coordinate[] hole_coord = geom.getInteriorRingN(j).getCoordinates();
Coordinate[] hole_coord_ = new Coordinate[hole_coord.length];
for (int i = 0; i < hole_coord.length; i++) {
hole_coord_[i] = new Coordinate(x0 + scaleY * (hole_coord[i].x - x0),
y0 + scaleY * (hole_coord[i].y - y0));
}
trous[j] = geom.getFactory().createLinearRing(hole_coord_);
}
return geom.getFactory().createPolygon(lr, trous);
}
示例10: findPtNotNode
import com.vividsolutions.jts.geom.LinearRing; //導入依賴的package包/類
/**
* Find a point from the list of testCoords
* that is NOT a node in the edge for the list of searchCoords
*
* @return the point found, or <code>null</code> if none found
*/
public static Coordinate findPtNotNode(
Coordinate[] testCoords,
LinearRing searchRing,
GeometryGraph graph) {
// find edge corresponding to searchRing.
Edge searchEdge = graph.findEdge(searchRing);
// find a point in the testCoords which is not a node of the searchRing
EdgeIntersectionList eiList = searchEdge.getEdgeIntersectionList();
// somewhat inefficient - is there a better way? (Use a node map, for instance?)
for (Coordinate pt : testCoords) {
if (!eiList.isIntersection(pt)) {
return pt;
}
}
return null;
}
示例11: checkValid
import com.vividsolutions.jts.geom.LinearRing; //導入依賴的package包/類
/**
* Checks validity of a LinearRing.
*/
private void checkValid(LinearRing g) {
this.checkInvalidCoordinates(g.getCoordinates());
if (this.validErr != null) {
return;
}
this.checkClosedRing(g);
if (this.validErr != null) {
return;
}
GeometryGraph graph = new GeometryGraph(0, g);
this.checkTooFewPoints(graph);
if (this.validErr != null) {
return;
}
LineIntersector li = new RobustLineIntersector();
graph.computeSelfNodes(li, true);
this.checkNoSelfIntersectingRings(graph);
}
示例12: checkShellsNotNested
import com.vividsolutions.jts.geom.LinearRing; //導入依賴的package包/類
/**
* Tests that no element polygon is wholly in the interior of another element polygon.
* <p>
* Preconditions:
* <ul>
* <li>shells do not partially overlap
* <li>shells do not touch along an edge
* <li>no duplicate rings exist
* </ul>
* This routine relies on the fact that while polygon shells may touch at one or
* more vertices, they cannot touch at ALL vertices.
*/
private void checkShellsNotNested(MultiPolygon mp, GeometryGraph graph) {
for (int i = 0; i < mp.getNumGeometries(); i++) {
Polygon p = (Polygon) mp.getGeometryN(i);
LinearRing shell = (LinearRing) p.getExteriorRing();
for (int j = 0; j < mp.getNumGeometries(); j++) {
if (i == j) {
continue;
}
Polygon p2 = (Polygon) mp.getGeometryN(j);
this.checkShellNotNested(shell, p2, graph);
if (this.validErr != null) {
return;
}
}
}
}
示例13: checkShellInsideHole
import com.vividsolutions.jts.geom.LinearRing; //導入依賴的package包/類
/**
* This routine checks to see if a shell is properly contained in a hole.
* It assumes that the edges of the shell and hole do not
* properly intersect.
*
* @return <code>null</code> if the shell is properly contained, or
* a Coordinate which is not inside the hole if it is not
*/
private Coordinate checkShellInsideHole(LinearRing shell, LinearRing hole, GeometryGraph graph) {
Coordinate[] shellPts = shell.getCoordinates();
Coordinate[] holePts = hole.getCoordinates();
// TODO: improve performance of this - by sorting pointlists for instance?
Coordinate shellPt = findPtNotNode(shellPts, hole, graph);
// if point is on shell but not hole, check that the shell is inside the hole
if (shellPt != null) {
boolean insideHole = CGAlgorithms.isPointInRing(shellPt, holePts);
if (!insideHole) {
return shellPt;
}
}
Coordinate holePt = findPtNotNode(holePts, shell, graph);
// if point is on hole but not shell, check that the hole is outside the shell
if (holePt != null) {
boolean insideShell = CGAlgorithms.isPointInRing(holePt, shellPts);
if (insideShell) {
return holePt;
}
return null;
}
Assert.shouldNeverReachHere("points in shell and hole appear to be equal");
return null;
}
示例14: addPolygonRing
import com.vividsolutions.jts.geom.LinearRing; //導入依賴的package包/類
/**
* Adds an offset curve for a polygon ring.
* The side and left and right topological location arguments
* assume that the ring is oriented CW.
* If the ring is in the opposite orientation,
* the left and right locations must be interchanged and the side flipped.
*
* @param coord the coordinates of the ring (must not contain repeated points)
* @param offsetDistance the distance at which to create the buffer
* @param side the side of the ring on which to construct the buffer line
* @param cwLeftLoc the location on the L side of the ring (if it is CW)
* @param cwRightLoc the location on the R side of the ring (if it is CW)
*/
private void addPolygonRing(Coordinate[] coord, double offsetDistance, int side, int cwLeftLoc, int cwRightLoc) {
// don't bother adding ring if it is "flat" and will disappear in the output
if (offsetDistance == 0.0 && coord.length < LinearRing.MINIMUM_VALID_SIZE) {
return;
}
int leftLoc = cwLeftLoc;
int rightLoc = cwRightLoc;
if (coord.length >= LinearRing.MINIMUM_VALID_SIZE
&& CGAlgorithms.isCCW(coord)) {
leftLoc = cwRightLoc;
rightLoc = cwLeftLoc;
side = Position.opposite(side);
}
Coordinate[] curve = this.curveBuilder.getRingCurve(coord, side, offsetDistance);
this.addCurve(curve, leftLoc, rightLoc);
}
示例15: read
import com.vividsolutions.jts.geom.LinearRing; //導入依賴的package包/類
/**
* Converts a flat path to a {@link Geometry}.
*
* @param pathIt the path to convert
* @return a Geometry representing the path
*/
public Geometry read(PathIterator pathIt) {
List pathPtSeq = toCoordinates(pathIt);
List polys = new ArrayList();
int seqIndex = 0;
while (seqIndex < pathPtSeq.size()) {
// assume next seq is shell
// TODO: test this
Coordinate[] pts = (Coordinate[]) pathPtSeq.get(seqIndex);
LinearRing shell = this.geometryFactory.createLinearRing(pts);
seqIndex++;
List holes = new ArrayList();
// add holes as long as rings are CCW
while (seqIndex < pathPtSeq.size() && this.isHole((Coordinate[]) pathPtSeq.get(seqIndex))) {
Coordinate[] holePts = (Coordinate[]) pathPtSeq.get(seqIndex);
LinearRing hole = this.geometryFactory.createLinearRing(holePts);
holes.add(hole);
seqIndex++;
}
LinearRing[] holeArray = GeometryFactory.toLinearRingArray(holes);
polys.add(this.geometryFactory.createPolygon(shell, holeArray));
}
return this.geometryFactory.buildGeometry(polys);
}