org.locationtech.jts.geom.GeometryFactory.buildGeometry()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(353)

本文整理了Java中org.locationtech.jts.geom.GeometryFactory.buildGeometry()方法的一些代码示例,展示了GeometryFactory.buildGeometry()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GeometryFactory.buildGeometry()方法的具体详情如下:
包路径:org.locationtech.jts.geom.GeometryFactory
类名称:GeometryFactory
方法名:buildGeometry

GeometryFactory.buildGeometry介绍

[英]Build an appropriate Geometry, MultiGeometry, or GeometryCollection to contain the Geometrys in it. For example:

  • If geomList contains a single Polygon, the Polygon is returned.
  • If geomList contains several Polygons, a MultiPolygon is returned.
  • If geomList contains some Polygons and some LineStrings, a GeometryCollection is returned.
  • If geomList is empty, an empty GeometryCollection is returned
    Note that this method does not "flatten" Geometries in the input, and hence if any MultiGeometries are contained in the input a GeometryCollection containing them will be returned.
    [中]构建适当的GeometryMultiGeometryGeometryCollection以包含其中的Geometrys。例如:
    *如果geomList包含单个Polygon,则返回Polygon
    *如果geomList包含多个Polygon,则返回一个MultiPolygon
    *如果geomList包含一些Polygon和一些LineStrings,则返回一个GeometryCollection
    *如果geomList为空,则返回一个空GeometryCollection
    请注意,此方法不会“展平”输入中的几何图形,因此,如果输入中包含任何多重几何图形,将返回包含它们的GeometryCollection。

代码示例

代码示例来源:origin: geotools/geotools

public Geometry buildGeometry(Collection geomList) {
  return delegate.buildGeometry(geomList);
}

代码示例来源:origin: locationtech/spatial4j

/**
 * Attempts to retype a geometry collection under the following circumstances, returning
 * null if the collection can not be retyped.
 * <ul>
 *    <li>Single object collections are collapsed down to the object.</li>
 *    <li>Homogenous collections are recast as the appropriate subclass.</li>
 * </ul>
 *
 * @see GeometryFactory#buildGeometry(Collection)
 */
private Geometry narrowCollectionIfPossible(GeometryCollection gc) {
 List<Geometry> geoms = new ArrayList<>();
 for (int i = 0; i < gc.getNumGeometries(); i++) {
  geoms.add(gc.getGeometryN(i));
 }
 Geometry result = gc.getFactory().buildGeometry(geoms);
 return !result.getClass().equals(GeometryCollection.class) ? result : null;
}

代码示例来源:origin: locationtech/spatial4j

@Override
 public Shape build() {
  Class<?> last = null;
  List<Geometry> geoms = new ArrayList<>(shapes.size());
  for(Shape s : shapes) {
   if (last != null && last != s.getClass()) {
    return super.build();
   }
   if (s instanceof JtsGeometry) {
    geoms.add(((JtsGeometry)s).getGeom());
   } else if (s instanceof JtsPoint) {
    geoms.add(((JtsPoint)s).getGeom());
   } else {
    return super.build();
   }
   last = s.getClass();
  }
  return makeShapeFromGeometry(geometryFactory.buildGeometry(geoms));
 }
}

代码示例来源:origin: geotools/geotools

private Geometry decodeGeometryCollection(int shapeIndex) throws SqlServerBinaryParseException {
  Collection<Geometry> geometries = new ArrayList<Geometry>();
  for (int i = shapeIndex + 1; i < binary.getShapes().length; i++) {
    Shape subShape = binary.getShapes()[i];
    if (subShape.getParentOffset() == shapeIndex) {
      geometries.add(decode(i, subShape.getType()));
    }
  }
  return gf.buildGeometry(geometries);
}

代码示例来源:origin: geotools/geotools

private static final Geometry cloneGeometry(GeometryCollection geom, int dimension) {
  if (geom.getNumGeometries() == 0) {
    Geometry[] gs = new Geometry[0];
    return geomFac.createGeometryCollection(gs);
  }
  ArrayList gs = new ArrayList(geom.getNumGeometries());
  int n = geom.getNumGeometries();
  for (int t = 0; t < n; t++) {
    gs.add(cloneGeometry(geom.getGeometryN(t), dimension));
  }
  return geomFac.buildGeometry(gs);
}

代码示例来源:origin: locationtech/spatial4j

didUnwrap |= (geometryUnwrapped != geometryN);
return !didUnwrap ? geom : geom.getFactory().buildGeometry(list);

代码示例来源:origin: locationtech/spatial4j

pair.add(geometryFactory.toGeometry(new Envelope(
     ctx.getWorldBounds().getMinX(), r.getMaxX(), r.getMinY(), r.getMaxY())));
 return geometryFactory.buildGeometry(pair);//a MultiPolygon or MultiLineString
} else {
 return geometryFactory.toGeometry(new Envelope(r.getMinX(), r.getMaxX(), r.getMinY(), r.getMaxY()));

代码示例来源:origin: locationtech/jts

private Geometry bufferUnion(List geoms)
{
  GeometryFactory factory = ((Geometry) geoms.get(0)).getFactory();
  Geometry gColl = factory.buildGeometry(geoms);
  Geometry unionAll = gColl.buffer(0.0);
 return unionAll;
}

代码示例来源:origin: locationtech/jts

public Geometry combine(Geometry orig, Geometry geom)
{
 List origList = extractElements(orig, true);
 List geomList = extractElements(geom, true);
 origList.addAll(geomList);
 
 if (origList.size() == 0) {
  // return a clone of the orig geometry
  return (Geometry) orig.clone();
 }
 // return the "simplest possible" geometry
 return geomFactory.buildGeometry(origList);
}

代码示例来源:origin: locationtech/jts

public static Geometry extractLines(Geometry g)
{
 List lines = LinearComponentExtracter.getLines(g);
 return g.getFactory().buildGeometry(lines);
}
public static Geometry extractSegments(Geometry g)

代码示例来源:origin: locationtech/jts

public static Geometry valid(Geometry a)
{
 List selected = new ArrayList();
 for (int i = 0; i < a.getNumGeometries(); i++ ) {
  Geometry g = a.getGeometryN(i);
  if (g.isValid()) {
   selected.add(g);
  }
 }
 return a.getFactory().buildGeometry(selected);
}
public static Geometry invalid(Geometry a)

代码示例来源:origin: locationtech/jts

public static Geometry invalid(Geometry a)
{
 List selected = new ArrayList();
 for (int i = 0; i < a.getNumGeometries(); i++ ) {
  Geometry g = a.getGeometryN(i);
  if (! g.isValid()) {
   selected.add(g);
  }
 }
 return a.getFactory().buildGeometry(selected);
}
public static Geometry lengthGreaterThan(Geometry a, final double minLen)

代码示例来源:origin: locationtech/jts

protected Geometry transformMultiPoint(MultiPoint geom, Geometry parent) {
 List transGeomList = new ArrayList();
 for (int i = 0; i < geom.getNumGeometries(); i++) {
  Geometry transformGeom = transformPoint((Point) geom.getGeometryN(i), geom);
  if (transformGeom == null) continue;
  if (transformGeom.isEmpty()) continue;
  transGeomList.add(transformGeom);
 }
 return factory.buildGeometry(transGeomList);
}

代码示例来源:origin: locationtech/jts

private Object invokeRepeated(Geometry geom, Object[] args, double argStart) {
 List results = new ArrayList();
 int repeatArgIndex = repeatableArgIndex(fun);
 for (int i = 1; i <= count; i++) {
  double val = argStart * i;
  Geometry result = (Geometry) fun.invoke(geom, copyArgs(args, repeatArgIndex, val));
  if (result == null) continue;
  
  FunctionsUtil.showIndicator(result);
  results.add(result);
 }
 return geom.getFactory().buildGeometry(results);
}

代码示例来源:origin: locationtech/jts

Geometry loadData(String file) 
throws Exception 
{
 List geoms = loadWKT(file);
 return geomFact.buildGeometry(geoms);
}

代码示例来源:origin: locationtech/jts

public static Geometry toLines(Geometry g1, Geometry g2)
{
 Geometry geoms = FunctionsUtil.buildGeometry(g1, g2);
 return FunctionsUtil.getFactoryOrDefault(g1, g2)
   .buildGeometry(LinearComponentExtracter.getLines(geoms));
}

代码示例来源:origin: locationtech/jts

public static Geometry strTreeBounds(Geometry geoms)
{
 STRtree index = buildSTRtree(geoms);
 List bounds = new ArrayList();
 addBounds(index.getRoot(), bounds, geoms.getFactory());
 return geoms.getFactory().buildGeometry(bounds);
}

代码示例来源:origin: locationtech/jts

public static Geometry polygonizeDangles(Geometry g)
{
 List lines = LineStringExtracter.getLines(g);
 Polygonizer polygonizer = new Polygonizer();
 polygonizer.add(lines);
 Collection geom = polygonizer.getDangles();
 return g.getFactory().buildGeometry(geom);
}
public static Geometry polygonizeCutEdges(Geometry g)

代码示例来源:origin: locationtech/jts

public static Geometry polygonizeCutEdges(Geometry g)
{
 List lines = LineStringExtracter.getLines(g);
 Polygonizer polygonizer = new Polygonizer();
 polygonizer.add(lines);
 Collection geom = polygonizer.getCutEdges();
 return g.getFactory().buildGeometry(geom);
}
public static Geometry polygonizeInvalidRingLines(Geometry g)

代码示例来源:origin: locationtech/jts

private Geometry dissolveLines(Geometry lines) {
 Geometry dissolved = lines.union();
 LineMerger merger = new LineMerger();
 merger.add(dissolved);
 Collection mergedColl = merger.getMergedLineStrings();
 Geometry merged = lines.getFactory().buildGeometry(mergedColl);
 return merged;
}

相关文章