当前位置: 首页>>代码示例>>Java>>正文


Java LinearRing类代码示例

本文整理汇总了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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:GeoJSONShapeParserTests.java

示例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);  
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:19,代码来源:InFieldGraphBuilder.java

示例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);
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:22,代码来源:GeometryJSON.java

示例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);
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:24,代码来源:PolygonConversionUtil.java

示例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);
}
 
开发者ID:westnordost,项目名称:StreetComplete,代码行数:22,代码来源:JTSConst.java

示例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);
}
 
开发者ID:PDOK,项目名称:gml3-jts,代码行数:19,代码来源:GML321ToLineConvertor.java

示例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;
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:21,代码来源:EdgeRing.java

示例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 );
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:26,代码来源:GeoToolsPrimitiveFromJsonFactory.java

示例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);
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:36,代码来源:JtsAlgorithms.java

示例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;
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:23,代码来源:IsValidOp.java

示例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);
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:23,代码来源:IsValidOp.java

示例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;
            }
        }
    }
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:29,代码来源:IsValidOp.java

示例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;
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:33,代码来源:IsValidOp.java

示例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);
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:31,代码来源:OffsetCurveSetBuilder.java

示例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);
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:32,代码来源:ShapeReader.java


注:本文中的com.vividsolutions.jts.geom.LinearRing类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。