本文整理匯總了Java中com.vividsolutions.jts.geom.Polygon.getNumInteriorRing方法的典型用法代碼示例。如果您正苦於以下問題:Java Polygon.getNumInteriorRing方法的具體用法?Java Polygon.getNumInteriorRing怎麽用?Java Polygon.getNumInteriorRing使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.vividsolutions.jts.geom.Polygon
的用法示例。
在下文中一共展示了Polygon.getNumInteriorRing方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: polyStats
import com.vividsolutions.jts.geom.Polygon; //導入方法依賴的package包/類
private static FeatureStats polyStats(Geometry geom) {
final FeatureStats featureStats = new FeatureStats();
for (int i = 0; i < geom.getNumGeometries(); ++i) {
final Polygon nextPoly = (Polygon) geom.getGeometryN(i);
// Stats: exterior ring
final LineString exteriorRing = nextPoly.getExteriorRing();
featureStats.totalPts += exteriorRing.getNumPoints();
featureStats.repeatedPts += checkRepeatedPoints2d(exteriorRing);
// Stats: interior rings
for (int ringIndex = 0; ringIndex < nextPoly.getNumInteriorRing(); ++ringIndex) {
final LineString nextInteriorRing = nextPoly.getInteriorRingN(ringIndex);
featureStats.totalPts += nextInteriorRing.getNumPoints();
featureStats.repeatedPts += checkRepeatedPoints2d(nextInteriorRing);
}
}
return featureStats;
}
示例2: toJSON
import com.vividsolutions.jts.geom.Polygon; //導入方法依賴的package包/類
public static JSONArray toJSON(Polygon poly)
{
JSONArray coords = new JSONArray(1 + poly.getNumInteriorRing());
LineString shell = poly.getExteriorRing();
boolean inverse = shell.getNumPoints() > 1 ? !CoordinateSequences.isCCW(shell.getCoordinateSequence()) : false;
coords.put(toJSON(shell, inverse));
if (poly.getNumInteriorRing() > 0)
{
int nRings = poly.getNumInteriorRing();
for (int j = 0; j < nRings; ++j)
{
LineString ring = poly.getInteriorRingN(j);
inverse = ring.getNumPoints() > 1 ? CoordinateSequences.isCCW(ring.getCoordinateSequence()) : false;
coords.put(toJSON(ring, inverse));
}
}
return coords;
}
示例3: explodeMultiPolygon
import com.vividsolutions.jts.geom.Polygon; //導入方法依賴的package包/類
/** */
public static GeometryCollection explodeMultiPolygon (MultiPolygon mp) {
List<LinearRing> result = new ArrayList<LinearRing>(mp.getNumGeometries()*2);
for (int i = 0; i < mp.getNumGeometries(); i += 1) {
Polygon p = (Polygon)mp.getGeometryN(i);
result.add((LinearRing)p.getExteriorRing());
for (int j = 0; j < p.getNumInteriorRing(); j += 1) {
result.add((LinearRing)p.getInteriorRingN(j));
}
}
return mp.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(result));
}
示例4: assertEquals
import com.vividsolutions.jts.geom.Polygon; //導入方法依賴的package包/類
public static void assertEquals(Polygon p1, Polygon p2) {
Assert.assertEquals(p1.getNumInteriorRing(), p2.getNumInteriorRing());
assertEquals(p1.getExteriorRing(), p2.getExteriorRing());
// TODO: This test do not check all permutations of linestrings. So the test
// fails if the holes of the polygons are not ordered the same way
for (int i = 0; i < p1.getNumInteriorRing(); i++) {
assertEquals(p1.getInteriorRingN(i), p2.getInteriorRingN(i));
}
}
示例5: run
import com.vividsolutions.jts.geom.Polygon; //導入方法依賴的package包/類
public void run() {
File rootFolder = new File(tomtomFolder);
List<String> countries = asList(rootFolder.list(directoryFileFilter()));
log.info("Listing tomtom files for {} countries : {} ", countries.size(), countries);
List<Geometry> allPolygons = countries.stream() //
.map(country -> new File(rootFolder.getAbsolutePath() + "/" + country)) //
.filter(CoastlineGenerator::hasA0Files) //
.map(file -> new File(file, getA0Files(file))) //
.flatMap(file -> readFeatures(file).stream()) //
.map(Feature::getGeometry) //
.map(CoastlineGenerator::cropIfNeeded) //
.collect(toList());
Geometry naturalEarthPolygon = getNaturalEarthGeometry();
log.info("Merging {} tomtom polygons with naturalEarth polygon", allPolygons.size());
allPolygons.add(naturalEarthPolygon);
MultiPolygon coastlineMultipolygon = (MultiPolygon) new CascadedPolygonUnion(allPolygons).union().reverse();
log.info("Serializing coastlines.");
for (int i = 0; i < coastlineMultipolygon.getNumGeometries(); i++) {
Polygon polygon = (Polygon) coastlineMultipolygon.getGeometryN(i);
serializer.write(GEOMETRY_FACTORY.createPolygon(polygon.getExteriorRing().getCoordinateSequence()), COASTLINE_TAG);
if (polygon.getNumInteriorRing() != 0) {
for (int j = 0; j < polygon.getNumInteriorRing(); j++) {
serializer.write(GEOMETRY_FACTORY.createPolygon(polygon.getInteriorRingN(j).getCoordinateSequence()), COASTLINE_TAG);
}
}
}
serializer.close();
}
示例6: addCoordinateArrays
import com.vividsolutions.jts.geom.Polygon; //導入方法依賴的package包/類
public void addCoordinateArrays(final Geometry geometry, final boolean orientPolygons,
final List<Coordinate[]> coordArrayList) {
if (geometry.getDimension() <= 0) {
return;
} else if (geometry instanceof LineString) {
final LineString l = (LineString) geometry;
coordArrayList.add(l.getCoordinates());
} else if (geometry instanceof Polygon) {
final Polygon poly = (Polygon) geometry;
Coordinate[] shell = poly.getExteriorRing().getCoordinates();
if (orientPolygons) {
shell = ensureOrientation(CGAlgorithms.CLOCKWISE, shell);
}
coordArrayList.add(shell);
for (int numRing = 0; numRing < poly.getNumInteriorRing(); numRing++) {
Coordinate[] hole = poly.getInteriorRingN(numRing).getCoordinates();
if (orientPolygons) {
hole = ensureOrientation(
CGAlgorithms.COUNTERCLOCKWISE, hole);
}
coordArrayList.add(hole);
}
} else if (geometry instanceof GeometryCollection) {
final GeometryCollection gc = (GeometryCollection) geometry;
for (int numGeom = 0; numGeom < gc.getNumGeometries(); numGeom++) {
addCoordinateArrays(gc.getGeometryN(numGeom), orientPolygons,
coordArrayList);
}
}
}
示例7: removeCollinearVertices
import com.vividsolutions.jts.geom.Polygon; //導入方法依賴的package包/類
/**
* Removes collinear vertices from the provided {@link Polygon}.
*
* @param polygon the instance of a {@link Polygon} to remove collinear vertices from.
* @return a new instance of the provided {@link Polygon} without collinear vertices.
*/
static Polygon removeCollinearVertices(final Polygon polygon) {
if (polygon == null) {
throw new NullPointerException("The provided Polygon is null");
}
// reuse existing factory
final GeometryFactory gf = polygon.getFactory();
// work on the exterior ring
LineString exterior = polygon.getExteriorRing();
LineString shell = removeCollinearVertices(exterior);
if ((shell == null) || shell.isEmpty()) {
return null;
}
// work on the holes
List<LineString> holes = new ArrayList<LineString>();
final int size = polygon.getNumInteriorRing();
for (int i = 0; i < size; i++) {
LineString hole = polygon.getInteriorRingN(i);
hole = removeCollinearVertices(hole);
if ((hole != null) && !hole.isEmpty()) {
holes.add(hole);
}
}
return gf.createPolygon((LinearRing) shell, holes.toArray(new LinearRing[holes.size()]));
}
示例8: getArea
import com.vividsolutions.jts.geom.Polygon; //導入方法依賴的package包/類
public static double getArea(Geometry geom, Boolean inMeters) throws Exception
{
if (inMeters) {
if (geom instanceof Polygon)
{
Polygon poly = (Polygon) geom;
double area = Math.abs(getSignedArea(poly.getExteriorRing().getCoordinateSequence()));
for (int i = 0; i < poly.getNumInteriorRing(); i++) {
LineString hole = poly.getInteriorRingN(i);
area -= Math.abs(getSignedArea(hole.getCoordinateSequence()));
}
return area;
}
else if (geom instanceof LineString)
{
LineString ring = (LineString)geom;
return getSignedArea(ring.getCoordinateSequence());
}
else
{
if (TRANSFORM_WGS84_SPHERICALMERCATOR == null) {
String wkt = "PROJCS[\"WGS 84 / Pseudo-Mercator\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]],PROJECTION[\"Mercator_1SP\"],PARAMETER[\"central_meridian\",0],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH],AUTHORITY[\"EPSG\",\"3857\"]]";
CoordinateReferenceSystem crs = CRS.parseWKT(wkt);// CRS.decode("EPSG:3857");
TRANSFORM_WGS84_SPHERICALMERCATOR = CRS.findMathTransform(DefaultGeographicCRS.WGS84, crs, true);
}
Geometry transformedGeometry = JTS.transform(geom, TRANSFORM_WGS84_SPHERICALMERCATOR);
return transformedGeometry.getArea();
}
} else {
return geom.getArea();
}
}
示例9: validate
import com.vividsolutions.jts.geom.Polygon; //導入方法依賴的package包/類
private void validate(final Geometry geom, final List<ValidationResult> validationErrors) {
if (geom.isEmpty()) {
return;
}
if (geom instanceof GeometryCollection) {
final GeometryCollection gc = (GeometryCollection) geom;
for (int numGeom = 0; numGeom < gc.getNumGeometries(); numGeom++) {
validate(gc.getGeometryN(numGeom), validationErrors);
}
}
final ValidationResult result = new ValidationResult();
result.setWkt(geom.toText());
final List<String> messages = new ArrayList<String>();
if (!geom.isValid()) {
messages.add("Error en topología básica");
}
if (!geom.isSimple()) {
messages.add("No es una geometría simple");
}
if (repeatedPointTester.hasRepeatedPoint(geom)) {
messages.add("Se encuentran vértices repetidos");
}
if (geom instanceof Polygon) {
final Polygon polygon = (Polygon) geom;
if (CGAlgorithms.isCCW(polygon.getExteriorRing().getCoordinates())) {
messages.add("Error en orientación del polígono");
} else {
for (int numRing = 0; numRing < polygon.getNumInteriorRing(); numRing++) {
if (!CGAlgorithms.isCCW(polygon.getInteriorRingN(numRing).getCoordinates())) {
messages.add("Error en orientación del polígono en anillos interiores");
break;
}
}
}
if (!validateMinPolygonArea(geom)) {
messages.add("Error en validación mínima de area de un polígono");
}
}
if (!validateMinSegmentLength(geom)) {
messages.add("Error en validación mínima de longitud de segmento. Coordenadas");
result.setErrorsPoints(errorCoordinates);
}
if(!messages.isEmpty()) {
result.setMessages(messages);
validationErrors.add(result);
}
}