本文整理汇总了Java中com.vividsolutions.jts.geom.MultiPolygon.getGeometryN方法的典型用法代码示例。如果您正苦于以下问题:Java MultiPolygon.getGeometryN方法的具体用法?Java MultiPolygon.getGeometryN怎么用?Java MultiPolygon.getGeometryN使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vividsolutions.jts.geom.MultiPolygon
的用法示例。
在下文中一共展示了MultiPolygon.getGeometryN方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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;
}
}
}
}
示例3: toDoc
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
@Override
public ODocument toDoc(JtsGeometry shape) {
ODocument doc = new ODocument(getName());
MultiPolygon multiPolygon = (MultiPolygon) shape.getGeom();
List<List<List<List<Double>>>> polyCoordinates = new ArrayList<List<List<List<Double>>>>();
int n = multiPolygon.getNumGeometries();
for (int i = 0; i < n; i++) {
Geometry geom = multiPolygon.getGeometryN(i);
polyCoordinates.add(coordinatesFromPolygon((Polygon) geom));
}
doc.field(COORDINATES, polyCoordinates);
return doc;
}
示例4: simplify
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
public MultiPolygon simplify(MultiPolygon jtsMultiPolygon){
int numGeomtries = jtsMultiPolygon.getNumGeometries();
Polygon[] newPolys = new Polygon[numGeomtries];
for (int i = 0; i < numGeomtries; i++){
Geometry geom = jtsMultiPolygon.getGeometryN(i);
if (geom instanceof Polygon){
//if (geom.getGeometryType().equals("MultiPolygon")){
Polygon poly = (Polygon)geom;
Polygon newPoly = simplify(poly);
newPolys[i] = newPoly;
}else{
throw new RuntimeException("geom is not a polygon, geom == "+geom);
}
}
return new MultiPolygon(newPolys, this.geometryFactory);
}
示例5: doInBackground
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
@Override
protected Collection<PolygonOptions> doInBackground(Geometry... features) {
Collection<PolygonOptions> polygons = new ArrayList<PolygonOptions>(features.length);
for (Geometry feature : features) {
if (feature instanceof com.vividsolutions.jts.geom.Polygon) {
polygons.add(generatePolygon((com.vividsolutions.jts.geom.Polygon)feature));
}
else if(feature instanceof com.vividsolutions.jts.geom.MultiPolygon) {
MultiPolygon multiPolygon = (MultiPolygon)feature;
for(int i = 0; i < multiPolygon.getNumGeometries(); i++) {
Geometry geometry = multiPolygon.getGeometryN(i);
if(geometry instanceof com.vividsolutions.jts.geom.Polygon) {
polygons.add(generatePolygon((com.vividsolutions.jts.geom.Polygon)geometry));
}
//nested MultiPolygons are ignored for now. Recursive solution has performance implications.
}
}
}
return polygons;
}
示例6: doInBackground
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
@Override
protected List<PolygonOptions> doInBackground(Void... voids) {
startTime = System.currentTimeMillis();
Log.d(TAG, "transforming geometries to polygons");
List<PolygonOptions> polygons = new ArrayList<>(features.size());
for (Geometry feature : features) {
// For now all offline map features are polygons
if ("Polygon".equals(feature.getGeometryType())) {
polygons.add(transformPolygon((com.vividsolutions.jts.geom.Polygon) feature));
}
else if ("MultiPolygon".equals(feature.getGeometryType())) {
MultiPolygon mp = (MultiPolygon) feature;
for (int i = 0; i < mp.getNumGeometries(); i++) {
com.vividsolutions.jts.geom.Polygon polygon = (com.vividsolutions.jts.geom.Polygon) mp.getGeometryN(i);
polygons.add(transformPolygon(polygon));
}
}
}
return polygons;
}
示例7: extractCoordinates
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
private static GeoJsonMultiPolygonCoordinateSet extractCoordinates(MultiPolygon multiPolygon) {
GeoJsonMultiPolygonCoordinateSet multiPolygonCoordinateSet = new GeoJsonMultiPolygonCoordinateSet();
for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
Polygon polygon = (Polygon) multiPolygon.getGeometryN(i);
GeoJsonPolygonCoordinateSet polygonCoordinateSet = new GeoJsonPolygonCoordinateSet();
GeoJsonRingCoordinateSet exteriorRingCoordinateSet = getExteriorRingCoordinateSet(polygon);
polygonCoordinateSet.add(exteriorRingCoordinateSet);
for (int j = 0; j < polygon.getNumInteriorRing(); j++) {
GeoJsonRingCoordinateSet interiorRingCoordinateSet = getInteriorRingCoordinateSet(polygon, j);
polygonCoordinateSet.add(interiorRingCoordinateSet);
}
multiPolygonCoordinateSet.add(polygonCoordinateSet);
}
return multiPolygonCoordinateSet;
}
示例8: explodeMultiPolygon
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的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));
}
示例9: assertEquals
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
public static void assertEquals(MultiPolygon p1, MultiPolygon p2) {
Assert.assertEquals(p1.getNumGeometries(), p2.getNumGeometries());
// TODO: This test do not check all permutations. So the Test fails
// if the inner polygons are not ordered the same way in both Multipolygons
for (int i = 0; i < p1.getNumGeometries(); i++) {
Geometry a = p1.getGeometryN(i);
Geometry b = p2.getGeometryN(i);
assertEquals(a, b);
}
}
示例10: run
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的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();
}
示例11: toJSON
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
public static JSONArray toJSON(MultiPolygon multiPoly)
{
int size = multiPoly.getNumGeometries();
JSONArray coords = new JSONArray(size);
for (int i = 0; i < size; i++)
{
Polygon poly = (Polygon)multiPoly.getGeometryN(i);
coords.put(toJSON(poly));
}
return coords;
}
示例12: toShape
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
/**
* Convert a multipolygon to a shape using the coordinate transformation.
*
* @param mp the polygon to transform.
* @param ct the coordinate transformation to use.
* @return the created shape.
*/
public static Area toShape(MultiPolygon mp, CoordinateTransformer ct) {
Area area = new Area();
for (int i = 0; i < mp.getNumGeometries(); i++) {
Geometry geom = mp.getGeometryN(i);
if (geom instanceof Polygon) {
Area a = toShape((Polygon) geom, ct);
area.add(a);
}
}
return area;
}
示例13: computeLocation
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
private void computeLocation(Coordinate p, Geometry geom) {
if (geom instanceof Point) {
this.updateLocationInfo(this.locate(p, (Point) geom));
}
if (geom instanceof LineString) {
this.updateLocationInfo(this.locate(p, (LineString) geom));
} else if (geom instanceof Polygon) {
this.updateLocationInfo(this.locate(p, (Polygon) geom));
} else if (geom instanceof MultiLineString) {
MultiLineString ml = (MultiLineString) geom;
for (int i = 0; i < ml.getNumGeometries(); i++) {
LineString l = (LineString) ml.getGeometryN(i);
this.updateLocationInfo(this.locate(p, l));
}
} else if (geom instanceof MultiPolygon) {
MultiPolygon mpoly = (MultiPolygon) geom;
for (int i = 0; i < mpoly.getNumGeometries(); i++) {
Polygon poly = (Polygon) mpoly.getGeometryN(i);
this.updateLocationInfo(this.locate(p, poly));
}
} else if (geom instanceof GeometryCollection) {
Iterator geomi = new GeometryCollectionIterator(geom);
while (geomi.hasNext()) {
Geometry g2 = (Geometry) geomi.next();
if (g2 != geom) {
this.computeLocation(p, g2);
}
}
}
}
示例14: addMultiPolygon
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
private void addMultiPolygon(String name, MultiPolygon multiPoly, int color) {
for (int iPoly = 0; iPoly < multiPoly.getNumGeometries(); iPoly++) {
final Polygon poly = (Polygon) multiPoly.getGeometryN(iPoly);
final int colorPoly = (color != -1) ? color : randColor(poly);
addPolygon(name + "-" + iPoly, poly, colorPoly);
}
}
示例15: convertToSVGPath
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
/**
* Converts a MultiPolygon to a SVG string for the d attribute of a path
* element.
*
* @param multiPolygon The geometry to convert.
* @return A string for the d attribute of a SVG path element.
*/
private String convertToSVGPath(MultiPolygon multiPolygon) {
int numPolygons = multiPolygon.getNumGeometries();
String svgPath = "";
for (int i = 0; i < numPolygons; i++) {
Polygon polygon = (Polygon) multiPolygon.getGeometryN(i);
svgPath += " ";
svgPath += convertToSVGPath(polygon);
}
return svgPath;
}