本文整理匯總了Java中com.vividsolutions.jts.geom.GeometryFactory.createMultiPolygon方法的典型用法代碼示例。如果您正苦於以下問題:Java GeometryFactory.createMultiPolygon方法的具體用法?Java GeometryFactory.createMultiPolygon怎麽用?Java GeometryFactory.createMultiPolygon使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.vividsolutions.jts.geom.GeometryFactory
的用法示例。
在下文中一共展示了GeometryFactory.createMultiPolygon方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: repair
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的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);
}
}
示例2: testTractCentroidDistance
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的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);
}
示例3: smoothMultiPolygon
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的package包/類
private static Geometry smoothMultiPolygon(GeometryFactory factory, GeometrySmoother smoother,
Geometry geom, double fit) {
final int N = geom.getNumGeometries();
Polygon[] smoothed = new Polygon[N];
for (int i = 0; i < N; i++) {
smoothed[i] = smoother.smooth((Polygon) geom.getGeometryN(i), fit);
}
return factory.createMultiPolygon(smoothed);
}
示例4: processSurfacicGrid
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的package包/類
/**
* Cette fonction permet d'extraire en géométrie géoxygene les triangles du
* MNT compris dans le rectangle formé par dpMin et dpMax en 2D
*
* @param dpMin point inférieur gauche du rectangle
* @param dpMax point supérieur droit du rectangle
* @return une liste de polygones décrivant les géométries du MNT compris dans
* le rectangle formé par les 2 points en 2D
*/
@Override
public MultiPolygon processSurfacicGrid(double xmin, double xmax,
double ymin, double ymax) {
GeometryFactory fac = new GeometryFactory();
// On récupère dans quels triangles se trouvent dpMin et dpMax
int posxMin = (int) ((xmin - this.xIni) / (this.stepX * this.sampling));
int posyMin = (int) ((ymin - this.yIni) / (this.stepY * this.sampling));
int posxMax = 1 + (int) ((xmax - this.xIni) / (this.stepX * this.sampling));
int posyMax = 1 + (int) ((ymax - this.yIni) / (this.stepY * this.sampling));
// On récupère les sommets extérieurs de ces triangles (ceux qui
// permettent d'englober totalement le rectangle dpMin, dpMax
Coordinate dpOrigin = new Coordinate(posxMin * this.stepX + this.xIni,
posyMin * this.stepY + this.yIni);
Coordinate dpFin = new Coordinate(posxMax * this.stepX + this.xIni, posyMax
* this.stepY + this.yIni);
// On évalue le nombre de mailles à couvrir
int nbInterX = Math.max(1, (int) ((dpFin.x - dpOrigin.x) / this.stepX));
int nbInterY = Math.max(1,
(int) ((int) ((dpFin.y - dpOrigin.y) / this.stepY)));
Polygon[] lPolys = new Polygon[2 * nbInterX * nbInterY];
int indPoly = 0;
// On crée une géométrie géoxygne pour chacune de ces mailles
// (2 triangles par maille)
for (int i = 0; i < nbInterX; i++) {
for (int j = 0; j < nbInterY; j++) {
Coordinate dp1 = new Coordinate(dpOrigin.x + i * this.stepX, dpOrigin.y
+ j * this.stepY);
Coordinate dp2 = new Coordinate(dpOrigin.x + (i + 1) * this.stepX,
dpOrigin.y + j * this.stepY);
Coordinate dp3 = new Coordinate(dpOrigin.x + i * this.stepX, dpOrigin.y
+ (j + 1) * this.stepY);
Coordinate dp4 = new Coordinate(dpOrigin.x + (i + 1) * this.stepX,
dpOrigin.y + (j + 1) * this.stepY);
Coordinate[] coord = new Coordinate[4];
coord[0] = dp1;
coord[1] = dp2;
coord[2] = dp4;
coord[3] = dp1;
LinearRing l1 = fac.createLinearRing(coord);
Coordinate[] coord2 = new Coordinate[4];
coord2[0] = dp1;
coord2[1] = dp4;
coord2[2] = dp3;
coord2[3] = dp1;
LinearRing l2 = fac.createLinearRing(coord2);
lPolys[indPoly] = fac.createPolygon(l1, null);
indPoly++;
lPolys[indPoly] = fac.createPolygon(l2, null);
indPoly++;
}
}
// On renvoie la liste des triangles
return fac.createMultiPolygon(lPolys);
}
示例5: multipolygon
import com.vividsolutions.jts.geom.GeometryFactory; //導入方法依賴的package包/類
/**
* Create a Multipolygon from a set of coordinates. Each primary array contains a polygon which
* in turn contains an array of linestrings. These line Strings are represented as an array of
* coordinates. The first linestring will be the shell of the polygon the others define holes
* within the polygon.
*
* @param factory {@link GeometryFactory} to use
* @param polygons definition of polygons
* @return a new Multipolygon
*/
protected static MultiPolygon multipolygon(GeometryFactory factory, Coordinate[][][] polygons) {
Polygon[] polygonSet = new Polygon[polygons.length];
for (int i = 0; i < polygonSet.length; i++) {
polygonSet[i] = polygon(factory, polygons[i]);
}
return factory.createMultiPolygon(polygonSet);
}