本文整理汇总了Java中com.vividsolutions.jts.geom.MultiPolygon类的典型用法代码示例。如果您正苦于以下问题:Java MultiPolygon类的具体用法?Java MultiPolygon怎么用?Java MultiPolygon使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MultiPolygon类属于com.vividsolutions.jts.geom包,在下文中一共展示了MultiPolygon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNegExtPolyRings
import com.vividsolutions.jts.geom.MultiPolygon; //导入依赖的package包/类
@Test
public void testNegExtPolyRings() {
try {
// Single MultiPolygon with two triangles that have negative area from shoelace formula
// Support for 'V1' MVTs.
final JtsMvt mvt = loadMvt(
"src/test/resources/mapbox/vector_tile_js/multi_poly_neg_exters.mvt",
MvtReader.RING_CLASSIFIER_V1);
final List<Geometry> geoms = getAllGeometries(mvt);
assertEquals(1, geoms.size());
assertTrue(geoms.get(0) instanceof MultiPolygon);
} catch (IOException exception) {
fail(exception.getMessage());
}
}
示例2: repair
import com.vividsolutions.jts.geom.MultiPolygon; //导入依赖的package包/类
/**
*
* @param geom
* @return
*/
public static Geometry repair (Geometry geom) {
GeometryFactory factory = geom.getFactory();
if (geom instanceof MultiPolygon) {
MultiPolygon mp = (MultiPolygon)geom;
Polygon[] polys = new Polygon[mp.getNumGeometries()];
for (int i = 0; i < mp.getNumGeometries(); i += 1) {
polys[i] = repair((Polygon)mp.getGeometryN(i));
}
return factory.createMultiPolygon(polys);
} else if (geom instanceof Polygon) {
return repair((Polygon)geom);
} else if (geom.getGeometryType().equals("GeometryCollection")) {
GeometryCollection gc = (GeometryCollection)geom;
Geometry[] geoms = new Geometry[gc.getNumGeometries()];
for (int i = 0; i < gc.getNumGeometries(); i += 1) {
geoms[i] = repair(gc.getGeometryN(i));
}
Thread.dumpStack();
return factory.createGeometryCollection(geoms);
} else {
return(geom);
}
}
示例3: assertEquals
import com.vividsolutions.jts.geom.MultiPolygon; //导入依赖的package包/类
public static void assertEquals(Geometry s1, Geometry s2) {
if(s1 instanceof LineString && s2 instanceof LineString) {
assertEquals((LineString) s1, (LineString) s2);
} else if (s1 instanceof Polygon && s2 instanceof Polygon) {
assertEquals((Polygon) s1, (Polygon) s2);
} else if (s1 instanceof MultiPoint && s2 instanceof MultiPoint) {
Assert.assertEquals(s1, s2);
} else if (s1 instanceof MultiPolygon && s2 instanceof MultiPolygon) {
assertEquals((MultiPolygon) s1, (MultiPolygon) s2);
} else if (s1 instanceof MultiLineString && s2 instanceof MultiLineString) {
assertEquals((MultiLineString) s1, (MultiLineString) s2);
} else {
throw new RuntimeException("equality of shape types not supported [" + s1.getClass().getName() + " and " + s2.getClass().getName() + "]");
}
}
示例4: toGeomType
import com.vividsolutions.jts.geom.MultiPolygon; //导入依赖的package包/类
/**
* Get the MVT type mapping for the provided JTS Geometry.
*
* @param geometry JTS Geometry to get MVT type for
* @return MVT type for the given JTS Geometry, may return
* {@link uk.os.vt.mvt.VectorTile.Tile.GeomType#UNKNOWN}
*/
public static VectorTile.Tile.GeomType toGeomType(Geometry geometry) {
VectorTile.Tile.GeomType result = VectorTile.Tile.GeomType.UNKNOWN;
if (geometry instanceof Point
|| geometry instanceof MultiPoint) {
result = VectorTile.Tile.GeomType.POINT;
} else if (geometry instanceof LineString
|| geometry instanceof MultiLineString) {
result = VectorTile.Tile.GeomType.LINESTRING;
} else if (geometry instanceof Polygon
|| geometry instanceof MultiPolygon) {
result = VectorTile.Tile.GeomType.POLYGON;
}
return result;
}
示例5: removeCollinearVertices
import com.vividsolutions.jts.geom.MultiPolygon; //导入依赖的package包/类
/**
* Removes collinear vertices from the provided {@link Geometry}.
*
* <p>
* For the moment this implementation only accepts, {@link Polygon}, {@link LineString} and {@link MultiPolygon} It will throw an exception if the
* geometry is not one of those types
*
* @param g the instance of a {@link Geometry} to remove collinear vertices from.
* @return a new instance of the provided {@link Geometry} without collinear vertices.
*/
public static Geometry removeCollinearVertices(final Geometry g) {
if (g == null) {
throw new NullPointerException("The provided Geometry is null");
}
if (g instanceof LineString) {
return removeCollinearVertices((LineString) g);
} else if (g instanceof Polygon) {
return removeCollinearVertices((Polygon) g);
} else if (g instanceof MultiPolygon) {
MultiPolygon mp = (MultiPolygon) g;
Polygon[] parts = new Polygon[mp.getNumGeometries()];
for (int i = 0; i < mp.getNumGeometries(); i++) {
Polygon part = (Polygon) mp.getGeometryN(i);
part = removeCollinearVertices(part);
parts[i] = part;
}
return g.getFactory().createMultiPolygon(parts);
}
throw new IllegalArgumentException(
"This method can work on LineString, Polygon and Multipolygon: " + g.getClass());
}
示例6: toJSON
import com.vividsolutions.jts.geom.MultiPolygon; //导入依赖的package包/类
public static JSONArray toJSON(Geometry geom, StringBuffer buffer) throws Exception
{
if (geom instanceof Polygon)
{
return toJSON((Polygon)geom);
}
else if (geom instanceof LineString)
{
return toJSON((LineString)geom, false);
}
else if (geom instanceof Point)
{
return toJSON((Point)geom);
}
else if (geom instanceof MultiPolygon)
{
return toJSON((MultiPolygon)geom);
}
else
{
throw new Exception("toJSON function is not implemented for " + geom.getGeometryType());
}
}
示例7: CommunityAreas
import com.vividsolutions.jts.geom.MultiPolygon; //导入依赖的package包/类
public CommunityAreas() {
communities = new HashMap<>();
try {
File f = new File(shapeFilePath);
ShapefileDataStore shapefile = new ShapefileDataStore(f.toURI().toURL());
SimpleFeatureIterator features = shapefile.getFeatureSource().getFeatures().features();
SimpleFeature shp;
while (features.hasNext()) {
shp = features.next();
int id = Integer.parseInt((String) shp.getAttribute("AREA_NUMBE"));
String name = (String) shp.getAttribute("COMMUNITY");
MultiPolygon boundary = (MultiPolygon) shp.getDefaultGeometry();
CommunityArea ca = new CommunityArea(id, name, boundary);
communities.put(id, ca);
}
features.close();
shapefile.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
示例8: Tracts
import com.vividsolutions.jts.geom.MultiPolygon; //导入依赖的package包/类
public Tracts() {
tracts = new HashMap<>();
try {
SimpleFeatureIterator features = getShapeFileFeatures();
SimpleFeature shp;
while (features.hasNext()) {
shp = features.next();
int id = Integer.parseInt((String) shp.getAttribute("tractce10"));
MultiPolygon boundary = (MultiPolygon) shp.getDefaultGeometry();
Tract t = new Tract(id, boundary);
tracts.put(id, t);
}
features.close();
shapefile.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
示例9: testAllShapesArePolygon
import com.vividsolutions.jts.geom.MultiPolygon; //导入依赖的package包/类
public void testAllShapesArePolygon() {
try {
SimpleFeatureIterator features = Tracts.getShapeFileFeatures();
SimpleFeature shp = features.next();
int fieldSize = shp.getType().getTypes().size();
assertEquals(fieldSize, 10);
assertEquals(shp.getType().getType(3).getName().getLocalPart(), "tractce10");
assertEquals(shp.getType().getType(0).getName().getLocalPart(), "MultiPolygon");
for (int i = 0; i < fieldSize; i++){
System.out.println(shp.getType().getType(i).getName().getLocalPart());
}
int cnt = 1;
while (features.hasNext()) {
shp = features.next();
MultiPolygon g = (MultiPolygon) shp.getDefaultGeometry();
cnt ++;
}
assertEquals(cnt, 801);
features.close();
Tracts.shapefile.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
示例10: testTractCentroidDistance
import com.vividsolutions.jts.geom.MultiPolygon; //导入依赖的package包/类
public void testTractCentroidDistance() {
GeometryFactory gf = new GeometryFactory();
Coordinate[] coords1 = new Coordinate[]{
new Coordinate(0, 0), new Coordinate(2, 0), new Coordinate(2,2),
new Coordinate(0, 2), new Coordinate(0, 0)
};
MultiPolygon mp1 = gf.createMultiPolygon(new Polygon[] {gf.createPolygon(coords1)});
Tract t1 = new Tract(1, mp1);
assertEquals(t1.getCentroid().getX(), 1.0);
assertEquals(t1.getCentroid().getY(), 1.0);
Coordinate[] coords2 = new Coordinate[]{
new Coordinate(0, 10), new Coordinate(2, 10), new Coordinate(2,12),
new Coordinate(0, 12), new Coordinate(0, 10)
};
MultiPolygon mp2 = gf.createMultiPolygon(new Polygon[] {gf.createPolygon(coords2)});
Tract t2 = new Tract(2, mp2);
assertEquals(t2.getCentroid().getX(), 1.0);
assertEquals(t2.getCentroid().getY(), 11.0);
assertEquals(t1.distanceTo(t2), 10.0);
}
示例11: fromSimpleFeature
import com.vividsolutions.jts.geom.MultiPolygon; //导入依赖的package包/类
public static GeoInfo fromSimpleFeature(SimpleFeature feature) {
GeoInfo that = new GeoInfo();
for (Property p: feature.getProperties()) {
if (p.getName().toString().equals("NAME"))
that.name = p.getValue().toString();
if (p.getName().toString().equals("STATE"))
that.state = p.getValue().toString();
if (p.getName().toString().equals("COUNTY"))
that.county = p.getValue().toString();
if (p.getName().toString().equals("CITY"))
that.city = p.getValue().toString();
}
that.multiPolygon = (MultiPolygon) feature.getDefaultGeometry();
return that;
}
示例12: checkShellsNotNested
import com.vividsolutions.jts.geom.MultiPolygon; //导入依赖的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: checkNegativeValid
import com.vividsolutions.jts.geom.MultiPolygon; //导入依赖的package包/类
private void checkNegativeValid() {
// Assert: only polygonal inputs can be checked for negative buffers
// MD - could generalize this to handle GCs too
if (!(this.input instanceof Polygon
|| this.input instanceof MultiPolygon
|| this.input instanceof GeometryCollection
)) {
return;
}
Geometry inputCurve = this.getPolygonLines(this.input);
this.checkMinimumDistance(inputCurve, this.result, this.minValidDistance);
if (!this.isValid) {
return;
}
this.checkMaximumDistance(inputCurve, this.result, this.maxValidDistance);
}
示例14: add
import com.vividsolutions.jts.geom.MultiPolygon; //导入依赖的package包/类
private void add(Geometry g) {
if (g.isEmpty()) {
return;
}
if (g instanceof Polygon) {
this.addPolygon((Polygon) g);
}
// LineString also handles LinearRings
else if (g instanceof LineString) {
this.addLineString((LineString) g);
} else if (g instanceof Point) {
this.addPoint((Point) g);
} else if (g instanceof MultiPoint) {
this.addCollection((MultiPoint) g);
} else if (g instanceof MultiLineString) {
this.addCollection((MultiLineString) g);
} else if (g instanceof MultiPolygon) {
this.addCollection((MultiPolygon) g);
} else if (g instanceof GeometryCollection) {
this.addCollection((GeometryCollection) g);
} else {
throw new UnsupportedOperationException(g.getClass().getName());
}
}
示例15: computeSelfNodes
import com.vividsolutions.jts.geom.MultiPolygon; //导入依赖的package包/类
/**
* Compute self-nodes, taking advantage of the Geometry type to
* minimize the number of intersection tests. (E.g. rings are
* not tested for self-intersection, since they are assumed to be valid).
*
* @param li the LineIntersector to use
* @param computeRingSelfNodes if <false>, intersection checks are optimized to not test rings for self-intersection
* @return the SegmentIntersector used, containing information about the intersections found
*/
public SegmentIntersector computeSelfNodes(LineIntersector li, boolean computeRingSelfNodes) {
SegmentIntersector si = new SegmentIntersector(li, true, false);
EdgeSetIntersector esi = this.createEdgeSetIntersector();
// optimized test for Polygons and Rings
if (!computeRingSelfNodes
&& (this.parentGeom instanceof LinearRing
|| this.parentGeom instanceof Polygon
|| this.parentGeom instanceof MultiPolygon)) {
esi.computeIntersections(this.edges, si, false);
} else {
esi.computeIntersections(this.edges, si, true);
}
//System.out.println("SegmentIntersector # tests = " + si.numTests);
this.addSelfIntersectionNodes(this.argIndex);
return si;
}