当前位置: 首页>>代码示例>>Java>>正文


Java MultiPolygon.getGeometryN方法代码示例

本文整理汇总了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());
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:34,代码来源:JTS.java

示例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;
            }
        }
    }
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:29,代码来源:IsValidOp.java

示例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;
}
 
开发者ID:orientechnologies,项目名称:orientdb-spatial,代码行数:17,代码来源:OMultiPolygonShapeBuilder.java

示例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);
}
 
开发者ID:rpax,项目名称:straightedge,代码行数:17,代码来源:FogOfWarTest.java

示例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;
}
 
开发者ID:ngageoint,项目名称:anti-piracy-android-app,代码行数:23,代码来源:OfflineMap.java

示例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;
}
 
开发者ID:ngageoint,项目名称:disconnected-content-explorer-android,代码行数:24,代码来源:OfflineMap.java

示例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;
}
 
开发者ID:SEEG-Oxford,项目名称:ABRAID-MP,代码行数:18,代码来源:GeoJsonMultiPolygonGeometry.java

示例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));
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:13,代码来源:JTSUtil.java

示例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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:ElasticsearchGeoAssertions.java

示例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();
}
 
开发者ID:Mappy,项目名称:fpm,代码行数:31,代码来源:CoastlineGenerator.java

示例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;
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:14,代码来源:GeometryJSON.java

示例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;
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:19,代码来源:Jts2Awt.java

示例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);
            }
        }
    }
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:31,代码来源:PointLocator.java

示例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);
    }
}
 
开发者ID:sevar83,项目名称:SpatiAtlas,代码行数:8,代码来源:MapFragment.java

示例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;
}
 
开发者ID:Seandebasti,项目名称:Flox,代码行数:18,代码来源:SVGExporter.java


注:本文中的com.vividsolutions.jts.geom.MultiPolygon.getGeometryN方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。