當前位置: 首頁>>代碼示例>>Java>>正文


Java GeometryFactory.createMultiPolygon方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:29,代碼來源:JTSUtil.java

示例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);
}
 
開發者ID:thekingofkings,項目名稱:embedding,代碼行數:24,代碼來源:TractsTest.java

示例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);
}
 
開發者ID:GIScience,項目名稱:openrouteservice,代碼行數:13,代碼來源:JTS.java

示例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);
}
 
開發者ID:IGNF,項目名稱:geoxygene,代碼行數:78,代碼來源:DTMPostGIS.java

示例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);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:PolygonBuilder.java


注:本文中的com.vividsolutions.jts.geom.GeometryFactory.createMultiPolygon方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。