本文整理汇总了Java中com.vividsolutions.jts.geom.MultiPolygon.getNumGeometries方法的典型用法代码示例。如果您正苦于以下问题:Java MultiPolygon.getNumGeometries方法的具体用法?Java MultiPolygon.getNumGeometries怎么用?Java MultiPolygon.getNumGeometries使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vividsolutions.jts.geom.MultiPolygon
的用法示例。
在下文中一共展示了MultiPolygon.getNumGeometries方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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());
}
示例3: 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;
}
}
}
}
示例4: writeMultiPolygon
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
private void writeMultiPolygon(MultiPolygon mp, Writer writer, int level)
throws IOException {
this.startLine(level, writer);
this.startGeomTag(GMLConstants.GML_MULTI_POLYGON, mp, writer);
for (int t = 0; t < mp.getNumGeometries(); t++) {
this.startLine(level + 1, writer);
this.startGeomTag(GMLConstants.GML_POLYGON_MEMBER, null, writer);
this.writePolygon((Polygon) mp.getGeometryN(t), writer, level + 2);
this.startLine(level + 1, writer);
this.endGeomTag(GMLConstants.GML_POLYGON_MEMBER, writer);
}
this.startLine(level, writer);
this.endGeomTag(GMLConstants.GML_MULTI_POLYGON, writer);
}
示例5: appendMultiPolygonText
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
/**
* Converts a <code>MultiPolygon</code> to <MultiPolygon Text> format,
* then appends it to the writer.
*
* @param multiPolygon the <code>MultiPolygon</code> to process
* @param writer the output writer to append to
*/
private void appendMultiPolygonText(MultiPolygon multiPolygon, int level, Writer writer)
throws IOException {
if (multiPolygon.isEmpty()) {
writer.write("EMPTY");
} else {
int level2 = level;
boolean doIndent = false;
writer.write("(");
for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
if (i > 0) {
writer.write(", ");
level2 = level + 1;
doIndent = true;
}
this.appendPolygonText((Polygon) multiPolygon.getGeometryN(i), level2, doIndent, writer);
}
writer.write(")");
}
}
示例6: calcul3DArea
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
public double calcul3DArea(IGeometry geom) throws Exception {
double area = -1;
if (geom instanceof GM_OrientableSurface || geom instanceof GM_MultiSurface<?>) {
// On la convertit en JTS
Geometry geomJTS = JtsGeOxygene.makeJtsGeom(geom);
if (geomJTS instanceof Polygon) {
// Polygon on applique tout de suite
area = area + this.calcul3DArea((Polygon) geomJTS);
} else
if (geomJTS instanceof MultiPolygon) {
// MultiPolygon on l'applique par morceaux
MultiPolygon multiP = (MultiPolygon) geomJTS;
int nGeom = multiP.getNumGeometries();
for (int j = 0; j < nGeom; j++) {
area = area + this.calcul3DArea((Polygon) multiP.getGeometryN(j));
}
} else {
// Type de géométrie non reconnue
logger.warn("Geomtrie non reconnue" + geomJTS.getClass().toString());
}
} else {
// Type de géométrie non reconnue
logger.warn("Geomtrie non reconnue" + geom.getClass().toString());
}
return area;
}
示例7: 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;
}
示例8: 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);
}
示例9: getExteriorRing
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
@Override
public GamaShape getExteriorRing(final IScope scope) {
// WARNING Only in 2D
Geometry result = getInnerGeometry();
if (result instanceof Polygon) {
result = ((Polygon) result).getExteriorRing();
} else
if (result instanceof MultiPolygon) {
final MultiPolygon mp = (MultiPolygon) result;
final LineString lines[] = new LineString[mp.getNumGeometries()];
for (int i = 0; i < mp.getNumGeometries(); i++) {
lines[i] = ((Polygon) mp.getGeometryN(i)).getExteriorRing();
}
result = GeometryUtils.GEOMETRY_FACTORY.createMultiLineString(lines);
}
return new GamaShape(result);
}
示例10: 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;
}
示例11: repair
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
/** */
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);
}
}
示例12: 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;
}
示例13: 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;
}
示例14: getHealthMapCountryGeometryMap
import com.vividsolutions.jts.geom.MultiPolygon; //导入方法依赖的package包/类
/**
* Gets a mapping between HealthMap country ID and the geometry of the associated GAUL countries.
* If the HealthMap country has no associated geometries, it does not appear in the map.
* @return A mapping as described above.
*/
public Map<Integer, MultiPolygon> getHealthMapCountryGeometryMap() {
if (healthMapCountryGeometryMap == null) {
// This will retrieve the countries from the Hibernate cache if already obtained by HealthMapLookupData
List<HealthMapCountry> countries = geometryService.getAllHealthMapCountries();
healthMapCountryGeometryMap = new HashMap<>();
for (HealthMapCountry country : countries) {
if (country.getCountries() != null) {
List<MultiPolygon> countryGeometries = extract(country.getCountries(), on(Country.class).getGeom());
MultiPolygon countryGeometry = GeometryUtils.concatenate(countryGeometries);
if (countryGeometry.getNumGeometries() > 0) {
healthMapCountryGeometryMap.put(country.getId(), countryGeometry);
}
}
}
}
return healthMapCountryGeometryMap;
}
示例15: 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));
}