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


Java MultiPolygon類代碼示例

本文整理匯總了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());
  }
}
 
開發者ID:OrdnanceSurvey,項目名稱:vt-support,代碼行數:17,代碼來源:MvtReaderTest.java

示例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);
    }
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:29,代碼來源:JTSUtil.java

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

示例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;
}
 
開發者ID:OrdnanceSurvey,項目名稱:vt-support,代碼行數:26,代碼來源:JtsAdapter.java

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

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

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

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

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

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

示例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;
}
 
開發者ID:confluentinc,項目名稱:strata-tutorials,代碼行數:19,代碼來源:GeoInfo.java

示例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;
            }
        }
    }
}
 
開發者ID:gegy1000,項目名稱:Earth,代碼行數:29,代碼來源:IsValidOp.java

示例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);
}
 
開發者ID:gegy1000,項目名稱:Earth,代碼行數:19,代碼來源:BufferDistanceValidator.java

示例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());
    }
}
 
開發者ID:gegy1000,項目名稱:Earth,代碼行數:26,代碼來源:OffsetCurveSetBuilder.java

示例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;
    }
 
開發者ID:gegy1000,項目名稱:Earth,代碼行數:26,代碼來源:GeometryGraph.java


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