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


Java Polygonizer.getPolygons方法代码示例

本文整理汇总了Java中com.vividsolutions.jts.operation.polygonize.Polygonizer.getPolygons方法的典型用法代码示例。如果您正苦于以下问题:Java Polygonizer.getPolygons方法的具体用法?Java Polygonizer.getPolygons怎么用?Java Polygonizer.getPolygons使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.vividsolutions.jts.operation.polygonize.Polygonizer的用法示例。


在下文中一共展示了Polygonizer.getPolygons方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import com.vividsolutions.jts.operation.polygonize.Polygonizer; //导入方法依赖的package包/类
void run()
        throws Exception {
    WKTReader rdr = new WKTReader();
    Collection lines = new ArrayList();

    lines.add(rdr.read("LINESTRING (0 0 , 10 10)"));   // isolated edge
    lines.add(rdr.read("LINESTRING (185 221, 100 100)"));   //dangling edge
    lines.add(rdr.read("LINESTRING (185 221, 88 275, 180 316)"));
    lines.add(rdr.read("LINESTRING (185 221, 292 281, 180 316)"));
    lines.add(rdr.read("LINESTRING (189 98, 83 187, 185 221)"));
    lines.add(rdr.read("LINESTRING (189 98, 325 168, 185 221)"));

    Polygonizer polygonizer = new Polygonizer();
    polygonizer.add(lines);

    Collection polys = polygonizer.getPolygons();

    System.out.println("Polygons formed (" + polys.size() + "):");
    System.out.println(polys);
}
 
开发者ID:Semantive,项目名称:jts,代码行数:21,代码来源:PolygonizeExample.java

示例2: execute

import com.vividsolutions.jts.operation.polygonize.Polygonizer; //导入方法依赖的package包/类
public void execute(Scope scope)
  throws Exception
{
    Polygonizer polygonizer = new Polygonizer();
    int geomIndex = SchemaUtil.getColumnWithType(inputLines.getRows().getSchema(), Geometry.class);
    //TODO: handle no geometry case (return empty table)
    RowIterator i = inputLines.getRows().iterator();
    while (true) {
      Row row = i.next();
      if (row == null)
        break;
      Geometry g = (Geometry) row.getValue(geomIndex);
      polygonizer.add(g);
    }
    Collection polys = polygonizer.getPolygons();
    result = createGeometryTable(polys);
}
 
开发者ID:dr-jts,项目名称:jeql,代码行数:18,代码来源:PolygonizeCommand.java

示例3: splitPolygon

import com.vividsolutions.jts.operation.polygonize.Polygonizer; //导入方法依赖的package包/类
/**
 * {@link Polygon} by {@link LineString} split.
 * 
 * <p>From JTS ml: http://lists.refractions.net/pipermail/jts-devel/2008-September/002666.html</p> 
 * 
 * @param polygon the input polygon.
 * @param line the input line to use to split.
 * @return the list of split polygons.
 */
public static List<Polygon> splitPolygon( Polygon polygon, LineString line ) {
    /*
     * Use MCIndexNoder to node the polygon and linestring together, 
     * Polygonizer to polygonize the noded edges, and then PointLocater 
     * to determine which of the resultant polygons correspond to 
     * the input polygon. 
     */
    IntersectionAdder _intersector = new IntersectionAdder(new RobustLineIntersector());
    MCIndexNoder mci = new MCIndexNoder();
    mci.setSegmentIntersector(_intersector);
    NodedSegmentString pSeg = new NodedSegmentString(polygon.getCoordinates(), null);
    NodedSegmentString lSeg = new NodedSegmentString(line.getCoordinates(), null);
    List<NodedSegmentString> nodesSegmentStringList = new ArrayList<NodedSegmentString>();
    nodesSegmentStringList.add(pSeg);
    nodesSegmentStringList.add(lSeg);
    mci.computeNodes(nodesSegmentStringList);
    Polygonizer polygonizer = new Polygonizer();
    List<LineString> lsList = new ArrayList<LineString>();
    for( Object o : mci.getMonotoneChains() ) {
        MonotoneChain mtc = (MonotoneChain) o;
        LineString l = gf().createLineString(mtc.getCoordinates());
        lsList.add(l);
    }
    Geometry nodedLineStrings = lsList.get(0);
    for( int i = 1; i < lsList.size(); i++ ) {
        nodedLineStrings = nodedLineStrings.union(lsList.get(i));
    }
    polygonizer.add(nodedLineStrings);
    @SuppressWarnings("unchecked")
    Collection<Polygon> polygons = polygonizer.getPolygons();
    List<Polygon> newPolygons = new ArrayList<Polygon>();
    PointLocator pl = new PointLocator();
    for( Polygon p : polygons ) {
        if (pl.locate(p.getInteriorPoint().getCoordinate(), p) == Location.INTERIOR) {
            newPolygons.add(p);
        }
    }
    return newPolygons;
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:49,代码来源:GeometryUtilities.java

示例4: cutOnPoles

import com.vividsolutions.jts.operation.polygonize.Polygonizer; //导入方法依赖的package包/类
/**
 * Cut given polygon on poles (89 and -89)
 */
private static String cutOnPoles(String polygonWKT) throws Exception
{
   JtsSpatialContextFactory noCheckFactory = new JtsSpatialContextFactory();
   noCheckFactory.datelineRule = DatelineRule.none;
   noCheckFactory.validationRule = ValidationRule.none;
   JtsSpatialContext noCheckContext = noCheckFactory.newSpatialContext();
   JtsWKTReaderShapeParser noCheckParser =
         new JtsWKTReaderShapeParser(noCheckContext, noCheckFactory);

   JtsGeometry polygon = (JtsGeometry) noCheckParser.parse(polygonWKT);
   JtsGeometry northPole =
         (JtsGeometry) noCheckParser.parse("LINESTRING(180 89, 0 89, -180 89)");
   JtsGeometry southPole =
         (JtsGeometry) noCheckParser.parse("LINESTRING(180 -89, 0 -89, -180 -89)");

   LineMerger lm = new LineMerger();
   lm.add(polygon.getGeom());
   lm.add(northPole.getGeom());
   lm.add(southPole.getGeom());

   Geometry geometry = UnaryUnionOp.union(lm.getMergedLineStrings());

   Polygonizer polygonizer = new Polygonizer();
   polygonizer.add(geometry);

   List<Polygon> foundPolygons = (List<Polygon>) polygonizer.getPolygons();
   List<Polygon> filteredPolygons = new ArrayList<>();
   for (Polygon p: foundPolygons)
   {
      // removing polygons over the poles
      if (p.getCentroid().getCoordinate().y < 89 && p.getCentroid().getCoordinate().y > -89)
      {
         filteredPolygons.add(p);
      }
   }

   Geometry res = null;

   if (!filteredPolygons.isEmpty())
   {
      res = filteredPolygons.get(0);
   }
   if (filteredPolygons.size() > 1)
   {
      // Should not happen...
      LOGGER.error("A Multipolygon was found, instead of a single polygon. Only the first one is retained.");
   }

   WKTWriter wkw = new WKTWriter();
   return wkw.write(res);
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:55,代码来源:JTSFootprintParser.java

示例5: process

import com.vividsolutions.jts.operation.polygonize.Polygonizer; //导入方法依赖的package包/类
@Execute
public void process() throws Exception {
    checkNull(inMap);

    outMap = new DefaultFeatureCollection();

    EGeometryType geometryType = EGeometryType.forGeometryDescriptor(inMap.getSchema().getGeometryDescriptor());
    switch( geometryType ) {
    case LINE:
    case MULTILINE:
        break;
    default:
        throw new ModelsIllegalargumentException("The module only works with line layers.", this, pm);
    }

    List<Geometry> linesList = FeatureUtilities.featureCollectionToGeometriesList(inMap, true, null);

    // Polygonization
    final Polygonizer polygonizer = new Polygonizer();
    polygonizer.add(linesList);
    @SuppressWarnings("unchecked")
    final Collection<Polygon> polygonizedLines = polygonizer.getPolygons();

    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("polygonized");
    b.setCRS(inMap.getSchema().getCoordinateReferenceSystem());
    b.add("the_geom", Polygon.class);
    b.add(fNewId, String.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);

    List<Geometry> pointGeometries = new ArrayList<Geometry>();
    if (inPoints != null) {
        fId = FeatureUtilities.findAttributeName(inPoints.getSchema(), fId);
        pointGeometries = FeatureUtilities.featureCollectionToGeometriesList(inPoints, false, fId);
    }

    pm.beginTask("Generating polygon features...", polygonizedLines.size());
    int index = 0;
    for( Polygon polygon : polygonizedLines ) {
        String attribute = String.valueOf(index++);
        if (inPoints != null) {
            attribute = "-";
            for( Geometry point : pointGeometries ) {
                if (polygon.contains(point)) {
                    attribute = point.getUserData().toString();
                    break;
                }
            }
        }

        Object[] values = new Object[]{polygon, attribute};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(null);
        ((DefaultFeatureCollection) outMap).add(feature);

        pm.worked(1);
    }
    pm.done();
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:61,代码来源:OmsLinesPolygonizer.java


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